diff --git a/source/php/LinkUpdater/LinkUpdater.php b/source/php/LinkUpdater/LinkUpdater.php index 3f96ec8..ea27fdc 100644 --- a/source/php/LinkUpdater/LinkUpdater.php +++ b/source/php/LinkUpdater/LinkUpdater.php @@ -101,6 +101,18 @@ private function isValidReplaceRequest(string $oldLink, string $newLink): bool private function replaceLinks(string $oldLink, string $newLink): int { $db = $this->database->getInstance(); + + //Get the post ids that contain the old link + $postIds = $db->get_col( + $db->prepare( + "SELECT ID + FROM $db->posts + WHERE post_content LIKE %s", + '%' . $db->esc_like($oldLink) . '%' + ) + ); + + //Update the post content $db->query( $db->prepare( "UPDATE $db->posts @@ -111,9 +123,26 @@ private function replaceLinks(string $oldLink, string $newLink): int '%' . $db->esc_like($oldLink) . '%' ) ); + + //Clear the object cache for the post ids + $this->clearObjectCache($postIds); + + //Return the number of rows affected return $db->rows_affected; } + /** + * Clear the object cache for the post ids + * + * @param array $postIds + */ + private function clearObjectCache(array $postIds): void + { + foreach ($postIds as $postId) { + $this->wpService->cleanPostCache($postId); + } + } + /** * Check if the post type should be replaced * @param string $postType