[MediaWiki-commits] [Gerrit] Refactor setclaim to use changeops - change (mediawiki...Wikibase)
Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/88017 Change subject: Refactor setclaim to use changeops .. Refactor setclaim to use changeops This is the final api modules that was not using changeops! Now it does! Change-Id: I80dce3af7fec3e4c922ada87646be581873267f9 --- M repo/includes/ChangeOp/ChangeOpClaim.php M repo/includes/api/ModifyClaim.php M repo/includes/api/SetClaim.php M repo/tests/phpunit/includes/api/SetClaimTest.php 4 files changed, 113 insertions(+), 155 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/17/88017/1 diff --git a/repo/includes/ChangeOp/ChangeOpClaim.php b/repo/includes/ChangeOp/ChangeOpClaim.php index 6f3e540..0f4576e 100644 --- a/repo/includes/ChangeOp/ChangeOpClaim.php +++ b/repo/includes/ChangeOp/ChangeOpClaim.php @@ -4,6 +4,7 @@ use InvalidArgumentException; use Wikibase\Claim; +use Wikibase\Claims; use Wikibase\Entity; use Wikibase\Lib\ClaimGuidGenerator; use Wikibase\Lib\ClaimGuidValidator; @@ -65,8 +66,7 @@ if( $this->claim->getGuid() === null ){ $this->claim->setGuid( $this->guidGenerator->newGuid() ); } - $guid = $this->claim->getGuid(); - $guid = $guidParser->parse( $guid ); + $guid = $guidParser->parse( $this->claim->getGuid() ); if ( $guidValidator->validate( $guid->getSerialization() ) === false ) { throw new ChangeOpException( "Claim does not have a valid GUID" ); @@ -74,8 +74,15 @@ throw new ChangeOpException( "Claim GUID invalid for given entity" ); } - $entity->addClaim( $this->claim ); - $this->updateSummary( $summary, 'add' ); + $claims = new Claims( $entity->getClaims() ); + if( $claims->hasClaimWithGuid( $guid->getSerialization() ) ){ + $claims->removeClaimWithGuid( $guid->getSerialization() ); + $this->updateSummary( $summary, 'update' ); + } else { + $this->updateSummary( $summary, 'create' ); + } + $claims->addClaim( $this->claim ); + $entity->setClaims( $claims ); return true; } diff --git a/repo/includes/api/ModifyClaim.php b/repo/includes/api/ModifyClaim.php index 3b83d6c..851cbc3 100644 --- a/repo/includes/api/ModifyClaim.php +++ b/repo/includes/api/ModifyClaim.php @@ -39,12 +39,19 @@ protected $claimGuidParser; /** +* @since 0.5 +* +* @var SnakValidationHelper +*/ + protected $snakValidation; + + /** * see ApiBase::__construct() */ public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) { parent::__construct( $mainModule, $moduleName, $modulePrefix ); - $snakValidation = new SnakValidationHelper( + $this->snakValidation = new SnakValidationHelper( $this, WikibaseRepo::getDefaultInstance()->getPropertyDataTypeLookup(), WikibaseRepo::getDefaultInstance()->getDataTypeFactory(), @@ -57,7 +64,7 @@ WikibaseRepo::getDefaultInstance()->getSnakConstructionService(), WikibaseRepo::getDefaultInstance()->getEntityIdParser(), WikibaseRepo::getDefaultInstance()->getClaimGuidValidator(), - $snakValidation + $this->snakValidation ); $this->claimGuidParser = WikibaseRepo::getDefaultInstance()->getClaimGuidParser(); diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php index beb29ba..bc13bb8 100644 --- a/repo/includes/api/SetClaim.php +++ b/repo/includes/api/SetClaim.php @@ -2,62 +2,38 @@ namespace Wikibase\Api; +use ApiMain, ApiBase, MWException; use DataValues\IllegalValueException; -use ApiMain; use Diff\Comparer\ComparableComparer; use Diff\OrderedListDiffer; -use MWException; -use ApiBase; +use FormatJson; use Diff\ListDiffer; use ValueFormatters\FormatterOptions; use ValueFormatters\ValueFormatter; +use Wikibase\ChangeOp\ChangeOpClaim; +use Wikibase\ChangeOp\ChangeOpException; +use Wikibase\ClaimDiffer; +use Wikibase\Claims; +use Wikibase\ClaimSummaryBuilder; use Wikibase\EntityContent; use Wikibase\Claim; use Wikibase\EntityContentFactory; -use Wikibase\ClaimDiffer; -use Wikibase\ClaimSaver; -use Wikibase\ClaimSummaryBuilder; +use Wikibase\Lib\ClaimGuidGenerator; +use Wikibase\Lib\Serializers\SerializerFactory; use Wikibase\Lib\SnakFormatter; use Wikibase\Repo\WikibaseRepo; use Wikibase\Summary; -use Wikibase\Validators\ValidatorErrorLocalizer; /** * API module for creating or updat
[MediaWiki-commits] [Gerrit] Refactor setclaim to use changeops - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. Change subject: Refactor setclaim to use changeops .. Refactor setclaim to use changeops This is the final api modules that was not using changeops! Now it does! Change-Id: I80dce3af7fec3e4c922ada87646be581873267f9 --- M repo/includes/ChangeOp/ChangeOpClaim.php M repo/includes/api/ModifyClaim.php M repo/includes/api/SetClaim.php M repo/tests/phpunit/includes/api/SetClaimTest.php 4 files changed, 115 insertions(+), 156 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/includes/ChangeOp/ChangeOpClaim.php b/repo/includes/ChangeOp/ChangeOpClaim.php index 6f3e540..0f4576e 100644 --- a/repo/includes/ChangeOp/ChangeOpClaim.php +++ b/repo/includes/ChangeOp/ChangeOpClaim.php @@ -4,6 +4,7 @@ use InvalidArgumentException; use Wikibase\Claim; +use Wikibase\Claims; use Wikibase\Entity; use Wikibase\Lib\ClaimGuidGenerator; use Wikibase\Lib\ClaimGuidValidator; @@ -65,8 +66,7 @@ if( $this->claim->getGuid() === null ){ $this->claim->setGuid( $this->guidGenerator->newGuid() ); } - $guid = $this->claim->getGuid(); - $guid = $guidParser->parse( $guid ); + $guid = $guidParser->parse( $this->claim->getGuid() ); if ( $guidValidator->validate( $guid->getSerialization() ) === false ) { throw new ChangeOpException( "Claim does not have a valid GUID" ); @@ -74,8 +74,15 @@ throw new ChangeOpException( "Claim GUID invalid for given entity" ); } - $entity->addClaim( $this->claim ); - $this->updateSummary( $summary, 'add' ); + $claims = new Claims( $entity->getClaims() ); + if( $claims->hasClaimWithGuid( $guid->getSerialization() ) ){ + $claims->removeClaimWithGuid( $guid->getSerialization() ); + $this->updateSummary( $summary, 'update' ); + } else { + $this->updateSummary( $summary, 'create' ); + } + $claims->addClaim( $this->claim ); + $entity->setClaims( $claims ); return true; } diff --git a/repo/includes/api/ModifyClaim.php b/repo/includes/api/ModifyClaim.php index 3b83d6c..851cbc3 100644 --- a/repo/includes/api/ModifyClaim.php +++ b/repo/includes/api/ModifyClaim.php @@ -39,12 +39,19 @@ protected $claimGuidParser; /** +* @since 0.5 +* +* @var SnakValidationHelper +*/ + protected $snakValidation; + + /** * see ApiBase::__construct() */ public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) { parent::__construct( $mainModule, $moduleName, $modulePrefix ); - $snakValidation = new SnakValidationHelper( + $this->snakValidation = new SnakValidationHelper( $this, WikibaseRepo::getDefaultInstance()->getPropertyDataTypeLookup(), WikibaseRepo::getDefaultInstance()->getDataTypeFactory(), @@ -57,7 +64,7 @@ WikibaseRepo::getDefaultInstance()->getSnakConstructionService(), WikibaseRepo::getDefaultInstance()->getEntityIdParser(), WikibaseRepo::getDefaultInstance()->getClaimGuidValidator(), - $snakValidation + $this->snakValidation ); $this->claimGuidParser = WikibaseRepo::getDefaultInstance()->getClaimGuidParser(); diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php index beb29ba..d29a737 100644 --- a/repo/includes/api/SetClaim.php +++ b/repo/includes/api/SetClaim.php @@ -2,62 +2,39 @@ namespace Wikibase\Api; -use DataValues\IllegalValueException; use ApiMain; +use ApiBase; +use MWException; +use DataValues\IllegalValueException; use Diff\Comparer\ComparableComparer; use Diff\OrderedListDiffer; -use MWException; -use ApiBase; +use FormatJson; use Diff\ListDiffer; use ValueFormatters\FormatterOptions; -use ValueFormatters\ValueFormatter; +use Wikibase\ChangeOp\ChangeOpClaim; +use Wikibase\ChangeOp\ChangeOpException; +use Wikibase\ClaimDiffer; +use Wikibase\Claims; +use Wikibase\ClaimSummaryBuilder; use Wikibase\EntityContent; use Wikibase\Claim; use Wikibase\EntityContentFactory; -use Wikibase\ClaimDiffer; -use Wikibase\ClaimSaver; -use Wikibase\ClaimSummaryBuilder; +use Wikibase\Lib\ClaimGuidGenerator; +use Wikibase\Lib\Serializers\SerializerFactory; use Wikibase\Lib\SnakFormatter; use Wikibase\Repo\WikibaseRepo; use Wikibase\Summary; -use Wikibase\Validators\ValidatorErrorLocalizer; /** * API module for creating or updating an entire