@@ -26,24 +26,24 @@ discard block |
||
| 26 | 26 | $this->app = $app; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Imports a payload. |
|
| 31 | - * @param Writing_On_GitHub_Payload $payload |
|
| 32 | - * |
|
| 33 | - * @return string|WP_Error |
|
| 34 | - */ |
|
| 29 | + /** |
|
| 30 | + * Imports a payload. |
|
| 31 | + * @param Writing_On_GitHub_Payload $payload |
|
| 32 | + * |
|
| 33 | + * @return string|WP_Error |
|
| 34 | + */ |
|
| 35 | 35 | public function payload( Writing_On_GitHub_Payload $payload ) { |
| 36 | 36 | |
| 37 | 37 | $result = $this->app->api()->fetch()->compare( $payload->get_before_commit_id() ); |
| 38 | 38 | |
| 39 | 39 | if ( is_wp_error( $result ) ) { |
| 40 | - /* @var WP_Error $result */ |
|
| 40 | + /* @var WP_Error $result */ |
|
| 41 | 41 | return $result; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ( is_array( $result ) ) { |
|
| 45 | - $result = $this->import_files( $result ); |
|
| 46 | - } |
|
| 44 | + if ( is_array( $result ) ) { |
|
| 45 | + $result = $this->import_files( $result ); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | if ( is_wp_error( $result ) ) { |
| 49 | 49 | return $files; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * import blob by files |
| 57 | 57 | * @param Writing_On_GitHub_File_Info[] $files |
| 58 | - * |
|
| 58 | + * |
|
| 59 | 59 | * @return string|WP_Error |
| 60 | 60 | */ |
| 61 | 61 | protected function import_files( $files ) { |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | foreach ($delete_ids as $id) { |
| 74 | 74 | $result = $this->app->database()->delete_post( $id ); |
| 75 | 75 | if ( is_wp_error( $result ) ) { |
| 76 | - /* @var WP_Error $result */ |
|
| 77 | - $error = wogh_append_error( $error, $result ); |
|
| 76 | + /* @var WP_Error $result */ |
|
| 77 | + $error = wogh_append_error( $error, $result ); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -91,32 +91,32 @@ discard block |
||
| 91 | 91 | $result = $this->app->api()->fetch()->tree_recursive(); |
| 92 | 92 | |
| 93 | 93 | if ( is_wp_error( $result ) ) { |
| 94 | - /* @var WP_Error $result */ |
|
| 94 | + /* @var WP_Error $result */ |
|
| 95 | 95 | return $result; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if ( is_array( $result ) ) { |
|
| 99 | - $result = $this->import_files( $result ); |
|
| 100 | - } |
|
| 98 | + if ( is_array( $result ) ) { |
|
| 99 | + $result = $this->import_files( $result ); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | if ( is_wp_error( $result ) ) { |
| 103 | - /* @var WP_Error $result */ |
|
| 103 | + /* @var WP_Error $result */ |
|
| 104 | 104 | return $result; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | return __( 'Payload processed', 'writing-on-github' ); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Do compare |
|
| 112 | - * @param Writing_On_GitHub_File_Info[]|WP_Error $files |
|
| 113 | - * @param int[] &$delete_ids |
|
| 114 | - * |
|
| 115 | - * @return string|WP_Error |
|
| 116 | - */ |
|
| 110 | + /** |
|
| 111 | + * Do compare |
|
| 112 | + * @param Writing_On_GitHub_File_Info[]|WP_Error $files |
|
| 113 | + * @param int[] &$delete_ids |
|
| 114 | + * |
|
| 115 | + * @return string|WP_Error |
|
| 116 | + */ |
|
| 117 | 117 | protected function compare( $files, &$delete_ids ) { |
| 118 | 118 | if ( is_wp_error( $files ) ) { |
| 119 | - /* @var WP_Error $files */ |
|
| 119 | + /* @var WP_Error $files */ |
|
| 120 | 120 | return $files; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -29,34 +29,34 @@ 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 = ''; |
|
| 44 | + $error = ''; |
|
| 45 | 45 | |
| 46 | - foreach ( $posts as $post ) { |
|
| 47 | - $result = $this->update( $post->id() ); |
|
| 48 | - if ( is_wp_error( $result ) ) { |
|
| 49 | - /* @var WP_Error $result */ |
|
| 50 | - $error = wogh_append_error( $error, $result ); |
|
| 51 | - } |
|
| 52 | - } |
|
| 46 | + foreach ( $posts as $post ) { |
|
| 47 | + $result = $this->update( $post->id() ); |
|
| 48 | + if ( is_wp_error( $result ) ) { |
|
| 49 | + /* @var WP_Error $result */ |
|
| 50 | + $error = wogh_append_error( $error, $result ); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - if ( is_wp_error( $error ) ) { |
|
| 55 | - /* @var WP_Error $error */ |
|
| 56 | - return $error; |
|
| 57 | - } |
|
| 54 | + if ( is_wp_error( $error ) ) { |
|
| 55 | + /* @var WP_Error $error */ |
|
| 56 | + return $error; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 59 | + return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $post = $this->app->database()->fetch_by_id( $post_id ); |
| 87 | 87 | |
| 88 | 88 | if ( is_wp_error( $post ) ) { |
| 89 | - /* @var WP_Error $post */ |
|
| 89 | + /* @var WP_Error $post */ |
|
| 90 | 90 | return $post; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | $result = $this->new_posts( array( $post ) ); |
| 103 | 103 | |
| 104 | 104 | if ( is_wp_error( $result ) ) { |
| 105 | - /* @var WP_Error $result */ |
|
| 105 | + /* @var WP_Error $result */ |
|
| 106 | 106 | return $result; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | * @return string|WP_Error |
| 118 | 118 | */ |
| 119 | 119 | public function new_posts( array $posts ) { |
| 120 | - $persist = $this->app->api()->persist(); |
|
| 120 | + $persist = $this->app->api()->persist(); |
|
| 121 | 121 | |
| 122 | 122 | $error = ''; |
| 123 | 123 | foreach ( $posts as $post ) { |
| 124 | 124 | $result = $this->new_post( $post, $persist ); |
| 125 | 125 | if ( is_wp_error( $result ) ) { |
| 126 | - /* @var WP_Error $result */ |
|
| 127 | - $error = wogh_append_error( $error, $result ); |
|
| 126 | + /* @var WP_Error $result */ |
|
| 127 | + $error = wogh_append_error( $error, $result ); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | return $error; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 135 | + return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | protected function new_post( $post, $persist ) { |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $post = $this->app->database()->fetch_by_id( $post_id ); |
| 213 | 213 | |
| 214 | 214 | if ( is_wp_error( $post ) ) { |
| 215 | - /* @var WP_Error $post */ |
|
| 215 | + /* @var WP_Error $post */ |
|
| 216 | 216 | return $post; |
| 217 | 217 | } |
| 218 | 218 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
| 233 | 233 | |
| 234 | 234 | if ( is_wp_error( $result ) ) { |
| 235 | - /* @var WP_Error $result */ |
|
| 235 | + /* @var WP_Error $result */ |
|
| 236 | 236 | return $result; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | /** |
| 43 | 43 | * Queries the database for all of the supported posts. |
| 44 | 44 | * |
| 45 | - * @param bool $force |
|
| 46 | - * |
|
| 47 | - * @return Writing_On_GitHub_Post[]|WP_Error |
|
| 48 | - */ |
|
| 45 | + * @param bool $force |
|
| 46 | + * |
|
| 47 | + * @return Writing_On_GitHub_Post[]|WP_Error |
|
| 48 | + */ |
|
| 49 | 49 | public function fetch_all_supported( $force = false ) { |
| 50 | 50 | $args = array( |
| 51 | 51 | 'post_type' => $this->get_whitelisted_post_types(), |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /* @var Writing_On_GitHub_Post[] $results */ |
|
| 68 | + /* @var Writing_On_GitHub_Post[] $results */ |
|
| 69 | 69 | $results = array(); |
| 70 | 70 | foreach ( $post_ids as $post_id ) { |
| 71 | 71 | // Do not export posts that have already been exported |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | add_filter( 'content_save_pre', 'wp_filter_post_kses' ); |
| 133 | 133 | |
| 134 | 134 | if ( is_wp_error( $post_id ) ) { |
| 135 | - /* @var WP_Error $post_id */ |
|
| 136 | - $error = wogh_append_error( $error, $post_id ); |
|
| 135 | + /* @var WP_Error $post_id */ |
|
| 136 | + $error = wogh_append_error( $error, $post_id ); |
|
| 137 | 137 | |
| 138 | 138 | // Abort saving if updating the post fails. |
| 139 | 139 | continue; |
@@ -183,65 +183,65 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | // update tags |
| 185 | 185 | if ( ! empty( $meta['tags'] ) { |
| 186 | - $args['tags_input'] = $meta['tags']; |
|
| 186 | + $args['tags_input'] = $meta['tags']; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // update categories |
| 190 | 190 | if ( ! empty( $meta['categories'] ) { |
| 191 | - $categories = $meta['categories']; |
|
| 192 | - if ( ! is_array( $categories ) ) { |
|
| 193 | - $categories = array( $categories ); |
|
| 194 | - } |
|
| 195 | - $terms = get_terms( array( |
|
| 196 | - 'taxonomy' => 'category', |
|
| 197 | - 'fields' => 'id=>name', |
|
| 198 | - 'hide_empty' => 0, |
|
| 199 | - 'name' => $categories |
|
| 200 | - ) |
|
| 201 | - ); |
|
| 202 | - $map = array(); |
|
| 203 | - foreach ( $categories as $name ) { |
|
| 204 | - $map[$name] = 1; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $ids = array(); |
|
| 208 | - if ( ! empty( $terms ) ) { |
|
| 209 | - foreach ( $terms as $id => $name ) { |
|
| 210 | - $ids[] = $id; |
|
| 211 | - unset( $map[$name] ); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // create new terms |
|
| 216 | - if ( ! empty( $map ) ) { |
|
| 217 | - foreach ( $map as $name => $value ) { |
|
| 218 | - $term = wp_insert_term( $name, 'category', array( 'parent' => 0 ) ); |
|
| 219 | - // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
| 220 | - $ids[] = $term['term_id']; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $args['post_category'] = $ids; |
|
| 191 | + $categories = $meta['categories']; |
|
| 192 | + if ( ! is_array( $categories ) ) { |
|
| 193 | + $categories = array( $categories ); |
|
| 194 | + } |
|
| 195 | + $terms = get_terms( array( |
|
| 196 | + 'taxonomy' => 'category', |
|
| 197 | + 'fields' => 'id=>name', |
|
| 198 | + 'hide_empty' => 0, |
|
| 199 | + 'name' => $categories |
|
| 200 | + ) |
|
| 201 | + ); |
|
| 202 | + $map = array(); |
|
| 203 | + foreach ( $categories as $name ) { |
|
| 204 | + $map[$name] = 1; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $ids = array(); |
|
| 208 | + if ( ! empty( $terms ) ) { |
|
| 209 | + foreach ( $terms as $id => $name ) { |
|
| 210 | + $ids[] = $id; |
|
| 211 | + unset( $map[$name] ); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // create new terms |
|
| 216 | + if ( ! empty( $map ) ) { |
|
| 217 | + foreach ( $map as $name => $value ) { |
|
| 218 | + $term = wp_insert_term( $name, 'category', array( 'parent' => 0 ) ); |
|
| 219 | + // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
| 220 | + $ids[] = $term['term_id']; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $args['post_category'] = $ids; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | return $args; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - private function get_post_id_by_filename( $filename, $pattern ) { |
|
| 231 | - preg_match( $pattern , $filename, $matches ); |
|
| 232 | - $title = $matches[4]; |
|
| 230 | + private function get_post_id_by_filename( $filename, $pattern ) { |
|
| 231 | + preg_match( $pattern , $filename, $matches ); |
|
| 232 | + $title = $matches[4]; |
|
| 233 | 233 | |
| 234 | - $query = new WP_Query( array( |
|
| 235 | - 'name' => $title, |
|
| 236 | - 'posts_per_page' => 1, |
|
| 237 | - 'post_type' => $this->get_whitelisted_post_types(), |
|
| 238 | - 'fields' => 'ids', |
|
| 239 | - ) ); |
|
| 234 | + $query = new WP_Query( array( |
|
| 235 | + 'name' => $title, |
|
| 236 | + 'posts_per_page' => 1, |
|
| 237 | + 'post_type' => $this->get_whitelisted_post_types(), |
|
| 238 | + 'fields' => 'ids', |
|
| 239 | + ) ); |
|
| 240 | 240 | |
| 241 | - $post_id = $query->get_posts(); |
|
| 242 | - $post_id = array_pop( $post_id ); |
|
| 243 | - return $post_id; |
|
| 244 | - } |
|
| 241 | + $post_id = $query->get_posts(); |
|
| 242 | + $post_id = array_pop( $post_id ); |
|
| 243 | + return $post_id; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * Deletes a post from the database based on its GitHub path. |
@@ -268,11 +268,11 @@ discard block |
||
| 268 | 268 | $directory = $parts ? array_shift( $parts ) : ''; |
| 269 | 269 | |
| 270 | 270 | if ( false !== strpos( $directory, 'post' ) ) { |
| 271 | - $post_id = get_post_id_by_filename( $filename, '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/' ); |
|
| 271 | + $post_id = get_post_id_by_filename( $filename, '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/' ); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | if ( ! $post_id ) { |
| 275 | - $post_id = get_post_id_by_filename( $filename, '/(.*)\.md/' ); |
|
| 275 | + $post_id = get_post_id_by_filename( $filename, '/(.*)\.md/' ); |
|
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | |
@@ -417,12 +417,12 @@ discard block |
||
| 417 | 417 | if ( ! empty( $display_name ) ) { |
| 418 | 418 | $search_string = esc_attr( $display_name ); |
| 419 | 419 | $query = new WP_User_Query( array( |
| 420 | - 'search' => "{$search_string}", |
|
| 421 | - 'search_columns' => array( |
|
| 422 | - 'display_name', |
|
| 423 | - 'user_nicename', |
|
| 424 | - 'user_login', |
|
| 425 | - ) |
|
| 420 | + 'search' => "{$search_string}", |
|
| 421 | + 'search_columns' => array( |
|
| 422 | + 'display_name', |
|
| 423 | + 'user_nicename', |
|
| 424 | + 'user_login', |
|
| 425 | + ) |
|
| 426 | 426 | ) ); |
| 427 | 427 | $users = $query->get_results(); |
| 428 | 428 | $user = empty($users) ? false : $users[0]; |
@@ -8,8 +8,8 @@ |
||
| 8 | 8 | * @return WP_Error |
| 9 | 9 | */ |
| 10 | 10 | function wogh_append_error( $error, $error2 ) { |
| 11 | - if ( is_wp_error( $error ) ) { |
|
| 12 | - $error->add( $error2->get_error_code(), $error2->get_error_message() ); |
|
| 13 | - } |
|
| 14 | - return $error2; |
|
| 11 | + if ( is_wp_error( $error ) ) { |
|
| 12 | + $error->add( $error2->get_error_code(), $error2->get_error_message() ); |
|
| 13 | + } |
|
| 14 | + return $error2; |
|
| 15 | 15 | } |