# Save a null revision in the page's history notifying of the move
$nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true, $user );
if ( !is_object( $nullRevision ) ) {
- throw new MWException( 'No valid null revision produced in ' . __METHOD__ );
+ throw new MWException( 'Failed to create null revision while moving page ID '
+ . $oldid . ' to ' . $nt->getPrefixedDBkey() );
}
$nullRevId = $nullRevision->insertOn( $dbw );
$rec = self::getRevisionStore()->newNullRevision( $dbw, $title, $comment, $minor, $user );
- return new Revision( $rec );
+ return $rec ? new Revision( $rec ) : null;
}
/**
use Psr\Log\NullLogger;
use RecentChange;
use Revision;
+use RuntimeException;
use stdClass;
use Title;
use User;
) {
$this->checkDatabaseWikiId( $dbw );
+ $pageId = $title->getArticleID();
+
// T51581: Lock the page table row to ensure no other process
// is adding a revision to the page at the same time.
// Avoid locking extra tables, compare T191892.
$pageLatest = $dbw->selectField(
'page',
'page_latest',
- [ 'page_id' => $title->getArticleID() ],
+ [ 'page_id' => $pageId ],
__METHOD__,
[ 'FOR UPDATE' ]
);
$title
);
+ if ( !$oldRevision ) {
+ $msg = "Failed to load latest revision ID $pageLatest of page ID $pageId.";
+ $this->logger->error(
+ $msg,
+ [ 'exception' => new RuntimeException( $msg ) ]
+ );
+ return null;
+ }
+
// Construct the new revision
$timestamp = wfTimestampNow(); // TODO: use a callback, so we can override it for testing.
$newRevision = MutableRevisionRecord::newFromParentRevision( $oldRevision );