jenkins-bot has submitted this change and it was merged.
Change subject: Replace deprecated Claims::hasClaimWithGuid method
......................................................................
Replace deprecated Claims::hasClaimWithGuid method
This reduces the number of calls to deprecated methods without
changing semantics.
Recheck.
Change-Id: I88f7b9b4bd5d85032b0ea44e29f5badeffdc5313
---
M repo/includes/ChangeOp/ChangeOpClaimRemove.php
M repo/includes/ChangeOp/ChangeOpMainSnak.php
M repo/includes/ChangeOp/ChangeOpQualifier.php
M repo/includes/ChangeOp/ChangeOpQualifierRemove.php
M repo/includes/ChangeOp/ChangeOpReference.php
M repo/includes/ChangeOp/ChangeOpReferenceRemove.php
M repo/includes/ChangeOp/ChangeOpStatementRank.php
M repo/includes/ClaimSummaryBuilder.php
M repo/includes/api/ClaimModificationHelper.php
M repo/includes/api/GetClaims.php
M repo/tests/phpunit/includes/api/SetClaimValueTest.php
M repo/tests/phpunit/includes/api/SetQualifierTest.php
12 files changed, 42 insertions(+), 34 deletions(-)
Approvals:
Aude: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/includes/ChangeOp/ChangeOpClaimRemove.php
b/repo/includes/ChangeOp/ChangeOpClaimRemove.php
index 0e6c727..7bff58f 100644
--- a/repo/includes/ChangeOp/ChangeOpClaimRemove.php
+++ b/repo/includes/ChangeOp/ChangeOpClaimRemove.php
@@ -77,10 +77,13 @@
* @throws ChangeOpException
*/
protected function removeClaim( Claims $claims, Summary $summary = null
) {
- if( !$claims->hasClaimWithGuid( $this->claimGuid ) ) {
+ $claim = $claims->getClaimWithGuid( $this->claimGuid );
+
+ if ( $claim === null ) {
throw new ChangeOpException( "Entity does not have
claim with GUID $this->claimGuid" );
}
- $removedSnak = $claims->getClaimWithGuid( $this->claimGuid
)->getMainSnak();
+
+ $removedSnak = $claim->getMainSnak();
$claims->removeClaimWithGuid( $this->claimGuid );
$this->updateSummary( $summary, 'remove', '',
$this->getClaimSummaryArgs( $removedSnak ) );
}
diff --git a/repo/includes/ChangeOp/ChangeOpMainSnak.php
b/repo/includes/ChangeOp/ChangeOpMainSnak.php
index e240ff1..a8d78f7 100644
--- a/repo/includes/ChangeOp/ChangeOpMainSnak.php
+++ b/repo/includes/ChangeOp/ChangeOpMainSnak.php
@@ -119,11 +119,12 @@
* @throws ChangeOpException
*/
private function setClaim( Claims $claims, Summary $summary = null ) {
- if( !$claims->hasClaimWithGuid( $this->claimGuid ) ) {
+ $claim = $claims->getClaimWithGuid( $this->claimGuid );
+
+ if ( $claim === null ) {
throw new ChangeOpException( "Entity does not have
claim with GUID " . $this->claimGuid );
}
- $claim = $claims->getClaimWithGuid( $this->claimGuid );
$propertyId = $claim->getMainSnak()->getPropertyId();
if ( !$propertyId->equals( $this->snak->getPropertyId() ) ) {
diff --git a/repo/includes/ChangeOp/ChangeOpQualifier.php
b/repo/includes/ChangeOp/ChangeOpQualifier.php
index 31c663f..587a931 100644
--- a/repo/includes/ChangeOp/ChangeOpQualifier.php
+++ b/repo/includes/ChangeOp/ChangeOpQualifier.php
@@ -81,12 +81,12 @@
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
+ $claim = $claims->getClaimWithGuid( $this->claimGuid );
- if( !$claims->hasClaimWithGuid( $this->claimGuid ) ) {
+ if ( $claim === null ) {
throw new ChangeOpException( "Entity does not have
claim with GUID $this->claimGuid" );
}
- $claim = $claims->getClaimWithGuid( $this->claimGuid );
$qualifiers = $claim->getQualifiers();
if ( $this->snakHash === '' ) {
diff --git a/repo/includes/ChangeOp/ChangeOpQualifierRemove.php
b/repo/includes/ChangeOp/ChangeOpQualifierRemove.php
index e359331..f7d1386 100644
--- a/repo/includes/ChangeOp/ChangeOpQualifierRemove.php
+++ b/repo/includes/ChangeOp/ChangeOpQualifierRemove.php
@@ -61,12 +61,12 @@
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
+ $claim = $claims->getClaimWithGuid( $this->claimGuid );
- if( !$claims->hasClaimWithGuid( $this->claimGuid ) ) {
+ if ( $claim === null ) {
throw new ChangeOpException( "Entity does not have
claim with GUID $this->claimGuid" );
}
- $claim = $claims->getClaimWithGuid( $this->claimGuid );
$qualifiers = $claim->getQualifiers();
$this->removeQualifier( $qualifiers, $summary );
diff --git a/repo/includes/ChangeOp/ChangeOpReference.php
b/repo/includes/ChangeOp/ChangeOpReference.php
index 2830423..b8a0a41 100644
--- a/repo/includes/ChangeOp/ChangeOpReference.php
+++ b/repo/includes/ChangeOp/ChangeOpReference.php
@@ -100,14 +100,13 @@
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
+ $claim = $claims->getClaimWithGuid( $this->claimGuid );
- if( !$claims->hasClaimWithGuid( $this->claimGuid ) ) {
+ if ( $claim === null ) {
throw new ChangeOpException( "Entity does not have
claim with GUID $this->claimGuid" );
}
- $claim = $claims->getClaimWithGuid( $this->claimGuid );
-
- if ( ! ( $claim instanceof Statement ) ) {
+ if ( !( $claim instanceof Statement ) ) {
throw new ChangeOpException( 'The referenced claim is
not a statement and thus cannot have references' );
}
diff --git a/repo/includes/ChangeOp/ChangeOpReferenceRemove.php
b/repo/includes/ChangeOp/ChangeOpReferenceRemove.php
index 7f38ced..812729d 100644
--- a/repo/includes/ChangeOp/ChangeOpReferenceRemove.php
+++ b/repo/includes/ChangeOp/ChangeOpReferenceRemove.php
@@ -62,12 +62,13 @@
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
- if( !$claims->hasClaimWithGuid( $this->claimGuid ) ) {
+ $claim = $claims->getClaimWithGuid( $this->claimGuid );
+
+ if ( $claim === null ) {
throw new ChangeOpException( "Entity does not have
claim with GUID $this->claimGuid" );
}
- $claim = $claims->getClaimWithGuid( $this->claimGuid );
- if ( ! ( $claim instanceof Statement ) ) {
+ if ( !( $claim instanceof Statement ) ) {
throw new ChangeOpException( 'The referenced claim is
not a statement and thus cannot have references' );
}
diff --git a/repo/includes/ChangeOp/ChangeOpStatementRank.php
b/repo/includes/ChangeOp/ChangeOpStatementRank.php
index b180f41..5ee7fd8 100644
--- a/repo/includes/ChangeOp/ChangeOpStatementRank.php
+++ b/repo/includes/ChangeOp/ChangeOpStatementRank.php
@@ -62,14 +62,13 @@
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
+ $claim = $claims->getClaimWithGuid( $this->claimGuid );
- if( !$claims->hasClaimWithGuid( $this->claimGuid ) ) {
+ if ( $claim === null ) {
throw new ChangeOpException( "Entity does not have
claim with GUID $this->claimGuid" );
}
- $claim = $claims->getClaimWithGuid( $this->claimGuid );
-
- if ( ! ( $claim instanceof Statement ) ) {
+ if ( !( $claim instanceof Statement ) ) {
throw new ChangeOpException( 'The referenced claim is
not a statement and thus cannot have a rank' );
}
diff --git a/repo/includes/ClaimSummaryBuilder.php
b/repo/includes/ClaimSummaryBuilder.php
index cd5bfd6..162a801 100644
--- a/repo/includes/ClaimSummaryBuilder.php
+++ b/repo/includes/ClaimSummaryBuilder.php
@@ -58,18 +58,19 @@
* @return Summary
*/
public function buildClaimSummary( Claims $existingClaims, Claim
$newClaim ) {
- $summary = new Summary( $this->apiModuleName );
+ $guid = $newClaim->getGuid();
+ $oldClaim = $existingClaims->getClaimWithGuid( $guid );
+ $summary = new Summary( $this->apiModuleName );
$summary->addAutoCommentArgs( 1 ); // only one claim touched,
so we're always having singular here
$summaryArgs = $this->buildSummaryArgs(
new Claims( array( $newClaim ) ),
- array($newClaim->getGuid())
+ array( $guid )
);
$summary->addAutoSummaryArgs( $summaryArgs );
- if ( $existingClaims->hasClaimWithGuid( $newClaim->getGuid() )
) {
+ if ( $oldClaim !== null ) {
//claim is changed
- $oldClaim = $existingClaims->getClaimWithGuid(
$newClaim->getGuid() );
$claimDifference = $this->claimDiffer->diffClaims(
$oldClaim, $newClaim );
if ( $claimDifference->isAtomic() ) {
@@ -112,9 +113,11 @@
private function buildSummaryArgs( Claims $claims, array $guids ) {
$pairs = array();
- foreach( $guids as $guid ) {
- if ( $claims->hasClaimWithGuid( $guid ) ) {
- $snak = $claims->getClaimWithGuid( $guid
)->getMainSnak();
+ foreach ( $guids as $guid ) {
+ $claim = $claims->getClaimWithGuid( $guid );
+
+ if ( $claim !== null ) {
+ $snak = $claim->getMainSnak();
$key =
$snak->getPropertyId()->getSerialization();
if ( !array_key_exists( $key, $pairs ) ) {
diff --git a/repo/includes/api/ClaimModificationHelper.php
b/repo/includes/api/ClaimModificationHelper.php
index 6ed4c16..fe12cd8 100644
--- a/repo/includes/api/ClaimModificationHelper.php
+++ b/repo/includes/api/ClaimModificationHelper.php
@@ -97,12 +97,13 @@
*/
public function getClaimFromEntity( $claimGuid, Entity $entity ) {
$claims = new Claims( $entity->getClaims() );
+ $claim = $claims->getClaimWithGuid( $claimGuid );
- if ( !$claims->hasClaimWithGuid( $claimGuid ) ) {
+ if ( $claim === null ) {
$this->errorReporter->dieError( 'Could not find the
claim' , 'no-such-claim' );
}
- return $claims->getClaimWithGuid( $claimGuid );
+ return $claim;
}
/**
diff --git a/repo/includes/api/GetClaims.php b/repo/includes/api/GetClaims.php
index c1ff7d1..8a8afa0 100644
--- a/repo/includes/api/GetClaims.php
+++ b/repo/includes/api/GetClaims.php
@@ -100,8 +100,8 @@
$claimsList = new Claims( $entity->getClaims() );
if ( $claimGuid !== null ) {
- return $claimsList->hasClaimWithGuid( $claimGuid ) ?
- array( $claimsList->getClaimWithGuid(
$claimGuid ) ) : array();
+ $claim = $claimsList->getClaimWithGuid( $claimGuid );
+ return $claim !== null ? array( $claim ) : array();
}
$claims = array();
diff --git a/repo/tests/phpunit/includes/api/SetClaimValueTest.php
b/repo/tests/phpunit/includes/api/SetClaimValueTest.php
index 206ca1a..c42daa4 100644
--- a/repo/tests/phpunit/includes/api/SetClaimValueTest.php
+++ b/repo/tests/phpunit/includes/api/SetClaimValueTest.php
@@ -158,11 +158,13 @@
$this->assertEquals( $claimCount, $claims->count(), 'Claim
count should not change after doing a setclaimvalue request' );
- $this->assertTrue( $claims->hasClaimWithGuid( $claimGuid ) );
+ $obtainedClaim = $claims->getClaimWithGuid( $claimGuid );
+
+ $this->assertNotNull( $obtainedClaim );
$dataValue = DataValueFactory::singleton()->newFromArray(
$claim['mainsnak']['datavalue'] );
- $this->assertTrue( $claims->getClaimWithGuid( $claimGuid
)->getMainSnak()->getDataValue()->equals( $dataValue ) );
+ $this->assertTrue(
$obtainedClaim->getMainSnak()->getDataValue()->equals( $dataValue ) );
}
/**
diff --git a/repo/tests/phpunit/includes/api/SetQualifierTest.php
b/repo/tests/phpunit/includes/api/SetQualifierTest.php
index e8e0bdf..12e5e31 100644
--- a/repo/tests/phpunit/includes/api/SetQualifierTest.php
+++ b/repo/tests/phpunit/includes/api/SetQualifierTest.php
@@ -177,10 +177,9 @@
$claims = new Claims( $entity->getClaims() );
- $this->assertTrue( $claims->hasClaimWithGuid( $params['claim']
) );
-
$claim = $claims->getClaimWithGuid( $params['claim'] );
+ $this->assertNotNull( $claim );
$this->assertTrue(
$claim->getQualifiers()->hasSnak( $qualifier ),
'The qualifier should exist in the qualifier list after
making the request'
--
To view, visit https://gerrit.wikimedia.org/r/203801
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I88f7b9b4bd5d85032b0ea44e29f5badeffdc5313
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits