@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * @return bool |
|
| 63 | + * @return boolean|null |
|
| 64 | 64 | */ |
| 65 | 65 | public function shutdown() { |
| 66 | 66 | return $this->sync( $this->post_id ); |
@@ -76,6 +76,9 @@ discard block |
||
| 76 | 76 | $this->post_id = $post_id; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | + /** |
|
| 80 | + * @param integer $post_id |
|
| 81 | + */ |
|
| 79 | 82 | private function sync( $post_id ) { |
| 80 | 83 | |
| 81 | 84 | try { |
@@ -6,98 +6,98 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Sync_Post_Hooks { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @var int Post id |
|
| 11 | - */ |
|
| 12 | - public $post_id; |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * @var \Wordlift_Log_Service |
|
| 16 | - */ |
|
| 17 | - private $log; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var Sync_Service |
|
| 21 | - */ |
|
| 22 | - private $sync_service; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var Sync_Object_Adapter_Factory |
|
| 26 | - */ |
|
| 27 | - private $sync_object_factory; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Sync_Post_Hooks constructor. |
|
| 31 | - * |
|
| 32 | - * @param Sync_Service $sync_service |
|
| 33 | - * @param Sync_Object_Adapter_Factory $sync_object_factory |
|
| 34 | - */ |
|
| 35 | - function __construct( $sync_service, $sync_object_factory ) { |
|
| 36 | - |
|
| 37 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 38 | - |
|
| 39 | - $this->sync_service = $sync_service; |
|
| 40 | - $this->sync_object_factory = $sync_object_factory; |
|
| 41 | - |
|
| 42 | - $this->register_hooks(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - private function register_hooks() { |
|
| 46 | - /** |
|
| 47 | - * Register hooks for post and meta. |
|
| 48 | - */ |
|
| 49 | - add_action( 'save_post', array( $this, 'save_post' ) ); |
|
| 50 | - add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 51 | - add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 52 | - add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 53 | - add_action( 'delete_post', array( $this, 'delete_post' ) ); |
|
| 54 | - /** |
|
| 55 | - * @todo: Might need to change this, this will be called |
|
| 56 | - * for every request, sync will occur on editor. |
|
| 57 | - */ |
|
| 58 | - add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
| 59 | - |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return bool |
|
| 64 | - */ |
|
| 65 | - public function shutdown() { |
|
| 66 | - return $this->sync( $this->post_id ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function save_post( $post_id ) { |
|
| 70 | - |
|
| 71 | - $this->post_id = $post_id; |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) { |
|
| 76 | - $this->post_id = $post_id; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - private function sync( $post_id ) { |
|
| 80 | - |
|
| 81 | - try { |
|
| 82 | - $post = get_post( $post_id ); |
|
| 83 | - $this->sync_service->sync_many( array( |
|
| 84 | - $this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ), |
|
| 85 | - $this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ) |
|
| 86 | - ) ); |
|
| 87 | - } catch ( \Exception $e ) { |
|
| 88 | - $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public function delete_post( $post_id ) { |
|
| 94 | - |
|
| 95 | - try { |
|
| 96 | - $this->sync_service->delete_one( Object_Type_Enum::POST, $post_id ); |
|
| 97 | - } catch ( \Exception $e ) { |
|
| 98 | - $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - } |
|
| 9 | + /** |
|
| 10 | + * @var int Post id |
|
| 11 | + */ |
|
| 12 | + public $post_id; |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * @var \Wordlift_Log_Service |
|
| 16 | + */ |
|
| 17 | + private $log; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var Sync_Service |
|
| 21 | + */ |
|
| 22 | + private $sync_service; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var Sync_Object_Adapter_Factory |
|
| 26 | + */ |
|
| 27 | + private $sync_object_factory; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Sync_Post_Hooks constructor. |
|
| 31 | + * |
|
| 32 | + * @param Sync_Service $sync_service |
|
| 33 | + * @param Sync_Object_Adapter_Factory $sync_object_factory |
|
| 34 | + */ |
|
| 35 | + function __construct( $sync_service, $sync_object_factory ) { |
|
| 36 | + |
|
| 37 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 38 | + |
|
| 39 | + $this->sync_service = $sync_service; |
|
| 40 | + $this->sync_object_factory = $sync_object_factory; |
|
| 41 | + |
|
| 42 | + $this->register_hooks(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + private function register_hooks() { |
|
| 46 | + /** |
|
| 47 | + * Register hooks for post and meta. |
|
| 48 | + */ |
|
| 49 | + add_action( 'save_post', array( $this, 'save_post' ) ); |
|
| 50 | + add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 51 | + add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 52 | + add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 53 | + add_action( 'delete_post', array( $this, 'delete_post' ) ); |
|
| 54 | + /** |
|
| 55 | + * @todo: Might need to change this, this will be called |
|
| 56 | + * for every request, sync will occur on editor. |
|
| 57 | + */ |
|
| 58 | + add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
| 59 | + |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return bool |
|
| 64 | + */ |
|
| 65 | + public function shutdown() { |
|
| 66 | + return $this->sync( $this->post_id ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function save_post( $post_id ) { |
|
| 70 | + |
|
| 71 | + $this->post_id = $post_id; |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) { |
|
| 76 | + $this->post_id = $post_id; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + private function sync( $post_id ) { |
|
| 80 | + |
|
| 81 | + try { |
|
| 82 | + $post = get_post( $post_id ); |
|
| 83 | + $this->sync_service->sync_many( array( |
|
| 84 | + $this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ), |
|
| 85 | + $this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ) |
|
| 86 | + ) ); |
|
| 87 | + } catch ( \Exception $e ) { |
|
| 88 | + $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public function delete_post( $post_id ) { |
|
| 94 | + |
|
| 95 | + try { |
|
| 96 | + $this->sync_service->delete_one( Object_Type_Enum::POST, $post_id ); |
|
| 97 | + } catch ( \Exception $e ) { |
|
| 98 | + $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | * @param Sync_Service $sync_service |
| 33 | 33 | * @param Sync_Object_Adapter_Factory $sync_object_factory |
| 34 | 34 | */ |
| 35 | - function __construct( $sync_service, $sync_object_factory ) { |
|
| 35 | + function __construct($sync_service, $sync_object_factory) { |
|
| 36 | 36 | |
| 37 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 37 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
| 38 | 38 | |
| 39 | 39 | $this->sync_service = $sync_service; |
| 40 | 40 | $this->sync_object_factory = $sync_object_factory; |
@@ -46,16 +46,16 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * Register hooks for post and meta. |
| 48 | 48 | */ |
| 49 | - add_action( 'save_post', array( $this, 'save_post' ) ); |
|
| 50 | - add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 51 | - add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 52 | - add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
| 53 | - add_action( 'delete_post', array( $this, 'delete_post' ) ); |
|
| 49 | + add_action('save_post', array($this, 'save_post')); |
|
| 50 | + add_action('added_post_meta', array($this, 'changed_post_meta'), 10, 4); |
|
| 51 | + add_action('updated_post_meta', array($this, 'changed_post_meta'), 10, 4); |
|
| 52 | + add_action('deleted_post_meta', array($this, 'changed_post_meta'), 10, 4); |
|
| 53 | + add_action('delete_post', array($this, 'delete_post')); |
|
| 54 | 54 | /** |
| 55 | 55 | * @todo: Might need to change this, this will be called |
| 56 | 56 | * for every request, sync will occur on editor. |
| 57 | 57 | */ |
| 58 | - add_action( 'shutdown', array( $this, 'shutdown' ) ); |
|
| 58 | + add_action('shutdown', array($this, 'shutdown')); |
|
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | |
@@ -63,39 +63,39 @@ discard block |
||
| 63 | 63 | * @return bool |
| 64 | 64 | */ |
| 65 | 65 | public function shutdown() { |
| 66 | - return $this->sync( $this->post_id ); |
|
| 66 | + return $this->sync($this->post_id); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function save_post( $post_id ) { |
|
| 69 | + public function save_post($post_id) { |
|
| 70 | 70 | |
| 71 | 71 | $this->post_id = $post_id; |
| 72 | 72 | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) { |
|
| 75 | + public function changed_post_meta($meta_id, $post_id, $meta_key, $_meta_value) { |
|
| 76 | 76 | $this->post_id = $post_id; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - private function sync( $post_id ) { |
|
| 79 | + private function sync($post_id) { |
|
| 80 | 80 | |
| 81 | 81 | try { |
| 82 | - $post = get_post( $post_id ); |
|
| 83 | - $this->sync_service->sync_many( array( |
|
| 84 | - $this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ), |
|
| 85 | - $this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ) |
|
| 86 | - ) ); |
|
| 87 | - } catch ( \Exception $e ) { |
|
| 88 | - $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e ); |
|
| 82 | + $post = get_post($post_id); |
|
| 83 | + $this->sync_service->sync_many(array( |
|
| 84 | + $this->sync_object_factory->create(Object_Type_Enum::POST, $post_id), |
|
| 85 | + $this->sync_object_factory->create(Object_Type_Enum::USER, $post->post_author) |
|
| 86 | + )); |
|
| 87 | + } catch (\Exception $e) { |
|
| 88 | + $this->log->error("An error occurred while trying to sync post $post_id: ".$e->getMessage(), $e); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - public function delete_post( $post_id ) { |
|
| 93 | + public function delete_post($post_id) { |
|
| 94 | 94 | |
| 95 | 95 | try { |
| 96 | - $this->sync_service->delete_one( Object_Type_Enum::POST, $post_id ); |
|
| 97 | - } catch ( \Exception $e ) { |
|
| 98 | - $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e ); |
|
| 96 | + $this->sync_service->delete_one(Object_Type_Enum::POST, $post_id); |
|
| 97 | + } catch (\Exception $e) { |
|
| 98 | + $this->log->error("An error occurred while trying to delete post $post_id: ".$e->getMessage(), $e); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | } |