Esempio n. 1
0
 private function _revert($commitHash, $method)
 {
     if (!$this->canRevert()) {
         return RevertStatus::NOT_CLEAN_WORKING_DIRECTORY;
     }
     $commitHashForDiff = $method === "undo" ? sprintf("%s~1..%s", $commitHash, $commitHash) : $commitHash;
     $modifiedFiles = $this->repository->getModifiedFiles($commitHashForDiff);
     $vpIdsInModifiedFiles = $this->getAllVpIdsFromModifiedFiles($modifiedFiles);
     if ($method === "undo") {
         $status = $this->revertOneCommit($commitHash);
         $changeInfo = new RevertChangeInfo(RevertChangeInfo::ACTION_UNDO, $commitHash);
     } else {
         $status = $this->revertToCommit($commitHash);
         $changeInfo = new RevertChangeInfo(RevertChangeInfo::ACTION_ROLLBACK, $commitHash);
     }
     if ($status !== RevertStatus::OK) {
         return $status;
     }
     $this->committer->forceChangeInfo($changeInfo);
     $this->committer->commit();
     $vpIdsInModifiedFiles = array_merge($vpIdsInModifiedFiles, $this->getAllVpIdsFromModifiedFiles($modifiedFiles));
     $vpIdsInModifiedFiles = array_unique($vpIdsInModifiedFiles, SORT_REGULAR);
     $this->synchronizationProcess->synchronize($vpIdsInModifiedFiles);
     $affectedPosts = $this->getAffectedPosts($modifiedFiles);
     $this->updateChangeDateForPosts($affectedPosts);
     do_action('vp_revert');
     return RevertStatus::OK;
 }
Esempio n. 2
0
 private function updateDatabase($status)
 {
     $diff = $this->gitRepository->getDiff();
     $vpidRegex = "/([\\da-f]{32})/i";
     $optionRegex = "/.*vpdb[\\/\\\\]options[\\/\\\\].+[\\/\\\\](.+)\\.ini/i";
     preg_match_all($vpidRegex, $diff, $vpidMatches);
     preg_match_all($optionRegex, $diff, $optionNameMatches);
     $entitiesToSynchronize = array_unique(array_merge($vpidMatches[1], $optionNameMatches[1]));
     $this->synchronizationProcess->synchronize($entitiesToSynchronize);
 }
Esempio n. 3
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;
 }
 private function updateDatabase($status)
 {
     $fullDiff = $this->gitRepository->getDiff();
     $diffFiles = explode('diff --git', $fullDiff);
     $vpdbName = basename(VP_VPDB_DIR);
     $vpidRegex = "/([\\da-f]{32})/i";
     $optionRegex = "/.*{$vpdbName}[\\/\\\\]options[\\/\\\\].+[\\/\\\\](.+)\\.ini/i";
     $entitiesToSynchronize = [];
     foreach ($diffFiles as $diff) {
         $firstLine = substr($diff, 0, strpos($diff, "\n"));
         $parent = null;
         if (preg_match($optionRegex, $firstLine, $matches)) {
             $entitiesToSynchronize[] = ['vp_id' => $matches[1], 'parent' => null];
         } elseif (preg_match($vpidRegex, $firstLine, $matches)) {
             $parent = $matches[1];
         }
         preg_match_all($vpidRegex, $diff, $vpidMatches);
         foreach ($vpidMatches[1] as $match) {
             $entitiesToSynchronize[] = ['vp_id' => $match, 'parent' => $parent];
         }
     }
     $entitiesToSynchronize = array_unique($entitiesToSynchronize, SORT_REGULAR);
     $this->synchronizationProcess->synchronize($entitiesToSynchronize);
 }