Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #770 from versionpress/588-date-modified-not-handl…
Browse files Browse the repository at this point in the history
…ed-correctly

[#588] - post_modified and post_modified_gmt are updated to "NOW"
  • Loading branch information
octopuss committed Mar 8, 2016
2 parents 6b657ef + 8a5ad1b commit ff504f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions plugins/versionpress/src/Git/Reverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,30 @@ private function _revert($commitHash, $method) {
}

$this->committer->forceChangeInfo($changeInfo);
$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);
$affectedPosts = $this->getAffectedPosts($modifiedFiles);
$this->updateChangeDateForPosts($affectedPosts);

do_action('vp_revert');
return RevertStatus::OK;
}

private function updateChangeDateForPosts($vpIds) {
$storage = $this->storageFactory->getStorage('post');
$date = current_time('mysql');
$dateGmt = current_time('mysql', true);
foreach ($vpIds as $vpId) {
$sql = "update {$this->database->prefix}posts set post_modified = '{$date}', post_modified_gmt = '{$dateGmt}' where ID = (select id from {$this->database->prefix}vp_id where vp_id = unhex('{$vpId}'))";
$this->database->query($sql);
$post = $storage->loadEntity($vpId, null);
$post['post_modified'] = $date;
$post['post_modified_gmt'] = $dateGmt;
$storage->save($post);
}
}

Expand Down
12 changes: 6 additions & 6 deletions plugins/versionpress/tests/End2End/Utils/PostTypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function runUpdatePostTest() {
$commitAsserter->assertNumCommits(1);
$commitAsserter->assertCommitAction("post/edit");
$commitAsserter->assertCommitTag("VP-Post-Type", $this->getPostType());
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_content,post_title");
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_content,post_title,post_modified,post_modified_gmt");
$commitAsserter->assertCleanWorkingDirectory();
DBAsserter::assertFilesEqualDatabase();
}
Expand All @@ -61,12 +61,12 @@ public function runUpdatePostViaQuickEditTest() {
$commitAsserter->assertCommitsAreEquivalent();
$commitAsserter->assertCommitTag("VP-Post-Type", $this->getPostType());
try {
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_title");
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_title,post_modified,post_modified_gmt");
} catch (PHPUnit_Framework_AssertionFailedError $e) {
// Since WP 4.2 there is a bug in WP.
// The ping_status might be changed by the quick edit form.
// Reported here: https://core.trac.wordpress.org/ticket/31977
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_title,ping_status");
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_title,ping_status,post_modified,post_modified_gmt");
}
$commitAsserter->assertCleanWorkingDirectory();
DBAsserter::assertFilesEqualDatabase();
Expand All @@ -81,7 +81,7 @@ public function runTrashPostTest() {
$commitAsserter->assertNumCommits(1);
$commitAsserter->assertCommitAction("post/trash");
$commitAsserter->assertCommitTag("VP-Post-Type", $this->getPostType());
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_status");
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_status,post_modified,post_modified_gmt");
$commitAsserter->assertCleanWorkingDirectory();
DBAsserter::assertFilesEqualDatabase();
}
Expand All @@ -95,7 +95,7 @@ public function runUndoTrashTest() {
$commitAsserter->assertNumCommits(1);
$commitAsserter->assertCommitAction("post/untrash");
$commitAsserter->assertCommitTag("VP-Post-Type", $this->getPostType());
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_status");
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_status,post_modified,post_modified_gmt");
$commitAsserter->assertCleanWorkingDirectory();
DBAsserter::assertFilesEqualDatabase();
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public function runPublishDraftTest() {
$commitAsserter->assertNumCommits(1);
$commitAsserter->assertCommitAction("post/publish");
$commitAsserter->assertCommitTag("VP-Post-Type", $this->getPostType());
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_date,post_date_gmt,post_content,post_status,post_name");
$commitAsserter->assertCommitTag("VP-Post-UpdatedProperties", "post_date,post_date_gmt,post_content,post_status,post_name,post_modified,post_modified_gmt");
$commitAsserter->assertCleanWorkingDirectory();
DBAsserter::assertFilesEqualDatabase();
}
Expand Down

0 comments on commit ff504f7

Please sign in to comment.