public static runWpCliCommand ( $command, $subcommand, $args = [], $cwd = null ) |
private function runVPInternalCommand($subcommand, $args = [], $cwd = null) { $args = $args + ['require' => __DIR__ . '/vp-internal.php']; return VPCommandUtils::runWpCliCommand('vp-internal', $subcommand, $args, $cwd); }
/** * 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()); } }
/** * Finishes clone operation * * @subcommand finish-restore-site * * @when before_wp_load * */ public function finishRestore($args, $assoc_args) { define('SHORTINIT', true); $wpConfigPath = \WP_CLI\Utils\locate_wp_config(); require_once $wpConfigPath; require ABSPATH . WPINC . '/formatting.php'; require ABSPATH . WPINC . '/link-template.php'; require ABSPATH . WPINC . '/shortcodes.php'; require ABSPATH . WPINC . '/taxonomy.php'; wp_plugin_directory_constants(); require_once WP_PLUGIN_DIR . '/versionpress/bootstrap.php'; $versionPressContainer = DIContainer::getConfiguredInstance(); /** @var ActionsDefinitionRepository $actionsDefinitionRepository */ $actionsDefinitionRepository = $versionPressContainer->resolve(VersionPressServices::ACTIONS_DEFINITION_REPOSITORY); $actionsDefinitionRepository->restoreAllDefinitionFilesFromHistory(); // Truncate tables /** @var Database $database */ $database = $versionPressContainer->resolve(VersionPressServices::DATABASE); /** @var DbSchemaInfo $dbSchema */ $dbSchema = $versionPressContainer->resolve(VersionPressServices::DB_SCHEMA); $tables = array_map(function ($entityName) use($dbSchema) { return $dbSchema->getPrefixedTableName($entityName); }, array_merge($dbSchema->getAllEntityNames(), array_map(function ($referenceDetails) { return $referenceDetails['junction-table']; }, $dbSchema->getAllMnReferences()))); $tables = array_filter($tables, function ($table) use($database) { return $table !== $database->options; }); foreach ($tables as $table) { $truncateCmd = "TRUNCATE TABLE `{$table}`"; @$database->query($truncateCmd); // Intentional @ - not existing table is ok for us but TRUNCATE ends with error } // Create VersionPress tables /** @var \VersionPress\Initialization\Initializer $initializer */ $initializer = $versionPressContainer->resolve(VersionPressServices::INITIALIZER); $initializer->createVersionPressTables(); WP_CLI::success("VersionPress tables created"); // Install Custom merge driver MergeDriverInstaller::installMergeDriver(VP_PROJECT_ROOT, VERSIONPRESS_PLUGIN_DIR, VP_VPDB_DIR); WP_CLI::success("Git merge driver added"); // Run synchronization /** @var SynchronizationProcess $syncProcess */ $syncProcess = $versionPressContainer->resolve(VersionPressServices::SYNCHRONIZATION_PROCESS); $syncProcess->synchronizeAll(); WP_CLI::success("Database synchronized"); VPCommandUtils::runWpCliCommand('vp-internal', 'flush-regenerable-values', ['require' => __FILE__]); }