Ejemplo n.º 1
0
 /**
  * Calls the content API to get the post's contents and metadata
  *
  * Returns Object the response from the API
  *
  * @param WordPress_GitHub_Sync_Post $post Post to retrieve remote contents for.
  *
  * @return mixed
  */
 public function remote_contents($post)
 {
     return $this->call('GET', $this->content_endpoint() . $post->github_path());
 }
Ejemplo n.º 2
0
 /**
  * Returns a blob for the provided post.
  *
  * @param WordPress_GitHub_Sync_Post $post Post to retrieve blob for.
  *
  * @return WordPress_GitHub_Sync_Blob
  */
 protected function get_blob_for_post(WordPress_GitHub_Sync_Post $post)
 {
     if ($blob = $this->get_blob_by_sha($post->sha())) {
         return $blob;
     }
     if ($blob = $this->get_blob_by_path($post->github_path())) {
         return $blob;
     }
     return $post->to_blob();
 }
Ejemplo n.º 3
0
 /**
  * Use the new tree to save sha data
  * for all the updated posts
  */
 public function save_post_shas($tree)
 {
     foreach ($this->posts as $post_id) {
         $post = new WordPress_GitHub_Sync_Post($post_id);
         $match = false;
         foreach ($tree as $blob) {
             // this might be a problem if the filename changed since it was set
             // (i.e. post updated in middle mass export)
             // solution?
             if ($post->github_path() === $blob->path) {
                 $post->set_sha($blob->sha);
                 $match = true;
                 break;
             }
         }
         if (!$match) {
             WordPress_GitHub_Sync::write_log(__('No sha matched for post ID ', WordPress_GitHub_Sync::$text_domain) . $post_id);
         }
     }
 }
Ejemplo n.º 4
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']);
 }
Ejemplo n.º 5
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));
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Creates a blob with the data required for the tree.
  *
  * @param WordPress_GitHub_Sync_Post $post
  *
  * @return stdClass
  */
 public function blob_from_post($post)
 {
     $blob = new stdClass();
     $blob->path = $post->github_path();
     $blob->mode = '100644';
     $blob->type = 'blob';
     $blob->content = $post->github_content();
     return $blob;
 }