73 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
75 # Sneak a single revision into place
78 $userId = $user->getId();
79 $userText = $user->getName();
82 $userText = $importableRevision->
getUser();
89 $page = $this->wikiPageFactory->newFromTitle( $importableRevision->
getTitle() );
90 $page->loadPageData(
'fromdbmaster' );
91 if ( !$page->exists() ) {
93 $pageId = $page->insertOn( $dbw );
97 $pageId = $page->getId();
103 $prior = (bool)$dbw->selectField(
'revision',
'1',
104 [
'rev_page' => $pageId,
105 'rev_timestamp' => $dbw->timestamp( $importableRevision->
getTimestamp() ),
111 $this->logger->debug( __METHOD__ .
": skipping existing revision for [[" .
112 $importableRevision->
getTitle()->getPrefixedText() .
"]], timestamp " .
122 $this->logger->debug( __METHOD__ .
': got invalid $pageId when importing revision of [[' .
123 $importableRevision->
getTitle()->getPrefixedText() .
']], timestamp ' .
131 $qi = $this->revisionStore->getQueryInfo();
132 $prevRevRow = $dbw->selectRow( $qi[
'tables'], $qi[
'fields'],
134 'rev_page' => $pageId,
135 'rev_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $importableRevision->
getTimestamp() ) ),
139 'rev_timestamp DESC',
146 # @todo FIXME: Use original rev_id optionally (better for backups)
149 $revisionRecord->setParentId( $prevRevRow ? (
int)$prevRevRow->rev_id : 0 );
150 $revisionRecord->setComment(
151 CommentStoreComment::newUnsavedComment( $importableRevision->
getComment() )
160 }
catch ( InvalidArgumentException $ex ) {
161 $revUser = RequestContext::getMain()->getUser();
163 $revisionRecord->setUser( $revUser );
165 $originalRevision = $prevRevRow
166 ? $this->revisionStore->newRevisionFromRow(
168 IDBAccessObject::READ_LATEST,
173 foreach ( $importableRevision->
getSlotRoles() as $role ) {
174 if ( !$this->slotRoleRegistry->isDefinedRole( $role ) ) {
175 throw new MWException(
"Undefined slot role $role" );
178 $newContent = $importableRevision->
getContent( $role );
179 if ( !$originalRevision || !$originalRevision->hasSlot( $role ) ) {
180 $revisionRecord->setContent( $role, $newContent );
182 $originalSlot = $originalRevision->getSlot( $role );
183 if ( !$originalSlot->hasSameContent( $importableRevision->
getSlot( $role ) ) ) {
184 $revisionRecord->setContent( $role, $newContent );
186 $revisionRecord->inheritSlot( $originalRevision->getSlot( $role ) );
191 $revisionRecord->setTimestamp( $importableRevision->
getTimestamp() );
192 $revisionRecord->setMinorEdit( $importableRevision->
getMinor() );
193 $revisionRecord->setPageId( $pageId );
195 $latestRevId = $page->getLatest();
197 $inserted = $this->revisionStore->insertRevisionOn( $revisionRecord, $dbw );
198 if ( $latestRevId ) {
201 $latestRevTimestamp = (int)$this->revisionStore->getTimestampFromId(
203 RevisionStore::READ_LATEST
206 $latestRevTimestamp = 0;
208 if ( $importableRevision->
getTimestamp() > $latestRevTimestamp ) {
209 $changed = $page->updateRevisionOn( $dbw, $inserted, $latestRevId );
214 $tags = $importableRevision->
getTags();
215 if ( $tags !== [] ) {
219 if ( $changed !==
false && $this->doUpdates ) {
220 $this->logger->debug( __METHOD__ .
": running updates" );
223 $page->doEditUpdates(
226 [
'created' => $created,
'oldcountable' =>
'no-change' ]