| @@ 39-74 (lines=36) @@ | ||
| 36 | * |
|
| 37 | * @return string|WP_Error |
|
| 38 | */ |
|
| 39 | public function full() { |
|
| 40 | $posts = $this->app->database()->fetch_all_supported(); |
|
| 41 | ||
| 42 | if ( is_wp_error( $posts ) ) { |
|
| 43 | return $posts; |
|
| 44 | } |
|
| 45 | ||
| 46 | $master = $this->app->api()->fetch()->master(); |
|
| 47 | ||
| 48 | if ( is_wp_error( $master ) ) { |
|
| 49 | return $master; |
|
| 50 | } |
|
| 51 | ||
| 52 | foreach ( $posts as $post ) { |
|
| 53 | $master->tree()->add_post_to_tree( $post ); |
|
| 54 | } |
|
| 55 | ||
| 56 | $master->set_message( |
|
| 57 | apply_filters( |
|
| 58 | 'wpghs_commit_msg_full', |
|
| 59 | sprintf( |
|
| 60 | 'Full export from WordPress at %s (%s)', |
|
| 61 | site_url(), |
|
| 62 | get_bloginfo( 'name' ) |
|
| 63 | ) |
|
| 64 | ) . $this->get_commit_msg_tag() |
|
| 65 | ); |
|
| 66 | ||
| 67 | $result = $this->app->api()->persist()->commit( $master ); |
|
| 68 | ||
| 69 | if ( is_wp_error( $result ) ) { |
|
| 70 | return $result; |
|
| 71 | } |
|
| 72 | ||
| 73 | return $this->update_shas( $posts ); |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Updates the provided post ID in master. |
|
| @@ 168-202 (lines=35) @@ | ||
| 165 | * |
|
| 166 | * @return string|WP_Error |
|
| 167 | */ |
|
| 168 | public function delete( $post_id ) { |
|
| 169 | $post = $this->app->database()->fetch_by_id( $post_id ); |
|
| 170 | ||
| 171 | if ( is_wp_error( $post ) ) { |
|
| 172 | return $post; |
|
| 173 | } |
|
| 174 | ||
| 175 | $master = $this->app->api()->fetch()->master(); |
|
| 176 | ||
| 177 | if ( is_wp_error( $master ) ) { |
|
| 178 | return $master; |
|
| 179 | } |
|
| 180 | ||
| 181 | $master->tree()->remove_post_from_tree( $post ); |
|
| 182 | $master->set_message( |
|
| 183 | apply_filters( |
|
| 184 | 'wpghs_commit_msg_delete', |
|
| 185 | sprintf( |
|
| 186 | 'Deleting %s via WordPress at %s (%s)', |
|
| 187 | $post->github_path(), |
|
| 188 | site_url(), |
|
| 189 | get_bloginfo( 'name' ) |
|
| 190 | ), |
|
| 191 | $post |
|
| 192 | ) . $this->get_commit_msg_tag() |
|
| 193 | ); |
|
| 194 | ||
| 195 | $result = $this->app->api()->persist()->commit( $master ); |
|
| 196 | ||
| 197 | if ( is_wp_error( $result ) ) { |
|
| 198 | return $result; |
|
| 199 | } |
|
| 200 | ||
| 201 | return __( 'Export to GitHub completed successfully.', 'wordpress-github-sync' ); |
|
| 202 | } |
|
| 203 | ||
| 204 | /** |
|
| 205 | * Use the new tree to save sha data |
|