Merge "WikiPage: keep touch date consistent"

This commit is contained in:
jenkins-bot 2021-03-24 12:40:44 +00:00 committed by Gerrit Code Review
commit 526e8f0ee9
2 changed files with 34 additions and 2 deletions

View file

@ -884,7 +884,9 @@ class WikiPage implements Page, IDBAccessObject, PageRecord {
*/
private function setLastEdit( RevisionRecord $revRecord ) {
$this->mLastRevision = $revRecord;
$this->mLatest = $revRecord->getId();
$this->mTimestamp = $revRecord->getTimestamp();
$this->mTouched = max( $this->mTouched, $revRecord->getTimestamp() );
}
/**
@ -1547,7 +1549,6 @@ class WikiPage implements Page, IDBAccessObject, PageRecord {
if ( $result ) {
$this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
$this->setLastEdit( $revision );
$this->mLatest = $revision->getId();
$this->mRedirectTarget = null;
$this->mHasRedirectTarget = null;
$this->mPageIsRedirectField = (bool)$rt;
@ -2224,7 +2225,6 @@ class WikiPage implements Page, IDBAccessObject, PageRecord {
// TODO: this is currently redundant to what is done in updateRevisionOn.
// But updateRevisionOn() should move into PageStore, and then this will be needed.
$this->setLastEdit( $revRec );
$this->mLatest = $revRec->getId();
}
return $updater->getStatus();

View file

@ -326,6 +326,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase {
$this->hideDeprecated( 'Revision::getContent' );
$this->hideDeprecated( 'Revision::__construct' );
$this->hideDeprecated( 'Revision::getId' );
$this->hideDeprecated( 'Revision::getTimestamp' );
$this->hideDeprecated( 'WikiPage::getRevision' );
$this->hideDeprecated( "MediaWiki\Storage\PageUpdater::doCreate status get 'revision'" );
$this->hideDeprecated( "MediaWiki\Storage\PageUpdater::doModify status get 'revision'" );
@ -352,6 +353,10 @@ class WikiPageDbTest extends MediaWikiLangTestCase {
$this->assertSame( $status->value['revision']->getSha1(), $page->getRevision()->getSha1() );
$this->assertTrue( $status->value['revision']->getContent()->equals( $content ), 'equals' );
$this->assertSame( $status->value['revision']->getId(), $page->getLatest() );
$this->assertSame( $status->value['revision']->getTimestamp(), $page->getTimestamp() );
$this->assertSame( $status->value['revision']->getTimestamp(), $page->getTouched() );
$content = ContentHandler::makeContent(
"At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
. "Stet clita kasd [[gubergren]], no sea takimata sanctus est. ~~~~",
@ -2766,4 +2771,31 @@ more stuff
$this->assertSame( $page->isRedirect(), $record->isRedirect() );
}
/**
* @covers WikiPage::setLastEdit
* @covers WikiPage::getTouched
*/
public function testGetTouched() {
$page = $this->createPage( __METHOD__, 'whatever' );
$touched = $this->db->selectField( 'page', 'page_touched', [ 'page_id' => $page->getId() ] );
$touched = MWTimestamp::convert( TS_MW, $touched );
// Internal cache of the touched time was set after the page was created
$this->assertSame( $touched, $page->getTouched() );
$touched = MWTimestamp::convert( TS_MW, MWTimestamp::convert( TS_UNIX, $touched ) + 100 );
$page->getTitle()->invalidateCache( $touched );
// Re-load touched time
$page = $this->newPage( $page->getTitle() );
$this->assertSame( $touched, $page->getTouched() );
// Cause the latest revision to be loaded
$page->getRevisionRecord();
// Make sure the internal cache of the touched time was not overwritten
$this->assertSame( $touched, $page->getTouched() );
}
}