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

Change subject: Fixes to qualifiers changeops and api module
......................................................................


Fixes to qualifiers changeops and api module

Change-Id: Id3dd32aac632f439c13034b4655d06381b826125
---
M repo/includes/api/SetQualifier.php
M repo/includes/changeop/ChangeOpQualifier.php
2 files changed, 20 insertions(+), 3 deletions(-)

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



diff --git a/repo/includes/api/SetQualifier.php 
b/repo/includes/api/SetQualifier.php
index 975bbb1..718a7d1 100644
--- a/repo/includes/api/SetQualifier.php
+++ b/repo/includes/api/SetQualifier.php
@@ -5,6 +5,7 @@
 use ApiBase;
 use Wikibase\Entity;
 use Wikibase\Claims;
+use Wikibase\Claim;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\ChangeOpQualifier;
 use Wikibase\ChangeOpException;
@@ -69,6 +70,10 @@
 
                $claim = $claims->getClaimWithGuid( $claimGuid );
 
+               if ( isset( $params['snakhash'] ) ) {
+                       $this->validateReferenceHash( $claim, 
$params['snakhash'] );
+               }
+
                $changeOp = $this->getChangeOp();
 
                try {
@@ -113,6 +118,18 @@
        /**
         * @since 0.4
         *
+        * @param Claim $claim
+        * @param string $qualifierHash
+        */
+       protected function validateQualifierHash( Claim $claim, $qualifierHash 
) {
+               if ( !$claim->getReferences()->hasReferenceHash( $qualifierHash 
) ) {
+                       $this->dieUsage( "Claim does not have a qualifier with 
the given hash" , 'no-such-reference' );
+               }
+       }
+
+       /**
+        * @since 0.4
+        *
         * @return ChangeOpQualifier
         */
        protected function getChangeOp() {
diff --git a/repo/includes/changeop/ChangeOpQualifier.php 
b/repo/includes/changeop/ChangeOpQualifier.php
index d4c05eb..10ee9bc 100644
--- a/repo/includes/changeop/ChangeOpQualifier.php
+++ b/repo/includes/changeop/ChangeOpQualifier.php
@@ -76,7 +76,7 @@
         */
        public function __construct( $claimGuid, $snak, $snakHash, 
EntityIdFormatter $idFormatter ) {
                if ( !is_string( $claimGuid ) || $claimGuid === '' ) {
-                       throw new InvalidArgumentException( '$snakHash needs to 
be a string and must not be empty' );
+                       throw new InvalidArgumentException( '$claimGuid needs 
to be a string and must not be empty' );
                }
 
                if ( !is_string( $snakHash ) ) {
@@ -129,7 +129,7 @@
                        if ( $this->snak != null ) {
                                $this->setQualifier( $qualifiers, $summary );
                        } else {
-                               $this->removeQualifiers( $qualifiers, $summary 
);
+                               $this->removeQualifier( $qualifiers, $summary );
                        }
                }
 
@@ -184,7 +184,7 @@
         *
         * @throws ChangeOpException
         */
-       protected function removeQualifiers( Snaks $qualifiers, Summary 
$summary = null ) {
+       protected function removeQualifier( Snaks $qualifiers, Summary $summary 
= null ) {
                if ( !$qualifiers->hasSnakHash( $this->snakHash ) ) {
                        throw new ChangeOpException( "Qualifier with hash 
$this->snakHash does not exist" );
                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id3dd32aac632f439c13034b4655d06381b826125
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@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