feat: lit/divi-move, lit/divi-delete, lit/divi-duplicate-node
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:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Divi\Pages;
|
||||
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Abilities\ToolResult;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\AttrMap;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\NodeSummary;
|
||||
use WP_Error;
|
||||
|
||||
/**
|
||||
* lit/divi-duplicate-node: copies a node with everything inside right behind the original
|
||||
* (spec §5.7). The copy's admin label gets " (Kopie)"; read-only nodes (global modules,
|
||||
* foreign blocks) are copied unchanged, as a whole, byte-identical reference.
|
||||
*/
|
||||
final class DiviDuplicateNodeAbility implements Ability
|
||||
{
|
||||
public function __construct(private DiviWriter $writer)
|
||||
{
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'lit/divi-duplicate-node';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Divi-Knoten duplizieren';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Dupliziert einen Divi-Knoten samt Inhalt direkt hinter das Original; das Admin-Label der Kopie endet '
|
||||
. 'auf „(Kopie)“. tree_rev aus lit-divi-outline ist Pflicht.';
|
||||
}
|
||||
|
||||
public function inputSchema(): array
|
||||
{
|
||||
return [
|
||||
'type' => 'object',
|
||||
'properties' => array_merge(DiviWriter::inputProperties(), [
|
||||
'id' => ['type' => 'string', 'description' => 'Pfad-ID des zu duplizierenden Knotens.'],
|
||||
]),
|
||||
'required' => ['post_id', 'tree_rev', 'id'],
|
||||
'additionalProperties' => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function outputSchema(): ?array
|
||||
{
|
||||
return ToolResult::schema(['tree_rev' => ['type' => 'string']], ['tree_rev']);
|
||||
}
|
||||
|
||||
public function annotations(): array
|
||||
{
|
||||
return ['readonly' => false, 'destructive' => false, 'idempotent' => false];
|
||||
}
|
||||
|
||||
public function isDirect(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function permission(array $input): bool|WP_Error
|
||||
{
|
||||
$page = $this->writer->page($input);
|
||||
|
||||
return $page instanceof WP_Error ? $page : true;
|
||||
}
|
||||
|
||||
public function execute(array $input): mixed
|
||||
{
|
||||
$page = $this->writer->page($input);
|
||||
if ($page instanceof WP_Error) {
|
||||
return $page;
|
||||
}
|
||||
|
||||
$id = is_string($input['id'] ?? null) ? $input['id'] : '';
|
||||
$node = $page->index->find($id);
|
||||
if ($node === null) {
|
||||
return DiviPageLoader::unknownNode($id, $page->post);
|
||||
}
|
||||
|
||||
$copy = $this->writer->composition($page)->editor()->duplicate($page->index, $node);
|
||||
if ($copy->isDivi() && ! $copy->isOpaque()) {
|
||||
$label = NodeSummary::label($node);
|
||||
$copy->setAttrs(AttrMap::set($copy->attrs(), 'module.meta.adminLabel', [
|
||||
'desktop' => ['value' => ($label === '' ? $node->shortName() : $label) . ' (Kopie)'],
|
||||
]));
|
||||
}
|
||||
|
||||
$change = (new DiviChange(sprintf('Knoten %s dupliziert', $id)))->changed($copy, 'duplicated');
|
||||
|
||||
return $this->writer->save($this->name(), $page, $change, $input);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user