示例#1
0
 private function revert($commits, $method)
 {
     if (!$this->canRevert()) {
         return RevertStatus::NOT_CLEAN_WORKING_DIRECTORY;
     }
     vp_commit_all_frequently_written_entities();
     uasort($commits, function ($a, $b) {
         return $this->repository->wasCreatedAfter($b, $a);
     });
     $modifiedFiles = [];
     $vpIdsInModifiedFiles = [];
     foreach ($commits as $commitHash) {
         $commitHashForDiff = $method === "undo" ? sprintf("%s~1..%s", $commitHash, $commitHash) : $commitHash;
         $modifiedFiles = array_merge($modifiedFiles, $this->repository->getModifiedFiles($commitHashForDiff));
         $modifiedFiles = array_unique($modifiedFiles, SORT_REGULAR);
         $vpIdsInModifiedFiles = array_merge($vpIdsInModifiedFiles, $this->getAllVpIdsFromModifiedFiles($modifiedFiles));
         $vpIdsInModifiedFiles = array_unique($vpIdsInModifiedFiles, SORT_REGULAR);
         if ($method === "undo") {
             $status = $this->revertOneCommit($commitHash);
         } else {
             $status = $this->revertToCommit($commitHash);
         }
         if ($status !== RevertStatus::OK) {
             return $status;
         }
         vp_force_action('versionpress', $method, $commitHash, [], [["type" => "path", "path" => "*"]]);
     }
     if (!$this->repository->willCommit()) {
         return RevertStatus::NOTHING_TO_COMMIT;
     }
     $affectedPosts = $this->getAffectedPosts($modifiedFiles);
     $this->updateChangeDateForPosts($affectedPosts);
     $this->committer->commit();
     $vpIdsInModifiedFiles = array_merge($vpIdsInModifiedFiles, $this->getAllVpIdsFromModifiedFiles($modifiedFiles));
     $vpIdsInModifiedFiles = array_unique($vpIdsInModifiedFiles, SORT_REGULAR);
     $this->synchronizationProcess->synchronize($vpIdsInModifiedFiles);
     do_action('vp_revert', $modifiedFiles);
     return RevertStatus::OK;
 }
示例#2
0
/**
 * 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;
    }
}
示例#3
0
 /**
  * @param string $action install or delete or update
  * @param array $packages
  * @param array $plugins
  * @param array $themes
  */
 private function forceRelatedActions($action, $packages, $plugins, $themes)
 {
     foreach ($packages as $package) {
         if ($package['type'] === 'wordpress-plugin') {
             $fileAndName = $this->getPluginFileAndName($package['name'], $plugins);
             do_action('vp_plugin_changed', $action, $fileAndName['plugin-file'], $fileAndName['name']);
         } elseif ($package['type'] === 'wordpress-theme') {
             $stylesheetAndName = $this->getThemeStylesheetAndName($package['name'], $themes);
             do_action('vp_theme_changed', $stylesheetAndName['stylesheet'], $stylesheetAndName['name']);
         } elseif ($package['type'] === 'wordpress-core') {
             do_action('vp_wordpress_updated', $package['version']);
         } else {
             $composerFiles = [["type" => "path", "path" => VP_PROJECT_ROOT . '/composer.json'], ["type" => "path", "path" => VP_PROJECT_ROOT . '/composer.lock']];
             vp_force_action('composer', $action, $package['name'], [], $composerFiles);
         }
     }
 }
示例#4
0
        $path .= "*";
    } else {
        $path .= $type . "s/" . $name . "-" . $languageCode . ".*";
    }
    $filesChange = ["type" => "path", "path" => $path];
    $optionChange = ["type" => "all-storage-files", "entity" => "option"];
    $files = [$filesChange, $optionChange];
    vp_force_action('translation', $action, null, $tags, $files);
}, 10, 4);
add_action('vp_versionpress_changed', function ($action, $version) {
    if ($action === 'deactivate') {
        $files = [["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"]];
    } else {
        $files = [["type" => "path", "path" => "*"]];
    }
    vp_force_action('versionpress', $action, $version, [], $files);
}, 10, 2);
add_filter('vp_action_description_versionpress', function ($message, $action, $commitHash) {
    if ($action !== 'undo' && $action !== 'rollback') {
        return $message;
    }
    global $versionPressContainer;
    /** @var GitRepository $gitRepository */
    $gitRepository = $versionPressContainer->resolve(VersionPressServices::GIT_REPOSITORY);
    /** @var CommitMessageParser $commitMessageParser */
    $commitMessageParser = $versionPressContainer->resolve(VersionPressServices::COMMIT_MESSAGE_PARSER);
    $revertedCommit = $gitRepository->getCommit($commitHash);
    if ($action === 'undo') {
        $changeInfo = $commitMessageParser->parse($revertedCommit->getMessage());
        $message = str_replace('%/commit-message/%', $changeInfo->getChangeDescription(), $message);
    } elseif ($action === 'rollback') {