Changeset 3060628
- Timestamp:
- 03/28/2024 03:07:29 PM (2 years ago)
- Location:
- headless
- Files:
-
- 3 deleted
- 9 edited
- 64 copied
-
tags/2.2.2 (copied) (copied from headless/trunk)
-
tags/2.2.2/LICENSE (copied) (copied from headless/trunk/LICENSE)
-
tags/2.2.2/README.txt (copied) (copied from headless/trunk/README.txt) (2 diffs)
-
tags/2.2.2/classes (copied) (copied from headless/trunk/classes)
-
tags/2.2.2/classes/Ajax.php (copied) (copied from headless/trunk/classes/Ajax.php) (1 diff)
-
tags/2.2.2/classes/BlockPreparations/CoreEmbedBlockPreparation.php (copied) (copied from headless/trunk/classes/BlockPreparations/CoreEmbedBlockPreparation.php)
-
tags/2.2.2/classes/BlockPreparations/EmbedBlockPreparation.php (copied) (copied from headless/trunk/classes/BlockPreparations/EmbedBlockPreparation.php)
-
tags/2.2.2/classes/BlockPreparations/FreeFormBlockPreparation.php (copied) (copied from headless/trunk/classes/BlockPreparations/FreeFormBlockPreparation.php)
-
tags/2.2.2/classes/BlockPreparations/GalleryBlockPreparation.php (copied) (copied from headless/trunk/classes/BlockPreparations/GalleryBlockPreparation.php)
-
tags/2.2.2/classes/BlockPreparations/ImageBlockPreparation.php (copied) (copied from headless/trunk/classes/BlockPreparations/ImageBlockPreparation.php)
-
tags/2.2.2/classes/BlockPreparations/ParagraphBlockPreparation.php (copied) (copied from headless/trunk/classes/BlockPreparations/ParagraphBlockPreparation.php)
-
tags/2.2.2/classes/BlockPreparations/ReferenceBlockPreparation.php (copied) (copied from headless/trunk/classes/BlockPreparations/ReferenceBlockPreparation.php)
-
tags/2.2.2/classes/BlockPreparations/TagCloudPreparation.php (copied) (copied from headless/trunk/classes/BlockPreparations/TagCloudPreparation.php)
-
tags/2.2.2/classes/Components/Assets.php (copied) (copied from headless/trunk/classes/Components/Assets.php)
-
tags/2.2.2/classes/Components/Database.php (copied) (copied from headless/trunk/classes/Components/Database.php)
-
tags/2.2.2/classes/Dashboard.php (copied) (copied from headless/trunk/classes/Dashboard.php) (1 diff)
-
tags/2.2.2/classes/Extensions.php (copied) (copied from headless/trunk/classes/Extensions.php)
-
tags/2.2.2/classes/Extensions/CommentAuthorUser.php (copied) (copied from headless/trunk/classes/Extensions/CommentAuthorUser.php)
-
tags/2.2.2/classes/Extensions/ContentBlocks.php (copied) (copied from headless/trunk/classes/Extensions/ContentBlocks.php)
-
tags/2.2.2/classes/Extensions/FeaturedMedia.php (copied) (copied from headless/trunk/classes/Extensions/FeaturedMedia.php)
-
tags/2.2.2/classes/Extensions/Taxonomies.php (copied) (copied from headless/trunk/classes/Extensions/Taxonomies.php)
-
tags/2.2.2/classes/Headers.php (copied) (copied from headless/trunk/classes/Headers.php)
-
tags/2.2.2/classes/Headquarter.php (copied) (copied from headless/trunk/classes/Headquarter.php)
-
tags/2.2.2/classes/Interfaces/IBlockPreparation.php (copied) (copied from headless/trunk/classes/Interfaces/IBlockPreparation.php)
-
tags/2.2.2/classes/Interfaces/ICommentRouteExtension.php (copied) (copied from headless/trunk/classes/Interfaces/ICommentRouteExtension.php)
-
tags/2.2.2/classes/Interfaces/ITermRouteExtension.php (copied) (copied from headless/trunk/classes/Interfaces/ITermRouteExtension.php)
-
tags/2.2.2/classes/Interfaces/IUserRouteExtension.php (copied) (copied from headless/trunk/classes/Interfaces/IUserRouteExtension.php)
-
tags/2.2.2/classes/Links.php (deleted)
-
tags/2.2.2/classes/Log.php (copied) (copied from headless/trunk/classes/Log.php)
-
tags/2.2.2/classes/Migration.php (copied) (copied from headless/trunk/classes/Migration.php)
-
tags/2.2.2/classes/Model/CommentRouteExtensions.php (copied) (copied from headless/trunk/classes/Model/CommentRouteExtensions.php)
-
tags/2.2.2/classes/Model/Frontend.php (copied) (copied from headless/trunk/classes/Model/Frontend.php)
-
tags/2.2.2/classes/Model/TermRouteExtensions.php (copied) (copied from headless/trunk/classes/Model/TermRouteExtensions.php)
-
tags/2.2.2/classes/Model/UserRouteExtensions.php (copied) (copied from headless/trunk/classes/Model/UserRouteExtensions.php)
-
tags/2.2.2/classes/PluginAssets.php (copied) (copied from headless/trunk/classes/PluginAssets.php)
-
tags/2.2.2/classes/Post.php (copied) (copied from headless/trunk/classes/Post.php)
-
tags/2.2.2/classes/Preview.php (copied) (copied from headless/trunk/classes/Preview.php)
-
tags/2.2.2/classes/Query.php (copied) (copied from headless/trunk/classes/Query.php) (1 diff)
-
tags/2.2.2/classes/Revalidate.php (copied) (copied from headless/trunk/classes/Revalidate.php) (3 diffs)
-
tags/2.2.2/classes/Schedule.php (copied) (copied from headless/trunk/classes/Schedule.php) (2 diffs)
-
tags/2.2.2/classes/Security.php (copied) (copied from headless/trunk/classes/Security.php)
-
tags/2.2.2/classes/Store (copied) (copied from headless/trunk/classes/Store)
-
tags/2.2.2/classes/Store/RevalidationDatabase.php (copied) (copied from headless/trunk/classes/Store/RevalidationDatabase.php) (3 diffs)
-
tags/2.2.2/dist (copied) (copied from headless/trunk/dist)
-
tags/2.2.2/dist/admin.asset.php (copied) (copied from headless/trunk/dist/admin.asset.php)
-
tags/2.2.2/dist/admin.js (copied) (copied from headless/trunk/dist/admin.js)
-
tags/2.2.2/dist/admin.js.map (copied) (copied from headless/trunk/dist/admin.js.map)
-
tags/2.2.2/dist/gutenberg.asset.php (copied) (copied from headless/trunk/dist/gutenberg.asset.php)
-
tags/2.2.2/dist/gutenberg.css (copied) (copied from headless/trunk/dist/gutenberg.css)
-
tags/2.2.2/dist/gutenberg.css.map (copied) (copied from headless/trunk/dist/gutenberg.css.map)
-
tags/2.2.2/dist/gutenberg.js (copied) (copied from headless/trunk/dist/gutenberg.js)
-
tags/2.2.2/dist/gutenberg.js.map (copied) (copied from headless/trunk/dist/gutenberg.js.map)
-
tags/2.2.2/dist/gutenberg.ts.asset.php (deleted)
-
tags/2.2.2/dist/gutenberg.ts.js (deleted)
-
tags/2.2.2/headless.php (copied) (copied from headless/trunk/headless.php) (2 diffs)
-
tags/2.2.2/public-functions.php (copied) (copied from headless/trunk/public-functions.php)
-
tags/2.2.2/vendor (copied) (copied from headless/trunk/vendor)
-
tags/2.2.2/vendor/autoload.php (copied) (copied from headless/trunk/vendor/autoload.php)
-
tags/2.2.2/vendor/composer/ClassLoader.php (copied) (copied from headless/trunk/vendor/composer/ClassLoader.php)
-
tags/2.2.2/vendor/composer/InstalledVersions.php (copied) (copied from headless/trunk/vendor/composer/InstalledVersions.php)
-
tags/2.2.2/vendor/composer/autoload_classmap.php (copied) (copied from headless/trunk/vendor/composer/autoload_classmap.php)
-
tags/2.2.2/vendor/composer/autoload_namespaces.php (copied) (copied from headless/trunk/vendor/composer/autoload_namespaces.php)
-
tags/2.2.2/vendor/composer/autoload_psr4.php (copied) (copied from headless/trunk/vendor/composer/autoload_psr4.php)
-
tags/2.2.2/vendor/composer/autoload_real.php (copied) (copied from headless/trunk/vendor/composer/autoload_real.php)
-
tags/2.2.2/vendor/composer/autoload_static.php (copied) (copied from headless/trunk/vendor/composer/autoload_static.php)
-
tags/2.2.2/vendor/composer/installed.json (copied) (copied from headless/trunk/vendor/composer/installed.json)
-
tags/2.2.2/vendor/composer/installed.php (copied) (copied from headless/trunk/vendor/composer/installed.php) (2 diffs)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/classes/Ajax.php (modified) (1 diff)
-
trunk/classes/Dashboard.php (modified) (1 diff)
-
trunk/classes/Query.php (modified) (1 diff)
-
trunk/classes/Revalidate.php (modified) (3 diffs)
-
trunk/classes/Schedule.php (modified) (2 diffs)
-
trunk/classes/Store/RevalidationDatabase.php (modified) (3 diffs)
-
trunk/headless.php (modified) (2 diffs)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
headless/tags/2.2.2/README.txt
r3033669 r3060628 6 6 Tested up to: 6.4.3 7 7 Requires PHP: 8.0 8 Stable tag: 2.2. 08 Stable tag: 2.2.2 9 9 License: GPLv3 10 10 License URI: http://www.gnu.org/licenses/gpl … … 27 27 28 28 == Changelog == 29 30 = 2.2.2 = 31 * Feature: revalidate comments on schedule 32 * Bugfix: hl_post_type filter with any now working 33 29 34 30 35 = 2.2.0 = -
headless/tags/2.2.2/classes/Ajax.php
r3033669 r3060628 56 56 if(isset($_GET[self::GET_POST_ID]) && !empty($_GET[self::GET_POST_ID])){ 57 57 $postId = intval($_GET[self::GET_POST_ID]); 58 $result = $this->plugin->revalidate->revalidateByP ostId($frontends[$frontendIndex], $postId);58 $result = $this->plugin->revalidate->revalidateByPathByPostId($frontends[$frontendIndex], $postId); 59 59 if($result instanceof \WP_Error){ 60 60 wp_send_json_error($result); -
headless/tags/2.2.2/classes/Dashboard.php
r3033669 r3060628 39 39 40 40 <p>Pending posts to be revalidated: <?= $this->plugin->dbRevalidation->countPendingPosts(); ?></p> 41 <p>Pending comments to be revalidated: <?= $this->plugin->dbRevalidation->countPendingComments(); ?></p> 41 42 42 43 <button class="button button-secondary" id="headless-revalidate-pending">Revalidate pending</button> -
headless/tags/2.2.2/classes/Query.php
r2748985 r3060628 29 29 public static function getRequestPostTypes( \WP_REST_Request $request ) { 30 30 $post_types = $request->get_param( static::POST_TYPE ); 31 if(in_array("any",$post_types)){ 32 return ["any"]; 33 } 31 34 if ( empty( $post_types ) ) { 32 35 return []; -
headless/tags/2.2.2/classes/Revalidate.php
r2901812 r3060628 10 10 public function onCreate() { 11 11 parent::onCreate(); 12 add_action('save_post', [$this, 'save_post']); 13 add_action('edit_comment', [$this, 'edit_comment']); 12 add_action('save_post', [$this, 'on_post_change']); 13 add_action('edit_comment', [$this, 'on_comment_change']); 14 add_action('wp_insert_comment', [$this, 'on_comment_change']); 14 15 } 15 16 16 public function save_post($post_id){17 public function on_post_change($post_id){ 17 18 if(wp_is_post_revision($post_id)) return; 18 19 $this->plugin->dbRevalidation->addPost($post_id); 19 20 } 20 21 21 public function edit_comment($comment_id){22 public function on_comment_change($comment_id){ 22 23 $comment = get_comment($comment_id); 23 24 $this->plugin->dbRevalidation->addPost($comment->comment_post_ID); 25 $this->plugin->dbRevalidation->addComment($comment_id); 26 } 27 28 function revalidateComments($post_id){ 29 $frontends = $this->plugin->headquarter->getFrontends(); 30 $results = []; 31 foreach ($frontends as $frontend){ 32 $results[] = $this->revalidateByTag( 33 $frontend, 34 apply_filters(Plugin::FILTER_REVALIDATE_COMMENTS_BY_TAG, "post-$post_id-comments") 35 ); 36 } 37 return $results; 24 38 } 25 39 … … 33 47 $results = []; 34 48 foreach ($frontends as $frontend){ 35 $results[] = $this->revalidateByPostId($frontend, $post_id); 49 $results[] = $this->revalidateByTag($frontend, "post-$post_id"); 50 $results[] = $this->revalidateByPathByPostId($frontend, $post_id); 36 51 } 37 52 return $results; 38 53 } 39 54 40 function revalidateByP ostId(Frontend $frontend, $post_id) {55 function revalidateByPathByPostId(Frontend $frontend, $post_id) { 41 56 $permalink = get_permalink($post_id); 42 57 $path = parse_url($permalink, PHP_URL_PATH); … … 52 67 return $this->executeRavalidation( 53 68 apply_filters(Plugin::FILTER_REVALIDATE_BY_PATH_URL, $url, $path, $frontend) 69 ); 70 } 71 72 function revalidateByTag(Frontend $frontend, string $tag) { 73 $baseUrl = $frontend->getBaseUrl(); 74 $url = untrailingslashit($baseUrl)."/api/revalidate?secret_token=".HEADLESS_SECRET_TOKEN."&tag=".urlencode($tag); 75 return $this->executeRavalidation( 76 apply_filters(Plugin::FILTER_REVALIDATE_BY_TAG_URL, $url, $tag, $frontend) 54 77 ); 55 78 } -
headless/tags/2.2.2/classes/Schedule.php
r2901812 r3060628 36 36 $now = time(); 37 37 38 $commentIds = $this->plugin->dbRevalidation->getPendingComments(); 39 foreach ($commentIds as $id){ 40 $comment = get_comment($id); 41 $postId = $comment->comment_post_ID; 42 $results = $this->plugin->revalidate->revalidateComments($postId); 43 44 $success = true; 45 foreach ($results as $result){ 46 if($result instanceof \WP_Error){ 47 $this->plugin->log->warning($result->get_error_message()); 48 $title = get_the_title($id); 49 $this->plugin->log->warning("revalidate comment id: $id ; post: $postId $title"); 50 $success = false; 51 } 52 } 53 54 if($success){ 55 $this->plugin->dbRevalidation->setCommentState($id); 56 } else { 57 $this->plugin->dbRevalidation->setCommentState($id, "error"); 58 } 59 } 60 38 61 $postIds = $this->plugin->dbRevalidation->getPendingPosts(); 39 62 … … 61 84 } 62 85 86 87 88 63 89 // do stuff like revalidating landingpages 64 90 do_action(Plugin::ACTION_REVALIDATION_SIDE_EFFECT, $postIds); 91 92 65 93 66 94 $this->setLastRevalidationRun($now); -
headless/tags/2.2.2/classes/Store/RevalidationDatabase.php
r2977228 r3060628 12 12 class RevalidationDatabase extends Database { 13 13 14 const TYPE_POST = "post"; 15 const TYPE_COMMENT = "comment"; 16 14 17 function init() { 15 18 $this->table = $this->wpdb->prefix . "headless_revalidate"; 16 19 } 17 20 18 /** 19 * @param int $post_id 20 * @return bool|int 21 */ 22 public function addPost( $post_id ) { 21 private function addContent(string $id, string $type) { 23 22 return $this->wpdb->replace( 24 23 $this->table, 25 24 [ 26 "content_id" => $post_id,27 "content_type" => "post",25 "content_id" => $id, 26 "content_type" => $type, 28 27 "revalidated_at" => null, 29 28 "revalidation_state" => "pending", … … 32 31 } 33 32 33 public function addPost(int $post_id) { 34 return $this->addContent($post_id, self::TYPE_POST); 35 } 36 37 public function addComment(string $comment_id) { 38 return $this->addContent($comment_id, self::TYPE_COMMENT); 39 } 40 41 34 42 /** 35 * @param int $after 43 * @return Int[] 44 */ 45 private function getPendingContents(string $type): array { 46 $sql = $this->wpdb->prepare( 47 "SELECT content_id FROM $this->table WHERE content_type = '%s' AND revalidation_state = 'pending'", 48 $type 49 ); 50 return $this->wpdb->get_col($sql); 51 } 52 53 /** 36 54 * 37 55 * @return Int[] 38 56 */ 39 public function getPendingPosts() { 40 $sql = "SELECT content_id FROM $this->table WHERE content_type = 'post' AND revalidation_state = 'pending'"; 41 return $this->wpdb->get_col( $sql); 57 public function getPendingPosts(): array { 58 return $this->getPendingContents(self::TYPE_POST); 42 59 } 43 60 44 /** 45 * @param int $after 46 * 47 * @return int 48 */ 49 public function countPendingPosts(): int{ 50 $sql = "SELECT count(content_id) FROM $this->table WHERE content_type = 'post' AND revalidation_state = 'pending'"; 61 public function getPendingComments(): array { 62 return $this->getPendingContents(self::TYPE_COMMENT); 63 } 64 65 66 private function countPendingContents(string $type): int { 67 $sql = $this->wpdb->prepare( 68 "SELECT count(content_id) FROM $this->table WHERE content_type = '%s' AND revalidation_state = 'pending'", 69 $type 70 ); 51 71 return intval($this->wpdb->get_var($sql)); 52 72 } 53 73 54 public function setPostState(int $post_id, $state = "revalidated") { 74 public function countPendingPosts(): int { 75 return $this->countPendingContents(self::TYPE_POST); 76 } 77 78 public function countPendingComments(): int { 79 return $this->countPendingContents(self::TYPE_COMMENT); 80 } 81 82 public function setContentState(int $id, string $type, $state = "revalidated") { 55 83 return $this->wpdb->update( 56 84 $this->table, 57 85 [ 58 "revalidated_at" => current_time( 'mysql'),86 "revalidated_at" => current_time('mysql'), 59 87 "revalidation_state" => $state, 60 88 ], 61 89 [ 62 "content_id" => $ post_id,63 "content_type" => "post",90 "content_id" => $id, 91 "content_type" => $type, 64 92 ], 65 93 ["%s", "%s"], … … 68 96 } 69 97 98 public function setPostState(int $post_id, $state = "revalidated") { 99 return $this->setContentState($post_id, self::TYPE_POST, $state); 100 } 101 102 public function setCommentState(int $comment_id, $state = "revalidated") { 103 return $this->setContentState($comment_id, self::TYPE_COMMENT, $state); 104 } 105 70 106 public function createTables() { 71 107 parent::createTables(); 72 \dbDelta( "CREATE TABLE IF NOT EXISTS $this->table108 \dbDelta("CREATE TABLE IF NOT EXISTS $this->table 73 109 ( 74 110 id bigint(20) unsigned auto_increment, -
headless/tags/2.2.2/headless.php
r3033669 r3060628 5 5 * Plugin URI: https://github.com/palasthotel/headless 6 6 * Description: Adds features to use WordPress as headless CMS 7 * Version: 2.2. 07 * Version: 2.2.2 8 8 * Author: Palasthotel (Edward Bock) <edward.bock@palasthotel.de> 9 9 * Author URI: http://www.palasthotel.de … … 94 94 const FILTER_FRONTENDS = "headless_frontends"; 95 95 const FILTER_REVALIDATE_BY_PATH_URL = "headless_revalidate_by_path_url"; 96 const FILTER_REVALIDATE_BY_TAG_URL = "headless_revalidate_by_tag_url"; 97 const FILTER_REVALIDATE_COMMENTS_BY_TAG = "headless_revalidate_comments_by_tag"; 96 98 const FILTER_REVALIDATE_PERMALINK_PATH = "headless_revalidate_permalink_path"; 97 99 const OPTION_LAST_REVALIDATION_RUN = "headless_last_revalidation_run"; -
headless/tags/2.2.2/vendor/composer/installed.php
r3033669 r3060628 4 4 'pretty_version' => 'dev-main', 5 5 'version' => 'dev-main', 6 'reference' => ' dbd1b93a4b371dbbe1368ba0301bf88e86cb9723',6 'reference' => '1c6b6a45575b82a64578c37f33ec77db281733fc', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-main', 15 15 'version' => 'dev-main', 16 'reference' => ' dbd1b93a4b371dbbe1368ba0301bf88e86cb9723',16 'reference' => '1c6b6a45575b82a64578c37f33ec77db281733fc', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../', -
headless/trunk/README.txt
r3033669 r3060628 6 6 Tested up to: 6.4.3 7 7 Requires PHP: 8.0 8 Stable tag: 2.2. 08 Stable tag: 2.2.2 9 9 License: GPLv3 10 10 License URI: http://www.gnu.org/licenses/gpl … … 27 27 28 28 == Changelog == 29 30 = 2.2.2 = 31 * Feature: revalidate comments on schedule 32 * Bugfix: hl_post_type filter with any now working 33 29 34 30 35 = 2.2.0 = -
headless/trunk/classes/Ajax.php
r3033669 r3060628 56 56 if(isset($_GET[self::GET_POST_ID]) && !empty($_GET[self::GET_POST_ID])){ 57 57 $postId = intval($_GET[self::GET_POST_ID]); 58 $result = $this->plugin->revalidate->revalidateByP ostId($frontends[$frontendIndex], $postId);58 $result = $this->plugin->revalidate->revalidateByPathByPostId($frontends[$frontendIndex], $postId); 59 59 if($result instanceof \WP_Error){ 60 60 wp_send_json_error($result); -
headless/trunk/classes/Dashboard.php
r3033669 r3060628 39 39 40 40 <p>Pending posts to be revalidated: <?= $this->plugin->dbRevalidation->countPendingPosts(); ?></p> 41 <p>Pending comments to be revalidated: <?= $this->plugin->dbRevalidation->countPendingComments(); ?></p> 41 42 42 43 <button class="button button-secondary" id="headless-revalidate-pending">Revalidate pending</button> -
headless/trunk/classes/Query.php
r2748985 r3060628 29 29 public static function getRequestPostTypes( \WP_REST_Request $request ) { 30 30 $post_types = $request->get_param( static::POST_TYPE ); 31 if(in_array("any",$post_types)){ 32 return ["any"]; 33 } 31 34 if ( empty( $post_types ) ) { 32 35 return []; -
headless/trunk/classes/Revalidate.php
r2901812 r3060628 10 10 public function onCreate() { 11 11 parent::onCreate(); 12 add_action('save_post', [$this, 'save_post']); 13 add_action('edit_comment', [$this, 'edit_comment']); 12 add_action('save_post', [$this, 'on_post_change']); 13 add_action('edit_comment', [$this, 'on_comment_change']); 14 add_action('wp_insert_comment', [$this, 'on_comment_change']); 14 15 } 15 16 16 public function save_post($post_id){17 public function on_post_change($post_id){ 17 18 if(wp_is_post_revision($post_id)) return; 18 19 $this->plugin->dbRevalidation->addPost($post_id); 19 20 } 20 21 21 public function edit_comment($comment_id){22 public function on_comment_change($comment_id){ 22 23 $comment = get_comment($comment_id); 23 24 $this->plugin->dbRevalidation->addPost($comment->comment_post_ID); 25 $this->plugin->dbRevalidation->addComment($comment_id); 26 } 27 28 function revalidateComments($post_id){ 29 $frontends = $this->plugin->headquarter->getFrontends(); 30 $results = []; 31 foreach ($frontends as $frontend){ 32 $results[] = $this->revalidateByTag( 33 $frontend, 34 apply_filters(Plugin::FILTER_REVALIDATE_COMMENTS_BY_TAG, "post-$post_id-comments") 35 ); 36 } 37 return $results; 24 38 } 25 39 … … 33 47 $results = []; 34 48 foreach ($frontends as $frontend){ 35 $results[] = $this->revalidateByPostId($frontend, $post_id); 49 $results[] = $this->revalidateByTag($frontend, "post-$post_id"); 50 $results[] = $this->revalidateByPathByPostId($frontend, $post_id); 36 51 } 37 52 return $results; 38 53 } 39 54 40 function revalidateByP ostId(Frontend $frontend, $post_id) {55 function revalidateByPathByPostId(Frontend $frontend, $post_id) { 41 56 $permalink = get_permalink($post_id); 42 57 $path = parse_url($permalink, PHP_URL_PATH); … … 52 67 return $this->executeRavalidation( 53 68 apply_filters(Plugin::FILTER_REVALIDATE_BY_PATH_URL, $url, $path, $frontend) 69 ); 70 } 71 72 function revalidateByTag(Frontend $frontend, string $tag) { 73 $baseUrl = $frontend->getBaseUrl(); 74 $url = untrailingslashit($baseUrl)."/api/revalidate?secret_token=".HEADLESS_SECRET_TOKEN."&tag=".urlencode($tag); 75 return $this->executeRavalidation( 76 apply_filters(Plugin::FILTER_REVALIDATE_BY_TAG_URL, $url, $tag, $frontend) 54 77 ); 55 78 } -
headless/trunk/classes/Schedule.php
r2901812 r3060628 36 36 $now = time(); 37 37 38 $commentIds = $this->plugin->dbRevalidation->getPendingComments(); 39 foreach ($commentIds as $id){ 40 $comment = get_comment($id); 41 $postId = $comment->comment_post_ID; 42 $results = $this->plugin->revalidate->revalidateComments($postId); 43 44 $success = true; 45 foreach ($results as $result){ 46 if($result instanceof \WP_Error){ 47 $this->plugin->log->warning($result->get_error_message()); 48 $title = get_the_title($id); 49 $this->plugin->log->warning("revalidate comment id: $id ; post: $postId $title"); 50 $success = false; 51 } 52 } 53 54 if($success){ 55 $this->plugin->dbRevalidation->setCommentState($id); 56 } else { 57 $this->plugin->dbRevalidation->setCommentState($id, "error"); 58 } 59 } 60 38 61 $postIds = $this->plugin->dbRevalidation->getPendingPosts(); 39 62 … … 61 84 } 62 85 86 87 88 63 89 // do stuff like revalidating landingpages 64 90 do_action(Plugin::ACTION_REVALIDATION_SIDE_EFFECT, $postIds); 91 92 65 93 66 94 $this->setLastRevalidationRun($now); -
headless/trunk/classes/Store/RevalidationDatabase.php
r2977228 r3060628 12 12 class RevalidationDatabase extends Database { 13 13 14 const TYPE_POST = "post"; 15 const TYPE_COMMENT = "comment"; 16 14 17 function init() { 15 18 $this->table = $this->wpdb->prefix . "headless_revalidate"; 16 19 } 17 20 18 /** 19 * @param int $post_id 20 * @return bool|int 21 */ 22 public function addPost( $post_id ) { 21 private function addContent(string $id, string $type) { 23 22 return $this->wpdb->replace( 24 23 $this->table, 25 24 [ 26 "content_id" => $post_id,27 "content_type" => "post",25 "content_id" => $id, 26 "content_type" => $type, 28 27 "revalidated_at" => null, 29 28 "revalidation_state" => "pending", … … 32 31 } 33 32 33 public function addPost(int $post_id) { 34 return $this->addContent($post_id, self::TYPE_POST); 35 } 36 37 public function addComment(string $comment_id) { 38 return $this->addContent($comment_id, self::TYPE_COMMENT); 39 } 40 41 34 42 /** 35 * @param int $after 43 * @return Int[] 44 */ 45 private function getPendingContents(string $type): array { 46 $sql = $this->wpdb->prepare( 47 "SELECT content_id FROM $this->table WHERE content_type = '%s' AND revalidation_state = 'pending'", 48 $type 49 ); 50 return $this->wpdb->get_col($sql); 51 } 52 53 /** 36 54 * 37 55 * @return Int[] 38 56 */ 39 public function getPendingPosts() { 40 $sql = "SELECT content_id FROM $this->table WHERE content_type = 'post' AND revalidation_state = 'pending'"; 41 return $this->wpdb->get_col( $sql); 57 public function getPendingPosts(): array { 58 return $this->getPendingContents(self::TYPE_POST); 42 59 } 43 60 44 /** 45 * @param int $after 46 * 47 * @return int 48 */ 49 public function countPendingPosts(): int{ 50 $sql = "SELECT count(content_id) FROM $this->table WHERE content_type = 'post' AND revalidation_state = 'pending'"; 61 public function getPendingComments(): array { 62 return $this->getPendingContents(self::TYPE_COMMENT); 63 } 64 65 66 private function countPendingContents(string $type): int { 67 $sql = $this->wpdb->prepare( 68 "SELECT count(content_id) FROM $this->table WHERE content_type = '%s' AND revalidation_state = 'pending'", 69 $type 70 ); 51 71 return intval($this->wpdb->get_var($sql)); 52 72 } 53 73 54 public function setPostState(int $post_id, $state = "revalidated") { 74 public function countPendingPosts(): int { 75 return $this->countPendingContents(self::TYPE_POST); 76 } 77 78 public function countPendingComments(): int { 79 return $this->countPendingContents(self::TYPE_COMMENT); 80 } 81 82 public function setContentState(int $id, string $type, $state = "revalidated") { 55 83 return $this->wpdb->update( 56 84 $this->table, 57 85 [ 58 "revalidated_at" => current_time( 'mysql'),86 "revalidated_at" => current_time('mysql'), 59 87 "revalidation_state" => $state, 60 88 ], 61 89 [ 62 "content_id" => $ post_id,63 "content_type" => "post",90 "content_id" => $id, 91 "content_type" => $type, 64 92 ], 65 93 ["%s", "%s"], … … 68 96 } 69 97 98 public function setPostState(int $post_id, $state = "revalidated") { 99 return $this->setContentState($post_id, self::TYPE_POST, $state); 100 } 101 102 public function setCommentState(int $comment_id, $state = "revalidated") { 103 return $this->setContentState($comment_id, self::TYPE_COMMENT, $state); 104 } 105 70 106 public function createTables() { 71 107 parent::createTables(); 72 \dbDelta( "CREATE TABLE IF NOT EXISTS $this->table108 \dbDelta("CREATE TABLE IF NOT EXISTS $this->table 73 109 ( 74 110 id bigint(20) unsigned auto_increment, -
headless/trunk/headless.php
r3033669 r3060628 5 5 * Plugin URI: https://github.com/palasthotel/headless 6 6 * Description: Adds features to use WordPress as headless CMS 7 * Version: 2.2. 07 * Version: 2.2.2 8 8 * Author: Palasthotel (Edward Bock) <edward.bock@palasthotel.de> 9 9 * Author URI: http://www.palasthotel.de … … 94 94 const FILTER_FRONTENDS = "headless_frontends"; 95 95 const FILTER_REVALIDATE_BY_PATH_URL = "headless_revalidate_by_path_url"; 96 const FILTER_REVALIDATE_BY_TAG_URL = "headless_revalidate_by_tag_url"; 97 const FILTER_REVALIDATE_COMMENTS_BY_TAG = "headless_revalidate_comments_by_tag"; 96 98 const FILTER_REVALIDATE_PERMALINK_PATH = "headless_revalidate_permalink_path"; 97 99 const OPTION_LAST_REVALIDATION_RUN = "headless_last_revalidation_run"; -
headless/trunk/vendor/composer/installed.php
r3033669 r3060628 4 4 'pretty_version' => 'dev-main', 5 5 'version' => 'dev-main', 6 'reference' => ' dbd1b93a4b371dbbe1368ba0301bf88e86cb9723',6 'reference' => '1c6b6a45575b82a64578c37f33ec77db281733fc', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-main', 15 15 'version' => 'dev-main', 16 'reference' => ' dbd1b93a4b371dbbe1368ba0301bf88e86cb9723',16 'reference' => '1c6b6a45575b82a64578c37f33ec77db281733fc', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.