jenkins-bot has submitted this change and it was merged.

Change subject: Database schema improvements (T102992)
......................................................................


Database schema improvements (T102992)

Change-Id: I05048ca7d321ca052111d2c5262d13c6433b4c9d
---
M includes/ExternalDataRepo.php
M includes/UpdateExternalData/ExternalDataImporter.php
M sql/create_wbqev_dump_information.sql
M sql/create_wbqev_identifier_properties.sql
M tests/phpunit/DumpMetaInformation/SqlDumpMetaInformationRepoTest.php
M tests/phpunit/ExternalDataRepoTest.php
M tests/phpunit/UpdateExternalData/UpdateExternalDataTest.php
7 files changed, 56 insertions(+), 69 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/ExternalDataRepo.php b/includes/ExternalDataRepo.php
index 548d6d0..0d13e57 100755
--- a/includes/ExternalDataRepo.php
+++ b/includes/ExternalDataRepo.php
@@ -2,6 +2,7 @@
 
 namespace WikibaseQuality\ExternalValidation;
 
+use DBError;
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikimedia\Assert\Assert;
 
@@ -31,14 +32,13 @@
                Assert::parameterElementType( 'string', $dumpIds, '$dumpIds' );
                Assert::parameterElementType( 'string', $externalIds, 
'$externalIds' );
                Assert::parameterElementType( 
'Wikibase\DataModel\Entity\PropertyId', $propertyIds, '$propertyIds' );
+               Assert::parameter( count( $dumpIds ) > 0, '$dumpIds', '$dumpIds 
has to contain at least one element.' );
+               Assert::parameter( count( $externalIds ) > 0, '$externalIds', 
'$externalIds has to contain at least one element.' );
 
-               $conditions = array();
-               if ( $dumpIds ) {
-                       $conditions['dump_id'] = $dumpIds;
-               }
-               if ( $externalIds ) {
-                       $conditions['external_id'] = $externalIds;
-               }
+               $conditions = array(
+                       'dump_id' => $dumpIds,
+                       'external_id' => $externalIds
+               );
                if ( $propertyIds ) {
                        $conditions['pid'] = $propertyIds;
                }
@@ -101,10 +101,17 @@
                        $externalDataBatch
                );
 
-               $db->commit( __METHOD__, "flush" );
-               wfWaitForSlaves();
+               try {
+                       $db->begin();
+                       $result = $db->insert( self::TABLE_NAME, $accumulator );
+                       $db->commit();
+               }
+               catch( DBError $ex ) {
+                       $db->rollback();
+                       throw $ex;
+               }
 
-               return $db->insert( self::TABLE_NAME, $accumulator );
+               return $result;
        }
 
        /**
diff --git a/includes/UpdateExternalData/ExternalDataImporter.php 
b/includes/UpdateExternalData/ExternalDataImporter.php
index 44249aa..231668f 100755
--- a/includes/UpdateExternalData/ExternalDataImporter.php
+++ b/includes/UpdateExternalData/ExternalDataImporter.php
@@ -149,6 +149,7 @@
                                catch( \DBError $e ) {
                                        exit( 'Unknown database error 
occurred.' );
                                }
+                               wfWaitForSlaves();
 
                                $this->log( "\r\033[K" );
                                $this->log( "$i rows inserted" );
diff --git a/sql/create_wbqev_dump_information.sql 
b/sql/create_wbqev_dump_information.sql
index 8762bc6..516f36f 100644
--- a/sql/create_wbqev_dump_information.sql
+++ b/sql/create_wbqev_dump_information.sql
@@ -1,7 +1,7 @@
 CREATE TABLE IF NOT EXISTS /*_*/wbqev_dump_information (
   id           VARBINARY(25)   PRIMARY KEY NOT NULL,
   source_qid   VARBINARY(15)   NOT NULL,
-  import_date  VARBINARY(25)   NOT NULL,
+  import_date  CHAR(14)        NOT NULL,
   language     VARBINARY(10)   NOT NULL,
   source_url   VARBINARY(300)  UNIQUE NOT NULL,
   size         INT UNSIGNED    NOT NULL,
diff --git a/sql/create_wbqev_identifier_properties.sql 
b/sql/create_wbqev_identifier_properties.sql
index 56d8469..d417cc0 100644
--- a/sql/create_wbqev_identifier_properties.sql
+++ b/sql/create_wbqev_identifier_properties.sql
@@ -2,4 +2,6 @@
   identifier_pid  VARBINARY(15)  NOT NULL,
   dump_id         VARBINARY(25)  NOT NULL,
   PRIMARY KEY (identifier_pid, dump_id)
-) /*$wgDBTableOptions*/;
\ No newline at end of file
+) /*$wgDBTableOptions*/;
+
+CREATE INDEX /*i*/dump_id ON /*_*/wbqev_identifier_properties (dump_id);
\ No newline at end of file
diff --git 
a/tests/phpunit/DumpMetaInformation/SqlDumpMetaInformationRepoTest.php 
b/tests/phpunit/DumpMetaInformation/SqlDumpMetaInformationRepoTest.php
index 472bc27..3966c9d 100755
--- a/tests/phpunit/DumpMetaInformation/SqlDumpMetaInformationRepoTest.php
+++ b/tests/phpunit/DumpMetaInformation/SqlDumpMetaInformationRepoTest.php
@@ -312,30 +312,18 @@
     public function testSaveDumpMetaInformation( DumpMetaInformation 
$dumpMetaInformation ) {
         $this->dumpMetaInformationRepo->save( $dumpMetaInformation );
 
-        $this->assertSelect(
+        $actualRow = $this->db->selectRow(
             SqlDumpMetaInformationRepo::META_TABLE_NAME,
-            array(
-                'id',
-                'source_qid',
-                'import_date',
-                'language',
-                'source_url',
-                'size',
-                'license_qid'
-            ),
-            array( 'id' => $dumpMetaInformation->getDumpId() ),
-            array(
-                array(
-                    $dumpMetaInformation->getDumpId(),
-                    
$dumpMetaInformation->getSourceItemId()->getSerialization(),
-                    $dumpMetaInformation->getImportDate(),
-                    $dumpMetaInformation->getLanguageCode(),
-                    $dumpMetaInformation->getSourceUrl(),
-                    $dumpMetaInformation->getSize(),
-                    
$dumpMetaInformation->getLicenseItemId()->getSerialization()
-                )
-            )
+            '*',
+            array( 'id' => $dumpMetaInformation->getDumpId() )
         );
+        $this->assertEquals( $dumpMetaInformation->getDumpId(), $actualRow->id 
);
+        $this->assertEquals( 
$dumpMetaInformation->getSourceItemId()->getSerialization(), 
$actualRow->source_qid );
+        $this->assertEquals( $dumpMetaInformation->getImportDate(), 
wfTimestamp( TS_MW, $actualRow->import_date ) );
+        $this->assertEquals( $dumpMetaInformation->getLanguageCode(), 
$actualRow->language );
+        $this->assertEquals( $dumpMetaInformation->getSourceUrl(), 
$actualRow->source_url );
+        $this->assertEquals( $dumpMetaInformation->getSize(), $actualRow->size 
);
+        $this->assertEquals( 
$dumpMetaInformation->getLicenseItemId()->getSerialization(), 
$actualRow->license_qid );
     }
 
     /**
diff --git a/tests/phpunit/ExternalDataRepoTest.php 
b/tests/phpunit/ExternalDataRepoTest.php
index 6a59b97..6bcf7e2 100755
--- a/tests/phpunit/ExternalDataRepoTest.php
+++ b/tests/phpunit/ExternalDataRepoTest.php
@@ -153,20 +153,8 @@
                                )
                        ),
                        array(
-                               array( 'fubar' ),
-                               array(),
-                               array(),
-                               array(
-                                       'fubar' => array(
-                                               'bar' => array(
-                                                       'P3' => array( 'baz' )
-                                               )
-                                       )
-                               )
-                       ),
-                       array(
                                array( 42 ),
-                               array( 'foo', 'bar' ),
+                               array('foo', 'bar'),
                                array(
                                        new PropertyId( 'P1' ),
                                        new PropertyId( 'P3' )
@@ -183,6 +171,20 @@
                                ),
                                null,
                                'InvalidArgumentException'
+                       ),
+                       array(
+                               array(),
+                               array('foo', 'bar'),
+                               array(),
+                               null,
+                               'InvalidArgumentException'
+                       ),
+                       array(
+                               array('foo', 'bar'),
+                               array(),
+                               array(),
+                               null,
+                               'InvalidArgumentException'
                        )
                );
        }
diff --git a/tests/phpunit/UpdateExternalData/UpdateExternalDataTest.php 
b/tests/phpunit/UpdateExternalData/UpdateExternalDataTest.php
index e437e49..473b961 100755
--- a/tests/phpunit/UpdateExternalData/UpdateExternalDataTest.php
+++ b/tests/phpunit/UpdateExternalData/UpdateExternalDataTest.php
@@ -104,30 +104,17 @@
                $maintenanceScript->execute();
 
                // Run assertions on meta information
-               $this->assertSelect(
+               $actualRow = $this->db->selectRow(
                        SqlDumpMetaInformationRepo::META_TABLE_NAME,
-                       array(
-                               'source_qid',
-                               'import_date',
-                               'language',
-                               'source_url',
-                               'size',
-                               'license_qid'
-                       ),
-                       array(
-                               'id' => 'foobar'
-                       ),
-                       array(
-                               array(
-                                       'Q36578',
-                                       '20150401144144',
-                                       'de',
-                                       'http://www.foo.bar',
-                                       590798465,
-                                       'Q6938433'
-                               )
-                       )
+                       '*',
+                       array( 'id' => 'foobar' )
                );
+               $this->assertEquals( 'Q36578', $actualRow->source_qid );
+               $this->assertEquals( '20150401144144', wfTimestamp( TS_MW, 
$actualRow->import_date ) );
+               $this->assertEquals( 'de', $actualRow->language );
+               $this->assertEquals( 'http://www.foo.bar', 
$actualRow->source_url );
+               $this->assertEquals( '590798465', $actualRow->size );
+               $this->assertEquals( 'Q6938433', $actualRow->license_qid );
 
                // Run assertions on identifier properties
                $this->assertSelect(

-- 
To view, visit https://gerrit.wikimedia.org/r/222869
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I05048ca7d321ca052111d2c5262d13c6433b4c9d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/WikibaseQualityExternalValidation
Gerrit-Branch: v1
Gerrit-Owner: Soeren.oldag <soeren_ol...@freenet.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Jonaskeutel <jonas.keu...@student.hpi.de>
Gerrit-Reviewer: Soeren.oldag <soeren_ol...@freenet.de>
Gerrit-Reviewer: Springle <sprin...@wikimedia.org>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to