import: Don't try duplicate detection when the sha1 is unavailable
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 23 Apr 2018 20:57:28 +0000 (16:57 -0400)
committerLegoktm <legoktm@member.fsf.org>
Thu, 26 Apr 2018 05:13:30 +0000 (05:13 +0000)
Trying to compare a string field with 0 (cast from false) raises an
error in PostgreSQL, and we're expecting it to not detect duplicates in
that situation anyway.

Change-Id: Ibff6daee6bbec00e37532e03c9ece041ba612de0
(cherry picked from commit f09d66de2ab88e3ed39fc21b3805cea90eee5bfe)

includes/import/ImportableOldRevisionImporter.php

index 33fad3e..066a3ea 100644 (file)
@@ -68,18 +68,20 @@ class ImportableOldRevisionImporter implements OldRevisionImporter {
 
                        // Note: sha1 has been in XML dumps since 2012. If you have an
                        // older dump, the duplicate detection here won't work.
-                       $prior = $dbw->selectField( 'revision', '1',
-                               [ 'rev_page' => $pageId,
+                       if ( $importableRevision->getSha1Base36() !== false ) {
+                               $prior = $dbw->selectField( 'revision', '1',
+                                       [ 'rev_page' => $pageId,
                                        'rev_timestamp' => $dbw->timestamp( $importableRevision->getTimestamp() ),
                                        'rev_sha1' => $importableRevision->getSha1Base36() ],
-                               __METHOD__
-                       );
-                       if ( $prior ) {
-                               // @todo FIXME: This could fail slightly for multiple matches :P
-                               $this->logger->debug( __METHOD__ . ": skipping existing revision for [[" .
-                                       $importableRevision->getTitle()->getPrefixedText() . "]], timestamp " .
-                                       $importableRevision->getTimestamp() . "\n" );
-                               return false;
+                                       __METHOD__
+                               );
+                               if ( $prior ) {
+                                       // @todo FIXME: This could fail slightly for multiple matches :P
+                                       $this->logger->debug( __METHOD__ . ": skipping existing revision for [[" .
+                                               $importableRevision->getTitle()->getPrefixedText() . "]], timestamp " .
+                                               $importableRevision->getTimestamp() . "\n" );
+                                       return false;
+                               }
                        }
                }