PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.4.2
WooCommerce Square v5.4.2
5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Internal / Abilities / Domain / GetSyncStatus.php
woocommerce-square / includes / Internal / Abilities / Domain Last commit date
AbstractSquareAbility.php 1 month ago GetConnectionStatus.php 1 month ago GetLocations.php 1 month ago GetOrderPaymentStatus.php 1 month ago GetPendingJobs.php 1 month ago GetProductSyncState.php 1 month ago GetSyncRecords.php 1 month ago GetSyncStatus.php 1 month ago
GetSyncStatus.php
104 lines
1 <?php
2 /**
3 * Get sync status ability definition.
4 *
5 * @package WooCommerce\Square
6 */
7
8 // @phan-file-suppress PhanUndeclaredClassMethod, PhanUndeclaredFunction @phan-suppress-current-line UnusedSuppression -- Abilities API + AbilityDefinition added in WC 10.9; suppression covers older-WC compat runs where this class never loads.
9
10 namespace WooCommerce\Square\Internal\Abilities\Domain;
11
12 defined( 'ABSPATH' ) || exit;
13
14 use Automattic\WooCommerce\Abilities\AbilityDefinition;
15 use WooCommerce\Square\Internal\Abilities\Abilities_Registrar;
16
17 /**
18 * Registers the woocommerce-square/get-sync-status ability.
19 *
20 * Reference ability for the Square for WooCommerce Abilities API rollout —
21 * zero-arg overview answering "is Square product/inventory sync healthy?".
22 * Returns a small associative array composed from six accessor methods on
23 * the Sync handler: whether a sync is currently in progress, the id of the
24 * running job (if any), the last product- and inventory-sync timestamps,
25 * the next scheduled sync timestamp, and whether product sync is enabled.
26 *
27 * Today this state is only exposed via the `wc_square_get_sync_with_square_status`
28 * wp_ajax_* handler; this ability fills the agent-facing gap without adding
29 * a new REST endpoint.
30 *
31 * @internal Only loaded when WooCommerce 10.9+ is active. The
32 * Abilities_Registrar short-circuits before referencing this
33 * class on earlier WC versions; PHP's lazy autoload means the
34 * unresolved AbilityDefinition interface FQN never reaches the
35 * parser there.
36 */
37 class GetSyncStatus extends AbstractSquareAbility implements AbilityDefinition {
38
39 public static function get_name(): string {
40 return 'woocommerce-square/get-sync-status';
41 }
42
43 public static function get_registration_args(): array {
44 return array(
45 'label' => __( 'Get Square sync status', 'woocommerce-square' ),
46 'description' => __( 'Return the current Square sync state — whether a sync is in progress, the last product- and inventory-sync timestamps, the next scheduled sync, and whether product sync is enabled.', 'woocommerce-square' ),
47 'category' => self::CATEGORY_SLUG,
48 'input_schema' => array(
49 'type' => 'object',
50 'default' => (object) array(),
51 'properties' => array(),
52 'additionalProperties' => false,
53 ),
54 'execute_callback' => array( self::class, 'execute' ),
55 'permission_callback' => array( Abilities_Registrar::class, 'can_manage_woocommerce_square' ),
56 // output_schema deliberately omitted — see first-ability-template §"output_schema omission rule".
57 'meta' => array(
58 'annotations' => array(
59 'readonly' => true,
60 'destructive' => false,
61 'idempotent' => true,
62 ),
63 'show_in_rest' => true,
64 'mcp' => array(
65 'public' => true,
66 ),
67 ),
68 );
69 }
70
71 /**
72 * Execute callback.
73 *
74 * Composes a small associative array from the Sync handler's read methods.
75 * The job object returned by `get_job_in_progress()` is coerced to a
76 * stable string id (or null) — the internal class shape is not part of
77 * the ability contract.
78 *
79 * @param mixed $input Ignored; the ability accepts no input.
80 * @return array|\WP_Error Associative array of sync state, or WP_Error
81 * when the plugin has not finished initializing.
82 */
83 public static function execute( $input = null ) {
84 unset( $input );
85
86 $sync_handler = self::get_sync_handler_or_error();
87 if ( is_wp_error( $sync_handler ) ) {
88 return $sync_handler;
89 }
90
91 $job = $sync_handler->get_job_in_progress();
92 $current_job_id = ( is_object( $job ) && isset( $job->id ) ) ? (string) $job->id : null;
93
94 return array(
95 'is_in_progress' => (bool) $sync_handler->is_sync_in_progress(),
96 'is_sync_enabled' => (bool) $sync_handler->is_sync_enabled(),
97 'current_job_id' => $current_job_id,
98 'last_synced_at' => $sync_handler->get_last_synced_at(),
99 'inventory_last_synced_at' => $sync_handler->get_inventory_last_synced_at(),
100 'next_sync_at' => $sync_handler->get_next_sync_at(),
101 );
102 }
103 }
104