PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / trunk
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! vtrunk
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / full-site-import / Abilities / RetryFullSiteImportAbility.php

RetryFullSiteImportAbility.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! trunk, at modules/full-site-import/Abilities/RetryFullSiteImportAbility.php

80 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * `templately/retry-full-site-import` — resume a recoverable (needs_retry) or
4 * stalled (running) import (spec 042 US4, FR-010). Shares the advance path with
5 * `FullSiteImportStatusAbility` (task T016) — the pipeline resumes from the
6 * saved `progress`, it does not restart.
7 *
8 * Terminal detection: a `complete`/`failed` slice clears the one-active-import
9 * guard, whereas `needs_retry` leaves it set. So if the handle is no longer the
10 * user's active handle, the import already finished and there is nothing to
11 * resume (`not_retryable`).
12 *
13 * @package Templately\Modules\FullSiteImport\Abilities
14 */
15
16 namespace Templately\Modules\FullSiteImport\Abilities;
17
18 use Templately\Modules\FullSiteImport\Utils\SessionData;
19 use Templately\Modules\McpCore\Registry\ToolDescriptor;
20 use Templately\Modules\FullSiteImport\Abilities\Support\FsiActiveImportGuard;
21 use Templately\Modules\McpCore\Support\Permissions;
22 use WP_Error;
23
24 class RetryFullSiteImportAbility {
25
26 const ID = 'templately/retry-full-site-import';
27
28 public static function descriptor(): array {
29 return [
30 'id' => self::ID,
31 'label' => __( 'Retry Templately Full Site Import', 'templately' ),
32 'description' => __( 'Resume a full-site import that reported a recoverable error, continuing from where it stopped (does not restart). Keep polling full-site-import-status afterward.', 'templately' ),
33 'input_schema' => [
34 'type' => 'object',
35 'properties' => [
36 'handle' => [ 'type' => 'string' ],
37 ],
38 'required' => [ 'handle' ],
39 'additionalProperties' => false,
40 ],
41 'output_schema' => [
42 'type' => 'object',
43 'properties' => [
44 'handle' => [ 'type' => 'string' ],
45 'status' => [ 'type' => 'string' ],
46 'progress' => [ 'type' => 'integer' ],
47 'phase' => [ 'type' => 'string' ],
48 ],
49 ],
50 'execute_callback' => [ self::class, 'execute' ],
51 'permission_callback' => [ Permissions::class, 'can_use_abilities' ],
52 'access_level' => ToolDescriptor::ACCESS_FULL,
53 'annotations' => [ 'readonly' => false, 'destructive' => false, 'idempotent' => false ],
54 ];
55 }
56
57 /**
58 * @param array $input
59 * @return array|WP_Error
60 */
61 public static function execute( array $input ) {
62 $handle = FullSiteImportStatusAbility::sanitize_handle( $input['handle'] ?? '' );
63 if ( is_wp_error( $handle ) ) {
64 return $handle;
65 }
66
67 $session_data = SessionData::get_data( $handle );
68 if ( empty( $session_data ) || ! is_array( $session_data ) ) {
69 return new WP_Error( 'expired_handle', __( 'Unknown or expired import handle.', 'templately' ) );
70 }
71
72 $active = FsiActiveImportGuard::get_active( get_current_user_id() );
73 if ( empty( $active ) || ( $active['session_id'] ?? '' ) !== $handle ) {
74 return new WP_Error( 'not_retryable', __( 'This import has already finished and cannot be retried.', 'templately' ) );
75 }
76
77 return FullSiteImportStatusAbility::advance( $handle, 0, true );
78 }
79 }
80