Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/267314

Change subject: Renamed $constraintClaimGuid -> $constraintStatementGuid
......................................................................

Renamed $constraintClaimGuid -> $constraintStatementGuid

also fixed some of the long lines and made the code
more clear in places where Constraint is used.

Change-Id: I0c53f33c24b365a228f9211e9d32a7f5c3547f7b
---
M includes/Constraint.php
M includes/ConstraintRepository.php
M maintenance/UpdateConstraintsTable.php
3 files changed, 34 insertions(+), 24 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/14/267314/1

diff --git a/includes/Constraint.php b/includes/Constraint.php
index 97ba8b0..f92fd06 100644
--- a/includes/Constraint.php
+++ b/includes/Constraint.php
@@ -4,7 +4,6 @@
 
 use Wikibase\DataModel\Entity\PropertyId;
 
-
 /**
  * Class Constraint
  *
@@ -17,7 +16,12 @@
        /**
         * @var string
         */
-       private $constraintClaimGuid;
+       private $constraintStatementGuid;
+
+       /**
+        * @var PropertyId
+        */
+       private $propertyId;
 
        /**
         * @var string
@@ -30,33 +34,33 @@
        private $constraintTypeQid;
 
        /**
-        * @var PropertyId
-        */
-       private $propertyId;
-
-       /**
-        * @var array (variable length; key: string with parameter name (e.g. 
'property'); value: string (e.g. 'P21')
+        * @var array (key: string with parameter name (e.g. 'property'); 
value: string (e.g. 'P21'))
         */
        private $constraintParameters;
 
        /**
-        * @param string $constraintClaimGuid
+        * @param string $constraintStatementGuid
         * @param PropertyId $propertyId
         * @param string $constraintTypeQid
         * @param array $constraintParameters
         */
-       public function __construct( $constraintClaimGuid, PropertyId 
$propertyId, $constraintTypeQid, $constraintParameters) {
-               $this->constraintClaimGuid = $constraintClaimGuid;
-               $this->constraintTypeQid = $constraintTypeQid;
+       public function __construct(
+               $constraintStatementGuid,
+               PropertyId $propertyId,
+               $constraintTypeQid,
+               array $constraintParameters
+       ) {
+               $this->constraintStatementGuid = $constraintStatementGuid;
                $this->propertyId = $propertyId;
+               $this->constraintTypeQid = $constraintTypeQid;
                $this->constraintParameters = $constraintParameters;
        }
 
        /**
         * @return string
         */
-       public function getConstraintClaimGuid() {
-               return $this->constraintClaimGuid;
+       public function getConstraintStatementGuid() {
+               return $this->constraintStatementGuid;
        }
 
        /**
@@ -87,10 +91,10 @@
        }
 
        /**
-        * @return array (variable length; key: string with parameter name 
(e.g. 'property'); value: string (e.g. 'P21')
+        * @return array (key: string with parameter name (e.g. 'property'); 
value: string (e.g. 'P21'))
         */
        public function getConstraintParameters() {
                return $this->constraintParameters;
        }
 
-}
\ No newline at end of file
+}
diff --git a/includes/ConstraintRepository.php 
b/includes/ConstraintRepository.php
index df66a75..69b6407 100644
--- a/includes/ConstraintRepository.php
+++ b/includes/ConstraintRepository.php
@@ -81,10 +81,15 @@
                foreach( $results as $result ) {
                        $constraintTypeQid = $result->constraint_type_qid;
                        $constraintParameters = (array) json_decode( 
$result->constraint_parameters );
-                       $serializedPid = 'P' . $result->pid;
-                       $constraints[] = new Constraint( 
$result->constraint_guid, new PropertyId( $serializedPid ), $constraintTypeQid, 
$constraintParameters );
+
+                       $constraints[] = new Constraint(
+                               $result->constraint_guid,
+                               PropertyId::newFromNumber( $result->pid ),
+                               $constraintTypeQid,
+                               $constraintParameters
+                       );
                }
                return $constraints;
        }
 
-}
\ No newline at end of file
+}
diff --git a/maintenance/UpdateConstraintsTable.php 
b/maintenance/UpdateConstraintsTable.php
index e4bb6f5..058627e 100644
--- a/maintenance/UpdateConstraintsTable.php
+++ b/maintenance/UpdateConstraintsTable.php
@@ -51,10 +51,10 @@
        }
 
        private function insertValues( $constraintRepo, $csvFile ) {
-
                $i = 0;
                $db = wfGetDB( DB_MASTER );
                $accumulator = array();
+
                while ( true ) {
                        $data = fgetcsv( $csvFile );
                        if ( $data === false || ++$i % $this->mBatchSize === 0 
) {
@@ -75,12 +75,13 @@
                                }
                        }
 
-                       $constraintParameters = (array) json_decode( $data[3] );
+                       list( $statementGuid, $numericPropertyId, 
$constraintTypeQid, $params ) = $data;
+                       $constraintParameters = (array) json_decode( $params );
 
                        $accumulator[] = new Constraint(
-                               $data[0],
-                               PropertyId::newFromNumber( $data[1] ),
-                               $data[2],
+                               $statementGuid,
+                               PropertyId::newFromNumber( $numericPropertyId ),
+                               $constraintTypeQid,
                                $constraintParameters
                        );
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c53f33c24b365a228f9211e9d32a7f5c3547f7b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>

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

Reply via email to