@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * Updates all of the current posts in the database on master. |
31 | 31 | * |
32 | - * @param bool $force_all |
|
33 | - * @return string|WP_Error |
|
34 | - */ |
|
32 | + * @param bool $force_all |
|
33 | + * @return string|WP_Error |
|
34 | + */ |
|
35 | 35 | public function full( $force_all = false ) { |
36 | 36 | $posts = $this->app->database()->fetch_all_supported($force_all); |
37 | 37 | |
@@ -39,24 +39,24 @@ discard block |
||
39 | 39 | return $posts; |
40 | 40 | } |
41 | 41 | |
42 | - $error = false; |
|
42 | + $error = false; |
|
43 | 43 | |
44 | - foreach ( $posts as $post ) { |
|
45 | - $result = $this->update( $post->id() ); |
|
46 | - if ( is_wp_error( $result ) ) { |
|
47 | - if ( $error ) { |
|
48 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
49 | - } else { |
|
50 | - $error = $result; |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
44 | + foreach ( $posts as $post ) { |
|
45 | + $result = $this->update( $post->id() ); |
|
46 | + if ( is_wp_error( $result ) ) { |
|
47 | + if ( $error ) { |
|
48 | + $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
49 | + } else { |
|
50 | + $error = $result; |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - if ( is_wp_error( $error ) ) { |
|
56 | - return $error; |
|
57 | - } |
|
55 | + if ( is_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 |
@@ -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 | |
@@ -32,31 +32,31 @@ discard block |
||
32 | 32 | * @param bool $force_all |
33 | 33 | * @return string|WP_Error |
34 | 34 | */ |
35 | - public function full( $force_all = false ) { |
|
35 | + public function full($force_all = false) { |
|
36 | 36 | $posts = $this->app->database()->fetch_all_supported($force_all); |
37 | 37 | |
38 | - if ( is_wp_error( $posts ) ) { |
|
38 | + if (is_wp_error($posts)) { |
|
39 | 39 | return $posts; |
40 | 40 | } |
41 | 41 | |
42 | 42 | $error = false; |
43 | 43 | |
44 | - foreach ( $posts as $post ) { |
|
45 | - $result = $this->update( $post->id() ); |
|
46 | - if ( is_wp_error( $result ) ) { |
|
47 | - if ( $error ) { |
|
48 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
44 | + foreach ($posts as $post) { |
|
45 | + $result = $this->update($post->id()); |
|
46 | + if (is_wp_error($result)) { |
|
47 | + if ($error) { |
|
48 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
49 | 49 | } else { |
50 | 50 | $error = $result; |
51 | 51 | } |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - if ( is_wp_error( $error ) ) { |
|
55 | + if (is_wp_error($error)) { |
|
56 | 56 | return $error; |
57 | 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 | |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | * @param int $post_id |
66 | 66 | * @return boolean |
67 | 67 | */ |
68 | - protected function github_path( $post_id ) { |
|
69 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
68 | + protected function github_path($post_id) { |
|
69 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
70 | 70 | |
71 | - if ( $github_path && $this->app->api()->fetch()->exists( $github_path ) ) { |
|
71 | + if ($github_path && $this->app->api()->fetch()->exists($github_path)) { |
|
72 | 72 | return $github_path; |
73 | 73 | } |
74 | 74 | |
@@ -82,29 +82,29 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return string|WP_Error |
84 | 84 | */ |
85 | - public function update( $post_id ) { |
|
86 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
85 | + public function update($post_id) { |
|
86 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
87 | 87 | |
88 | - if ( is_wp_error( $post ) ) { |
|
88 | + if (is_wp_error($post)) { |
|
89 | 89 | return $post; |
90 | 90 | } |
91 | 91 | |
92 | - if ( 'trash' === $post->status() ) { |
|
93 | - return $this->delete( $post_id ); |
|
92 | + if ('trash' === $post->status()) { |
|
93 | + return $this->delete($post_id); |
|
94 | 94 | } |
95 | 95 | |
96 | - if ( $old_github_path = $this->github_path( $post->id() ) ) { |
|
96 | + if ($old_github_path = $this->github_path($post->id())) { |
|
97 | 97 | error_log("old_github_path: $old_github_path"); |
98 | 98 | $post->set_old_github_path($old_github_path); |
99 | 99 | } |
100 | 100 | |
101 | - $result = $this->new_posts( array( $post ) ); |
|
101 | + $result = $this->new_posts(array($post)); |
|
102 | 102 | |
103 | - if ( is_wp_error( $result ) ) { |
|
103 | + if (is_wp_error($result)) { |
|
104 | 104 | return $result; |
105 | 105 | } |
106 | 106 | |
107 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
107 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -114,16 +114,16 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return string|WP_Error |
116 | 116 | */ |
117 | - public function new_posts( array $posts ) { |
|
117 | + public function new_posts(array $posts) { |
|
118 | 118 | $error = false; |
119 | 119 | |
120 | 120 | $persist = $this->app->api()->persist(); |
121 | 121 | |
122 | - foreach ( $posts as $post ) { |
|
123 | - $result = $this->new_post( $post, $persist ); |
|
124 | - if ( is_wp_error( $result ) ) { |
|
125 | - if ( $error ) { |
|
126 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
122 | + foreach ($posts as $post) { |
|
123 | + $result = $this->new_post($post, $persist); |
|
124 | + if (is_wp_error($result)) { |
|
125 | + if ($error) { |
|
126 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
127 | 127 | } else { |
128 | 128 | $error = $result; |
129 | 129 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | // $result = $this->app->api()->persist()->commit( $master ); |
136 | 136 | |
137 | - if ( is_wp_error( $error ) ) { |
|
137 | + if (is_wp_error($error)) { |
|
138 | 138 | return $error; |
139 | 139 | } |
140 | 140 | |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | return true; |
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,14 +215,14 @@ 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 | 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,18 +230,18 @@ 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 | return $result; |
242 | 242 | } |
243 | 243 | |
244 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
244 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @return bool |
254 | 254 | */ |
255 | - public function set_user( $user_id ) { |
|
256 | - return update_option( self::EXPORT_USER_OPTION, (int) $user_id ); |
|
255 | + public function set_user($user_id) { |
|
256 | + return update_option(self::EXPORT_USER_OPTION, (int) $user_id); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | * @return string |
263 | 263 | */ |
264 | 264 | protected function get_commit_msg_tag() { |
265 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
265 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
266 | 266 | |
267 | - if ( ! $tag ) { |
|
268 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
267 | + if ( ! $tag) { |
|
268 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | return ' - ' . $tag; |