Every file under src/ exits outside WordPress (defined('ABSPATH') ||
exit; after the use block, so a direct request no longer prints a fatal
error with the server path); divi-convert-fixture.php gets the WP_CLI
guard the other integration scripts have. A unit test keeps both true;
PSR1 side-effects warning excluded for the guard.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
80 lines
2.3 KiB
PHP
80 lines
2.3 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace LIT\MCP\Integrations\Divi\Pages;
|
||
|
||
use LIT\MCP\Abilities\Annotations;
|
||
use LIT\MCP\Abilities\Errors;
|
||
use WP_Error;
|
||
|
||
defined('ABSPATH') || exit;
|
||
|
||
/**
|
||
* lit/divi-move: moves a node (with everything inside) to parent / before / after – also into
|
||
* another row or section, as long as the structure rules allow it (spec §5.7). Read-only
|
||
* nodes (global modules, foreign blocks) move as a whole, unchanged.
|
||
*/
|
||
final class DiviMoveAbility extends DiviWriteAbility
|
||
{
|
||
public function name(): string
|
||
{
|
||
return 'lit/divi-move';
|
||
}
|
||
|
||
public function label(): string
|
||
{
|
||
return 'Divi-Knoten verschieben';
|
||
}
|
||
|
||
public function description(): string
|
||
{
|
||
return 'Verschiebt einen Divi-Knoten samt Inhalt an eine neue Stelle (parent, before oder after; auch in '
|
||
. 'andere Zeilen oder Abschnitte). tree_rev aus lit-divi-outline ist Pflicht.';
|
||
}
|
||
|
||
public function inputSchema(): array
|
||
{
|
||
return [
|
||
'type' => 'object',
|
||
'properties' => array_merge(
|
||
DiviSchema::write(),
|
||
['id' => ['type' => 'string', 'description' => 'Pfad-ID des zu verschiebenden Knotens.']],
|
||
DiviSchema::position()
|
||
),
|
||
'required' => ['post_id', 'tree_rev', 'id'],
|
||
'additionalProperties' => false,
|
||
];
|
||
}
|
||
|
||
public function annotations(): array
|
||
{
|
||
return Annotations::write(false);
|
||
}
|
||
|
||
protected function change(DiviPage $page, array $input, DiviComposition $composition): DiviChange|WP_Error
|
||
{
|
||
$id = is_string($input['id'] ?? null) ? $input['id'] : '';
|
||
$node = $page->index->find($id);
|
||
if ($node === null) {
|
||
return DiviErrors::unknownNode($id, $page->post);
|
||
}
|
||
|
||
$editor = $composition->editor();
|
||
$position = $editor->position($page->index, $input);
|
||
if (is_string($position)) {
|
||
return DiviErrors::position($position);
|
||
}
|
||
|
||
$problem = $editor->move($page->index, $node, $position);
|
||
if ($problem !== null) {
|
||
return Errors::invalidInput(
|
||
'Verschieben nicht möglich; nichts wurde gespeichert.',
|
||
['position' => $problem]
|
||
);
|
||
}
|
||
|
||
return (new DiviChange(sprintf('Knoten %s verschoben', $id)))->record($node, 'moved');
|
||
}
|
||
}
|