| 1 |
<?php |
| 2 |
/** |
| 3 |
* Get import status ability. |
| 4 |
* |
| 5 |
* @package ThinkRank\Abilities\Import |
| 6 |
*/ |
| 7 |
|
| 8 |
declare(strict_types=1); |
| 9 |
|
| 10 |
namespace ThinkRank\Abilities\Import; |
| 11 |
|
| 12 |
use ThinkRank\Abilities\Ability_Base; |
| 13 |
use ThinkRank\Admin\Importers\Snapshot_Store; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Reports the status of captured SEO import snapshots. |
| 21 |
* |
| 22 |
* Reads the snapshot manifests maintained by the import pipeline. Each entry |
| 23 |
* reports the export `status` (`exporting`/`complete`), per-type record and |
| 24 |
* chunk totals, and migration timestamps (`last_migrated`, `migration_version`) |
| 25 |
* so an agent can tell whether a source has been exported and/or migrated. |
| 26 |
*/ |
| 27 |
class Get_Import_Status extends Ability_Base { |
| 28 |
/** |
| 29 |
* Source plugins that can hold a snapshot. |
| 30 |
* |
| 31 |
* @var string[] |
| 32 |
*/ |
| 33 |
private const ALLOWED_PLUGINS = [ 'yoast', 'rankmath', 'seopress', 'aioseo' ]; |
| 34 |
|
| 35 |
/** |
| 36 |
* Constructor. |
| 37 |
*/ |
| 38 |
public function __construct() { |
| 39 |
$this->id = 'thinkrank/get-import-status'; |
| 40 |
$this->label = __( 'Get SEO Import Status', 'thinkrank' ); |
| 41 |
$this->description = __( 'Report the status of captured SEO import snapshots: export status (exporting/complete), per-type record and chunk totals, and migration timestamps. Optionally scope to a single source plugin. Reports on the snapshots captured by run-seo-import.', 'thinkrank' ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* {@inheritDoc} |
| 46 |
* |
| 47 |
* @return array<string, bool|float|string> |
| 48 |
*/ |
| 49 |
public function get_annotations() { |
| 50 |
return [ |
| 51 |
'readonly' => true, |
| 52 |
'destructive' => false, |
| 53 |
'idempotent' => true, |
| 54 |
'priority' => 1.0, |
| 55 |
'openWorldHint' => false, |
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* {@inheritDoc} |
| 61 |
* |
| 62 |
* @return array<string, mixed> |
| 63 |
*/ |
| 64 |
public function get_input_schema() { |
| 65 |
return [ |
| 66 |
'type' => 'object', |
| 67 |
'additionalProperties' => false, |
| 68 |
'properties' => [ |
| 69 |
'plugin' => [ |
| 70 |
'type' => 'string', |
| 71 |
'description' => __( 'Optional source plugin to scope the status to.', 'thinkrank' ), |
| 72 |
'enum' => self::ALLOWED_PLUGINS, |
| 73 |
], |
| 74 |
], |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* {@inheritDoc} |
| 80 |
* |
| 81 |
* @return array<string, mixed> |
| 82 |
*/ |
| 83 |
public function get_output_schema() { |
| 84 |
return [ |
| 85 |
'type' => 'object', |
| 86 |
'properties' => [ |
| 87 |
'snapshots' => [ |
| 88 |
'type' => 'object', |
| 89 |
'additionalProperties' => true, |
| 90 |
], |
| 91 |
], |
| 92 |
]; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Execute ability. |
| 97 |
* |
| 98 |
* @param array<string, mixed> $input Ability input payload. |
| 99 |
* @return array<string, mixed> |
| 100 |
*/ |
| 101 |
public function execute( $input ) { |
| 102 |
$plugin = isset( $input['plugin'] ) ? sanitize_key( (string) $input['plugin'] ) : ''; |
| 103 |
|
| 104 |
if ( '' !== $plugin && in_array( $plugin, self::ALLOWED_PLUGINS, true ) ) { |
| 105 |
$manifest = Snapshot_Store::get_manifest( $plugin ); |
| 106 |
|
| 107 |
return [ |
| 108 |
'snapshots' => null === $manifest ? [] : [ $plugin => $manifest ], |
| 109 |
]; |
| 110 |
} |
| 111 |
|
| 112 |
return [ |
| 113 |
'snapshots' => Snapshot_Store::get_available_snapshots(), |
| 114 |
]; |
| 115 |
} |
| 116 |
} |
| 117 |
|