65 $dbw = $this->loadBalancer->getConnectionRef(
DB_MASTER );
67 # Sneak a single revision into place
70 $userId = intval( $user->getId() );
71 $userText = $user->getName();
74 $userText = $importableRevision->
getUser();
81 $page = WikiPage::factory( $importableRevision->
getTitle() );
82 $page->loadPageData(
'fromdbmaster' );
83 if ( !$page->exists() ) {
85 $pageId = $page->insertOn( $dbw );
89 $pageId = $page->getId();
95 $prior = $dbw->selectField(
'revision',
'1',
96 [
'rev_page' => $pageId,
97 'rev_timestamp' => $dbw->timestamp( $importableRevision->
getTimestamp() ),
103 $this->logger->debug( __METHOD__ .
": skipping existing revision for [[" .
104 $importableRevision->
getTitle()->getPrefixedText() .
"]], timestamp " .
114 $this->logger->debug( __METHOD__ .
': got invalid $pageId when importing revision of [[' .
115 $importableRevision->
getTitle()->getPrefixedText() .
']], timestamp ' .
123 $qi = $this->revisionStore->getQueryInfo();
124 $prevRevRow = $dbw->selectRow( $qi[
'tables'], $qi[
'fields'],
126 'rev_page' => $pageId,
127 'rev_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $importableRevision->
getTimestamp() ) ),
131 'rev_timestamp DESC',
138 # @todo FIXME: Use original rev_id optionally (better for backups)
141 $revisionRecord->setParentId( $prevRevRow ? (
int)$prevRevRow->rev_id : 0 );
142 $revisionRecord->setComment(
143 CommentStoreComment::newUnsavedComment( $importableRevision->
getComment() )
152 }
catch ( InvalidArgumentException $ex ) {
153 $revUser = RequestContext::getMain()->getUser();
155 $revisionRecord->setUser( $revUser );
157 $originalRevision = $prevRevRow
158 ? $this->revisionStore->newRevisionFromRow(
160 IDBAccessObject::READ_LATEST,
165 foreach ( $importableRevision->
getSlotRoles() as $role ) {
166 if ( !$this->slotRoleRegistry->isDefinedRole( $role ) ) {
167 throw new MWException(
"Undefined slot role $role" );
170 $newContent = $importableRevision->
getContent( $role );
171 if ( !$originalRevision || !$originalRevision->hasSlot( $role ) ) {
172 $revisionRecord->setContent( $role, $newContent );
174 $originalSlot = $originalRevision->getSlot( $role );
175 if ( !$originalSlot->hasSameContent( $importableRevision->
getSlot( $role ) ) ) {
176 $revisionRecord->setContent( $role, $newContent );
178 $revisionRecord->inheritSlot( $originalRevision->getSlot( $role ) );
183 $revisionRecord->setTimestamp( $importableRevision->
getTimestamp() );
184 $revisionRecord->setMinorEdit( $importableRevision->
getMinor() );
185 $revisionRecord->setPageId( $pageId );
187 $latestRevId = $page->getLatest();
189 $inserted = $this->revisionStore->insertRevisionOn( $revisionRecord, $dbw );
190 if ( $latestRevId ) {
193 $latestRevTimestamp = (int)$this->revisionStore->getTimestampFromId(
195 RevisionStore::READ_LATEST
198 $latestRevTimestamp = 0;
200 if ( $importableRevision->
getTimestamp() > $latestRevTimestamp ) {
201 $changed = $page->updateRevisionOn( $dbw, $inserted, $latestRevId );
206 $tags = $importableRevision->
getTags();
207 if ( $tags !== [] ) {
211 if ( $changed !==
false && $this->doUpdates ) {
212 $this->logger->debug( __METHOD__ .
": running updates" );
215 $page->doEditUpdates(
218 [
'created' => $created,
'oldcountable' =>
'no-change' ]