コード例 #1
0
 /**
  * Processes the request to pull changes into the current branch.
  * @access public
  */
 public function process_pull()
 {
     // Determine whether this is a request from the dashboard or a POST request.
     $from_dash = check_ajax_referer('dashboard_nonce', 'security', false);
     if ($from_dash == false) {
         if ($this->git->config_revisr_option('auto-pull') !== 'true') {
             wp_die(__('Cheatin’ uh?', 'revisr'));
         }
         $remote = new Revisr_Remote();
         $remote->check_token();
     }
     $this->git->reset();
     $this->git->fetch();
     $commits_since = $this->git->run("log {$this->git->branch}..{$this->git->remote}/{$this->git->branch} --pretty=oneline");
     if (is_array($commits_since)) {
         // Iterate through the commits to pull and add them to the database.
         foreach ($commits_since as $commit) {
             $commit_hash = substr($commit, 0, 7);
             $commit_msg = substr($commit, 40);
             $show_files = $this->git->run('show --pretty="format:" --name-status ' . $commit_hash);
             if (is_array($show_files)) {
                 $files_changed = array_filter($show_files);
                 $post = array('post_title' => $commit_msg, 'post_content' => '', 'post_type' => 'revisr_commits', 'post_status' => 'publish');
                 $post_id = wp_insert_post($post);
                 add_post_meta($post_id, 'commit_hash', $commit_hash);
                 add_post_meta($post_id, 'branch', $this->git->branch);
                 add_post_meta($post_id, 'files_changed', count($files_changed));
                 add_post_meta($post_id, 'committed_files', $files_changed);
                 $view_link = get_admin_url() . "post.php?post={$post_id}&action=edit";
                 $msg = sprintf(__('Pulled <a href="%s">#%s</a> from %s/%s.', 'revisr'), $view_link, $commit_hash, $this->git->remote, $this->git->branch);
                 Revisr_Admin::log($msg, 'pull');
             }
         }
     }
     if ($this->git->config_revisr_option('import-pulls') === 'true') {
         $this->db->backup();
         $undo_hash = $this->git->current_commit();
         $this->git->run("config --add revisr.last-db-backup {$undo_hash}");
     }
     // Pull the changes or return an error on failure.
     $this->git->pull();
 }