| 1 |
<?php |
| 2 |
/** |
| 3 |
* Get instant indexing history ability. |
| 4 |
* |
| 5 |
* @package ThinkRank\Abilities\Indexing |
| 6 |
*/ |
| 7 |
|
| 8 |
declare(strict_types=1); |
| 9 |
|
| 10 |
namespace ThinkRank\Abilities\Indexing; |
| 11 |
|
| 12 |
use ThinkRank\Abilities\Ability_Base; |
| 13 |
use ThinkRank\SEO\Instant_Indexing_Manager; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Retrieves the ThinkRank instant indexing (IndexNow) submission history. |
| 21 |
*/ |
| 22 |
class Get_Instant_Indexing_History extends Ability_Base { |
| 23 |
/** |
| 24 |
* Constructor. |
| 25 |
*/ |
| 26 |
public function __construct() { |
| 27 |
$this->id = 'thinkrank/get-instant-indexing-history'; |
| 28 |
$this->label = __( 'Get ThinkRank Instant Indexing History', 'thinkrank' ); |
| 29 |
$this->description = __( 'Retrieve the ThinkRank instant indexing (IndexNow) submission history, including submitted URLs, status, response codes, and timestamps. Lists the submissions made by submit-urls-to-index.', 'thinkrank' ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* {@inheritDoc} |
| 34 |
* |
| 35 |
* @return array<string, bool|float|string> |
| 36 |
*/ |
| 37 |
public function get_annotations() { |
| 38 |
return [ |
| 39 |
'readonly' => true, |
| 40 |
'destructive' => false, |
| 41 |
'idempotent' => true, |
| 42 |
'priority' => 1.0, |
| 43 |
'openWorldHint' => false, |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* {@inheritDoc} |
| 49 |
* |
| 50 |
* @return array<string, mixed> |
| 51 |
*/ |
| 52 |
public function get_input_schema() { |
| 53 |
return [ |
| 54 |
'type' => 'object', |
| 55 |
'additionalProperties' => false, |
| 56 |
'properties' => [ |
| 57 |
'limit' => [ |
| 58 |
'type' => 'integer', |
| 59 |
'description' => __( 'Maximum number of history rows to return. Use -1 for all.', 'thinkrank' ), |
| 60 |
'default' => 50, |
| 61 |
], |
| 62 |
], |
| 63 |
]; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* {@inheritDoc} |
| 68 |
* |
| 69 |
* @return array<string, mixed> |
| 70 |
*/ |
| 71 |
public function get_output_schema() { |
| 72 |
return [ |
| 73 |
'type' => 'object', |
| 74 |
'properties' => [ |
| 75 |
'history' => [ |
| 76 |
'type' => 'array', |
| 77 |
'items' => [ |
| 78 |
'type' => 'object', |
| 79 |
'properties' => [ |
| 80 |
'url' => [ 'type' => 'string' ], |
| 81 |
'status' => [ 'type' => 'string' ], |
| 82 |
'response_code' => [ 'type' => 'integer' ], |
| 83 |
'response_message' => [ 'type' => 'string' ], |
| 84 |
'created_at' => [ 'type' => 'string' ], |
| 85 |
], |
| 86 |
], |
| 87 |
], |
| 88 |
], |
| 89 |
]; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Execute ability. |
| 94 |
* |
| 95 |
* @param array<string, mixed> $input Ability input payload. |
| 96 |
* @return array<string, mixed> |
| 97 |
*/ |
| 98 |
public function execute( $input ) { |
| 99 |
$limit = isset( $input['limit'] ) ? (int) $input['limit'] : 50; |
| 100 |
|
| 101 |
$manager = new Instant_Indexing_Manager(); |
| 102 |
$history = $manager->get_history( $limit ); |
| 103 |
|
| 104 |
return [ |
| 105 |
'history' => is_array( $history ) ? array_values( $history ) : [], |
| 106 |
]; |
| 107 |
} |
| 108 |
} |
| 109 |
|