@@ -19,72 +19,72 @@ |
||
19 | 19 | */ |
20 | 20 | class Url_To_Entity_Transform_Function implements Mappings_Transform_Function { |
21 | 21 | |
22 | - /** |
|
23 | - * The {@link Wordlift_Entity_Uri_Service} instance. |
|
24 | - * |
|
25 | - * @var Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
26 | - */ |
|
27 | - private $entity_uri_service; |
|
28 | - |
|
29 | - /** |
|
30 | - * Url_To_Entity_Transform_Function constructor. |
|
31 | - * |
|
32 | - * @param Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
33 | - */ |
|
34 | - public function __construct( $entity_uri_service ) { |
|
35 | - |
|
36 | - $this->entity_uri_service = $entity_uri_service; |
|
37 | - |
|
38 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
39 | - |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Hook to add ourselves to the list of available transform functions. |
|
44 | - * |
|
45 | - * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
46 | - * |
|
47 | - * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
48 | - */ |
|
49 | - public function wl_mappings_transformation_functions( $value ) { |
|
50 | - |
|
51 | - $value[] = $this; |
|
52 | - |
|
53 | - return $value; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @inheritDoc |
|
58 | - */ |
|
59 | - public function get_name() { |
|
60 | - |
|
61 | - return 'url_to_entity'; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @inheritDoc |
|
66 | - */ |
|
67 | - public function get_label() { |
|
68 | - |
|
69 | - return __( 'URL to Entity', 'wordlift' ); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @inheritDoc |
|
74 | - */ |
|
75 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
76 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
77 | - |
|
78 | - // Get the entity by URI. |
|
79 | - $post = $this->entity_uri_service->get_entity( $data ); |
|
80 | - |
|
81 | - // If found, add the reference. |
|
82 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
83 | - // Add the entity among the references using the post ID. |
|
84 | - $references[] = $post->ID; |
|
85 | - } |
|
86 | - |
|
87 | - return array( '@id' => $data ); |
|
88 | - } |
|
22 | + /** |
|
23 | + * The {@link Wordlift_Entity_Uri_Service} instance. |
|
24 | + * |
|
25 | + * @var Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
26 | + */ |
|
27 | + private $entity_uri_service; |
|
28 | + |
|
29 | + /** |
|
30 | + * Url_To_Entity_Transform_Function constructor. |
|
31 | + * |
|
32 | + * @param Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
33 | + */ |
|
34 | + public function __construct( $entity_uri_service ) { |
|
35 | + |
|
36 | + $this->entity_uri_service = $entity_uri_service; |
|
37 | + |
|
38 | + add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
39 | + |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Hook to add ourselves to the list of available transform functions. |
|
44 | + * |
|
45 | + * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
46 | + * |
|
47 | + * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
48 | + */ |
|
49 | + public function wl_mappings_transformation_functions( $value ) { |
|
50 | + |
|
51 | + $value[] = $this; |
|
52 | + |
|
53 | + return $value; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @inheritDoc |
|
58 | + */ |
|
59 | + public function get_name() { |
|
60 | + |
|
61 | + return 'url_to_entity'; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @inheritDoc |
|
66 | + */ |
|
67 | + public function get_label() { |
|
68 | + |
|
69 | + return __( 'URL to Entity', 'wordlift' ); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @inheritDoc |
|
74 | + */ |
|
75 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
76 | + public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
77 | + |
|
78 | + // Get the entity by URI. |
|
79 | + $post = $this->entity_uri_service->get_entity( $data ); |
|
80 | + |
|
81 | + // If found, add the reference. |
|
82 | + if ( is_a( $post, 'WP_Post' ) ) { |
|
83 | + // Add the entity among the references using the post ID. |
|
84 | + $references[] = $post->ID; |
|
85 | + } |
|
86 | + |
|
87 | + return array( '@id' => $data ); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
33 | 33 | */ |
34 | - public function __construct( $entity_uri_service ) { |
|
34 | + public function __construct($entity_uri_service) { |
|
35 | 35 | |
36 | 36 | $this->entity_uri_service = $entity_uri_service; |
37 | 37 | |
38 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
38 | + add_filter('wl_mappings_transformation_functions', array($this, 'wl_mappings_transformation_functions')); |
|
39 | 39 | |
40 | 40 | } |
41 | 41 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return Mappings_Transform_Function[] An updated array with ourselves too. |
48 | 48 | */ |
49 | - public function wl_mappings_transformation_functions( $value ) { |
|
49 | + public function wl_mappings_transformation_functions($value) { |
|
50 | 50 | |
51 | 51 | $value[] = $this; |
52 | 52 | |
@@ -66,25 +66,25 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function get_label() { |
68 | 68 | |
69 | - return __( 'URL to Entity', 'wordlift' ); |
|
69 | + return __('URL to Entity', 'wordlift'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @inheritDoc |
74 | 74 | */ |
75 | 75 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
76 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
76 | + public function transform_data($data, $jsonld, &$references, $post_id) { |
|
77 | 77 | |
78 | 78 | // Get the entity by URI. |
79 | - $post = $this->entity_uri_service->get_entity( $data ); |
|
79 | + $post = $this->entity_uri_service->get_entity($data); |
|
80 | 80 | |
81 | 81 | // If found, add the reference. |
82 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
82 | + if (is_a($post, 'WP_Post')) { |
|
83 | 83 | // Add the entity among the references using the post ID. |
84 | 84 | $references[] = $post->ID; |
85 | 85 | } |
86 | 86 | |
87 | - return array( '@id' => $data ); |
|
87 | + return array('@id' => $data); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | } |
@@ -18,57 +18,57 @@ |
||
18 | 18 | */ |
19 | 19 | class Taxonomy_To_Terms_Transform_Function implements Mappings_Transform_Function { |
20 | 20 | |
21 | - /** |
|
22 | - * Taxonomy_To_Terms_Transform_Function constructor. |
|
23 | - */ |
|
24 | - public function __construct() { |
|
21 | + /** |
|
22 | + * Taxonomy_To_Terms_Transform_Function constructor. |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | 25 | |
26 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
26 | + add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Hook to add ourselves to the list of available transform functions. |
|
32 | - * |
|
33 | - * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
34 | - * |
|
35 | - * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
36 | - */ |
|
37 | - public function wl_mappings_transformation_functions( $value ) { |
|
30 | + /** |
|
31 | + * Hook to add ourselves to the list of available transform functions. |
|
32 | + * |
|
33 | + * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
34 | + * |
|
35 | + * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
36 | + */ |
|
37 | + public function wl_mappings_transformation_functions( $value ) { |
|
38 | 38 | |
39 | - $value[] = $this; |
|
39 | + $value[] = $this; |
|
40 | 40 | |
41 | - return $value; |
|
42 | - } |
|
41 | + return $value; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @inheritDoc |
|
46 | - */ |
|
47 | - public function get_name() { |
|
44 | + /** |
|
45 | + * @inheritDoc |
|
46 | + */ |
|
47 | + public function get_name() { |
|
48 | 48 | |
49 | - return 'taxonomy_to_terms'; |
|
50 | - } |
|
49 | + return 'taxonomy_to_terms'; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @inheritDoc |
|
54 | - */ |
|
55 | - public function get_label() { |
|
52 | + /** |
|
53 | + * @inheritDoc |
|
54 | + */ |
|
55 | + public function get_label() { |
|
56 | 56 | |
57 | - return __( 'Taxonomy to Terms', 'wordlift' ); |
|
58 | - } |
|
57 | + return __( 'Taxonomy to Terms', 'wordlift' ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @inheritDoc |
|
62 | - */ |
|
63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
60 | + /** |
|
61 | + * @inheritDoc |
|
62 | + */ |
|
63 | + public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
64 | 64 | |
65 | - $terms = wp_get_object_terms( $post_id, $data, array( 'fields' => 'names' ) ); |
|
65 | + $terms = wp_get_object_terms( $post_id, $data, array( 'fields' => 'names' ) ); |
|
66 | 66 | |
67 | - if ( ! is_array( $terms ) || empty( $terms ) ) { |
|
68 | - return null; |
|
69 | - } |
|
67 | + if ( ! is_array( $terms ) || empty( $terms ) ) { |
|
68 | + return null; |
|
69 | + } |
|
70 | 70 | |
71 | - return $terms; |
|
72 | - } |
|
71 | + return $terms; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct() { |
25 | 25 | |
26 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
26 | + add_filter('wl_mappings_transformation_functions', array($this, 'wl_mappings_transformation_functions')); |
|
27 | 27 | |
28 | 28 | } |
29 | 29 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return Mappings_Transform_Function[] An updated array with ourselves too. |
36 | 36 | */ |
37 | - public function wl_mappings_transformation_functions( $value ) { |
|
37 | + public function wl_mappings_transformation_functions($value) { |
|
38 | 38 | |
39 | 39 | $value[] = $this; |
40 | 40 | |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function get_label() { |
56 | 56 | |
57 | - return __( 'Taxonomy to Terms', 'wordlift' ); |
|
57 | + return __('Taxonomy to Terms', 'wordlift'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @inheritDoc |
62 | 62 | */ |
63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
63 | + public function transform_data($data, $jsonld, &$references, $post_id) { |
|
64 | 64 | |
65 | - $terms = wp_get_object_terms( $post_id, $data, array( 'fields' => 'names' ) ); |
|
65 | + $terms = wp_get_object_terms($post_id, $data, array('fields' => 'names')); |
|
66 | 66 | |
67 | - if ( ! is_array( $terms ) || empty( $terms ) ) { |
|
67 | + if ( ! is_array($terms) || empty($terms)) { |
|
68 | 68 | return null; |
69 | 69 | } |
70 | 70 |
@@ -5,71 +5,71 @@ |
||
5 | 5 | use Wordlift\Object_Type_Enum; |
6 | 6 | |
7 | 7 | class Sync_Post_Adapter extends Abstract_Sync_Object_Adapter { |
8 | - /** |
|
9 | - * @var int |
|
10 | - */ |
|
11 | - private $post_id; |
|
8 | + /** |
|
9 | + * @var int |
|
10 | + */ |
|
11 | + private $post_id; |
|
12 | 12 | |
13 | - /** |
|
14 | - * Sync_Term_Adapter constructor. |
|
15 | - * |
|
16 | - * @param int $post_id |
|
17 | - * |
|
18 | - * @throws \Exception when an error occurs. |
|
19 | - */ |
|
20 | - public function __construct( $post_id ) { |
|
21 | - parent::__construct( Object_Type_Enum::POST, $post_id ); |
|
13 | + /** |
|
14 | + * Sync_Term_Adapter constructor. |
|
15 | + * |
|
16 | + * @param int $post_id |
|
17 | + * |
|
18 | + * @throws \Exception when an error occurs. |
|
19 | + */ |
|
20 | + public function __construct( $post_id ) { |
|
21 | + parent::__construct( Object_Type_Enum::POST, $post_id ); |
|
22 | 22 | |
23 | - $this->post_id = $post_id; |
|
24 | - } |
|
23 | + $this->post_id = $post_id; |
|
24 | + } |
|
25 | 25 | |
26 | - public function is_published() { |
|
27 | - return ( 'publish' === get_post_status( $this->post_id ) ); |
|
28 | - } |
|
26 | + public function is_published() { |
|
27 | + return ( 'publish' === get_post_status( $this->post_id ) ); |
|
28 | + } |
|
29 | 29 | |
30 | - public function is_public() { |
|
31 | - // Check if the post type is public. |
|
32 | - $post_type = get_post_type( $this->post_id ); |
|
33 | - $post_type_obj = get_post_type_object( $post_type ); |
|
30 | + public function is_public() { |
|
31 | + // Check if the post type is public. |
|
32 | + $post_type = get_post_type( $this->post_id ); |
|
33 | + $post_type_obj = get_post_type_object( $post_type ); |
|
34 | 34 | |
35 | - return $post_type_obj->public; |
|
36 | - } |
|
35 | + return $post_type_obj->public; |
|
36 | + } |
|
37 | 37 | |
38 | - public function set_values( $arr ) { |
|
39 | - global $wpdb; |
|
38 | + public function set_values( $arr ) { |
|
39 | + global $wpdb; |
|
40 | 40 | |
41 | - $field_names = implode( ', ', array_map( 'esc_sql', array_keys( $arr ) ) ); |
|
42 | - $field_values = "'" . implode( "', '", array_map( 'esc_sql', array_values( $arr ) ) ) . "'"; |
|
41 | + $field_names = implode( ', ', array_map( 'esc_sql', array_keys( $arr ) ) ); |
|
42 | + $field_values = "'" . implode( "', '", array_map( 'esc_sql', array_values( $arr ) ) ) . "'"; |
|
43 | 43 | |
44 | - $update_stmt = implode( |
|
45 | - ', ', |
|
46 | - array_map( |
|
47 | - function ( $key ) use ( $arr ) { |
|
48 | - return "$key = '" . esc_sql( $arr[ $key ] ) . "'"; |
|
49 | - }, |
|
50 | - array_keys( $arr ) |
|
51 | - ) |
|
52 | - ); |
|
44 | + $update_stmt = implode( |
|
45 | + ', ', |
|
46 | + array_map( |
|
47 | + function ( $key ) use ( $arr ) { |
|
48 | + return "$key = '" . esc_sql( $arr[ $key ] ) . "'"; |
|
49 | + }, |
|
50 | + array_keys( $arr ) |
|
51 | + ) |
|
52 | + ); |
|
53 | 53 | |
54 | - $wpdb->query( |
|
55 | - $wpdb->prepare( |
|
56 | - "INSERT INTO {$wpdb->prefix}wl_entities( content_id, content_type, $field_names ) VALUES ( %d, %d, $field_values ) ON DUPLICATE KEY UPDATE $update_stmt;", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
57 | - $this->post_id, |
|
58 | - Object_Type_Enum::POST |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
54 | + $wpdb->query( |
|
55 | + $wpdb->prepare( |
|
56 | + "INSERT INTO {$wpdb->prefix}wl_entities( content_id, content_type, $field_names ) VALUES ( %d, %d, $field_values ) ON DUPLICATE KEY UPDATE $update_stmt;", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
57 | + $this->post_id, |
|
58 | + Object_Type_Enum::POST |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - public function get_value( $key ) { |
|
64 | - global $wpdb; |
|
63 | + public function get_value( $key ) { |
|
64 | + global $wpdb; |
|
65 | 65 | |
66 | - return $wpdb->get_var( |
|
67 | - $wpdb->prepare( |
|
68 | - "SELECT $key FROM {$wpdb->prefix}wl_entities WHERE content_id = %d AND content_type = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
69 | - $this->post_id, |
|
70 | - Object_Type_Enum::POST |
|
71 | - ) |
|
72 | - ); |
|
73 | - } |
|
66 | + return $wpdb->get_var( |
|
67 | + $wpdb->prepare( |
|
68 | + "SELECT $key FROM {$wpdb->prefix}wl_entities WHERE content_id = %d AND content_type = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
69 | + $this->post_id, |
|
70 | + Object_Type_Enum::POST |
|
71 | + ) |
|
72 | + ); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | } |
@@ -17,37 +17,37 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @throws \Exception when an error occurs. |
19 | 19 | */ |
20 | - public function __construct( $post_id ) { |
|
21 | - parent::__construct( Object_Type_Enum::POST, $post_id ); |
|
20 | + public function __construct($post_id) { |
|
21 | + parent::__construct(Object_Type_Enum::POST, $post_id); |
|
22 | 22 | |
23 | 23 | $this->post_id = $post_id; |
24 | 24 | } |
25 | 25 | |
26 | 26 | public function is_published() { |
27 | - return ( 'publish' === get_post_status( $this->post_id ) ); |
|
27 | + return ('publish' === get_post_status($this->post_id)); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function is_public() { |
31 | 31 | // Check if the post type is public. |
32 | - $post_type = get_post_type( $this->post_id ); |
|
33 | - $post_type_obj = get_post_type_object( $post_type ); |
|
32 | + $post_type = get_post_type($this->post_id); |
|
33 | + $post_type_obj = get_post_type_object($post_type); |
|
34 | 34 | |
35 | 35 | return $post_type_obj->public; |
36 | 36 | } |
37 | 37 | |
38 | - public function set_values( $arr ) { |
|
38 | + public function set_values($arr) { |
|
39 | 39 | global $wpdb; |
40 | 40 | |
41 | - $field_names = implode( ', ', array_map( 'esc_sql', array_keys( $arr ) ) ); |
|
42 | - $field_values = "'" . implode( "', '", array_map( 'esc_sql', array_values( $arr ) ) ) . "'"; |
|
41 | + $field_names = implode(', ', array_map('esc_sql', array_keys($arr))); |
|
42 | + $field_values = "'".implode("', '", array_map('esc_sql', array_values($arr)))."'"; |
|
43 | 43 | |
44 | 44 | $update_stmt = implode( |
45 | 45 | ', ', |
46 | 46 | array_map( |
47 | - function ( $key ) use ( $arr ) { |
|
48 | - return "$key = '" . esc_sql( $arr[ $key ] ) . "'"; |
|
47 | + function($key) use ($arr) { |
|
48 | + return "$key = '".esc_sql($arr[$key])."'"; |
|
49 | 49 | }, |
50 | - array_keys( $arr ) |
|
50 | + array_keys($arr) |
|
51 | 51 | ) |
52 | 52 | ); |
53 | 53 | |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | ); |
61 | 61 | } |
62 | 62 | |
63 | - public function get_value( $key ) { |
|
63 | + public function get_value($key) { |
|
64 | 64 | global $wpdb; |
65 | 65 | |
66 | 66 | return $wpdb->get_var( |
67 | 67 | $wpdb->prepare( |
68 | - "SELECT $key FROM {$wpdb->prefix}wl_entities WHERE content_id = %d AND content_type = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
68 | + "SELECT $key FROM {$wpdb->prefix}wl_entities WHERE content_id = %d AND content_type = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
69 | 69 | $this->post_id, |
70 | 70 | Object_Type_Enum::POST |
71 | 71 | ) |
@@ -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() { |