@@ -6,56 +6,56 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Sync_Background_Process_Wpjson_Endpoint { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @var Sync_Background_Process |
|
| 11 | - */ |
|
| 12 | - private $sync_background_process; |
|
| 9 | + /** |
|
| 10 | + * @var Sync_Background_Process |
|
| 11 | + */ |
|
| 12 | + private $sync_background_process; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Sync_Background_Process_Wpjson_Endpoint constructor. |
|
| 16 | - * |
|
| 17 | - * @param Sync_Background_Process $sync_background_process |
|
| 18 | - */ |
|
| 19 | - function __construct( $sync_background_process ) { |
|
| 14 | + /** |
|
| 15 | + * Sync_Background_Process_Wpjson_Endpoint constructor. |
|
| 16 | + * |
|
| 17 | + * @param Sync_Background_Process $sync_background_process |
|
| 18 | + */ |
|
| 19 | + function __construct( $sync_background_process ) { |
|
| 20 | 20 | |
| 21 | - add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
| 21 | + add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
| 22 | 22 | |
| 23 | - $this->sync_background_process = $sync_background_process; |
|
| 23 | + $this->sync_background_process = $sync_background_process; |
|
| 24 | 24 | |
| 25 | - } |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - function rest_api_init() { |
|
| 27 | + function rest_api_init() { |
|
| 28 | 28 | |
| 29 | - register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 30 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 31 | - 'callback' => array( $this->sync_background_process, 'start' ), |
|
| 32 | - 'permission_callback' => function () { |
|
| 33 | - $user = wp_get_current_user(); |
|
| 29 | + register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 30 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 31 | + 'callback' => array( $this->sync_background_process, 'start' ), |
|
| 32 | + 'permission_callback' => function () { |
|
| 33 | + $user = wp_get_current_user(); |
|
| 34 | 34 | |
| 35 | - return in_array( 'administrator', (array) $user->roles ); |
|
| 36 | - } |
|
| 37 | - ) ); |
|
| 35 | + return in_array( 'administrator', (array) $user->roles ); |
|
| 36 | + } |
|
| 37 | + ) ); |
|
| 38 | 38 | |
| 39 | - register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 40 | - 'methods' => WP_REST_Server::READABLE, |
|
| 41 | - 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
| 42 | - 'permission_callback' => function () { |
|
| 43 | - $user = wp_get_current_user(); |
|
| 39 | + register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 40 | + 'methods' => WP_REST_Server::READABLE, |
|
| 41 | + 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
| 42 | + 'permission_callback' => function () { |
|
| 43 | + $user = wp_get_current_user(); |
|
| 44 | 44 | |
| 45 | - return in_array( 'administrator', (array) $user->roles ); |
|
| 46 | - } |
|
| 47 | - ) ); |
|
| 45 | + return in_array( 'administrator', (array) $user->roles ); |
|
| 46 | + } |
|
| 47 | + ) ); |
|
| 48 | 48 | |
| 49 | - register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 50 | - 'methods' => WP_REST_Server::DELETABLE, |
|
| 51 | - 'callback' => array( $this->sync_background_process, 'stop' ), |
|
| 52 | - 'permission_callback' => function () { |
|
| 53 | - $user = wp_get_current_user(); |
|
| 49 | + register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 50 | + 'methods' => WP_REST_Server::DELETABLE, |
|
| 51 | + 'callback' => array( $this->sync_background_process, 'stop' ), |
|
| 52 | + 'permission_callback' => function () { |
|
| 53 | + $user = wp_get_current_user(); |
|
| 54 | 54 | |
| 55 | - return in_array( 'administrator', (array) $user->roles ); |
|
| 56 | - } |
|
| 57 | - ) ); |
|
| 55 | + return in_array( 'administrator', (array) $user->roles ); |
|
| 56 | + } |
|
| 57 | + ) ); |
|
| 58 | 58 | |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | } |
@@ -16,9 +16,9 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @param Sync_Background_Process $sync_background_process |
| 18 | 18 | */ |
| 19 | - function __construct( $sync_background_process ) { |
|
| 19 | + function __construct($sync_background_process) { |
|
| 20 | 20 | |
| 21 | - add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
| 21 | + add_action('rest_api_init', array($this, 'rest_api_init')); |
|
| 22 | 22 | |
| 23 | 23 | $this->sync_background_process = $sync_background_process; |
| 24 | 24 | |
@@ -26,35 +26,35 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | function rest_api_init() { |
| 28 | 28 | |
| 29 | - register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 29 | + register_rest_route('wordlift/v1', '/dataset/background/sync', array( |
|
| 30 | 30 | 'methods' => WP_REST_Server::CREATABLE, |
| 31 | - 'callback' => array( $this->sync_background_process, 'start' ), |
|
| 32 | - 'permission_callback' => function () { |
|
| 31 | + 'callback' => array($this->sync_background_process, 'start'), |
|
| 32 | + 'permission_callback' => function() { |
|
| 33 | 33 | $user = wp_get_current_user(); |
| 34 | 34 | |
| 35 | - return in_array( 'administrator', (array) $user->roles ); |
|
| 35 | + return in_array('administrator', (array) $user->roles); |
|
| 36 | 36 | } |
| 37 | - ) ); |
|
| 37 | + )); |
|
| 38 | 38 | |
| 39 | - register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 39 | + register_rest_route('wordlift/v1', '/dataset/background/sync', array( |
|
| 40 | 40 | 'methods' => WP_REST_Server::READABLE, |
| 41 | - 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
| 42 | - 'permission_callback' => function () { |
|
| 41 | + 'callback' => array($this->sync_background_process, 'get_info'), |
|
| 42 | + 'permission_callback' => function() { |
|
| 43 | 43 | $user = wp_get_current_user(); |
| 44 | 44 | |
| 45 | - return in_array( 'administrator', (array) $user->roles ); |
|
| 45 | + return in_array('administrator', (array) $user->roles); |
|
| 46 | 46 | } |
| 47 | - ) ); |
|
| 47 | + )); |
|
| 48 | 48 | |
| 49 | - register_rest_route( 'wordlift/v1', '/dataset/background/sync', array( |
|
| 49 | + register_rest_route('wordlift/v1', '/dataset/background/sync', array( |
|
| 50 | 50 | 'methods' => WP_REST_Server::DELETABLE, |
| 51 | - 'callback' => array( $this->sync_background_process, 'stop' ), |
|
| 52 | - 'permission_callback' => function () { |
|
| 51 | + 'callback' => array($this->sync_background_process, 'stop'), |
|
| 52 | + 'permission_callback' => function() { |
|
| 53 | 53 | $user = wp_get_current_user(); |
| 54 | 54 | |
| 55 | - return in_array( 'administrator', (array) $user->roles ); |
|
| 55 | + return in_array('administrator', (array) $user->roles); |
|
| 56 | 56 | } |
| 57 | - ) ); |
|
| 57 | + )); |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | |
@@ -11,123 +11,123 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Sync_Background_Process_Started_State extends Abstract_Sync_Background_Process_State { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var Sync_Background_Process |
|
| 16 | - */ |
|
| 17 | - private $context; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var Sync_Service |
|
| 21 | - */ |
|
| 22 | - private $sync_service; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var Sync_Background_Process_Stage[] |
|
| 26 | - */ |
|
| 27 | - private $stages; |
|
| 28 | - |
|
| 29 | - private $batch_size = 5; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Sync_Background_Process_Started_State constructor. |
|
| 33 | - * |
|
| 34 | - * @param Sync_Background_Process $context |
|
| 35 | - * @param Sync_Service $sync_service |
|
| 36 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
| 37 | - */ |
|
| 38 | - function __construct( $context, $sync_service, $sync_object_adapter_factory ) { |
|
| 39 | - parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
| 40 | - |
|
| 41 | - $this->context = $context; |
|
| 42 | - $this->sync_service = $sync_service; |
|
| 43 | - |
|
| 44 | - $this->stages = array( |
|
| 45 | - new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
| 46 | - new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
| 47 | - new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
| 48 | - ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - function enter() { |
|
| 52 | - // Delete the KG contents. |
|
| 53 | - $this->sync_service->delete_all(); |
|
| 54 | - |
|
| 55 | - // Clear caches. |
|
| 56 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 57 | - |
|
| 58 | - $counts = array_map( function ( $item ) { |
|
| 59 | - return $item->count(); |
|
| 60 | - }, $this->stages ); |
|
| 14 | + /** |
|
| 15 | + * @var Sync_Background_Process |
|
| 16 | + */ |
|
| 17 | + private $context; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var Sync_Service |
|
| 21 | + */ |
|
| 22 | + private $sync_service; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var Sync_Background_Process_Stage[] |
|
| 26 | + */ |
|
| 27 | + private $stages; |
|
| 28 | + |
|
| 29 | + private $batch_size = 5; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Sync_Background_Process_Started_State constructor. |
|
| 33 | + * |
|
| 34 | + * @param Sync_Background_Process $context |
|
| 35 | + * @param Sync_Service $sync_service |
|
| 36 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
| 37 | + */ |
|
| 38 | + function __construct( $context, $sync_service, $sync_object_adapter_factory ) { |
|
| 39 | + parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
| 40 | + |
|
| 41 | + $this->context = $context; |
|
| 42 | + $this->sync_service = $sync_service; |
|
| 43 | + |
|
| 44 | + $this->stages = array( |
|
| 45 | + new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
| 46 | + new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
| 47 | + new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + function enter() { |
|
| 52 | + // Delete the KG contents. |
|
| 53 | + $this->sync_service->delete_all(); |
|
| 54 | + |
|
| 55 | + // Clear caches. |
|
| 56 | + do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 57 | + |
|
| 58 | + $counts = array_map( function ( $item ) { |
|
| 59 | + return $item->count(); |
|
| 60 | + }, $this->stages ); |
|
| 61 | 61 | |
| 62 | - update_option( '_wl_sync_background_process_count', $counts, true ); |
|
| 63 | - update_option( '_wl_sync_background_process_stage', 0, true ); |
|
| 64 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
| 65 | - update_option( '_wl_sync_background_process_started', time(), true ); |
|
| 66 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
| 62 | + update_option( '_wl_sync_background_process_count', $counts, true ); |
|
| 63 | + update_option( '_wl_sync_background_process_stage', 0, true ); |
|
| 64 | + update_option( '_wl_sync_background_process_offset', 0, true ); |
|
| 65 | + update_option( '_wl_sync_background_process_started', time(), true ); |
|
| 66 | + update_option( '_wl_sync_background_process_updated', time(), true ); |
|
| 67 | 67 | |
| 68 | - $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
| 68 | + $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
| 69 | 69 | |
| 70 | - $this->context->push_to_queue( true ); |
|
| 71 | - $this->context->save()->dispatch(); |
|
| 72 | - } |
|
| 70 | + $this->context->push_to_queue( true ); |
|
| 71 | + $this->context->save()->dispatch(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - function leave() { |
|
| 75 | - $this->context->set_state( null ); |
|
| 76 | - } |
|
| 74 | + function leave() { |
|
| 75 | + $this->context->set_state( null ); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - function task( $args ) { |
|
| 78 | + function task( $args ) { |
|
| 79 | 79 | |
| 80 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
| 81 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
| 82 | - $counts = get_option( '_wl_sync_background_process_count' ); |
|
| 83 | - $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
| 80 | + $offset = get_option( '_wl_sync_background_process_offset' ); |
|
| 81 | + $stage = get_option( '_wl_sync_background_process_stage' ); |
|
| 82 | + $counts = get_option( '_wl_sync_background_process_count' ); |
|
| 83 | + $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
| 84 | 84 | |
| 85 | - add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
| 86 | - try { |
|
| 87 | - $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
| 88 | - $this->sync_service->sync_many( $object_adapters, true ); |
|
| 89 | - } catch ( \Exception $e ) { |
|
| 90 | - // ignored. |
|
| 91 | - } |
|
| 92 | - remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
| 85 | + add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
| 86 | + try { |
|
| 87 | + $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
| 88 | + $this->sync_service->sync_many( $object_adapters, true ); |
|
| 89 | + } catch ( \Exception $e ) { |
|
| 90 | + // ignored. |
|
| 91 | + } |
|
| 92 | + remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
| 93 | 93 | |
| 94 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
| 94 | + update_option( '_wl_sync_background_process_updated', time(), true ); |
|
| 95 | 95 | |
| 96 | - // Increase the offset. |
|
| 97 | - if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
| 98 | - update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
| 96 | + // Increase the offset. |
|
| 97 | + if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
| 98 | + update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
| 99 | 99 | |
| 100 | - return true; |
|
| 101 | - } |
|
| 100 | + return true; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - // Increase the stage. |
|
| 104 | - if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
| 105 | - update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
| 106 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
| 103 | + // Increase the stage. |
|
| 104 | + if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
| 105 | + update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
| 106 | + update_option( '_wl_sync_background_process_offset', 0, true ); |
|
| 107 | 107 | |
| 108 | - return true; |
|
| 109 | - } |
|
| 108 | + return true; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - // Stop processing. |
|
| 112 | - $this->context->stop(); |
|
| 111 | + // Stop processing. |
|
| 112 | + $this->context->stop(); |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 115 | - } |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Hook to provide a request to update the status on the server. |
|
| 119 | - * |
|
| 120 | - * @param array $args |
|
| 121 | - * |
|
| 122 | - * @return mixed |
|
| 123 | - */ |
|
| 124 | - public function api_service__request( $args ) { |
|
| 117 | + /** |
|
| 118 | + * Hook to provide a request to update the status on the server. |
|
| 119 | + * |
|
| 120 | + * @param array $args |
|
| 121 | + * |
|
| 122 | + * @return mixed |
|
| 123 | + */ |
|
| 124 | + public function api_service__request( $args ) { |
|
| 125 | 125 | |
| 126 | - $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
| 126 | + $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
| 127 | 127 | |
| 128 | - $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
|
| 128 | + $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
|
| 129 | 129 | |
| 130 | - return $args; |
|
| 131 | - } |
|
| 130 | + return $args; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | 133 | } |
@@ -35,16 +35,16 @@ discard block |
||
| 35 | 35 | * @param Sync_Service $sync_service |
| 36 | 36 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
| 37 | 37 | */ |
| 38 | - function __construct( $context, $sync_service, $sync_object_adapter_factory ) { |
|
| 39 | - parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
| 38 | + function __construct($context, $sync_service, $sync_object_adapter_factory) { |
|
| 39 | + parent::__construct(Sync_Background_Process::STATE_STARTED); |
|
| 40 | 40 | |
| 41 | 41 | $this->context = $context; |
| 42 | 42 | $this->sync_service = $sync_service; |
| 43 | 43 | |
| 44 | 44 | $this->stages = array( |
| 45 | - new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
| 46 | - new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
| 47 | - new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
| 45 | + new Sync_Background_Process_Posts_Stage($sync_object_adapter_factory), |
|
| 46 | + new Sync_Background_Process_Terms_Stage($sync_object_adapter_factory), |
|
| 47 | + new Sync_Background_Process_Users_Stage($sync_object_adapter_factory), |
|
| 48 | 48 | ); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,57 +53,57 @@ discard block |
||
| 53 | 53 | $this->sync_service->delete_all(); |
| 54 | 54 | |
| 55 | 55 | // Clear caches. |
| 56 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
| 56 | + do_action('wl_ttl_cache_cleaner__flush'); |
|
| 57 | 57 | |
| 58 | - $counts = array_map( function ( $item ) { |
|
| 58 | + $counts = array_map(function($item) { |
|
| 59 | 59 | return $item->count(); |
| 60 | - }, $this->stages ); |
|
| 60 | + }, $this->stages); |
|
| 61 | 61 | |
| 62 | - update_option( '_wl_sync_background_process_count', $counts, true ); |
|
| 63 | - update_option( '_wl_sync_background_process_stage', 0, true ); |
|
| 64 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
| 65 | - update_option( '_wl_sync_background_process_started', time(), true ); |
|
| 66 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
| 62 | + update_option('_wl_sync_background_process_count', $counts, true); |
|
| 63 | + update_option('_wl_sync_background_process_stage', 0, true); |
|
| 64 | + update_option('_wl_sync_background_process_offset', 0, true); |
|
| 65 | + update_option('_wl_sync_background_process_started', time(), true); |
|
| 66 | + update_option('_wl_sync_background_process_updated', time(), true); |
|
| 67 | 67 | |
| 68 | - $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
| 68 | + $this->context->set_state(Sync_Background_Process::STATE_STARTED); |
|
| 69 | 69 | |
| 70 | - $this->context->push_to_queue( true ); |
|
| 70 | + $this->context->push_to_queue(true); |
|
| 71 | 71 | $this->context->save()->dispatch(); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | function leave() { |
| 75 | - $this->context->set_state( null ); |
|
| 75 | + $this->context->set_state(null); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - function task( $args ) { |
|
| 78 | + function task($args) { |
|
| 79 | 79 | |
| 80 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
| 81 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
| 82 | - $counts = get_option( '_wl_sync_background_process_count' ); |
|
| 83 | - $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
| 80 | + $offset = get_option('_wl_sync_background_process_offset'); |
|
| 81 | + $stage = get_option('_wl_sync_background_process_stage'); |
|
| 82 | + $counts = get_option('_wl_sync_background_process_count'); |
|
| 83 | + $batch_size = min($counts[$stage] - $offset, $this->batch_size); |
|
| 84 | 84 | |
| 85 | - add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
| 85 | + add_filter('wl_api_service__request', array($this, 'api_service__request')); |
|
| 86 | 86 | try { |
| 87 | - $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
| 88 | - $this->sync_service->sync_many( $object_adapters, true ); |
|
| 89 | - } catch ( \Exception $e ) { |
|
| 87 | + $object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size); |
|
| 88 | + $this->sync_service->sync_many($object_adapters, true); |
|
| 89 | + } catch (\Exception $e) { |
|
| 90 | 90 | // ignored. |
| 91 | 91 | } |
| 92 | - remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
| 92 | + remove_filter('wl_api_service__request', array($this, 'api_service__request')); |
|
| 93 | 93 | |
| 94 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
| 94 | + update_option('_wl_sync_background_process_updated', time(), true); |
|
| 95 | 95 | |
| 96 | 96 | // Increase the offset. |
| 97 | - if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
| 98 | - update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
| 97 | + if (($offset + $batch_size) < $counts[$stage]) { |
|
| 98 | + update_option('_wl_sync_background_process_offset', $offset + $batch_size, true); |
|
| 99 | 99 | |
| 100 | 100 | return true; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // Increase the stage. |
| 104 | - if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
| 105 | - update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
| 106 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
| 104 | + if (($stage + 1) < count($this->stages)) { |
|
| 105 | + update_option('_wl_sync_background_process_stage', $stage + 1, true); |
|
| 106 | + update_option('_wl_sync_background_process_offset', 0, true); |
|
| 107 | 107 | |
| 108 | 108 | return true; |
| 109 | 109 | } |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | * |
| 122 | 122 | * @return mixed |
| 123 | 123 | */ |
| 124 | - public function api_service__request( $args ) { |
|
| 124 | + public function api_service__request($args) { |
|
| 125 | 125 | |
| 126 | - $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
| 126 | + $state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info())); |
|
| 127 | 127 | |
| 128 | 128 | $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
| 129 | 129 | |
@@ -4,29 +4,29 @@ |
||
| 4 | 4 | |
| 5 | 5 | abstract class Abstract_Sync_Background_Process_State implements Sync_Background_Process_State { |
| 6 | 6 | |
| 7 | - private $state; |
|
| 8 | - |
|
| 9 | - function __construct( $state ) { |
|
| 10 | - $this->state = $state; |
|
| 11 | - } |
|
| 12 | - |
|
| 13 | - function get_info() { |
|
| 14 | - $started = get_option( '_wl_sync_background_process_started' ); |
|
| 15 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
| 16 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
| 17 | - $counts = get_option( '_wl_sync_background_process_count', array( 0 ) ); |
|
| 18 | - $last_update = get_option( '_wl_sync_background_process_updated' ); |
|
| 19 | - |
|
| 20 | - // Calculate the overall index by adding the count of completed stages. |
|
| 21 | - $index = $offset + 1; |
|
| 22 | - for ( $i = 0; $i < $stage; $i ++ ) { |
|
| 23 | - $index += $counts[ $i ]; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - // Get the total count. |
|
| 27 | - $total_count = array_sum( $counts ); |
|
| 28 | - |
|
| 29 | - return new Sync_Background_Process_Info( $this->state, $started, $index, $total_count, $last_update ); |
|
| 30 | - } |
|
| 7 | + private $state; |
|
| 8 | + |
|
| 9 | + function __construct( $state ) { |
|
| 10 | + $this->state = $state; |
|
| 11 | + } |
|
| 12 | + |
|
| 13 | + function get_info() { |
|
| 14 | + $started = get_option( '_wl_sync_background_process_started' ); |
|
| 15 | + $offset = get_option( '_wl_sync_background_process_offset' ); |
|
| 16 | + $stage = get_option( '_wl_sync_background_process_stage' ); |
|
| 17 | + $counts = get_option( '_wl_sync_background_process_count', array( 0 ) ); |
|
| 18 | + $last_update = get_option( '_wl_sync_background_process_updated' ); |
|
| 19 | + |
|
| 20 | + // Calculate the overall index by adding the count of completed stages. |
|
| 21 | + $index = $offset + 1; |
|
| 22 | + for ( $i = 0; $i < $stage; $i ++ ) { |
|
| 23 | + $index += $counts[ $i ]; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + // Get the total count. |
|
| 27 | + $total_count = array_sum( $counts ); |
|
| 28 | + |
|
| 29 | + return new Sync_Background_Process_Info( $this->state, $started, $index, $total_count, $last_update ); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | } |
@@ -6,27 +6,27 @@ |
||
| 6 | 6 | |
| 7 | 7 | private $state; |
| 8 | 8 | |
| 9 | - function __construct( $state ) { |
|
| 9 | + function __construct($state) { |
|
| 10 | 10 | $this->state = $state; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | function get_info() { |
| 14 | - $started = get_option( '_wl_sync_background_process_started' ); |
|
| 15 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
| 16 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
| 17 | - $counts = get_option( '_wl_sync_background_process_count', array( 0 ) ); |
|
| 18 | - $last_update = get_option( '_wl_sync_background_process_updated' ); |
|
| 14 | + $started = get_option('_wl_sync_background_process_started'); |
|
| 15 | + $offset = get_option('_wl_sync_background_process_offset'); |
|
| 16 | + $stage = get_option('_wl_sync_background_process_stage'); |
|
| 17 | + $counts = get_option('_wl_sync_background_process_count', array(0)); |
|
| 18 | + $last_update = get_option('_wl_sync_background_process_updated'); |
|
| 19 | 19 | |
| 20 | 20 | // Calculate the overall index by adding the count of completed stages. |
| 21 | 21 | $index = $offset + 1; |
| 22 | - for ( $i = 0; $i < $stage; $i ++ ) { |
|
| 23 | - $index += $counts[ $i ]; |
|
| 22 | + for ($i = 0; $i < $stage; $i++) { |
|
| 23 | + $index += $counts[$i]; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Get the total count. |
| 27 | - $total_count = array_sum( $counts ); |
|
| 27 | + $total_count = array_sum($counts); |
|
| 28 | 28 | |
| 29 | - return new Sync_Background_Process_Info( $this->state, $started, $index, $total_count, $last_update ); |
|
| 29 | + return new Sync_Background_Process_Info($this->state, $started, $index, $total_count, $last_update); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | } |
@@ -4,24 +4,24 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface Sync_Background_Process_State { |
| 6 | 6 | |
| 7 | - function enter(); |
|
| 7 | + function enter(); |
|
| 8 | 8 | |
| 9 | - function leave(); |
|
| 9 | + function leave(); |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Task |
|
| 13 | - * |
|
| 14 | - * Override this method to perform any actions required on each |
|
| 15 | - * queue item. Return the modified item for further processing |
|
| 16 | - * in the next pass through. Or, return false to remove the |
|
| 17 | - * item from the queue. |
|
| 18 | - * |
|
| 19 | - * @param mixed $item Queue item to iterate over. |
|
| 20 | - * |
|
| 21 | - * @return mixed |
|
| 22 | - */ |
|
| 23 | - function task( $item ); |
|
| 11 | + /** |
|
| 12 | + * Task |
|
| 13 | + * |
|
| 14 | + * Override this method to perform any actions required on each |
|
| 15 | + * queue item. Return the modified item for further processing |
|
| 16 | + * in the next pass through. Or, return false to remove the |
|
| 17 | + * item from the queue. |
|
| 18 | + * |
|
| 19 | + * @param mixed $item Queue item to iterate over. |
|
| 20 | + * |
|
| 21 | + * @return mixed |
|
| 22 | + */ |
|
| 23 | + function task( $item ); |
|
| 24 | 24 | |
| 25 | - function get_info(); |
|
| 25 | + function get_info(); |
|
| 26 | 26 | |
| 27 | 27 | } |
| 28 | 28 | \ No newline at end of file |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | * |
| 21 | 21 | * @return mixed |
| 22 | 22 | */ |
| 23 | - function task( $item ); |
|
| 23 | + function task($item); |
|
| 24 | 24 | |
| 25 | 25 | function get_info(); |
| 26 | 26 | |
@@ -4,27 +4,27 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Sync_Background_Process_Info { |
| 6 | 6 | |
| 7 | - public $started; |
|
| 8 | - public $index; |
|
| 9 | - public $count; |
|
| 10 | - public $last_update; |
|
| 11 | - public $state; |
|
| 7 | + public $started; |
|
| 8 | + public $index; |
|
| 9 | + public $count; |
|
| 10 | + public $last_update; |
|
| 11 | + public $state; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Sync_Model constructor. |
|
| 15 | - * |
|
| 16 | - * @param $started |
|
| 17 | - * @param $index |
|
| 18 | - * @param $count |
|
| 19 | - * @param $last_update |
|
| 20 | - * @param $state |
|
| 21 | - */ |
|
| 22 | - public function __construct( $state, $started = null, $index = null, $count = null, $last_update = null ) { |
|
| 23 | - $this->started = $started; |
|
| 24 | - $this->index = $index; |
|
| 25 | - $this->count = (int) $count; |
|
| 26 | - $this->last_update = $last_update; |
|
| 27 | - $this->state = $state; |
|
| 28 | - } |
|
| 13 | + /** |
|
| 14 | + * Sync_Model constructor. |
|
| 15 | + * |
|
| 16 | + * @param $started |
|
| 17 | + * @param $index |
|
| 18 | + * @param $count |
|
| 19 | + * @param $last_update |
|
| 20 | + * @param $state |
|
| 21 | + */ |
|
| 22 | + public function __construct( $state, $started = null, $index = null, $count = null, $last_update = null ) { |
|
| 23 | + $this->started = $started; |
|
| 24 | + $this->index = $index; |
|
| 25 | + $this->count = (int) $count; |
|
| 26 | + $this->last_update = $last_update; |
|
| 27 | + $this->state = $state; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | * @param $last_update |
| 20 | 20 | * @param $state |
| 21 | 21 | */ |
| 22 | - public function __construct( $state, $started = null, $index = null, $count = null, $last_update = null ) { |
|
| 22 | + public function __construct($state, $started = null, $index = null, $count = null, $last_update = null) { |
|
| 23 | 23 | $this->started = $started; |
| 24 | 24 | $this->index = $index; |
| 25 | 25 | $this->count = (int) $count; |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface Sync_Background_Process_Stage { |
| 6 | 6 | |
| 7 | - function count(); |
|
| 7 | + function count(); |
|
| 8 | 8 | |
| 9 | - function get_sync_object_adapters( $offset, $batch_size ); |
|
| 9 | + function get_sync_object_adapters( $offset, $batch_size ); |
|
| 10 | 10 | |
| 11 | 11 | } |
@@ -6,6 +6,6 @@ |
||
| 6 | 6 | |
| 7 | 7 | function count(); |
| 8 | 8 | |
| 9 | - function get_sync_object_adapters( $offset, $batch_size ); |
|
| 9 | + function get_sync_object_adapters($offset, $batch_size); |
|
| 10 | 10 | |
| 11 | 11 | } |
@@ -7,42 +7,42 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class Sync_Background_Process_Terms_Stage { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @var Sync_Object_Adapter_Factory |
|
| 12 | - */ |
|
| 13 | - private $sync_object_adapter_factory; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * Sync_Background_Process_Posts_Stage constructor. |
|
| 17 | - * |
|
| 18 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
| 19 | - */ |
|
| 20 | - function __construct( $sync_object_adapter_factory ) { |
|
| 21 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - function count() { |
|
| 25 | - |
|
| 26 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
| 27 | - $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
| 28 | - |
|
| 29 | - global $wpdb; |
|
| 30 | - $sql = " |
|
| 10 | + /** |
|
| 11 | + * @var Sync_Object_Adapter_Factory |
|
| 12 | + */ |
|
| 13 | + private $sync_object_adapter_factory; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * Sync_Background_Process_Posts_Stage constructor. |
|
| 17 | + * |
|
| 18 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
| 19 | + */ |
|
| 20 | + function __construct( $sync_object_adapter_factory ) { |
|
| 21 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + function count() { |
|
| 25 | + |
|
| 26 | + $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
| 27 | + $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
| 28 | + |
|
| 29 | + global $wpdb; |
|
| 30 | + $sql = " |
|
| 31 | 31 | SELECT COUNT( 1 ) |
| 32 | 32 | FROM $wpdb->term_taxonomy |
| 33 | 33 | WHERE taxonomy IN ('$in_taxonomies') |
| 34 | 34 | "; |
| 35 | 35 | |
| 36 | - return $wpdb->get_var( $sql ); |
|
| 37 | - } |
|
| 36 | + return $wpdb->get_var( $sql ); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - function get_sync_object_adapters( $offset, $limit ) { |
|
| 39 | + function get_sync_object_adapters( $offset, $limit ) { |
|
| 40 | 40 | |
| 41 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
| 42 | - $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
| 41 | + $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
| 42 | + $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
| 43 | 43 | |
| 44 | - global $wpdb; |
|
| 45 | - $sql = " |
|
| 44 | + global $wpdb; |
|
| 45 | + $sql = " |
|
| 46 | 46 | SELECT term_id |
| 47 | 47 | FROM $wpdb->term_taxonomy |
| 48 | 48 | WHERE taxonomy IN ('$in_taxonomies') |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | LIMIT %d, %d |
| 51 | 51 | "; |
| 52 | 52 | |
| 53 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 53 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 54 | 54 | |
| 55 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids ); |
|
| 56 | - } |
|
| 55 | + return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids ); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | } |
@@ -17,14 +17,14 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
| 19 | 19 | */ |
| 20 | - function __construct( $sync_object_adapter_factory ) { |
|
| 20 | + function __construct($sync_object_adapter_factory) { |
|
| 21 | 21 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | function count() { |
| 25 | 25 | |
| 26 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
| 27 | - $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
| 26 | + $taxonomies = get_taxonomies(array('public' => true)); |
|
| 27 | + $in_taxonomies = implode("','", array_map('esc_sql', $taxonomies)); |
|
| 28 | 28 | |
| 29 | 29 | global $wpdb; |
| 30 | 30 | $sql = " |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | WHERE taxonomy IN ('$in_taxonomies') |
| 34 | 34 | "; |
| 35 | 35 | |
| 36 | - return $wpdb->get_var( $sql ); |
|
| 36 | + return $wpdb->get_var($sql); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - function get_sync_object_adapters( $offset, $limit ) { |
|
| 39 | + function get_sync_object_adapters($offset, $limit) { |
|
| 40 | 40 | |
| 41 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
| 42 | - $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
| 41 | + $taxonomies = get_taxonomies(array('public' => true)); |
|
| 42 | + $in_taxonomies = implode("','", array_map('esc_sql', $taxonomies)); |
|
| 43 | 43 | |
| 44 | 44 | global $wpdb; |
| 45 | 45 | $sql = " |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | LIMIT %d, %d |
| 51 | 51 | "; |
| 52 | 52 | |
| 53 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 53 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); |
|
| 54 | 54 | |
| 55 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids ); |
|
| 55 | + return $this->sync_object_adapter_factory->create_many(Object_Type_Enum::TERM, $ids); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | } |
@@ -8,49 +8,49 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class Sync_Background_Process_Posts_Stage { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var Sync_Object_Adapter_Factory |
|
| 13 | - */ |
|
| 14 | - private $sync_object_adapter_factory; |
|
| 11 | + /** |
|
| 12 | + * @var Sync_Object_Adapter_Factory |
|
| 13 | + */ |
|
| 14 | + private $sync_object_adapter_factory; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Sync_Background_Process_Posts_Stage constructor. |
|
| 18 | - * |
|
| 19 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
| 20 | - */ |
|
| 21 | - function __construct( $sync_object_adapter_factory ) { |
|
| 22 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * Sync_Background_Process_Posts_Stage constructor. |
|
| 18 | + * |
|
| 19 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
| 20 | + */ |
|
| 21 | + function __construct( $sync_object_adapter_factory ) { |
|
| 22 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - function count() { |
|
| 25 | + function count() { |
|
| 26 | 26 | |
| 27 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
| 27 | + $post_types = get_post_types( array( 'public' => true ) ); |
|
| 28 | 28 | |
| 29 | - global $wpdb; |
|
| 30 | - $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
| 31 | - $sql = " |
|
| 29 | + global $wpdb; |
|
| 30 | + $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
| 31 | + $sql = " |
|
| 32 | 32 | SELECT COUNT( 1 ) |
| 33 | 33 | FROM $wpdb->posts |
| 34 | 34 | WHERE post_type IN ('$in_post_type') |
| 35 | 35 | AND post_status IN ( 'publish', 'future', 'draft', 'pending', 'private' ) |
| 36 | 36 | "; |
| 37 | 37 | |
| 38 | - return $wpdb->get_var( $sql ); |
|
| 39 | - } |
|
| 38 | + return $wpdb->get_var( $sql ); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param int $offset |
|
| 43 | - * @param int $limit |
|
| 44 | - * |
|
| 45 | - * @return Sync_Object_Adapter[] |
|
| 46 | - */ |
|
| 47 | - function get_sync_object_adapters( $offset, $limit ) { |
|
| 41 | + /** |
|
| 42 | + * @param int $offset |
|
| 43 | + * @param int $limit |
|
| 44 | + * |
|
| 45 | + * @return Sync_Object_Adapter[] |
|
| 46 | + */ |
|
| 47 | + function get_sync_object_adapters( $offset, $limit ) { |
|
| 48 | 48 | |
| 49 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
| 49 | + $post_types = get_post_types( array( 'public' => true ) ); |
|
| 50 | 50 | |
| 51 | - global $wpdb; |
|
| 52 | - $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
| 53 | - $sql = " |
|
| 51 | + global $wpdb; |
|
| 52 | + $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
| 53 | + $sql = " |
|
| 54 | 54 | SELECT ID |
| 55 | 55 | FROM $wpdb->posts |
| 56 | 56 | WHERE post_type IN ('$in_post_type') |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | LIMIT %d, %d |
| 60 | 60 | "; |
| 61 | 61 | |
| 62 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 62 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 63 | 63 | |
| 64 | - return $this->sync_object_adapter_factory |
|
| 65 | - ->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) ); |
|
| 66 | - } |
|
| 64 | + return $this->sync_object_adapter_factory |
|
| 65 | + ->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) ); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -18,16 +18,16 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
| 20 | 20 | */ |
| 21 | - function __construct( $sync_object_adapter_factory ) { |
|
| 21 | + function __construct($sync_object_adapter_factory) { |
|
| 22 | 22 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | function count() { |
| 26 | 26 | |
| 27 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
| 27 | + $post_types = get_post_types(array('public' => true)); |
|
| 28 | 28 | |
| 29 | 29 | global $wpdb; |
| 30 | - $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
| 30 | + $in_post_type = implode("','", array_map('esc_sql', $post_types)); |
|
| 31 | 31 | $sql = " |
| 32 | 32 | SELECT COUNT( 1 ) |
| 33 | 33 | FROM $wpdb->posts |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | AND post_status IN ( 'publish', 'future', 'draft', 'pending', 'private' ) |
| 36 | 36 | "; |
| 37 | 37 | |
| 38 | - return $wpdb->get_var( $sql ); |
|
| 38 | + return $wpdb->get_var($sql); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -44,12 +44,12 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return Sync_Object_Adapter[] |
| 46 | 46 | */ |
| 47 | - function get_sync_object_adapters( $offset, $limit ) { |
|
| 47 | + function get_sync_object_adapters($offset, $limit) { |
|
| 48 | 48 | |
| 49 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
| 49 | + $post_types = get_post_types(array('public' => true)); |
|
| 50 | 50 | |
| 51 | 51 | global $wpdb; |
| 52 | - $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
| 52 | + $in_post_type = implode("','", array_map('esc_sql', $post_types)); |
|
| 53 | 53 | $sql = " |
| 54 | 54 | SELECT ID |
| 55 | 55 | FROM $wpdb->posts |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | LIMIT %d, %d |
| 60 | 60 | "; |
| 61 | 61 | |
| 62 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 62 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); |
|
| 63 | 63 | |
| 64 | 64 | return $this->sync_object_adapter_factory |
| 65 | - ->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) ); |
|
| 65 | + ->create_many(Object_Type_Enum::POST, array_map('intval', $ids)); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | } |
@@ -7,43 +7,43 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Sync_Background_Process_Users_Stage { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @var Sync_Object_Adapter_Factory |
|
| 12 | - */ |
|
| 13 | - private $sync_object_adapter_factory; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * Sync_Background_Process_Posts_Stage constructor. |
|
| 17 | - * |
|
| 18 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
| 19 | - */ |
|
| 20 | - function __construct( $sync_object_adapter_factory ) { |
|
| 21 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - function count() { |
|
| 25 | - |
|
| 26 | - global $wpdb; |
|
| 27 | - $sql = " |
|
| 10 | + /** |
|
| 11 | + * @var Sync_Object_Adapter_Factory |
|
| 12 | + */ |
|
| 13 | + private $sync_object_adapter_factory; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * Sync_Background_Process_Posts_Stage constructor. |
|
| 17 | + * |
|
| 18 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
| 19 | + */ |
|
| 20 | + function __construct( $sync_object_adapter_factory ) { |
|
| 21 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + function count() { |
|
| 25 | + |
|
| 26 | + global $wpdb; |
|
| 27 | + $sql = " |
|
| 28 | 28 | SELECT COUNT( 1 ) |
| 29 | 29 | FROM $wpdb->users |
| 30 | 30 | "; |
| 31 | 31 | |
| 32 | - return $wpdb->get_var( $sql ); |
|
| 33 | - } |
|
| 32 | + return $wpdb->get_var( $sql ); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - function get_sync_object_adapters( $offset, $limit ) { |
|
| 35 | + function get_sync_object_adapters( $offset, $limit ) { |
|
| 36 | 36 | |
| 37 | - global $wpdb; |
|
| 38 | - $sql = " |
|
| 37 | + global $wpdb; |
|
| 38 | + $sql = " |
|
| 39 | 39 | SELECT ID |
| 40 | 40 | FROM $wpdb->users |
| 41 | 41 | LIMIT %d, %d |
| 42 | 42 | "; |
| 43 | 43 | |
| 44 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 44 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 45 | 45 | |
| 46 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
| 47 | - } |
|
| 46 | + return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
| 19 | 19 | */ |
| 20 | - function __construct( $sync_object_adapter_factory ) { |
|
| 20 | + function __construct($sync_object_adapter_factory) { |
|
| 21 | 21 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | FROM $wpdb->users |
| 30 | 30 | "; |
| 31 | 31 | |
| 32 | - return $wpdb->get_var( $sql ); |
|
| 32 | + return $wpdb->get_var($sql); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - function get_sync_object_adapters( $offset, $limit ) { |
|
| 35 | + function get_sync_object_adapters($offset, $limit) { |
|
| 36 | 36 | |
| 37 | 37 | global $wpdb; |
| 38 | 38 | $sql = " |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | LIMIT %d, %d |
| 42 | 42 | "; |
| 43 | 43 | |
| 44 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); |
|
| 44 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); |
|
| 45 | 45 | |
| 46 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
| 46 | + return $this->sync_object_adapter_factory->create_many(Object_Type_Enum::USER, $ids); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | } |