/**
  * 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__]);
 }
Exemple #2
0
 private static function modify_wp_config($content)
 {
     $wp_config_path = Utils\locate_wp_config();
     $token = "/* That's all, stop editing!";
     list($before, $after) = explode($token, file_get_contents($wp_config_path));
     file_put_contents($wp_config_path, $before . $content . $token . $after);
 }
Exemple #3
0
 public function before_wp_load()
 {
     $this->init_config();
     $this->init_colorization();
     $this->init_logger();
     $this->check_root();
     if (empty($this->arguments)) {
         $this->arguments[] = 'help';
     }
     // Protect 'cli info' from most of the runtime
     if ('cli' === $this->arguments[0] && !empty($this->arguments[1]) && 'info' === $this->arguments[1]) {
         $this->_run_command();
         exit;
     }
     // Load bundled commands early, so that they're forced to use the same
     // APIs as non-bundled commands.
     Utils\load_command($this->arguments[0]);
     if (isset($this->config['require'])) {
         foreach ($this->config['require'] as $path) {
             if (!file_exists($path)) {
                 WP_CLI::error(sprintf("Required file '%s' doesn't exist", basename($path)));
             }
             Utils\load_file($path);
         }
     }
     // Show synopsis if it's a composite command.
     $r = $this->find_command_to_run($this->arguments);
     if (is_array($r)) {
         list($command) = $r;
         if ($command->can_have_subcommands()) {
             $command->show_usage();
             exit;
         }
     }
     // Handle --path parameter
     self::set_wp_root($this->find_wp_root());
     // First try at showing man page
     if ('help' === $this->arguments[0] && !$this->wp_exists()) {
         $this->_run_command();
     }
     // Handle --url parameter
     $url = self::guess_url($this->config);
     if ($url) {
         \WP_CLI::set_url($url);
     }
     $this->do_early_invoke('before_wp_load');
     $this->check_wp_version();
     if ($this->cmd_starts_with(array('core', 'config'))) {
         $this->_run_command();
         exit;
     }
     if (!Utils\locate_wp_config()) {
         WP_CLI::error("wp-config.php not found.\n" . "Either create one manually or use `wp core config`.");
     }
     if ($this->cmd_starts_with(array('db')) && !$this->cmd_starts_with(array('db', 'tables'))) {
         eval($this->get_wp_config_code());
         $this->_run_command();
         exit;
     }
     if ($this->cmd_starts_with(array('core', 'is-installed'))) {
         define('WP_INSTALLING', true);
     }
     if (count($this->arguments) >= 2 && $this->arguments[0] == 'core' && in_array($this->arguments[1], array('install', 'multisite-install'))) {
         define('WP_INSTALLING', true);
         // We really need a URL here
         if (!isset($_SERVER['HTTP_HOST'])) {
             $url = 'http://example.com';
             \WP_CLI::set_url($url);
         }
         if ('multisite-install' == $this->arguments[1]) {
             // need to fake some globals to skip the checks in wp-includes/ms-settings.php
             $url_parts = Utils\parse_url($url);
             self::fake_current_site_blog($url_parts);
             if (!defined('COOKIEHASH')) {
                 define('COOKIEHASH', md5($url_parts['host']));
             }
         }
     }
     if ($this->cmd_starts_with(array('import'))) {
         define('WP_LOAD_IMPORTERS', true);
         define('WP_IMPORTING', true);
     }
     if ($this->cmd_starts_with(array('plugin'))) {
         $GLOBALS['pagenow'] = 'plugins.php';
     }
 }
Exemple #4
0
 /**
  * Load WordPress, if it hasn't already been loaded
  */
 public function load_wordpress()
 {
     static $wp_cli_is_loaded;
     // Globals not explicitly globalized in WordPress
     global $site_id, $public, $current_site, $current_blog, $path, $shortcode_tags;
     if (!empty($wp_cli_is_loaded)) {
         return;
     }
     $wp_cli_is_loaded = true;
     WP_CLI::debug('Begin WordPress load', 'bootstrap');
     WP_CLI::do_hook('before_wp_load');
     $this->check_wp_version();
     $wp_config_path = Utils\locate_wp_config();
     if (!$wp_config_path) {
         WP_CLI::error("wp-config.php not found.\n" . "Either create one manually or use `wp core config`.");
     }
     WP_CLI::debug('wp-config.php path: ' . $wp_config_path, 'bootstrap');
     WP_CLI::do_hook('before_wp_config_load');
     // Load wp-config.php code, in the global scope
     $wp_cli_original_defined_vars = get_defined_vars();
     eval($this->get_wp_config_code());
     foreach (get_defined_vars() as $key => $var) {
         if (array_key_exists($key, $wp_cli_original_defined_vars) || 'wp_cli_original_defined_vars' === $key) {
             continue;
         }
         $GLOBALS[$key] = $var;
     }
     $this->maybe_update_url_from_domain_constant();
     WP_CLI::do_hook('after_wp_config_load');
     // Load WP-CLI utilities
     require WP_CLI_ROOT . '/php/utils-wp.php';
     // Load Core, mu-plugins, plugins, themes etc.
     require WP_CLI_ROOT . '/php/wp-settings-cli.php';
     // Fix memory limit. See http://core.trac.wordpress.org/ticket/14889
     @ini_set('memory_limit', -1);
     // Load all the admin APIs, for convenience
     require ABSPATH . 'wp-admin/includes/admin.php';
     add_filter('filesystem_method', function () {
         return 'direct';
     }, 99);
     // Handle --user parameter
     if (!defined('WP_INSTALLING')) {
         self::set_user($this->config);
     }
     WP_CLI::debug('Loaded WordPress', 'bootstrap');
     WP_CLI::do_hook('after_wp_load');
 }
Exemple #5
0
 private static function modify_wp_config($content)
 {
     $wp_config_path = Utils\locate_wp_config();
     $token = "/* That's all, stop editing!";
     $config_contents = file_get_contents($wp_config_path);
     if (false === strpos($config_contents, $token)) {
         return false;
     }
     list($before, $after) = explode($token, $config_contents);
     $content = PHP_EOL . PHP_EOL . trim($content) . PHP_EOL . PHP_EOL;
     file_put_contents($wp_config_path, $before . $content . $token . $after);
     return true;
 }
Exemple #6
0
 private function setConfigUrl($urlConstant, $pathConstant, $defaultPath, $baseUrl)
 {
     if (defined($pathConstant) && constant($pathConstant) !== $defaultPath) {
         $wpConfigDir = dirname(\WP_CLI\Utils\locate_wp_config());
         $relativePathToWpContent = str_replace($wpConfigDir, '', realpath(constant($pathConstant)));
         $url = rtrim(rtrim($baseUrl, '/') . str_replace('//', '/', '/' . $relativePathToWpContent), '/');
         $this->runVPInternalCommand('update-config', [$urlConstant, $url]);
     }
 }