@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | $this->app->semaphore()->unlock(); |
| 114 | 114 | |
| 115 | 115 | if ( is_wp_error( $result ) ) { |
| 116 | - /* @var WP_Error $result */ |
|
| 117 | - update_option( '_wogh_import_error', $result->get_error_message() ); |
|
| 116 | + /* @var WP_Error $result */ |
|
| 117 | + update_option( '_wogh_import_error', $result->get_error_message() ); |
|
| 118 | 118 | |
| 119 | 119 | return $this->app->response()->error( $result ); |
| 120 | 120 | } |
@@ -127,10 +127,10 @@ discard block |
||
| 127 | 127 | /** |
| 128 | 128 | * Export all the posts in the database to GitHub. |
| 129 | 129 | * |
| 130 | - * @param int $user_id |
|
| 131 | - * @param boolean $force |
|
| 132 | - * @return boolean |
|
| 133 | - */ |
|
| 130 | + * @param int $user_id |
|
| 131 | + * @param boolean $force |
|
| 132 | + * @return boolean |
|
| 133 | + */ |
|
| 134 | 134 | public function export_all( $user_id, $force = false ) { |
| 135 | 135 | if ( ! $this->app->semaphore()->is_open() ) { |
| 136 | 136 | return $this->app->response()->error( new WP_Error( |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @param Writing_On_GitHub $app Applicatio container. |
| 23 | 23 | */ |
| 24 | - public function __construct( Writing_On_GitHub $app ) { |
|
| 24 | + public function __construct(Writing_On_GitHub $app) { |
|
| 25 | 25 | $this->app = $app; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -34,57 +34,57 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function pull_posts() { |
| 36 | 36 | $this->set_ajax(); |
| 37 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
| 38 | - return $this->app->response()->error( new WP_Error( |
|
| 37 | + if ( ! $this->app->semaphore()->is_open()) { |
|
| 38 | + return $this->app->response()->error(new WP_Error( |
|
| 39 | 39 | 'semaphore_locked', |
| 40 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::pull_posts()' ) |
|
| 41 | - ) ); |
|
| 40 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::pull_posts()') |
|
| 41 | + )); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ( ! $this->app->request()->is_secret_valid() ) { |
|
| 45 | - return $this->app->response()->error( new WP_Error( |
|
| 44 | + if ( ! $this->app->request()->is_secret_valid()) { |
|
| 45 | + return $this->app->response()->error(new WP_Error( |
|
| 46 | 46 | 'invalid_headers', |
| 47 | - __( 'Failed to validate secret.', 'writing-on-github' ) |
|
| 48 | - ) ); |
|
| 47 | + __('Failed to validate secret.', 'writing-on-github') |
|
| 48 | + )); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | // ping |
| 52 | - if ( $this->app->request()->is_ping() ) { |
|
| 53 | - return $this->app->response()->success( __( 'Wordpress is ready.', 'writing-on-github' ) ); |
|
| 52 | + if ($this->app->request()->is_ping()) { |
|
| 53 | + return $this->app->response()->success(__('Wordpress is ready.', 'writing-on-github')); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // push |
| 57 | - if ( ! $this->app->request()->is_push() ) { |
|
| 58 | - return $this->app->response()->error( new WP_Error( |
|
| 57 | + if ( ! $this->app->request()->is_push()) { |
|
| 58 | + return $this->app->response()->error(new WP_Error( |
|
| 59 | 59 | 'invalid_headers', |
| 60 | - __( 'Failed to validate webhook event.', 'writing-on-github' ) |
|
| 61 | - ) ); |
|
| 60 | + __('Failed to validate webhook event.', 'writing-on-github') |
|
| 61 | + )); |
|
| 62 | 62 | } |
| 63 | 63 | $payload = $this->app->request()->payload(); |
| 64 | 64 | |
| 65 | - if ( ! $payload->should_import() ) { |
|
| 66 | - return $this->app->response()->error( new WP_Error( |
|
| 65 | + if ( ! $payload->should_import()) { |
|
| 66 | + return $this->app->response()->error(new WP_Error( |
|
| 67 | 67 | 'invalid_payload', |
| 68 | 68 | sprintf( |
| 69 | - __( "%s won't be imported.", 'writing-on-github' ), |
|
| 70 | - strtolower( $payload->get_commit_id() ) ? : '[Missing Commit ID]' |
|
| 69 | + __("%s won't be imported.", 'writing-on-github'), |
|
| 70 | + strtolower($payload->get_commit_id()) ?: '[Missing Commit ID]' |
|
| 71 | 71 | ) |
| 72 | - ) ); |
|
| 72 | + )); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $this->app->semaphore()->lock(); |
| 76 | - remove_action( 'save_post', array( $this, 'export_post' ) ); |
|
| 77 | - remove_action( 'delete_post', array( $this, 'delete_post' ) ); |
|
| 76 | + remove_action('save_post', array($this, 'export_post')); |
|
| 77 | + remove_action('delete_post', array($this, 'delete_post')); |
|
| 78 | 78 | |
| 79 | - $result = $this->app->import()->payload( $payload ); |
|
| 79 | + $result = $this->app->import()->payload($payload); |
|
| 80 | 80 | |
| 81 | 81 | $this->app->semaphore()->unlock(); |
| 82 | 82 | |
| 83 | - if ( is_wp_error( $result ) ) { |
|
| 84 | - return $this->app->response()->error( $result ); |
|
| 83 | + if (is_wp_error($result)) { |
|
| 84 | + return $this->app->response()->error($result); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - return $this->app->response()->success( $result ); |
|
| 87 | + return $this->app->response()->success($result); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -92,36 +92,36 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return boolean |
| 94 | 94 | */ |
| 95 | - public function import_master( $user_id ) { |
|
| 96 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
| 97 | - return $this->app->response()->error( new WP_Error( |
|
| 95 | + public function import_master($user_id) { |
|
| 96 | + if ( ! $this->app->semaphore()->is_open()) { |
|
| 97 | + return $this->app->response()->error(new WP_Error( |
|
| 98 | 98 | 'semaphore_locked', |
| 99 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::import_master()' ) |
|
| 100 | - ) ); |
|
| 99 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::import_master()') |
|
| 100 | + )); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $this->app->semaphore()->lock(); |
| 104 | - remove_action( 'save_post', array( $this, 'export_post' ) ); |
|
| 105 | - remove_action( 'save_post', array( $this, 'delete_post' ) ); |
|
| 104 | + remove_action('save_post', array($this, 'export_post')); |
|
| 105 | + remove_action('save_post', array($this, 'delete_post')); |
|
| 106 | 106 | |
| 107 | - if ( $user_id ) { |
|
| 108 | - wp_set_current_user( $user_id ); |
|
| 107 | + if ($user_id) { |
|
| 108 | + wp_set_current_user($user_id); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | $result = $this->app->import()->master(); |
| 112 | 112 | |
| 113 | 113 | $this->app->semaphore()->unlock(); |
| 114 | 114 | |
| 115 | - if ( is_wp_error( $result ) ) { |
|
| 115 | + if (is_wp_error($result)) { |
|
| 116 | 116 | /* @var WP_Error $result */ |
| 117 | - update_option( '_wogh_import_error', $result->get_error_message() ); |
|
| 117 | + update_option('_wogh_import_error', $result->get_error_message()); |
|
| 118 | 118 | |
| 119 | - return $this->app->response()->error( $result ); |
|
| 119 | + return $this->app->response()->error($result); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - update_option( '_wogh_import_complete', 'yes' ); |
|
| 122 | + update_option('_wogh_import_complete', 'yes'); |
|
| 123 | 123 | |
| 124 | - return $this->app->response()->success( $result ); |
|
| 124 | + return $this->app->response()->success($result); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -131,33 +131,33 @@ discard block |
||
| 131 | 131 | * @param boolean $force |
| 132 | 132 | * @return boolean |
| 133 | 133 | */ |
| 134 | - public function export_all( $user_id, $force = false ) { |
|
| 135 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
| 136 | - return $this->app->response()->error( new WP_Error( |
|
| 134 | + public function export_all($user_id, $force = false) { |
|
| 135 | + if ( ! $this->app->semaphore()->is_open()) { |
|
| 136 | + return $this->app->response()->error(new WP_Error( |
|
| 137 | 137 | 'semaphore_locked', |
| 138 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_all()' ) |
|
| 139 | - ) ); |
|
| 138 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_all()') |
|
| 139 | + )); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | $this->app->semaphore()->lock(); |
| 143 | 143 | |
| 144 | - if ( $user_id ) { |
|
| 145 | - wp_set_current_user( $user_id ); |
|
| 144 | + if ($user_id) { |
|
| 145 | + wp_set_current_user($user_id); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $result = $this->app->export()->full($force); |
| 149 | 149 | $this->app->semaphore()->unlock(); |
| 150 | 150 | |
| 151 | 151 | // Maybe move option updating out of this class/upgrade message display? |
| 152 | - if ( is_wp_error( $result ) ) { |
|
| 153 | - update_option( '_wogh_export_error', $result->get_error_message() ); |
|
| 152 | + if (is_wp_error($result)) { |
|
| 153 | + update_option('_wogh_export_error', $result->get_error_message()); |
|
| 154 | 154 | |
| 155 | - return $this->app->response()->error( $result ); |
|
| 155 | + return $this->app->response()->error($result); |
|
| 156 | 156 | } else { |
| 157 | - update_option( '_wogh_export_complete', 'yes' ); |
|
| 158 | - update_option( '_wogh_fully_exported', 'yes' ); |
|
| 157 | + update_option('_wogh_export_complete', 'yes'); |
|
| 158 | + update_option('_wogh_fully_exported', 'yes'); |
|
| 159 | 159 | |
| 160 | - return $this->app->response()->success( $result ); |
|
| 160 | + return $this->app->response()->success($result); |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
@@ -170,27 +170,27 @@ discard block |
||
| 170 | 170 | * |
| 171 | 171 | * @return boolean |
| 172 | 172 | */ |
| 173 | - public function export_post( $post_id ) { |
|
| 174 | - if ( wp_is_post_revision( $post_id ) ) { |
|
| 173 | + public function export_post($post_id) { |
|
| 174 | + if (wp_is_post_revision($post_id)) { |
|
| 175 | 175 | return; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
| 179 | - return $this->app->response()->error( new WP_Error( |
|
| 178 | + if ( ! $this->app->semaphore()->is_open()) { |
|
| 179 | + return $this->app->response()->error(new WP_Error( |
|
| 180 | 180 | 'semaphore_locked', |
| 181 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_post()' ) |
|
| 182 | - ) ); |
|
| 181 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_post()') |
|
| 182 | + )); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $this->app->semaphore()->lock(); |
| 186 | - $result = $this->app->export()->update( $post_id ); |
|
| 186 | + $result = $this->app->export()->update($post_id); |
|
| 187 | 187 | $this->app->semaphore()->unlock(); |
| 188 | 188 | |
| 189 | - if ( is_wp_error( $result ) ) { |
|
| 190 | - return $this->app->response()->error( $result ); |
|
| 189 | + if (is_wp_error($result)) { |
|
| 190 | + return $this->app->response()->error($result); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - return $this->app->response()->success( $result ); |
|
| 193 | + return $this->app->response()->success($result); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -202,27 +202,27 @@ discard block |
||
| 202 | 202 | * |
| 203 | 203 | * @return boolean |
| 204 | 204 | */ |
| 205 | - public function delete_post( $post_id ) { |
|
| 206 | - if ( wp_is_post_revision( $post_id ) ) { |
|
| 205 | + public function delete_post($post_id) { |
|
| 206 | + if (wp_is_post_revision($post_id)) { |
|
| 207 | 207 | return; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
| 211 | - return $this->app->response()->error( new WP_Error( |
|
| 210 | + if ( ! $this->app->semaphore()->is_open()) { |
|
| 211 | + return $this->app->response()->error(new WP_Error( |
|
| 212 | 212 | 'semaphore_locked', |
| 213 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::delete_post()' ) |
|
| 214 | - ) ); |
|
| 213 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::delete_post()') |
|
| 214 | + )); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | $this->app->semaphore()->lock(); |
| 218 | - $result = $this->app->export()->delete( $post_id ); |
|
| 218 | + $result = $this->app->export()->delete($post_id); |
|
| 219 | 219 | $this->app->semaphore()->unlock(); |
| 220 | 220 | |
| 221 | - if ( is_wp_error( $result ) ) { |
|
| 222 | - return $this->app->response()->error( $result ); |
|
| 221 | + if (is_wp_error($result)) { |
|
| 222 | + return $this->app->response()->error($result); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - return $this->app->response()->success( $result ); |
|
| 225 | + return $this->app->response()->success($result); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * than just returning data. |
| 232 | 232 | */ |
| 233 | 233 | protected function set_ajax() { |
| 234 | - if ( ! defined( 'WOGH_AJAX' ) ) { |
|
| 235 | - define( 'WOGH_AJAX', true ); |
|
| 234 | + if ( ! defined('WOGH_AJAX')) { |
|
| 235 | + define('WOGH_AJAX', true); |
|
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | } |