1 | <?php |
||
11 | class Writing_On_GitHub_Export { |
||
12 | |||
13 | /** |
||
14 | * Application container. |
||
15 | * |
||
16 | * @var Writing_On_GitHub |
||
17 | */ |
||
18 | protected $app; |
||
19 | |||
20 | /** |
||
21 | * Initializes a new export manager. |
||
22 | * |
||
23 | * @param Writing_On_GitHub $app Application container. |
||
24 | */ |
||
25 | public function __construct( Writing_On_GitHub $app ) { |
||
28 | |||
29 | /** |
||
30 | * Updates all of the current posts in the database on master. |
||
31 | * |
||
32 | * @param bool $force |
||
33 | * |
||
34 | * @return string|WP_Error |
||
35 | */ |
||
36 | public function full( $force = false ) { |
||
37 | $posts = $this->app->database()->fetch_all_supported( $force ); |
||
38 | |||
39 | if ( is_wp_error( $posts ) ) { |
||
40 | /* @var WP_Error $posts */ |
||
41 | return $posts; |
||
42 | } |
||
43 | |||
44 | $error = ''; |
||
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 | } |
||
53 | |||
54 | if ( is_wp_error( $error ) ) { |
||
55 | /* @var WP_Error $error */ |
||
56 | return $error; |
||
57 | } |
||
58 | |||
59 | return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
||
60 | } |
||
61 | |||
62 | |||
63 | /** |
||
64 | * Check if it exists in github |
||
65 | * @param int $post_id |
||
66 | * @return boolean |
||
67 | */ |
||
68 | protected function github_path( $post_id ) { |
||
77 | |||
78 | /** |
||
79 | * Updates the provided post ID in master. |
||
80 | * |
||
81 | * @param int $post_id Post ID to update. |
||
82 | * |
||
83 | * @return string|WP_Error |
||
84 | */ |
||
85 | public function update( $post_id ) { |
||
111 | |||
112 | /** |
||
113 | * Post to blob |
||
114 | * @param Writing_On_GitHub_Post $post |
||
115 | * @return WP_Error|Writing_On_GitHub_Blob |
||
116 | */ |
||
117 | protected function post_to_blob( Writing_On_GitHub_Post $post ) { |
||
135 | |||
136 | /** |
||
137 | * Export post to github |
||
138 | * @param Writing_On_GitHub_Post $post |
||
139 | * @return WP_Error|true |
||
140 | */ |
||
141 | public function export_post( Writing_On_GitHub_Post $post ) { |
||
219 | |||
220 | /** |
||
221 | * Deletes a provided post ID from master. |
||
222 | * |
||
223 | * @param int $post_id Post ID to delete. |
||
224 | * |
||
225 | * @return string|WP_Error |
||
226 | */ |
||
227 | public function delete( $post_id ) { |
||
257 | |||
258 | |||
259 | /** |
||
260 | * Saves the export user to the database. |
||
261 | * |
||
262 | * @param int $user_id User ID to export with. |
||
263 | * |
||
264 | * @return bool |
||
265 | */ |
||
266 | public function set_user( $user_id ) { |
||
269 | |||
270 | /** |
||
271 | * Gets the commit message tag. |
||
272 | * |
||
273 | * @return string |
||
274 | */ |
||
275 | protected function get_commit_msg_tag() { |
||
284 | } |
||
285 |