コード例 #1
0
ファイル: test-admin.php プロジェクト: E-2/Revisr
 /**
  * Tests the Revisr_Admin::clear_transients() method.
  */
 function test_clear_transients()
 {
     //First set a transient and make sure it exists.
     Revisr_Admin::alert('test_error', true);
     $transient = get_transient('revisr_error');
     $this->assertEquals('test_error', $transient);
     // Clear the transients and make sure they're really gone.
     Revisr_Admin::clear_transients();
     $new_transient = get_transient('revisr_error');
     $this->assertEquals(false, $new_transient);
 }
コード例 #2
0
 /**
  * Returns if a push failed.
  * @access public
  */
 public function null_push($output = '', $args = '')
 {
     $msg = __('Error pushing to the remote repository. The remote repository could be ahead, or there may be an authentication issue.', 'revisr');
     Revisr_Admin::alert($msg, true);
     Revisr_Admin::log(__('Error pushing changes to the remote repository.', 'revisr'), 'error');
     return;
 }
コード例 #3
0
ファイル: class-revisr-process.php プロジェクト: acchs/test
 /**
  * Processes the request to discard all untracked changes.
  * @access public
  */
 public function discard()
 {
     Revisr_Admin::verify_nonce($_REQUEST['revisr_dashboard_nonce'], 'revisr_dashboard_nonce');
     // Fires prior to a discard.
     do_action('revisr_pre_discard');
     if (revisr()->git->reset('--hard', 'HEAD', true)) {
         Revisr_Admin::log(__('Discarded all uncommitted changes.', 'revisr'), 'discard');
         Revisr_Admin::alert(__('Successfully discarded any uncommitted changes.', 'revisr'));
         // Fires after a successful discard.
         do_action('revisr_post_discard');
     }
     exit;
 }
コード例 #4
0
 /**
  * Processes the results and alerts the user as necessary.
  * @access public
  * @param  array $args An array containing the results of the backup.
  * @return boolean
  */
 public function callback($args)
 {
     if (in_array(false, $args)) {
         $msg = __('Error backing up the database.', 'revisr');
         Revisr_Admin::alert($msg, true);
         Revisr_Admin::log($msg, 'error');
     } else {
         $msg = __('Successfully backed up the database.', 'revisr');
         Revisr_Admin::alert($msg);
         Revisr_Admin::log($msg, 'backup');
         return true;
     }
     return false;
 }
コード例 #5
0
    /**
     * Makes sure that Revisr is compatible in the current environment.
     * @access public
     */
    public function check_compatibility()
    {
        if (!function_exists('exec')) {
            Revisr_Admin::alert(__('It appears that you don\'t have the PHP exec() function enabled on your server. This can be enabled in your php.ini.
				Check with your web host if you\'re not sure what this means.', 'revisr'), true);
            return false;
        }
        $git = new Revisr_Git();
        if (is_dir($git->dir . '/.git/') && !is_writeable($git->dir . '/.git/')) {
            Revisr_Admin::alert(__('Revisr requires write permissions to the repository. The recommended settings are 755 for directories, and 644 for files.', 'revisr'), true);
            return false;
        }
        return true;
    }
コード例 #6
0
 /**
  * Stages the array of files passed through the New Commit screen.
  * @access public
  * @param  array $staged_files The files to add/remove
  */
 public function stage_files($staged_files)
 {
     $errors = array();
     foreach ($staged_files as $result) {
         $file = substr($result, 3);
         $status = Revisr_Git::get_status(substr($result, 0, 2));
         if ($status == __('Deleted', 'revisr')) {
             if ($this->run("rm {$file}") === false) {
                 $errors[] = $file;
             }
         } else {
             if ($this->run("add {$file}") === false) {
                 $errors[] = $file;
             }
         }
     }
     if (!empty($errors)) {
         $msg = __('There was an error staging the files. Please check the settings and try again.', 'revisr');
         Revisr_Admin::alert($msg, true);
         Revisr_Admin::log(__('Error staging files.', 'revisr'), 'error');
     }
 }
コード例 #7
0
 /**
  * Processes the request to discard all untracked changes.
  * @access public
  */
 public function process_discard()
 {
     if (wp_verify_nonce($_REQUEST['revisr_dashboard_nonce'], 'revisr_dashboard_nonce')) {
         $this->revisr->git->reset('--hard', 'HEAD', true);
         Revisr_Admin::log(__('Discarded all uncommitted changes.', 'revisr'), 'discard');
         Revisr_Admin::alert(__('Successfully discarded any uncommitted changes.', 'revisr'));
     }
     exit;
 }
コード例 #8
0
ファイル: class-revisr-git.php プロジェクト: acchs/test
 /**
  * Stages the array of files passed through the New Commit screen.
  * @access public
  * @param  array 	$staged_files 	An array of files to add/remove.
  * @param  boolean 	$stage_all 		If set to true, skip the loop and add -A.
  * @return boolean
  */
 public function stage_files($staged_files, $stage_all = false)
 {
     // An empty array for errors.
     $errors = array();
     if (true === $stage_all) {
         if ($this->run('add', array('-A')) === false) {
             $errors[] = $staged_files;
         }
     } else {
         foreach ($staged_files as $result) {
             $file = substr($result, 3);
             $status = self::get_status(substr($result, 0, 2));
             if ($status == __('Deleted', 'revisr')) {
                 if ($this->run('rm', array($file)) === false) {
                     $errors[] = $file;
                 }
             } else {
                 if ($this->run('add', array($file)) === false) {
                     $errors[] = $file;
                 }
             }
         }
     }
     if (!empty($errors)) {
         $msg = __('There was an error staging the files. Please check the settings and try again.', 'revisr');
         Revisr_Admin::alert($msg, true);
         Revisr_Admin::log(__('Error staging files.', 'revisr'), 'error');
         return false;
     }
     return true;
 }
コード例 #9
0
 /**
  * Reverts all tracked tables to an earlier commit.
  * @access public
  * @param  boolean $redirect Whether or not to redirect via PHP.
  */
 public function restore($redirect = true)
 {
     // Make sure we really want to do this.
     if (!wp_verify_nonce($_REQUEST['revisr_revert_nonce'], 'revisr_revert_nonce')) {
         wp_die(__('Cheatin’ uh?', 'revisr'));
     }
     $commit = $_REQUEST['db_hash'];
     $branch = $_REQUEST['branch'];
     // Checkout the appropriate branch if necessary.
     if ($branch != $this->revisr->git->branch) {
         $this->revisr->git->checkout($branch);
     }
     /**
      * Backup the database and store the resulting commit hash
      * in memory so we can use it to create the revert link later.
      */
     $this->backup();
     $current_temp = $this->revisr->git->current_commit();
     if ($current_temp) {
         /**
          * If the backup was successful and we have the resulting commit hash,
          * run a revert on the sql files for the tracked tables and import them.
          */
         $tables = $this->get_tracked_tables();
         $checkout = array();
         foreach ($tables as $table) {
             $checkout[$table] = $this->revisr->git->run('checkout', array($commit, "{$this->backup_dir}revisr_{$table}.sql"));
         }
         if (!in_array(1, $checkout)) {
             $import = $this->import();
             if ($import) {
                 // Create a link to undo the revert if necessary.
                 $undo_nonce = wp_nonce_url(admin_url("admin-post.php?action=process_revert&revert_type=db&db_hash=" . $current_temp . "&branch=" . $_REQUEST['branch'] . "&backup_method=tables"), 'revisr_revert_nonce', 'revisr_revert_nonce');
                 $undo_msg = sprintf(__('Successfully reverted the database to a previous commit. <a href="%s">Undo</a>', 'revisr'), $undo_nonce);
                 // Store the undo link and alert the user.
                 Revisr_Admin::log($undo_msg, 'revert');
                 Revisr_Admin::alert($undo_msg);
             }
         } else {
             // There was an error importing the database.
             $msg = __('Error reverting one or more database tables.', 'revisr');
             Revisr_Admin::log($msg, 'error');
             Revisr_Admin::alert($msg, true);
         }
         // Redirect if necessary.
         if ($redirect !== false) {
             wp_redirect(get_admin_url() . 'admin.php?page=revisr');
             exit;
         }
     } else {
         wp_die(__('Something went wrong. Check your settings and try again.', 'revisr'));
     }
 }
コード例 #10
0
ファイル: class-revisr-db-import.php プロジェクト: acchs/test
 /**
  * Processes the results and alerts the user as necessary.
  * @access public
  * @param  array $args An array containing the results of the backup.
  * @return boolean
  */
 public function callback($args)
 {
     if (in_array(false, $args)) {
         // There were one or more errors with the import.
         $msg = __('Error importing the database.', 'revisr');
         Revisr_Admin::log($msg, 'error');
         Revisr_Admin::alert($msg, true);
     } else {
         // Everything imported properly.
         $get_hash = revisr()->git->run('config', array('revisr.last-db-backup'));
         $revert_link = '';
         if (is_array($get_hash)) {
             $undo_hash = $get_hash[0];
             $undo_url = get_admin_url() . 'admin-post.php?action=process_revert&revert_type=db&db_hash=' . $undo_hash;
             $undo_nonced = wp_nonce_url($undo_url, 'revisr_revert_nonce', 'revisr_revert_nonce');
             $revert_link = '<a href="' . $undo_nonced . '">' . __('Undo', 'revisr') . '</a>';
             revisr()->git->run('config', array('--unset', 'revisr.last-db-backup'));
         }
         // Alert the user.
         $msg = sprintf(__('Successfully imported the database. %s', 'revisr'), $revert_link);
         Revisr_Admin::log($msg, 'import');
         Revisr_Admin::alert($msg);
         // Fires after a successful database import.
         do_action('revisr_post_db_import');
         return true;
     }
     return false;
 }
コード例 #11
0
 /**
  * Processes the results and alerts the user as necessary.
  * @access public
  * @param  array $args An array containing the results of the backup.
  * @return boolean
  */
 public function callback($args)
 {
     if (in_array(false, $args)) {
         $msg = __('Error importing the database.', 'revisr');
         Revisr_Admin::log($msg, 'error');
         Revisr_Admin::alert($msg, true);
     } else {
         $get_hash = $this->revisr->git->run('config', array('revisr.last-db-backup'));
         $revert_url = '';
         if (is_array($get_hash)) {
             $undo_hash = $get_hash[0];
             $revert_url = '<a href="' . wp_nonce_url(admin_url("admin-post.php?action=revert_db&db_hash={$undo_hash}&branch={$this->revisr->git->branch}&backup_method=tables"), 'revert_db', 'revert_db_nonce') . '">' . __('Undo', 'revisr') . '</a>';
             $this->revisr->git->run('config', array('--unset', 'revisr.last-db-backup'));
         }
         $msg = sprintf(__('Successfully imported the database. %s', 'revisr'), $revert_url);
         Revisr_Admin::log($msg, 'import');
         Revisr_Admin::alert($msg);
         return true;
     }
     return false;
 }
コード例 #12
0
 /**
  * Processes the request to discard all untracked changes.
  * @access public
  */
 public function process_discard()
 {
     $this->git->reset('--hard', 'HEAD', true);
     Revisr_Admin::log(__('Discarded all uncommitted changes.', 'revisr'), 'discard');
     Revisr_Admin::alert(__('Successfully discarded any uncommitted changes.', 'revisr'));
     exit;
 }
コード例 #13
0
 /**
  * Callback for the revert_table action.
  * @access private
  * @param  array $status The status of the revert.
  */
 private function revert_callback($status)
 {
     if (in_array(1, $status)) {
         $msg = __('Error reverting one or more database tables.', 'revisr');
         Revisr_Admin::log($msg, 'error');
         Revisr_Admin::alert($msg, true);
     } else {
         $this->import();
     }
 }