Пример #1
0
 /**
  * Runs the import process for a provided sha.
  *
  * @param string $sha
  */
 public function run($sha)
 {
     $this->tree->fetch_sha($sha);
     if (!$this->tree->ready()) {
         WordPress_GitHub_Sync::write_log(__('Failed getting recursive tree with error: ', 'wordpress-github-sync') . $this->tree->last_error());
         return;
     }
     foreach ($this->tree as $blob) {
         $this->import_blob($blob);
     }
     WordPress_GitHub_Sync::write_log(__('Imported tree ', 'wordpress-github-sync') . $sha);
 }
Пример #2
0
 /**
  * Returns the commit's tree's sha.
  *
  * @return string
  */
 public function tree_sha()
 {
     if ($this->tree) {
         return $this->tree->sha();
     }
     if (isset($this->data->tree)) {
         return $this->data->tree->sha;
     }
     return '';
 }
Пример #3
0
 /**
  * Use the new tree to save sha data
  * for all the updated posts
  */
 public function save_post_shas()
 {
     foreach ($this->ids as $post_id) {
         $post = new WordPress_GitHub_Sync_Post($post_id);
         $blob = $this->tree->get_blob_for_path($post->github_path());
         if ($blob) {
             $post->set_sha($blob->sha);
         } else {
             WordPress_GitHub_Sync::write_log(sprintf(__('No sha matched for post ID %d', 'wordpress-github-sync'), $post_id));
         }
     }
 }
Пример #4
0
 /**
  * Retrieves a tree by sha recursively from the GitHub API
  *
  * @param string $sha Commit sha to retrieve tree from.
  *
  * @return WordPress_GitHub_Sync_Tree|WP_Error
  */
 protected function tree_recursive($sha)
 {
     if ($cache = $this->app->cache()->fetch_tree($sha)) {
         return $cache;
     }
     $data = $this->call('GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1');
     if (is_wp_error($data)) {
         return $data;
     }
     foreach ($data->tree as $index => $thing) {
         // We need to remove the trees because
         // the recursive tree includes both
         // the subtrees as well the subtrees' blobs.
         if ('tree' === $thing->type) {
             unset($data->tree[$index]);
         }
     }
     $tree = new WordPress_GitHub_Sync_Tree($data);
     $tree->set_blobs($this->blobs($data->tree));
     return $this->app->cache()->set_tree($sha, $tree);
 }
Пример #5
0
 /**
  * Create the tree by a set of blob ids.
  *
  * @param WordPress_GitHub_Sync_Tree $tree Tree to create.
  *
  * @return stdClass|WP_Error
  */
 protected function create_tree(WordPress_GitHub_Sync_Tree $tree)
 {
     return $this->call('POST', $this->tree_endpoint(), $tree->to_body());
 }
Пример #6
0
 public function test_should_remove_post_by_path()
 {
     $sha = '1234567890qwertyuiop';
     $this->blob->shouldReceive('sha')->andReturn($sha);
     $post_id = $this->factory->post->create();
     $post = new WordPress_GitHub_Sync_Post($post_id, $this->api);
     $this->blob->shouldReceive('path')->andReturn($post->github_path());
     $tree = new WordPress_GitHub_Sync_Tree(new stdClass());
     $tree->add_blob($this->blob);
     $tree->remove_post_from_tree($post);
     $this->assertCount(0, $blobs = $tree->blobs());
     $this->assertTrue($tree->is_changed());
     $body = $tree->to_body();
     $this->assertArrayHasKey('tree', $body);
     $this->assertCount(0, $body['tree']);
 }