/** * Checks whether the provided blob should be imported. * * @param WordPress_GitHub_Sync_Blob $blob Blob to validate. * * @return bool */ protected function importable_blob(WordPress_GitHub_Sync_Blob $blob) { global $wpdb; // Skip the repo's readme. if ('readme' === strtolower(substr($blob->path(), 0, 6))) { return false; } // If the blob sha already matches a post, then move on. if (!is_wp_error($this->app->database()->fetch_by_sha($blob->sha()))) { return false; } if (!$blob->has_frontmatter()) { return false; } return true; }
/** * Use the new tree to save sha data * for all the updated posts. * * @param WordPress_GitHub_Sync_Post[] $posts Posts to fetch updated shas for. * * @return string|WP_Error */ protected function update_shas(array $posts) { $master = $this->app->api()->fetch()->master(); $attempts = 1; while (is_wp_error($master) && $attempts < 5) { $master = $this->app->api()->fetch()->master(); $attempts++; } if (is_wp_error($master)) { // @todo throw a big warning! not having the latest shas is BAD // Solution: Show error message and link to kick off sha importing. return $master; } foreach ($posts as $post) { $blob = $master->tree()->get_blob_by_path($post->github_path()); if ($blob) { $this->app->database()->set_post_sha($post, $blob->sha()); } } return __('Export to GitHub completed successfully.', 'wordpress-github-sync'); }