← All changes
|
json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php
+35
-4
12.6.4
→
16.3-a.5
View file →
| @@ -8,8 +8,12 @@ | ||
| 8 | 8 | use Automattic\Jetpack\Sync\Replicastore; |
| 9 | 9 | use Automattic\Jetpack\Sync\Sender; |
| 10 | 10 | use Automattic\Jetpack\Sync\Settings; |
| 11 | 11 | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 13 | + exit( 0 ); | |
| 14 | +} | |
| 15 | + | |
| 12 | 16 | // phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound |
| 13 | 17 | |
| 14 | 18 | /** |
| 15 | 19 | * Sync endpoint class. |
| @@ -14,8 +18,10 @@ | ||
| 14 | 18 | /** |
| 15 | 19 | * Sync endpoint class. |
| 16 | 20 | * |
| 17 | 21 | * POST /sites/%s/sync |
| 22 | + * | |
| 23 | + * @phan-constructor-used-for-side-effects | |
| 18 | 24 | */ |
| 19 | 25 | class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint { |
| 20 | 26 | |
| 21 | 27 | /** |
| @@ -67,9 +73,9 @@ | ||
| 67 | 73 | |
| 68 | 74 | if ( empty( $modules ) ) { |
| 69 | 75 | $modules = null; |
| 70 | 76 | } |
| 71 | - return array( 'scheduled' => Actions::do_full_sync( $modules ) ); | |
| 77 | + return array( 'scheduled' => Actions::do_full_sync( $modules, 'jetpack_json_api_sync_endpoint' ) ); | |
| 72 | 78 | } |
| 73 | 79 | |
| 74 | 80 | /** |
| 75 | 81 | * Validate the queue. |
| @@ -93,8 +99,10 @@ | ||
| 93 | 99 | /** |
| 94 | 100 | * Sync status endpoint class. |
| 95 | 101 | * |
| 96 | 102 | * GET /sites/%s/sync/status |
| 103 | + * | |
| 104 | + * @phan-constructor-used-for-side-effects | |
| 97 | 105 | */ |
| 98 | 106 | class Jetpack_JSON_API_Sync_Status_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 99 | 107 | /** |
| 100 | 108 | * Callback for the endpoint. |
| @@ -102,9 +110,9 @@ | ||
| 102 | 110 | * @return array |
| 103 | 111 | */ |
| 104 | 112 | protected function result() { |
| 105 | 113 | $args = $this->query_args(); |
| 106 | - $fields = isset( $args['fields'] ) ? $args['fields'] : array(); | |
| 114 | + $fields = $args['fields'] ?? array(); | |
| 107 | 115 | return Actions::get_sync_status( $fields ); |
| 108 | 116 | } |
| 109 | 117 | } |
| 110 | 118 | |
| @@ -110,8 +118,10 @@ | ||
| 110 | 118 | |
| 111 | 119 | /** |
| 112 | 120 | * Sync Check Endpoint class. |
| 113 | 121 | * GET /sites/%s/data-check |
| 122 | + * | |
| 123 | + * @phan-constructor-used-for-side-effects | |
| 114 | 124 | */ |
| 115 | 125 | class Jetpack_JSON_API_Sync_Check_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 116 | 126 | /** |
| 117 | 127 | * Callback for the endpoint. |
| @@ -127,8 +137,10 @@ | ||
| 127 | 137 | |
| 128 | 138 | /** |
| 129 | 139 | * Sync histogram endpoint. |
| 130 | 140 | * GET /sites/%s/data-histogram |
| 141 | + * | |
| 142 | + * @phan-constructor-used-for-side-effects | |
| 131 | 143 | */ |
| 132 | 144 | class Jetpack_JSON_API_Sync_Histogram_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 133 | 145 | /** |
| 134 | 146 | * Callback for endpoint. |
| @@ -178,8 +190,10 @@ | ||
| 178 | 190 | } |
| 179 | 191 | |
| 180 | 192 | /** |
| 181 | 193 | * POST /sites/%s/sync/health |
| 194 | + * | |
| 195 | + * @phan-constructor-used-for-side-effects | |
| 182 | 196 | */ |
| 183 | 197 | class Jetpack_JSON_API_Sync_Modify_Health_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 184 | 198 | |
| 185 | 199 | /** |
| @@ -207,8 +221,10 @@ | ||
| 207 | 221 | } |
| 208 | 222 | |
| 209 | 223 | /** |
| 210 | 224 | * POST /sites/%s/sync/settings |
| 225 | + * | |
| 226 | + * @phan-constructor-used-for-side-effects | |
| 211 | 227 | */ |
| 212 | 228 | class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 213 | 229 | /** |
| 214 | 230 | * The endpoint callback. |
| @@ -243,8 +259,10 @@ | ||
| 243 | 259 | } |
| 244 | 260 | |
| 245 | 261 | /** |
| 246 | 262 | * GET /sites/%s/sync/settings |
| 263 | + * | |
| 264 | + * @phan-constructor-used-for-side-effects | |
| 247 | 265 | */ |
| 248 | 266 | class Jetpack_JSON_API_Sync_Get_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 249 | 267 | /** |
| 250 | 268 | * Endpoint callback. |
| @@ -258,8 +276,10 @@ | ||
| 258 | 276 | } |
| 259 | 277 | |
| 260 | 278 | /** |
| 261 | 279 | * GET /sites/%s/sync/object |
| 280 | + * | |
| 281 | + * @phan-constructor-used-for-side-effects | |
| 262 | 282 | */ |
| 263 | 283 | class Jetpack_JSON_API_Sync_Object extends Jetpack_JSON_API_Sync_Endpoint { |
| 264 | 284 | /** |
| 265 | 285 | * Endpoint callback. |
| @@ -294,8 +314,10 @@ | ||
| 294 | 314 | } |
| 295 | 315 | |
| 296 | 316 | /** |
| 297 | 317 | * Sync Now endpoint class. |
| 318 | + * | |
| 319 | + * @phan-constructor-used-for-side-effects | |
| 298 | 320 | */ |
| 299 | 321 | class Jetpack_JSON_API_Sync_Now_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 300 | 322 | /** |
| 301 | 323 | * Endpoint callback. |
| @@ -320,8 +342,10 @@ | ||
| 320 | 342 | } |
| 321 | 343 | |
| 322 | 344 | /** |
| 323 | 345 | * Sync checkout endpoint. |
| 346 | + * | |
| 347 | + * @phan-constructor-used-for-side-effects | |
| 324 | 348 | */ |
| 325 | 349 | class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 326 | 350 | /** |
| 327 | 351 | * Endpoint callback. |
| @@ -476,8 +500,10 @@ | ||
| 476 | 500 | } |
| 477 | 501 | |
| 478 | 502 | /** |
| 479 | 503 | * Close endpoint class. |
| 504 | + * | |
| 505 | + * @phan-constructor-used-for-side-effects | |
| 480 | 506 | */ |
| 481 | 507 | class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 482 | 508 | /** |
| 483 | 509 | * Endpoint callback. |
| @@ -510,8 +536,9 @@ | ||
| 510 | 536 | |
| 511 | 537 | // Update Full Sync Status if queue is "full_sync". |
| 512 | 538 | if ( 'full_sync' === $queue_name ) { |
| 513 | 539 | $full_sync_module = Modules::get_module( 'full-sync' ); |
| 540 | + '@phan-var \Automattic\Jetpack\Sync\Modules\Full_Sync_Immediately|\Automattic\Jetpack\Sync\Modules\Full_Sync $full_sync_module'; | |
| 514 | 541 | |
| 515 | 542 | $full_sync_module->update_sent_progress_action( $items ); |
| 516 | 543 | } |
| 517 | 544 | |
| @@ -547,9 +574,9 @@ | ||
| 547 | 574 | * @return string|null |
| 548 | 575 | */ |
| 549 | 576 | protected static function sanitize_item_ids( $item ) { |
| 550 | 577 | // lets not delete any options that don't start with jpsq_sync- |
| 551 | - if ( ! is_string( $item ) || substr( $item, 0, 5 ) !== 'jpsq_' ) { | |
| 578 | + if ( ! is_string( $item ) || ! str_starts_with( $item, 'jpsq_' ) ) { | |
| 552 | 579 | return null; |
| 553 | 580 | } |
| 554 | 581 | // Limit to A-Z,a-z,0-9,_,-,. |
| 555 | 582 | return preg_replace( '/[^A-Za-z0-9-_.]/', '', $item ); |
| @@ -556,9 +583,11 @@ | ||
| 556 | 583 | } |
| 557 | 584 | } |
| 558 | 585 | |
| 559 | 586 | /** |
| 560 | - * Unlock ednpoint class. | |
| 587 | + * Unlock endpoint class. | |
| 588 | + * | |
| 589 | + * @phan-constructor-used-for-side-effects | |
| 561 | 590 | */ |
| 562 | 591 | class Jetpack_JSON_API_Sync_Unlock_Endpoint extends Jetpack_JSON_API_Sync_Endpoint { |
| 563 | 592 | /** |
| 564 | 593 | * Endpoint callback. |
| @@ -587,8 +616,10 @@ | ||
| 587 | 616 | } |
| 588 | 617 | |
| 589 | 618 | /** |
| 590 | 619 | * Object ID range class. |
| 620 | + * | |
| 621 | + * @phan-constructor-used-for-side-effects | |
| 591 | 622 | */ |
| 592 | 623 | class Jetpack_JSON_API_Sync_Object_Id_Range extends Jetpack_JSON_API_Sync_Endpoint { |
| 593 | 624 | /** |
| 594 | 625 | * Endpoint callback. |