/**
  * 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__]);
 }
 /**
  * @param string $driver See MergeDriverInstaller::installMergeDriver()'s $driver parameter
  */
 private function installMergeDriver($driver)
 {
     MergeDriverInstaller::installMergeDriver(self::$repositoryDir, __DIR__ . '/../..', self::$repositoryDir, $driver);
 }
/**
 * Most of the actual deactivation work is done here. Called either as a response
 * to the user confirming the deactivation on `?page=versionpress/admin/deactivate.php`
 * or is called directly from vp_deactivate() if the confirmation screen was not necessary.
 */
function vp_admin_post_confirm_deactivation()
{
    //nonce verification is performed according to 'deactivate-plugin_versionpress/versionpress.php'
    // as a standard deactivation token for which nonce is generated
    if (!defined('WP_CLI')) {
        vp_verify_nonce('deactivate-plugin_versionpress/versionpress.php');
        vp_check_permissions();
    }
    define('VP_DEACTIVATING', true);
    if (WpdbReplacer::isReplaced()) {
        WpdbReplacer::restoreOriginal();
    }
    if (file_exists(VERSIONPRESS_ACTIVATION_FILE)) {
        FileSystem::remove(VERSIONPRESS_ACTIVATION_FILE);
    }
    $filesChangedByDeactivation = [["type" => "path", "path" => VP_VPDB_DIR . "/*"], ["type" => "path", "path" => ABSPATH . WPINC . "/wp-db.php"], ["type" => "path", "path" => ABSPATH . WPINC . "/wp-db.php.original"], ["type" => "path", "path" => ABSPATH . "/.gitattributes"]];
    vp_force_action('versionpress', 'deactivate', null, [], $filesChangedByDeactivation);
    MergeDriverInstaller::uninstallMergeDriver(VP_PROJECT_ROOT, VERSIONPRESS_PLUGIN_DIR, VP_VPDB_DIR);
    deactivate_plugins("versionpress/versionpress.php", true);
    if (defined('WP_ADMIN')) {
        wp_safe_redirect(admin_url("plugins.php"));
        exit;
    }
}
 private function createGitRepository()
 {
     if (!$this->repository->isVersioned()) {
         $this->reportProgressChange(InitializerStates::CREATING_GIT_REPOSITORY);
         $this->repository->init();
     }
     $this->installGitignore();
     MergeDriverInstaller::installMergeDriver(VP_PROJECT_ROOT, VERSIONPRESS_PLUGIN_DIR, VP_VPDB_DIR);
 }
 /**
  * @test
  */
 public function gitAttributesRemovedCorrectlyAfterUninstall()
 {
     $this->installMergeDriver('auto');
     MergeDriverInstaller::uninstallMergeDriver(self::$repositoryDir, __DIR__ . '/../..', self::$repositoryDir);
     $this->assertNotContains('vp-ini', file_get_contents(self::$repositoryDir . "/.git/config"));
     $this->assertFileNotExists(self::$repositoryDir . "/.gitattributes");
 }