@@ -29,36 +29,36 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * Updates all of the current posts in the database on master. |
| 31 | 31 | * |
| 32 | - * @param bool $force |
|
| 33 | - * |
|
| 34 | - * @return string|WP_Error |
|
| 35 | - */ |
|
| 32 | + * @param bool $force |
|
| 33 | + * |
|
| 34 | + * @return string|WP_Error |
|
| 35 | + */ |
|
| 36 | 36 | public function full( $force = false ) { |
| 37 | 37 | $posts = $this->app->database()->fetch_all_supported( $force ); |
| 38 | 38 | |
| 39 | 39 | if ( is_wp_error( $posts ) ) { |
| 40 | - /* @var WP_Error $posts */ |
|
| 40 | + /* @var WP_Error $posts */ |
|
| 41 | 41 | return $posts; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $error = false; |
|
| 44 | + $error = false; |
|
| 45 | 45 | |
| 46 | - foreach ( $posts as $post ) { |
|
| 47 | - $result = $this->update( $post->id() ); |
|
| 48 | - if ( is_wp_error( $result ) ) { |
|
| 49 | - if ( $error ) { |
|
| 50 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 51 | - } else { |
|
| 52 | - $error = $result; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 46 | + foreach ( $posts as $post ) { |
|
| 47 | + $result = $this->update( $post->id() ); |
|
| 48 | + if ( is_wp_error( $result ) ) { |
|
| 49 | + if ( $error ) { |
|
| 50 | + $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 51 | + } else { |
|
| 52 | + $error = $result; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - if ( is_wp_error( $error ) ) { |
|
| 58 | - return $error; |
|
| 59 | - } |
|
| 57 | + if ( is_wp_error( $error ) ) { |
|
| 58 | + return $error; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 61 | + return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $post = $this->app->database()->fetch_by_id( $post_id ); |
| 89 | 89 | |
| 90 | 90 | if ( is_wp_error( $post ) ) { |
| 91 | - /* @var WP_Error $post */ |
|
| 91 | + /* @var WP_Error $post */ |
|
| 92 | 92 | return $post; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $result = $this->new_posts( array( $post ) ); |
| 105 | 105 | |
| 106 | 106 | if ( is_wp_error( $result ) ) { |
| 107 | - /* @var WP_Error $result */ |
|
| 107 | + /* @var WP_Error $result */ |
|
| 108 | 108 | return $result; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | return $error; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 141 | + return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | protected function new_post( $post, $persist ) { |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $post = $this->app->database()->fetch_by_id( $post_id ); |
| 219 | 219 | |
| 220 | 220 | if ( is_wp_error( $post ) ) { |
| 221 | - /* @var WP_Error $post */ |
|
| 221 | + /* @var WP_Error $post */ |
|
| 222 | 222 | return $post; |
| 223 | 223 | } |
| 224 | 224 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
| 239 | 239 | |
| 240 | 240 | if ( is_wp_error( $result ) ) { |
| 241 | - /* @var WP_Error $result */ |
|
| 241 | + /* @var WP_Error $result */ |
|
| 242 | 242 | return $result; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param Writing_On_GitHub $app Application container. |
| 24 | 24 | */ |
| 25 | - public function __construct( Writing_On_GitHub $app ) { |
|
| 25 | + public function __construct(Writing_On_GitHub $app) { |
|
| 26 | 26 | $this->app = $app; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -33,32 +33,32 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return string|WP_Error |
| 35 | 35 | */ |
| 36 | - public function full( $force = false ) { |
|
| 37 | - $posts = $this->app->database()->fetch_all_supported( $force ); |
|
| 36 | + public function full($force = false) { |
|
| 37 | + $posts = $this->app->database()->fetch_all_supported($force); |
|
| 38 | 38 | |
| 39 | - if ( is_wp_error( $posts ) ) { |
|
| 39 | + if (is_wp_error($posts)) { |
|
| 40 | 40 | /* @var WP_Error $posts */ |
| 41 | 41 | return $posts; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $error = false; |
| 45 | 45 | |
| 46 | - foreach ( $posts as $post ) { |
|
| 47 | - $result = $this->update( $post->id() ); |
|
| 48 | - if ( is_wp_error( $result ) ) { |
|
| 49 | - if ( $error ) { |
|
| 50 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 46 | + foreach ($posts as $post) { |
|
| 47 | + $result = $this->update($post->id()); |
|
| 48 | + if (is_wp_error($result)) { |
|
| 49 | + if ($error) { |
|
| 50 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
| 51 | 51 | } else { |
| 52 | 52 | $error = $result; |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( is_wp_error( $error ) ) { |
|
| 57 | + if (is_wp_error($error)) { |
|
| 58 | 58 | return $error; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 61 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | * @param int $post_id |
| 68 | 68 | * @return boolean |
| 69 | 69 | */ |
| 70 | - protected function github_path( $post_id ) { |
|
| 71 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
| 70 | + protected function github_path($post_id) { |
|
| 71 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
| 72 | 72 | |
| 73 | - if ( $github_path && $this->app->api()->fetch()->exists( $github_path ) ) { |
|
| 73 | + if ($github_path && $this->app->api()->fetch()->exists($github_path)) { |
|
| 74 | 74 | return $github_path; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -84,31 +84,31 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return string|WP_Error |
| 86 | 86 | */ |
| 87 | - public function update( $post_id ) { |
|
| 88 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
| 87 | + public function update($post_id) { |
|
| 88 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
| 89 | 89 | |
| 90 | - if ( is_wp_error( $post ) ) { |
|
| 90 | + if (is_wp_error($post)) { |
|
| 91 | 91 | /* @var WP_Error $post */ |
| 92 | 92 | return $post; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if ( 'trash' === $post->status() ) { |
|
| 96 | - return $this->delete( $post_id ); |
|
| 95 | + if ('trash' === $post->status()) { |
|
| 96 | + return $this->delete($post_id); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if ( $old_github_path = $this->github_path( $post->id() ) ) { |
|
| 99 | + if ($old_github_path = $this->github_path($post->id())) { |
|
| 100 | 100 | error_log("old_github_path: $old_github_path"); |
| 101 | 101 | $post->set_old_github_path($old_github_path); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $result = $this->new_posts( array( $post ) ); |
|
| 104 | + $result = $this->new_posts(array($post)); |
|
| 105 | 105 | |
| 106 | - if ( is_wp_error( $result ) ) { |
|
| 106 | + if (is_wp_error($result)) { |
|
| 107 | 107 | /* @var WP_Error $result */ |
| 108 | 108 | return $result; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 111 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -118,36 +118,36 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return string|WP_Error |
| 120 | 120 | */ |
| 121 | - public function new_posts( array $posts ) { |
|
| 121 | + public function new_posts(array $posts) { |
|
| 122 | 122 | $error = false; |
| 123 | 123 | |
| 124 | 124 | $persist = $this->app->api()->persist(); |
| 125 | 125 | |
| 126 | - foreach ( $posts as $post ) { |
|
| 127 | - $result = $this->new_post( $post, $persist ); |
|
| 128 | - if ( is_wp_error( $result ) ) { |
|
| 129 | - if ( $error ) { |
|
| 130 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 126 | + foreach ($posts as $post) { |
|
| 127 | + $result = $this->new_post($post, $persist); |
|
| 128 | + if (is_wp_error($result)) { |
|
| 129 | + if ($error) { |
|
| 130 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
| 131 | 131 | } else { |
| 132 | 132 | $error = $result; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( is_wp_error( $error ) ) { |
|
| 137 | + if (is_wp_error($error)) { |
|
| 138 | 138 | return $error; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 141 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - protected function new_post( $post, $persist ) { |
|
| 144 | + protected function new_post($post, $persist) { |
|
| 145 | 145 | $github_path = $post->github_path(); |
| 146 | 146 | $old_github_path = $post->old_github_path(); |
| 147 | 147 | $blob = $post->to_blob(); |
| 148 | 148 | $result = false; |
| 149 | 149 | |
| 150 | - if ( $old_github_path && $old_github_path != $github_path ) { |
|
| 150 | + if ($old_github_path && $old_github_path != $github_path) { |
|
| 151 | 151 | // rename |
| 152 | 152 | $message = apply_filters( |
| 153 | 153 | 'wogh_commit_msg_move_post', |
@@ -155,20 +155,20 @@ discard block |
||
| 155 | 155 | 'Move %s to %s via WordPress at %s (%s)', |
| 156 | 156 | $old_github_path, $github_path, |
| 157 | 157 | site_url(), |
| 158 | - get_bloginfo( 'name' ) |
|
| 158 | + get_bloginfo('name') |
|
| 159 | 159 | ) |
| 160 | 160 | ) . $this->get_commit_msg_tag(); |
| 161 | 161 | |
| 162 | - $result = $persist->delete_file( $post->old_github_path(), $blob->sha(), $message ); |
|
| 163 | - if ( is_wp_error( $result ) ) { |
|
| 162 | + $result = $persist->delete_file($post->old_github_path(), $blob->sha(), $message); |
|
| 163 | + if (is_wp_error($result)) { |
|
| 164 | 164 | return $result; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $result = $persist->create_file( $blob, $message ); |
|
| 168 | - if ( is_wp_error( $result ) ) { |
|
| 167 | + $result = $persist->create_file($blob, $message); |
|
| 168 | + if (is_wp_error($result)) { |
|
| 169 | 169 | return $result; |
| 170 | 170 | } |
| 171 | - } elseif ( ! $old_github_path ) { |
|
| 171 | + } elseif ( ! $old_github_path) { |
|
| 172 | 172 | // create new |
| 173 | 173 | $message = apply_filters( |
| 174 | 174 | 'wogh_commit_msg_new_post', |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | 'Create new post %s from WordPress at %s (%s)', |
| 177 | 177 | $github_path, |
| 178 | 178 | site_url(), |
| 179 | - get_bloginfo( 'name' ) |
|
| 179 | + get_bloginfo('name') |
|
| 180 | 180 | ) |
| 181 | 181 | ) . $this->get_commit_msg_tag(); |
| 182 | - $result = $persist->create_file( $blob, $message ); |
|
| 183 | - if ( is_wp_error( $result ) ) { |
|
| 182 | + $result = $persist->create_file($blob, $message); |
|
| 183 | + if (is_wp_error($result)) { |
|
| 184 | 184 | return $result; |
| 185 | 185 | } |
| 186 | - } elseif ( $old_github_path && $old_github_path == $github_path ) { |
|
| 186 | + } elseif ($old_github_path && $old_github_path == $github_path) { |
|
| 187 | 187 | // update |
| 188 | 188 | $message = apply_filters( |
| 189 | 189 | 'wogh_commit_msg_update_post', |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | 'Update post %s from WordPress at %s (%s)', |
| 192 | 192 | $github_path, |
| 193 | 193 | site_url(), |
| 194 | - get_bloginfo( 'name' ) |
|
| 194 | + get_bloginfo('name') |
|
| 195 | 195 | ) |
| 196 | 196 | ) . $this->get_commit_msg_tag(); |
| 197 | - $result = $persist->update_file( $blob, $message ); |
|
| 198 | - if ( is_wp_error( $result ) ) { |
|
| 197 | + $result = $persist->update_file($blob, $message); |
|
| 198 | + if (is_wp_error($result)) { |
|
| 199 | 199 | return $result; |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -214,15 +214,15 @@ discard block |
||
| 214 | 214 | * |
| 215 | 215 | * @return string|WP_Error |
| 216 | 216 | */ |
| 217 | - public function delete( $post_id ) { |
|
| 218 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
| 217 | + public function delete($post_id) { |
|
| 218 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
| 219 | 219 | |
| 220 | - if ( is_wp_error( $post ) ) { |
|
| 220 | + if (is_wp_error($post)) { |
|
| 221 | 221 | /* @var WP_Error $post */ |
| 222 | 222 | return $post; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
| 225 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
| 226 | 226 | |
| 227 | 227 | $message = apply_filters( |
| 228 | 228 | 'wogh_commit_msg_delete', |
@@ -230,19 +230,19 @@ discard block |
||
| 230 | 230 | 'Deleting %s via WordPress at %s (%s)', |
| 231 | 231 | $github_path, |
| 232 | 232 | site_url(), |
| 233 | - get_bloginfo( 'name' ) |
|
| 233 | + get_bloginfo('name') |
|
| 234 | 234 | ), |
| 235 | 235 | $post |
| 236 | 236 | ) . $this->get_commit_msg_tag(); |
| 237 | 237 | |
| 238 | - $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
|
| 238 | + $result = $this->app->api()->persist()->delete_file($github_path, $post->sha(), $message); |
|
| 239 | 239 | |
| 240 | - if ( is_wp_error( $result ) ) { |
|
| 240 | + if (is_wp_error($result)) { |
|
| 241 | 241 | /* @var WP_Error $result */ |
| 242 | 242 | return $result; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 245 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * |
| 254 | 254 | * @return bool |
| 255 | 255 | */ |
| 256 | - public function set_user( $user_id ) { |
|
| 257 | - return update_option( self::EXPORT_USER_OPTION, (int) $user_id ); |
|
| 256 | + public function set_user($user_id) { |
|
| 257 | + return update_option(self::EXPORT_USER_OPTION, (int) $user_id); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | * @return string |
| 264 | 264 | */ |
| 265 | 265 | protected function get_commit_msg_tag() { |
| 266 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
| 266 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
| 267 | 267 | |
| 268 | - if ( ! $tag ) { |
|
| 269 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
| 268 | + if ( ! $tag) { |
|
| 269 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | return ' - ' . $tag; |