refactor: ChangeLog::recordPartial and column-size truncation
recordPartial() replaces the partial-log FollowUp blocks in content-create, content-update and post-replace-with-copy; record() truncates ability, object_type and object_id to their column sizes. 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:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\ChangeLog;
|
||||
|
||||
use LIT\MCP\Abilities\FollowUp;
|
||||
use LIT\MCP\Server\RequestContext;
|
||||
|
||||
/**
|
||||
@@ -44,9 +45,9 @@ class ChangeLog
|
||||
'created_at' => current_time('mysql', true),
|
||||
'user_id' => get_current_user_id(),
|
||||
'client' => $this->sanitizedClientName(),
|
||||
'ability' => $ability,
|
||||
'object_type' => $objectType,
|
||||
'object_id' => $objectId,
|
||||
'ability' => mb_substr($ability, 0, 100),
|
||||
'object_type' => mb_substr($objectType, 0, 50),
|
||||
'object_id' => mb_substr($objectId, 0, 191),
|
||||
'summary' => mb_substr($summary, 0, 500),
|
||||
'revision_id' => $revisionId,
|
||||
'snapshot_id' => $snapshotId,
|
||||
@@ -64,6 +65,27 @@ class ChangeLog
|
||||
return (int) $wpdb->insert_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a write that failed and could not be rolled back completely (result "partial").
|
||||
* Never throws: the caller is already reporting an error, a log failure only goes to
|
||||
* the PHP error log.
|
||||
*/
|
||||
public function recordPartial(
|
||||
string $ability,
|
||||
string $objectType,
|
||||
string $objectId,
|
||||
string $summary,
|
||||
?int $revisionId = null
|
||||
): void {
|
||||
$ignored = [];
|
||||
FollowUp::run(
|
||||
fn () => $this->record($ability, $objectType, $objectId, $summary, $revisionId, null, 'partial'),
|
||||
$ability . ' change log',
|
||||
'',
|
||||
$ignored
|
||||
);
|
||||
}
|
||||
|
||||
public function purgeOlderThan(int $days): int
|
||||
{
|
||||
$wpdb = $this->db();
|
||||
|
||||
Reference in New Issue
Block a user