/** * Processes the "auto-pull" functionality. * @access public */ public function run_autopull() { revisr()->git = new Revisr_Git(); // If auto-pull isn't enabled, we definitely don't want to do this. if (revisr()->git->get_config('revisr', 'auto-pull') !== 'true') { wp_die(__('Cheatin’ uh?', 'revisr')); } // Verify the provided token matches the token stored locally. $remote = new Revisr_Remote(); $remote->check_token(); // If we're still running at this point, we've successfully authenticated. revisr()->git->reset(); revisr()->git->fetch(); // Grab the commits that need to be pulled. $commits_since = revisr()->git->run('log', array(revisr()->git->branch . '..' . revisr()->git->remote . '/' . revisr()->git->branch, '--pretty=oneline')); // Maybe backup the database. if (revisr()->git->get_config('revisr', 'import-pulls') === 'true') { revisr()->db = new Revisr_DB(); revisr()->db->backup(); $undo_hash = revisr()->git->current_commit(); revisr()->git->set_config('revisr', 'last-db-backup', $undo_hash); } // Pull the changes or return an error on failure. revisr()->git->pull($commits_since); }
/** * 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(); }