Ejemplo n.º 1
0
 /**
  * After all the blobs are saved,
  * create the tree, commit, and adjust master ref
  */
 public function finalize()
 {
     if (!$this->changed) {
         $this->no_change();
         return;
     }
     WordPress_GitHub_Sync::write_log(__('Creating the tree.', WordPress_GitHub_Sync::$text_domain));
     $tree = $this->api->create_tree(array_values($this->tree));
     if (is_wp_error($tree)) {
         $this->error($tree);
         return;
     }
     WordPress_GitHub_Sync::write_log(__('Creating the commit.', WordPress_GitHub_Sync::$text_domain));
     $commit = $this->api->create_commit($tree->sha, $this->msg);
     if (is_wp_error($commit)) {
         $this->error($commit);
         return;
     }
     WordPress_GitHub_Sync::write_log(__('Setting the master branch to our new commit.', WordPress_GitHub_Sync::$text_domain));
     $ref = $this->api->set_ref($commit->sha);
     if (is_wp_error($ref)) {
         $this->error($ref);
         return;
     }
     $rtree = $this->api->last_tree_recursive();
     WordPress_GitHub_Sync::write_log(__('Saving the shas.', WordPress_GitHub_Sync::$text_domain));
     $this->save_post_shas($rtree);
     $this->success();
 }
Ejemplo n.º 2
0
 /**
  * Exports the tree as a new commit with a provided commit message.
  *
  * @param string $msg
  *
  * @return bool|WP_Error false if unchanged, true if success, WP_Error if error
  */
 public function export($msg)
 {
     if (!$this->changed) {
         return false;
     }
     WordPress_GitHub_Sync::write_log(__('Creating the tree.', 'wordpress-github-sync'));
     $tree = $this->api->create_tree(array_values($this->tree));
     if (is_wp_error($tree)) {
         return $tree;
     }
     WordPress_GitHub_Sync::write_log(__('Creating the commit.', 'wordpress-github-sync'));
     $commit = $this->api->create_commit($tree->sha, $msg);
     if (is_wp_error($commit)) {
         return $commit;
     }
     WordPress_GitHub_Sync::write_log(__('Setting the master branch to our new commit.', 'wordpress-github-sync'));
     $ref = $this->api->set_ref($commit->sha);
     if (is_wp_error($ref)) {
         return $ref;
     }
     return true;
 }