@@ -15,62 +15,62 @@ |
||
15 | 15 | */ |
16 | 16 | class Sync_Hooks_Entity_Relation { |
17 | 17 | |
18 | - /** |
|
19 | - * @var \Wordlift_Entity_Service |
|
20 | - */ |
|
21 | - private $entity_service; |
|
22 | - |
|
23 | - /** |
|
24 | - * Entity_Dct_Relation constructor. |
|
25 | - * |
|
26 | - * @param $entity_service \Wordlift_Entity_Service |
|
27 | - */ |
|
28 | - public function __construct( $entity_service ) { |
|
29 | - $this->entity_service = $entity_service; |
|
30 | - |
|
31 | - add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 ); |
|
32 | - } |
|
33 | - |
|
34 | - public function jsonld( $jsonld, $type, $post_id ) { |
|
35 | - |
|
36 | - // @@todo add support anything that isn't a POST. |
|
37 | - if ( Object_Type_Enum::POST !== $type ) { |
|
38 | - return $jsonld; |
|
39 | - } |
|
40 | - |
|
41 | - // Choose the dcterm property according to the post type. |
|
42 | - $property = $this->entity_service->is_entity( $post_id ) |
|
43 | - ? 'http://purl.org/dc/terms/relation' |
|
44 | - : 'http://purl.org/dc/terms/references'; |
|
45 | - |
|
46 | - $references = array_unique( $this->entity_service->get_related_entities( $post_id ) ); |
|
47 | - |
|
48 | - // Bail out if there are no references. |
|
49 | - if ( empty( $references ) ) { |
|
50 | - return $jsonld; |
|
51 | - } |
|
52 | - |
|
53 | - if ( ! isset( $jsonld[0][ $property ] ) ) { |
|
54 | - $jsonld[0][ $property ] = array(); |
|
55 | - } |
|
56 | - |
|
57 | - if ( ! is_array( $jsonld[0][ $property ] ) ) { |
|
58 | - $jsonld[0][ $property ] = array( $jsonld[0][ $property ] ); |
|
59 | - } |
|
60 | - |
|
61 | - $that = $this; |
|
62 | - $references_array = array_values( |
|
63 | - array_map( |
|
64 | - function ( $item ) use ( $that ) { |
|
65 | - return array( '@id' => $that->entity_service->get_uri( $item ) ); |
|
66 | - }, |
|
67 | - $references |
|
68 | - ) |
|
69 | - ); |
|
70 | - |
|
71 | - $jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array ); |
|
72 | - |
|
73 | - return $jsonld; |
|
74 | - } |
|
18 | + /** |
|
19 | + * @var \Wordlift_Entity_Service |
|
20 | + */ |
|
21 | + private $entity_service; |
|
22 | + |
|
23 | + /** |
|
24 | + * Entity_Dct_Relation constructor. |
|
25 | + * |
|
26 | + * @param $entity_service \Wordlift_Entity_Service |
|
27 | + */ |
|
28 | + public function __construct( $entity_service ) { |
|
29 | + $this->entity_service = $entity_service; |
|
30 | + |
|
31 | + add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 ); |
|
32 | + } |
|
33 | + |
|
34 | + public function jsonld( $jsonld, $type, $post_id ) { |
|
35 | + |
|
36 | + // @@todo add support anything that isn't a POST. |
|
37 | + if ( Object_Type_Enum::POST !== $type ) { |
|
38 | + return $jsonld; |
|
39 | + } |
|
40 | + |
|
41 | + // Choose the dcterm property according to the post type. |
|
42 | + $property = $this->entity_service->is_entity( $post_id ) |
|
43 | + ? 'http://purl.org/dc/terms/relation' |
|
44 | + : 'http://purl.org/dc/terms/references'; |
|
45 | + |
|
46 | + $references = array_unique( $this->entity_service->get_related_entities( $post_id ) ); |
|
47 | + |
|
48 | + // Bail out if there are no references. |
|
49 | + if ( empty( $references ) ) { |
|
50 | + return $jsonld; |
|
51 | + } |
|
52 | + |
|
53 | + if ( ! isset( $jsonld[0][ $property ] ) ) { |
|
54 | + $jsonld[0][ $property ] = array(); |
|
55 | + } |
|
56 | + |
|
57 | + if ( ! is_array( $jsonld[0][ $property ] ) ) { |
|
58 | + $jsonld[0][ $property ] = array( $jsonld[0][ $property ] ); |
|
59 | + } |
|
60 | + |
|
61 | + $that = $this; |
|
62 | + $references_array = array_values( |
|
63 | + array_map( |
|
64 | + function ( $item ) use ( $that ) { |
|
65 | + return array( '@id' => $that->entity_service->get_uri( $item ) ); |
|
66 | + }, |
|
67 | + $references |
|
68 | + ) |
|
69 | + ); |
|
70 | + |
|
71 | + $jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array ); |
|
72 | + |
|
73 | + return $jsonld; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -25,50 +25,50 @@ |
||
25 | 25 | * |
26 | 26 | * @param $entity_service \Wordlift_Entity_Service |
27 | 27 | */ |
28 | - public function __construct( $entity_service ) { |
|
28 | + public function __construct($entity_service) { |
|
29 | 29 | $this->entity_service = $entity_service; |
30 | 30 | |
31 | - add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 ); |
|
31 | + add_filter('wl_dataset__sync_service__sync_item__jsonld', array($this, 'jsonld'), 10, 3); |
|
32 | 32 | } |
33 | 33 | |
34 | - public function jsonld( $jsonld, $type, $post_id ) { |
|
34 | + public function jsonld($jsonld, $type, $post_id) { |
|
35 | 35 | |
36 | 36 | // @@todo add support anything that isn't a POST. |
37 | - if ( Object_Type_Enum::POST !== $type ) { |
|
37 | + if (Object_Type_Enum::POST !== $type) { |
|
38 | 38 | return $jsonld; |
39 | 39 | } |
40 | 40 | |
41 | 41 | // Choose the dcterm property according to the post type. |
42 | - $property = $this->entity_service->is_entity( $post_id ) |
|
42 | + $property = $this->entity_service->is_entity($post_id) |
|
43 | 43 | ? 'http://purl.org/dc/terms/relation' |
44 | 44 | : 'http://purl.org/dc/terms/references'; |
45 | 45 | |
46 | - $references = array_unique( $this->entity_service->get_related_entities( $post_id ) ); |
|
46 | + $references = array_unique($this->entity_service->get_related_entities($post_id)); |
|
47 | 47 | |
48 | 48 | // Bail out if there are no references. |
49 | - if ( empty( $references ) ) { |
|
49 | + if (empty($references)) { |
|
50 | 50 | return $jsonld; |
51 | 51 | } |
52 | 52 | |
53 | - if ( ! isset( $jsonld[0][ $property ] ) ) { |
|
54 | - $jsonld[0][ $property ] = array(); |
|
53 | + if ( ! isset($jsonld[0][$property])) { |
|
54 | + $jsonld[0][$property] = array(); |
|
55 | 55 | } |
56 | 56 | |
57 | - if ( ! is_array( $jsonld[0][ $property ] ) ) { |
|
58 | - $jsonld[0][ $property ] = array( $jsonld[0][ $property ] ); |
|
57 | + if ( ! is_array($jsonld[0][$property])) { |
|
58 | + $jsonld[0][$property] = array($jsonld[0][$property]); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $that = $this; |
62 | 62 | $references_array = array_values( |
63 | 63 | array_map( |
64 | - function ( $item ) use ( $that ) { |
|
65 | - return array( '@id' => $that->entity_service->get_uri( $item ) ); |
|
64 | + function($item) use ($that) { |
|
65 | + return array('@id' => $that->entity_service->get_uri($item)); |
|
66 | 66 | }, |
67 | 67 | $references |
68 | 68 | ) |
69 | 69 | ); |
70 | 70 | |
71 | - $jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array ); |
|
71 | + $jsonld[0][$property] = array_merge($jsonld[0][$property], $references_array); |
|
72 | 72 | |
73 | 73 | return $jsonld; |
74 | 74 | } |
@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | abstract class Abstract_Sync_Hooks { |
6 | 6 | |
7 | - private $queue = array(); |
|
7 | + private $queue = array(); |
|
8 | 8 | |
9 | - public function __construct() { |
|
9 | + public function __construct() { |
|
10 | 10 | |
11 | - // To sync at the end of the usual WordPress lifecycle |
|
12 | - add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
11 | + // To sync at the end of the usual WordPress lifecycle |
|
12 | + add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
13 | 13 | |
14 | - } |
|
14 | + } |
|
15 | 15 | |
16 | - protected function enqueue( $item ) { |
|
16 | + protected function enqueue( $item ) { |
|
17 | 17 | |
18 | - if ( empty( $this->queue ) || $item !== $this->queue[ count( $this->queue ) - 1 ] ) { |
|
19 | - $this->queue[] = $item; |
|
20 | - } |
|
18 | + if ( empty( $this->queue ) || $item !== $this->queue[ count( $this->queue ) - 1 ] ) { |
|
19 | + $this->queue[] = $item; |
|
20 | + } |
|
21 | 21 | |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function shutdown() { |
|
25 | - foreach ( $this->queue as $callback ) { |
|
26 | - call_user_func( array( $this, $callback[0] ), $callback[1] ); |
|
27 | - } |
|
28 | - } |
|
24 | + public function shutdown() { |
|
25 | + foreach ( $this->queue as $callback ) { |
|
26 | + call_user_func( array( $this, $callback[0] ), $callback[1] ); |
|
27 | + } |
|
28 | + } |
|
29 | 29 | |
30 | 30 | } |
@@ -9,21 +9,21 @@ |
||
9 | 9 | public function __construct() { |
10 | 10 | |
11 | 11 | // To sync at the end of the usual WordPress lifecycle |
12 | - add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
12 | + add_action('shutdown', array($this, 'shutdown')); |
|
13 | 13 | |
14 | 14 | } |
15 | 15 | |
16 | - protected function enqueue( $item ) { |
|
16 | + protected function enqueue($item) { |
|
17 | 17 | |
18 | - if ( empty( $this->queue ) || $item !== $this->queue[ count( $this->queue ) - 1 ] ) { |
|
18 | + if (empty($this->queue) || $item !== $this->queue[count($this->queue) - 1]) { |
|
19 | 19 | $this->queue[] = $item; |
20 | 20 | } |
21 | 21 | |
22 | 22 | } |
23 | 23 | |
24 | 24 | public function shutdown() { |
25 | - foreach ( $this->queue as $callback ) { |
|
26 | - call_user_func( array( $this, $callback[0] ), $callback[1] ); |
|
25 | + foreach ($this->queue as $callback) { |
|
26 | + call_user_func(array($this, $callback[0]), $callback[1]); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 |
@@ -4,33 +4,33 @@ |
||
4 | 4 | |
5 | 5 | abstract class Abstract_Sync_Background_Process_State implements Sync_Background_Process_State { |
6 | 6 | |
7 | - private $state; |
|
8 | - |
|
9 | - public function __construct( $state ) { |
|
10 | - $this->state = $state; |
|
11 | - } |
|
12 | - |
|
13 | - public 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 | - |
|
32 | - public function resume() { |
|
33 | - // do nothing. |
|
34 | - } |
|
7 | + private $state; |
|
8 | + |
|
9 | + public function __construct( $state ) { |
|
10 | + $this->state = $state; |
|
11 | + } |
|
12 | + |
|
13 | + public 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 | + |
|
32 | + public function resume() { |
|
33 | + // do nothing. |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | private $state; |
8 | 8 | |
9 | - public function __construct( $state ) { |
|
9 | + public function __construct($state) { |
|
10 | 10 | $this->state = $state; |
11 | 11 | } |
12 | 12 | |
13 | 13 | public 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 | public function resume() { |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | interface Sync_Background_Process_State { |
6 | 6 | |
7 | - public function enter(); |
|
8 | - |
|
9 | - public function leave(); |
|
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 | - public function task( $item ); |
|
24 | - |
|
25 | - public function get_info(); |
|
26 | - |
|
27 | - /** |
|
28 | - * Try to resume an interrupted task. |
|
29 | - */ |
|
30 | - public function resume(); |
|
7 | + public function enter(); |
|
8 | + |
|
9 | + public function leave(); |
|
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 | + public function task( $item ); |
|
24 | + |
|
25 | + public function get_info(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Try to resume an interrupted task. |
|
29 | + */ |
|
30 | + public function resume(); |
|
31 | 31 | |
32 | 32 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | * |
21 | 21 | * @return mixed |
22 | 22 | */ |
23 | - public function task( $item ); |
|
23 | + public function task($item); |
|
24 | 24 | |
25 | 25 | public function get_info(); |
26 | 26 |
@@ -6,82 +6,82 @@ |
||
6 | 6 | |
7 | 7 | class Sync_Background_Process_Wpjson_Endpoint { |
8 | 8 | |
9 | - /** |
|
10 | - * @var Sync_Background_Process |
|
11 | - */ |
|
12 | - private $sync_background_process; |
|
13 | - |
|
14 | - /** |
|
15 | - * Sync_Background_Process_Wpjson_Endpoint constructor. |
|
16 | - * |
|
17 | - * @param Sync_Background_Process $sync_background_process |
|
18 | - */ |
|
19 | - public function __construct( $sync_background_process ) { |
|
20 | - |
|
21 | - add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
22 | - |
|
23 | - $this->sync_background_process = $sync_background_process; |
|
24 | - |
|
25 | - } |
|
26 | - |
|
27 | - public function rest_api_init() { |
|
28 | - |
|
29 | - register_rest_route( |
|
30 | - 'wordlift/v1', |
|
31 | - '/dataset/background/sync', |
|
32 | - array( |
|
33 | - 'methods' => WP_REST_Server::CREATABLE, |
|
34 | - 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | - 'permission_callback' => function () { |
|
36 | - $user = wp_get_current_user(); |
|
37 | - |
|
38 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
39 | - }, |
|
40 | - ) |
|
41 | - ); |
|
42 | - |
|
43 | - register_rest_route( |
|
44 | - 'wordlift/v1', |
|
45 | - '/dataset/background/sync', |
|
46 | - array( |
|
47 | - 'methods' => WP_REST_Server::READABLE, |
|
48 | - 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | - 'permission_callback' => function () { |
|
50 | - $user = wp_get_current_user(); |
|
51 | - |
|
52 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
53 | - }, |
|
54 | - ) |
|
55 | - ); |
|
56 | - |
|
57 | - register_rest_route( |
|
58 | - 'wordlift/v1', |
|
59 | - '/dataset/background/sync', |
|
60 | - array( |
|
61 | - 'methods' => WP_REST_Server::DELETABLE, |
|
62 | - 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | - 'permission_callback' => function () { |
|
64 | - $user = wp_get_current_user(); |
|
65 | - |
|
66 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
67 | - }, |
|
68 | - ) |
|
69 | - ); |
|
70 | - |
|
71 | - register_rest_route( |
|
72 | - 'wordlift/v1', |
|
73 | - '/dataset/background/sync', |
|
74 | - array( |
|
75 | - 'methods' => 'PUT', |
|
76 | - 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | - 'permission_callback' => function () { |
|
78 | - $user = wp_get_current_user(); |
|
79 | - |
|
80 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
81 | - }, |
|
82 | - ) |
|
83 | - ); |
|
84 | - |
|
85 | - } |
|
9 | + /** |
|
10 | + * @var Sync_Background_Process |
|
11 | + */ |
|
12 | + private $sync_background_process; |
|
13 | + |
|
14 | + /** |
|
15 | + * Sync_Background_Process_Wpjson_Endpoint constructor. |
|
16 | + * |
|
17 | + * @param Sync_Background_Process $sync_background_process |
|
18 | + */ |
|
19 | + public function __construct( $sync_background_process ) { |
|
20 | + |
|
21 | + add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
22 | + |
|
23 | + $this->sync_background_process = $sync_background_process; |
|
24 | + |
|
25 | + } |
|
26 | + |
|
27 | + public function rest_api_init() { |
|
28 | + |
|
29 | + register_rest_route( |
|
30 | + 'wordlift/v1', |
|
31 | + '/dataset/background/sync', |
|
32 | + array( |
|
33 | + 'methods' => WP_REST_Server::CREATABLE, |
|
34 | + 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | + 'permission_callback' => function () { |
|
36 | + $user = wp_get_current_user(); |
|
37 | + |
|
38 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
39 | + }, |
|
40 | + ) |
|
41 | + ); |
|
42 | + |
|
43 | + register_rest_route( |
|
44 | + 'wordlift/v1', |
|
45 | + '/dataset/background/sync', |
|
46 | + array( |
|
47 | + 'methods' => WP_REST_Server::READABLE, |
|
48 | + 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | + 'permission_callback' => function () { |
|
50 | + $user = wp_get_current_user(); |
|
51 | + |
|
52 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
53 | + }, |
|
54 | + ) |
|
55 | + ); |
|
56 | + |
|
57 | + register_rest_route( |
|
58 | + 'wordlift/v1', |
|
59 | + '/dataset/background/sync', |
|
60 | + array( |
|
61 | + 'methods' => WP_REST_Server::DELETABLE, |
|
62 | + 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | + 'permission_callback' => function () { |
|
64 | + $user = wp_get_current_user(); |
|
65 | + |
|
66 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
67 | + }, |
|
68 | + ) |
|
69 | + ); |
|
70 | + |
|
71 | + register_rest_route( |
|
72 | + 'wordlift/v1', |
|
73 | + '/dataset/background/sync', |
|
74 | + array( |
|
75 | + 'methods' => 'PUT', |
|
76 | + 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | + 'permission_callback' => function () { |
|
78 | + $user = wp_get_current_user(); |
|
79 | + |
|
80 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
81 | + }, |
|
82 | + ) |
|
83 | + ); |
|
84 | + |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @param Sync_Background_Process $sync_background_process |
18 | 18 | */ |
19 | - public function __construct( $sync_background_process ) { |
|
19 | + public 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 | |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | '/dataset/background/sync', |
32 | 32 | array( |
33 | 33 | 'methods' => WP_REST_Server::CREATABLE, |
34 | - 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | - 'permission_callback' => function () { |
|
34 | + 'callback' => array($this->sync_background_process, 'start'), |
|
35 | + 'permission_callback' => function() { |
|
36 | 36 | $user = wp_get_current_user(); |
37 | 37 | |
38 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
38 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
39 | 39 | }, |
40 | 40 | ) |
41 | 41 | ); |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | '/dataset/background/sync', |
46 | 46 | array( |
47 | 47 | 'methods' => WP_REST_Server::READABLE, |
48 | - 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | - 'permission_callback' => function () { |
|
48 | + 'callback' => array($this->sync_background_process, 'get_info'), |
|
49 | + 'permission_callback' => function() { |
|
50 | 50 | $user = wp_get_current_user(); |
51 | 51 | |
52 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
52 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
53 | 53 | }, |
54 | 54 | ) |
55 | 55 | ); |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | '/dataset/background/sync', |
60 | 60 | array( |
61 | 61 | 'methods' => WP_REST_Server::DELETABLE, |
62 | - 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | - 'permission_callback' => function () { |
|
62 | + 'callback' => array($this->sync_background_process, 'stop'), |
|
63 | + 'permission_callback' => function() { |
|
64 | 64 | $user = wp_get_current_user(); |
65 | 65 | |
66 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
66 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
67 | 67 | }, |
68 | 68 | ) |
69 | 69 | ); |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | '/dataset/background/sync', |
74 | 74 | array( |
75 | 75 | 'methods' => 'PUT', |
76 | - 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | - 'permission_callback' => function () { |
|
76 | + 'callback' => array($this->sync_background_process, 'resume'), |
|
77 | + 'permission_callback' => function() { |
|
78 | 78 | $user = wp_get_current_user(); |
79 | 79 | |
80 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
80 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
81 | 81 | }, |
82 | 82 | ) |
83 | 83 | ); |
@@ -18,116 +18,116 @@ |
||
18 | 18 | */ |
19 | 19 | class Sync_Background_Process extends \Wordlift_Plugin_WP_Background_Process { |
20 | 20 | |
21 | - const STATE_STARTED = 'started'; |
|
22 | - const STATE_STOPPED = 'stopped'; |
|
23 | - |
|
24 | - protected $action = 'wl_dataset__sync'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var Sync_Service |
|
28 | - */ |
|
29 | - private $sync_service; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var Sync_Object_Adapter_Factory |
|
33 | - */ |
|
34 | - private $sync_object_adapter_factory; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var \Wordlift_Log_Service |
|
38 | - */ |
|
39 | - private $log; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var Sync_Background_Process_State |
|
43 | - */ |
|
44 | - private $state; |
|
45 | - |
|
46 | - /** |
|
47 | - * Sync_Background_Process constructor. |
|
48 | - * |
|
49 | - * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
|
50 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
51 | - */ |
|
52 | - public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
53 | - parent::__construct(); |
|
54 | - |
|
55 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
56 | - |
|
57 | - $this->sync_service = $sync_service; |
|
58 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
59 | - |
|
60 | - // Set the current state. |
|
61 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
62 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
63 | - } else { |
|
64 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
65 | - } |
|
66 | - |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * This function is called: |
|
71 | - * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
72 | - * - To synchronize a post, by passing a numeric ID. |
|
73 | - * |
|
74 | - * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
75 | - * |
|
76 | - * @param mixed $item Queue item to iterate over. |
|
77 | - * |
|
78 | - * @return int[]|false The next post IDs or false if there are no more. |
|
79 | - */ |
|
80 | - protected function task( $item ) { |
|
81 | - |
|
82 | - return $this->state->task( $item ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Transition to the started state. |
|
87 | - */ |
|
88 | - public function start() { |
|
89 | - $this->state->leave(); |
|
90 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
91 | - $this->state->enter(); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Transition to the stopped state. |
|
96 | - */ |
|
97 | - public function stop() { |
|
98 | - $this->state->leave(); |
|
99 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
100 | - $this->state->enter(); |
|
101 | - } |
|
102 | - |
|
103 | - public function resume() { |
|
104 | - $this->state->resume(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Get the current state. |
|
109 | - * |
|
110 | - * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
111 | - */ |
|
112 | - public function get_state() { |
|
113 | - return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Persist the current state. |
|
118 | - * |
|
119 | - * @param string $value |
|
120 | - * |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function set_state( $value ) { |
|
124 | - return null === $value |
|
125 | - ? delete_option( '_wl_sync_background_process_state' ) |
|
126 | - : update_option( '_wl_sync_background_process_state', $value, true ); |
|
127 | - } |
|
128 | - |
|
129 | - public function get_info() { |
|
130 | - return $this->state->get_info(); |
|
131 | - } |
|
21 | + const STATE_STARTED = 'started'; |
|
22 | + const STATE_STOPPED = 'stopped'; |
|
23 | + |
|
24 | + protected $action = 'wl_dataset__sync'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var Sync_Service |
|
28 | + */ |
|
29 | + private $sync_service; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var Sync_Object_Adapter_Factory |
|
33 | + */ |
|
34 | + private $sync_object_adapter_factory; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var \Wordlift_Log_Service |
|
38 | + */ |
|
39 | + private $log; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var Sync_Background_Process_State |
|
43 | + */ |
|
44 | + private $state; |
|
45 | + |
|
46 | + /** |
|
47 | + * Sync_Background_Process constructor. |
|
48 | + * |
|
49 | + * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
|
50 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
51 | + */ |
|
52 | + public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
53 | + parent::__construct(); |
|
54 | + |
|
55 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
56 | + |
|
57 | + $this->sync_service = $sync_service; |
|
58 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
59 | + |
|
60 | + // Set the current state. |
|
61 | + if ( self::STATE_STARTED === $this->get_state() ) { |
|
62 | + $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
63 | + } else { |
|
64 | + $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
65 | + } |
|
66 | + |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * This function is called: |
|
71 | + * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
72 | + * - To synchronize a post, by passing a numeric ID. |
|
73 | + * |
|
74 | + * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
75 | + * |
|
76 | + * @param mixed $item Queue item to iterate over. |
|
77 | + * |
|
78 | + * @return int[]|false The next post IDs or false if there are no more. |
|
79 | + */ |
|
80 | + protected function task( $item ) { |
|
81 | + |
|
82 | + return $this->state->task( $item ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Transition to the started state. |
|
87 | + */ |
|
88 | + public function start() { |
|
89 | + $this->state->leave(); |
|
90 | + $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
91 | + $this->state->enter(); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Transition to the stopped state. |
|
96 | + */ |
|
97 | + public function stop() { |
|
98 | + $this->state->leave(); |
|
99 | + $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
100 | + $this->state->enter(); |
|
101 | + } |
|
102 | + |
|
103 | + public function resume() { |
|
104 | + $this->state->resume(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Get the current state. |
|
109 | + * |
|
110 | + * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
111 | + */ |
|
112 | + public function get_state() { |
|
113 | + return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Persist the current state. |
|
118 | + * |
|
119 | + * @param string $value |
|
120 | + * |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function set_state( $value ) { |
|
124 | + return null === $value |
|
125 | + ? delete_option( '_wl_sync_background_process_state' ) |
|
126 | + : update_option( '_wl_sync_background_process_state', $value, true ); |
|
127 | + } |
|
128 | + |
|
129 | + public function get_info() { |
|
130 | + return $this->state->get_info(); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | } |
@@ -49,19 +49,19 @@ discard block |
||
49 | 49 | * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
50 | 50 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
51 | 51 | */ |
52 | - public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
52 | + public function __construct($sync_service, $sync_object_adapter_factory) { |
|
53 | 53 | parent::__construct(); |
54 | 54 | |
55 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
55 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
56 | 56 | |
57 | 57 | $this->sync_service = $sync_service; |
58 | 58 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
59 | 59 | |
60 | 60 | // Set the current state. |
61 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
62 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
61 | + if (self::STATE_STARTED === $this->get_state()) { |
|
62 | + $this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory); |
|
63 | 63 | } else { |
64 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
64 | + $this->state = new Sync_Background_Process_Stopped_State($this); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return int[]|false The next post IDs or false if there are no more. |
79 | 79 | */ |
80 | - protected function task( $item ) { |
|
80 | + protected function task($item) { |
|
81 | 81 | |
82 | - return $this->state->task( $item ); |
|
82 | + return $this->state->task($item); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function start() { |
89 | 89 | $this->state->leave(); |
90 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
90 | + $this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory); |
|
91 | 91 | $this->state->enter(); |
92 | 92 | } |
93 | 93 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function stop() { |
98 | 98 | $this->state->leave(); |
99 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
99 | + $this->state = new Sync_Background_Process_Stopped_State($this); |
|
100 | 100 | $this->state->enter(); |
101 | 101 | } |
102 | 102 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
111 | 111 | */ |
112 | 112 | public function get_state() { |
113 | - return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
113 | + return get_option('_wl_sync_background_process_state', self::STATE_STOPPED); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return bool |
122 | 122 | */ |
123 | - public function set_state( $value ) { |
|
123 | + public function set_state($value) { |
|
124 | 124 | return null === $value |
125 | - ? delete_option( '_wl_sync_background_process_state' ) |
|
126 | - : update_option( '_wl_sync_background_process_state', $value, true ); |
|
125 | + ? delete_option('_wl_sync_background_process_state') |
|
126 | + : update_option('_wl_sync_background_process_state', $value, true); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | public function get_info() { |
@@ -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 | - public function __construct( $sync_object_adapter_factory ) { |
|
21 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
22 | - } |
|
23 | - |
|
24 | - public 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 | + public function __construct( $sync_object_adapter_factory ) { |
|
21 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
22 | + } |
|
23 | + |
|
24 | + public 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 ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
37 | - } |
|
36 | + return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
37 | + } |
|
38 | 38 | |
39 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
39 | + public 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 ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
53 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
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 | - public function __construct( $sync_object_adapter_factory ) { |
|
20 | + public function __construct($sync_object_adapter_factory) { |
|
21 | 21 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
22 | 22 | } |
23 | 23 | |
24 | 24 | public 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 ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
36 | + return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
37 | 37 | } |
38 | 38 | |
39 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
39 | + public 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 ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
53 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
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 | - public 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 | + public function __construct( $sync_object_adapter_factory ) { |
|
22 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
23 | + } |
|
24 | 24 | |
25 | - public function count() { |
|
25 | + public 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 ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
39 | - } |
|
38 | + return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param int $offset |
|
43 | - * @param int $limit |
|
44 | - * |
|
45 | - * @return Sync_Object_Adapter[] |
|
46 | - */ |
|
47 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
41 | + /** |
|
42 | + * @param int $offset |
|
43 | + * @param int $limit |
|
44 | + * |
|
45 | + * @return Sync_Object_Adapter[] |
|
46 | + */ |
|
47 | + public 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 ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
62 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
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 | - public function __construct( $sync_object_adapter_factory ) { |
|
21 | + public function __construct($sync_object_adapter_factory) { |
|
22 | 22 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
23 | 23 | } |
24 | 24 | |
25 | 25 | public 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 ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
38 | + return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return Sync_Object_Adapter[] |
46 | 46 | */ |
47 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
47 | + public 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 ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
62 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
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,39 +7,39 @@ discard block |
||
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; |
|
10 | + /** |
|
11 | + * @var Sync_Object_Adapter_Factory |
|
12 | + */ |
|
13 | + private $sync_object_adapter_factory; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Sync_Background_Process_Posts_Stage constructor. |
|
17 | - * |
|
18 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
19 | - */ |
|
20 | - public function __construct( $sync_object_adapter_factory ) { |
|
21 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
22 | - } |
|
15 | + /** |
|
16 | + * Sync_Background_Process_Posts_Stage constructor. |
|
17 | + * |
|
18 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
19 | + */ |
|
20 | + public function __construct( $sync_object_adapter_factory ) { |
|
21 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
22 | + } |
|
23 | 23 | |
24 | - public function count() { |
|
24 | + public function count() { |
|
25 | 25 | |
26 | - global $wpdb; |
|
27 | - $in_post_type = $this->get_post_types_string(); |
|
28 | - $sql = " |
|
26 | + global $wpdb; |
|
27 | + $in_post_type = $this->get_post_types_string(); |
|
28 | + $sql = " |
|
29 | 29 | SELECT COUNT( DISTINCT post_author ) |
30 | 30 | FROM $wpdb->posts |
31 | 31 | WHERE post_type IN ('$in_post_type') |
32 | 32 | AND post_status IN ( 'publish', 'future', 'draft', 'pending', 'private' ) |
33 | 33 | "; |
34 | 34 | |
35 | - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
36 | - } |
|
35 | + return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
36 | + } |
|
37 | 37 | |
38 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
38 | + public function get_sync_object_adapters( $offset, $limit ) { |
|
39 | 39 | |
40 | - global $wpdb; |
|
41 | - $in_post_type = $this->get_post_types_string(); |
|
42 | - $sql = " |
|
40 | + global $wpdb; |
|
41 | + $in_post_type = $this->get_post_types_string(); |
|
42 | + $sql = " |
|
43 | 43 | SELECT DISTINCT post_author |
44 | 44 | FROM $wpdb->posts |
45 | 45 | WHERE post_type IN ('$in_post_type') |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | LIMIT %d, %d |
48 | 48 | "; |
49 | 49 | |
50 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
50 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
51 | 51 | |
52 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
53 | - } |
|
52 | + return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected function get_post_types_string() { |
|
59 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
55 | + /** |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected function get_post_types_string() { |
|
59 | + $post_types = get_post_types( array( 'public' => true ) ); |
|
60 | 60 | |
61 | - return implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
62 | - } |
|
61 | + return implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
19 | 19 | */ |
20 | - public function __construct( $sync_object_adapter_factory ) { |
|
20 | + public function __construct($sync_object_adapter_factory) { |
|
21 | 21 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
22 | 22 | } |
23 | 23 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | AND post_status IN ( 'publish', 'future', 'draft', 'pending', 'private' ) |
33 | 33 | "; |
34 | 34 | |
35 | - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
35 | + return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
36 | 36 | } |
37 | 37 | |
38 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
38 | + public function get_sync_object_adapters($offset, $limit) { |
|
39 | 39 | |
40 | 40 | global $wpdb; |
41 | 41 | $in_post_type = $this->get_post_types_string(); |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | LIMIT %d, %d |
48 | 48 | "; |
49 | 49 | |
50 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
50 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
51 | 51 | |
52 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
52 | + return $this->sync_object_adapter_factory->create_many(Object_Type_Enum::USER, $ids); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @return string |
57 | 57 | */ |
58 | 58 | protected function get_post_types_string() { |
59 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
59 | + $post_types = get_post_types(array('public' => true)); |
|
60 | 60 | |
61 | - return implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
61 | + return implode("','", array_map('esc_sql', $post_types)); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | } |