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