refactor: DiviTextSearch out of the replace-text ability (M2)

The SQL prefilter and the per-page hit computation move to DiviTextSearch;
DiviPageLoader::loadWritable serves DiviWriter::page and the dry run;
PostStatuses::NOT_CONTENT replaces the duplicated status list (same set,
order in the SQL list only). The private log() wrapper is inlined.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-26 18:26:10 +02:00
co-authored by Claude Opus 5.5
parent d2cc82f31b
commit afa19ffcd8
7 changed files with 185 additions and 117 deletions
+4 -5
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace LIT\MCP\Integrations\Media;
use Closure;
use LIT\MCP\Integrations\WordPress\PostStatuses;
use LIT\MCP\Log;
/**
@@ -59,8 +60,6 @@ class MediaUsageFinder
/** [gallery ids="…"] and Divi 4 gallery_ids="…" – quotes also JSON-escaped inside Divi 5 blocks. */
private const ID_LIST_PATTERN = '/(?:\[gallery\b[^\]]*?\bids|\bgallery_ids)=(?:"|\'|\\\\u0022)?([\d,\s]+)/i';
private const EXCLUDED_STATUSES = "'auto-draft', 'trash', 'inherit'";
/** Set by results() when a query of the current collect() run failed. */
private bool $queryFailed = false;
@@ -190,7 +189,7 @@ class MediaUsageFinder
/** @return list<object> */
private function featured(\wpdb $wpdb, int $attachmentId, int $limit): array
{
$statuses = self::EXCLUDED_STATUSES;
$statuses = PostStatuses::NOT_CONTENT;
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- only table names and a constant.
return $this->results($wpdb, $wpdb->prepare(
@@ -213,7 +212,7 @@ class MediaUsageFinder
}
$placeholders = implode(', ', array_fill(0, count($keys), '%s'));
$statuses = self::EXCLUDED_STATUSES;
$statuses = PostStatuses::NOT_CONTENT;
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- $placeholders holds one %s per key.
return $this->results($wpdb, $wpdb->prepare(
@@ -381,7 +380,7 @@ class MediaUsageFinder
}
$conditions = implode(' OR ', array_fill(0, count($likes), 'p.post_content LIKE %s'));
$statuses = self::EXCLUDED_STATUSES;
$statuses = PostStatuses::NOT_CONTENT;
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- only placeholders, table names, a constant.
return $this->results($wpdb, $wpdb->prepare(