Example #1
1
 /**
  * Finishes `vp push`
  *
  * @subcommand finish-push
  *
  */
 public function finishPush($args, $assoc_args)
 {
     global $versionPressContainer;
     // Update working copy
     $resetCommand = "git reset --hard";
     $process = VPCommandUtils::exec($resetCommand);
     if (!$process->isSuccessful()) {
         WP_CLI::error("Working directory couldn't be reset");
     }
     // Run synchronization
     /** @var SynchronizationProcess $syncProcess */
     $syncProcess = $versionPressContainer->resolve(VersionPressServices::SYNCHRONIZATION_PROCESS);
     $syncProcess->synchronizeAll();
     vp_flush_regenerable_options();
     vp_disable_maintenance();
     $this->flushRewriteRules();
     vp_enable_maintenance();
 }
function _vp_revert($reverterMethod)
{
    global $versionPressContainer;
    vp_verify_nonce('vp_revert');
    vp_check_permissions();
    $commitHash = $_GET['commit'];
    if (!preg_match('/^[0-9a-f]+$/', $commitHash)) {
        exit;
    }
    /** @var Reverter $reverter */
    $reverter = $versionPressContainer->resolve(VersionPressServices::REVERTER);
    vp_enable_maintenance();
    $revertStatus = call_user_func([$reverter, $reverterMethod], [$commitHash]);
    vp_disable_maintenance();
    $adminPage = menu_page_url('versionpress', false);
    if ($revertStatus !== RevertStatus::OK) {
        wp_safe_redirect(add_query_arg('error', $revertStatus, $adminPage));
    } else {
        wp_safe_redirect($adminPage);
    }
    exit;
}
Example #3
0
function _vp_revert($reverterMethod)
{
    global $versionPressContainer;
    /** @var Reverter $reverter */
    $reverter = $versionPressContainer->resolve(VersionPressServices::REVERTER);
    $commitHash = $_GET['commit'];
    vp_enable_maintenance();
    $revertStatus = call_user_func(array($reverter, $reverterMethod), $commitHash);
    vp_disable_maintenance();
    $adminPage = menu_page_url('versionpress', false);
    if ($revertStatus !== RevertStatus::OK) {
        wp_redirect(add_query_arg('error', $revertStatus, $adminPage));
    } else {
        wp_redirect($adminPage);
    }
}
 /**
  * @param string $reverterMethod
  * @param array $commits
  * @return WP_REST_Response|WP_Error
  */
 public function revertCommits($reverterMethod, $commits)
 {
     vp_enable_maintenance();
     $revertStatus = call_user_func([$this->reverter, $reverterMethod], $commits);
     vp_disable_maintenance();
     if ($revertStatus !== RevertStatus::OK) {
         return $this->getError($revertStatus);
     }
     return new WP_REST_Response(true);
 }
 /**
  * Main entry point
  * @param bool $isUpdate Initializer creates `versionpress/update` action if is set to true
  */
 public function initializeVersionPress($isUpdate = false)
 {
     /** @noinspection PhpUsageOfSilenceOperatorInspection */
     @set_time_limit(0);
     // intentionally @ - if it's disabled we can't do anything but try the initialization
     $this->reportProgressChange(InitializerStates::START);
     vp_enable_maintenance();
     try {
         $this->tryToUseIdsFromDatabase();
         $this->createVersionPressTables();
         $this->lockDatabase();
         $this->saveDatabaseToStorages();
         $this->commitDatabase();
         $this->createGitRepository();
         $this->activateVersionPress();
         $this->copyAccessRulesFiles();
         $this->createCommonConfig();
         $this->installComposerScripts();
         $this->doInitializationCommit($isUpdate);
         $this->persistActionsDefinitions();
         vp_disable_maintenance();
         $this->reportProgressChange(InitializerStates::FINISHED);
     } catch (InitializationAbortedException $ex) {
         $this->reportProgressChange(InitializerStates::ABORTED);
     }
 }
 /**
  * Finishes `vp push`
  *
  * @subcommand finish-push
  *
  */
 public function finishPush($args, $assoc_args)
 {
     global $versionPressContainer;
     // Update working copy
     $resetCommand = "git reset --hard";
     $process = VPCommandUtils::exec($resetCommand);
     if (!$process->isSuccessful()) {
         WP_CLI::error("Working directory couldn't be reset");
     }
     // Install current Composer dependencies
     if (file_exists(VP_PROJECT_ROOT . '/composer.json')) {
         $process = VPCommandUtils::exec('composer install', VP_PROJECT_ROOT);
         if ($process->isSuccessful()) {
             WP_CLI::success('Installed Composer dependencies');
         } else {
             WP_CLI::error('Composer dependencies could not be restored.');
         }
     }
     /** @var ActionsDefinitionRepository $actionsDefinitionRepository */
     $actionsDefinitionRepository = $versionPressContainer->resolve(VersionPressServices::ACTIONS_DEFINITION_REPOSITORY);
     $actionsDefinitionRepository->restoreAllDefinitionFilesFromHistory();
     // Run synchronization
     /** @var SynchronizationProcess $syncProcess */
     $syncProcess = $versionPressContainer->resolve(VersionPressServices::SYNCHRONIZATION_PROCESS);
     $syncProcess->synchronizeAll();
     vp_flush_regenerable_options();
     vp_disable_maintenance();
     $this->flushRewriteRules();
     vp_enable_maintenance();
 }