Exemplo n.º 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();
 }
Exemplo n.º 2
0
 /**
  * Switches the maintenance mode on or off for a site specified by a remote.
  * The remote must be "local" - on the same filesystem. If no remote name is
  * given, the current site's maintenance mode is switched.
  *
  * @param string $onOrOff "on" | "off"
  * @param string|null $remoteName
  */
 private function switchMaintenance($onOrOff, $remoteName = null)
 {
     $remotePath = $remoteName ? $this->getRemoteUrl($remoteName) : null;
     $process = VPCommandUtils::runWpCliCommand('vp-internal', 'maintenance', array($onOrOff, 'require' => $this->getVPInternalCommandPath()), $remotePath);
     if ($process->isSuccessful()) {
         WP_CLI::success("Maintenance mode turned {$onOrOff}" . ($remoteName ? " for '{$remoteName}'" : ""));
     } else {
         WP_CLI::error("Maintenance mode couldn't be switched" . ($remoteName ? " for '{$remoteName}'" : "") . ". Details:\n\n" . $process->getConsoleOutput());
     }
 }
Exemplo n.º 3
0
 /**
  * @test
  */
 public function revertAllCanRevertToCommitInParallelBranch()
 {
     VPCommandUtils::exec('git branch test', self::$repositoryPath);
     $this->commitFile('some-file', 'Some commit');
     VPCommandUtils::exec('git checkout test', self::$repositoryPath);
     $this->commitFile('other-file', 'Other commit');
     $hash = self::$repository->getLastCommitHash();
     VPCommandUtils::exec('git checkout master', self::$repositoryPath);
     VPCommandUtils::exec('git merge test', self::$repositoryPath);
     $commitAsserter = $this->createCommitAsserter();
     self::$repository->revertAll($hash);
     $this->commit('Revert all');
     $commitAsserter->assertNumCommits(1);
     $commitAsserter->assertCleanWorkingDirectory();
     $commitAsserter->assertCountOfAffectedFiles(1);
     $commitAsserter->assertCommitPath('D', 'some-file');
 }
Exemplo n.º 4
0
 /**
  * @param $assoc_args
  * @param $requirementsScope string of the requirements
  */
 private function checkVpRequirements($assoc_args, $requirementsScope)
 {
     require_once ABSPATH . WPINC . '/formatting.php';
     require_once ABSPATH . WPINC . '/theme.php';
     require_once ABSPATH . WPINC . '/link-template.php';
     global $versionPressContainer;
     $database = $versionPressContainer->resolve(VersionPressServices::WPDB);
     $schema = $requirementsScope === RequirementsChecker::ENVIRONMENT ? null : $versionPressContainer->resolve(VersionPressServices::DB_SCHEMA);
     $requirementsChecker = new RequirementsChecker($database, $schema, $requirementsScope);
     $report = $requirementsChecker->getRequirements();
     foreach ($report as $requirement) {
         if ($requirement['fulfilled']) {
             WP_CLI::success($requirement['name']);
         } else {
             if ($requirement['level'] === 'critical') {
                 WP_CLI::error($requirement['name'], false);
             } else {
                 VPCommandUtils::warning($requirement['name']);
             }
             WP_CLI::log('  ' . $requirement['help']);
         }
     }
     WP_CLI::line('');
     if (!$requirementsChecker->isWithoutCriticalErrors()) {
         WP_CLI::error('VersionPress cannot be fully activated.');
     }
     if (!$requirementsChecker->isEverythingFulfilled()) {
         WP_CLI::confirm('There are some warnings. Continue?', $assoc_args);
     }
 }
Exemplo n.º 5
0
 /**
  * @test
  */
 public function rollbackWorksWithMergeCommits()
 {
     $commitHash = $this->gitRepository->getLastCommitHash();
     $sitePath = self::$testConfig->testSite->path;
     VPCommandUtils::exec('git branch test', $sitePath);
     self::$wpAutomation->createOption('vp_option_master', 'foo');
     VPCommandUtils::exec('git checkout test', $sitePath);
     self::$wpAutomation->createOption('vp_option_test', 'foo');
     VPCommandUtils::exec('git checkout master', $sitePath);
     VPCommandUtils::exec('git merge test', $sitePath);
     VPCommandUtils::exec('git branch -d test', $sitePath);
     $this->commitAsserter->reset();
     self::$wpAutomation->runWpCliCommand('vp', 'rollback', [$commitHash]);
     $this->commitAsserter->assertNumCommits(1);
     $this->commitAsserter->assertCleanWorkingDirectory();
     $this->commitAsserter->assertCountOfAffectedFiles(2);
     $this->commitAsserter->assertCommitPath('D', '%vpdb%/options/vp/vp_option_master.ini');
     $this->commitAsserter->assertCommitPath('D', '%vpdb%/options/vp/vp_option_test.ini');
     DBAsserter::assertFilesEqualDatabase();
 }
Exemplo n.º 6
0
 /**
  * Sets or updates constant or variable in wp-config.php
  *
  * ## OPTIONS
  *
  * <constant>
  * : Name of constant or variable that will be changed.
  *
  * <value>
  * : Desired value. Supported types are: string, int, float and bool.
  *
  * [--plain]
  * : The value will be used as is - without type detection, quoting etc.
  *
  * [--variable]
  * : Will set a variable instead of constant. Useful for $table_prefix.
  *
  * [--common]
  * : The constant / variable will be set in wp-config.common.php.
  *
  * @subcommand update-config
  *
  *
  * @when before_wp_load
  */
 public function updateConfig($args = [], $assoc_args = [])
 {
     require_once __DIR__ . '/VPCommandUtils.php';
     require_once __DIR__ . '/../Initialization/WpConfigSplitter.php';
     require_once __DIR__ . '/../Utils/WpConfigEditor.php';
     require_once __DIR__ . '/../Utils/WordPressMissingFunctions.php';
     $wpConfigPath = WordPressMissingFunctions::getWpConfigPath();
     $updateCommonConfig = isset($assoc_args['common']);
     if ($updateCommonConfig) {
         $wpConfigPath = dirname($wpConfigPath) . '/' . WpConfigSplitter::COMMON_CONFIG_NAME;
     }
     if ($wpConfigPath === false) {
         WP_CLI::error('Config file does not exist. Please run `wp core config` first.');
     }
     $constantOrVariableName = $args[0];
     $isVariable = isset($assoc_args['variable']);
     $usePlainValue = isset($assoc_args['plain']);
     $value = $usePlainValue ? $args[1] : VPCommandUtils::fixTypeOfValue($args[1]);
     $wpConfigEditor = new WpConfigEditor($wpConfigPath, $updateCommonConfig);
     try {
         if ($isVariable) {
             $wpConfigEditor->updateConfigVariable($constantOrVariableName, $value, $usePlainValue);
         } else {
             $wpConfigEditor->updateConfigConstant($constantOrVariableName, $value, $usePlainValue);
         }
     } catch (\Exception $e) {
         WP_CLI::error('Cannot find place for defining the ' . ($isVariable ? 'variable' : 'constant') . '. Config was probably edited manually.');
     }
 }