getPage() public method

Returns a subset of commits ordered from newest to oldest.
public getPage ( $pageNumber ) : Commit[]
$pageNumber
return Commit[]
Exemplo n.º 1
0
 /**
  * @param WP_REST_Request $request
  * @return WP_REST_Response|\WP_Error
  */
 public function getCommits(WP_REST_Request $request)
 {
     $gitLogPaginator = new GitLogPaginator($this->gitRepository);
     $gitLogPaginator->setCommitsPerPage(25);
     $page = intval($request['page']);
     $commits = $gitLogPaginator->getPage($page);
     if (empty($commits)) {
         return new \WP_Error('notice', 'No more commits to show.', array('status' => 403));
     }
     $preActivationHash = trim(file_get_contents(VERSIONPRESS_ACTIVATION_FILE));
     if (empty($preActivationHash)) {
         $initialCommitHash = $this->gitRepository->getInitialCommit()->getHash();
     } else {
         $initialCommitHash = $this->gitRepository->getChildCommit($preActivationHash);
     }
     $isChildOfInitialCommit = $this->gitRepository->wasCreatedAfter($commits[0]->getHash(), $initialCommitHash);
     $isFirstCommit = $page === 0;
     $result = array();
     foreach ($commits as $commit) {
         $isChildOfInitialCommit = $isChildOfInitialCommit && $commit->getHash() !== $initialCommitHash;
         $canUndoCommit = $isChildOfInitialCommit && !$commit->isMerge();
         $canRollbackToThisCommit = !$isFirstCommit && ($isChildOfInitialCommit || $commit->getHash() === $initialCommitHash);
         $changeInfo = ChangeInfoMatcher::buildChangeInfo($commit->getMessage());
         $isEnabled = $isChildOfInitialCommit || $canRollbackToThisCommit || $commit->getHash() === $initialCommitHash;
         $fileChanges = $this->getFileChanges($commit);
         $changeInfoList = $changeInfo instanceof ChangeInfoEnvelope ? $changeInfo->getChangeInfoList() : array();
         $result[] = array("hash" => $commit->getHash(), "date" => $commit->getDate()->format('c'), "message" => $changeInfo->getChangeDescription(), "canUndo" => $canUndoCommit, "canRollback" => $canRollbackToThisCommit, "isEnabled" => $isEnabled, "isInitial" => $commit->getHash() === $initialCommitHash, "isMerge" => $commit->isMerge(), "changes" => array_merge($this->convertChangeInfoList($changeInfoList), $fileChanges));
         $isFirstCommit = false;
     }
     return new WP_REST_Response(array('pages' => $gitLogPaginator->getPrettySteps($page), 'commits' => $result));
 }
Exemplo n.º 2
0
 /**
  * @param WP_REST_Request $request
  * @return WP_REST_Response|WP_Error
  */
 public function getCommits(WP_REST_Request $request)
 {
     $gitLogPaginator = new GitLogPaginator($this->gitRepository);
     $query = urldecode(stripslashes($request['query']));
     $rules = QueryLanguageUtils::createRulesFromQueries([$query]);
     $gitLogQuery = !empty($rules) ? QueryLanguageUtils::createGitLogQueryFromRule($rules[0]) : '';
     $gitLogPaginator->setQuery($gitLogQuery);
     $gitLogPaginator->setCommitsPerPage(25);
     $page = intval($request['page']);
     $commits = $gitLogPaginator->getPage($page);
     if (empty($commits)) {
         return new WP_Error('notice', 'No more commits to show.', ['status' => 404]);
     }
     $initialCommitHash = $this->getInitialCommitHash();
     $isChildOfInitialCommit = $this->gitRepository->wasCreatedAfter($commits[0]->getHash(), $initialCommitHash);
     $isFirstCommit = $page === 0;
     $result = [];
     foreach ($commits as $commit) {
         $isChildOfInitialCommit = $isChildOfInitialCommit && $this->gitRepository->wasCreatedAfter($commit->getHash(), $initialCommitHash);
         $canUndoCommit = $isChildOfInitialCommit && !$commit->isMerge();
         $canRollbackToThisCommit = !$isFirstCommit && ($isChildOfInitialCommit || $commit->getHash() === $initialCommitHash);
         $changeInfo = $this->commitMessageParser->parse($commit->getMessage());
         $isEnabled = $isChildOfInitialCommit || $commit->getHash() === $initialCommitHash;
         $skipVpdbFiles = $changeInfo->getChangeInfoList()[0] instanceof TrackedChangeInfo;
         $fileChanges = $this->getFileChanges($commit, $skipVpdbFiles);
         $environment = $changeInfo instanceof ChangeInfoEnvelope ? $changeInfo->getEnvironment() : '?';
         $changeInfoList = $changeInfo instanceof ChangeInfoEnvelope ? $changeInfo->getChangeInfoList() : [];
         $result[] = ["hash" => $commit->getHash(), "date" => $commit->getDate()->format('c'), "message" => $changeInfo->getChangeDescription(), "parentHashes" => $commit->getParentHashes(), "canUndo" => $canUndoCommit, "canRollback" => $canRollbackToThisCommit, "isEnabled" => $isEnabled, "isInitial" => $commit->getHash() === $initialCommitHash, "isMerge" => $commit->isMerge(), "environment" => $environment, "changes" => array_values(array_filter(array_merge($this->convertChangeInfoList($changeInfoList), $fileChanges))), "author" => ["name" => $commit->getAuthorName(), "email" => $commit->getAuthorEmail(), "avatar" => get_avatar_url($commit->getAuthorEmail())]];
         $isFirstCommit = false;
     }
     return new WP_REST_Response(['pages' => $gitLogPaginator->getPrettySteps($page), 'commits' => $result]);
 }
Exemplo n.º 3
0
    <?php 
global $versionPressContainer;
/** @var GitRepository $repository */
$repository = $versionPressContainer->resolve(VersionPressServices::GIT_REPOSITORY);
/** @var CommitMessageParser $commitMessageParser */
$commitMessageParser = $versionPressContainer->resolve(VersionPressServices::COMMIT_MESSAGE_PARSER);
$preActivationHash = trim(file_get_contents(VERSIONPRESS_ACTIVATION_FILE));
if (empty($preActivationHash)) {
    $initialCommitHash = $repository->getInitialCommit()->getHash();
} else {
    $initialCommitHash = $repository->getChildCommit($preActivationHash);
}
$gitLogPaginator = new GitLogPaginator($repository);
$gitLogPaginator->setCommitsPerPage(25);
$page = isset($_GET['vp-page']) ? intval($_GET['vp-page']) : 0;
$commits = $gitLogPaginator->getPage($page);
$isChildOfInitialCommit = $repository->wasCreatedAfter($commits[0]->getHash(), $initialCommitHash);
$isFirstCommit = $page === 0;
$disabledCommitsMessage = "\n        <tr class=\"post-1 type-post status-publish format-standard hentry\n                    category-uncategorized alternate note level-0\">\n            <td colspan=\"3\">VersionPress is not able to undo changes made before it has been activated.</td>\n        </tr>\n        ";
if (!$isChildOfInitialCommit && $commits[0]->getHash() !== $initialCommitHash) {
    echo $disabledCommitsMessage;
}
foreach ($commits as $key => $commit) {
    $isChildOfInitialCommit = $isChildOfInitialCommit && $commit->getHash() !== $initialCommitHash;
    $canUndoCommit = $isChildOfInitialCommit && !$commit->isMerge();
    $canRollbackToThisCommit = !$isFirstCommit && ($isChildOfInitialCommit || $commit->getHash() === $initialCommitHash);
    $commitDate = $commit->getDate()->format('d-M-y H:i:s');
    $changeInfo = $commitMessageParser->parse($commit->getMessage());
    $undoSnippet = "<a " . "href='" . admin_url('admin.php?action=vp_show_undo_confirm&method=undo&commit=' . $commit->getHash()) . "' " . "class='vp-undo' " . "data-commit='" . $commit->getHash() . "' " . "data-commit-message=\"" . htmlspecialchars($changeInfo->getChangeDescription()) . "\"" . "style='text-decoration:none; white-space:nowrap;' " . "title='Reverts changes done by this commit'>Undo this</a>";
    $rollbackSnippet = "<a " . "href='" . admin_url('admin.php?action=vp_show_undo_confirm&method=rollback&commit=' . $commit->getHash()) . "' " . "class='vp-rollback' " . "data-commit='" . $commit->getHash() . "' " . "data-commit-date='" . $commitDate . "'" . "style='text-decoration:none; white-space:nowrap;' " . "title='Reverts site back to this state; effectively undos all the change up to this commit'>" . "Roll back to this</a>";
    $versioningSnippet = "";