Bene has uploaded a new change for review. https://gerrit.wikimedia.org/r/220509
Change subject: Replace Claims with StatementList in ChangeOpQualifier[Remove] ...................................................................... Replace Claims with StatementList in ChangeOpQualifier[Remove] Change-Id: I8d4546e0668324fecb86ff785974a0f403715c55 --- M repo/includes/ChangeOp/ChangeOpQualifier.php M repo/includes/ChangeOp/ChangeOpQualifierRemove.php 2 files changed, 40 insertions(+), 32 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/09/220509/1 diff --git a/repo/includes/ChangeOp/ChangeOpQualifier.php b/repo/includes/ChangeOp/ChangeOpQualifier.php index 8cfa3b8..d28edd1 100644 --- a/repo/includes/ChangeOp/ChangeOpQualifier.php +++ b/repo/includes/ChangeOp/ChangeOpQualifier.php @@ -4,10 +4,10 @@ use InvalidArgumentException; use ValueValidators\Result; -use Wikibase\DataModel\Claim\Claims; use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Snak\Snak; use Wikibase\DataModel\Snak\SnakList; +use Wikibase\DataModel\Statement\StatementListHolder; use Wikibase\Summary; use Wikibase\Validators\SnakValidator; @@ -26,7 +26,7 @@ * * @var string */ - protected $claimGuid; + protected $statementGuid; /** * @since 0.4 @@ -52,23 +52,23 @@ * * @since 0.4 * - * @param string $claimGuid + * @param string $statementGuid * @param Snak $snak * @param string $snakHash * @param SnakValidator $snakValidator * * @throws InvalidArgumentException */ - public function __construct( $claimGuid, Snak $snak, $snakHash, SnakValidator $snakValidator ) { - if ( !is_string( $claimGuid ) || $claimGuid === '' ) { - throw new InvalidArgumentException( '$claimGuid needs to be a string and must not be empty' ); + public function __construct( $statementGuid, Snak $snak, $snakHash, SnakValidator $snakValidator ) { + if ( !is_string( $statementGuid ) || $statementGuid === '' ) { + throw new InvalidArgumentException( '$statementGuid needs to be a string and must not be empty' ); } if ( !is_string( $snakHash ) ) { throw new InvalidArgumentException( '$snakHash needs to be a string' ); } - $this->claimGuid = $claimGuid; + $this->statementGuid = $statementGuid; $this->snak = $snak; $this->snakHash = $snakHash; $this->snakValidator = $snakValidator; @@ -80,14 +80,18 @@ * - the qualifier gets set to $snak when $snakHash and $snak are set */ public function apply( Entity $entity, Summary $summary = null ) { - $claims = new Claims( $entity->getClaims() ); - $claim = $claims->getClaimWithGuid( $this->claimGuid ); - - if ( $claim === null ) { - throw new ChangeOpException( "Entity does not have claim with GUID $this->claimGuid" ); + if ( !( $entity instanceof StatementListHolder ) ) { + throw new InvalidArgumentException( '$entity must be a StatementListHolder' ); } - $qualifiers = $claim->getQualifiers(); + $statements = $entity->getStatements(); + $statement = $statements->getFirstStatementWithGuid( $this->statementGuid ); + + if ( $statement === null ) { + throw new ChangeOpException( "Entity does not have a statement with GUID $this->statementGuid" ); + } + + $qualifiers = $statement->getQualifiers(); if ( $this->snakHash === '' ) { $this->addQualifier( $qualifiers, $summary ); @@ -95,8 +99,8 @@ $this->setQualifier( $qualifiers, $summary ); } - $claim->setQualifiers( $qualifiers ); - $entity->setClaims( $claims ); + $statement->setQualifiers( $qualifiers ); + $entity->setStatements( $statements ); return true; } @@ -111,7 +115,7 @@ */ protected function addQualifier( SnakList $qualifiers, Summary $summary = null ) { if ( $qualifiers->hasSnak( $this->snak ) ) { - throw new ChangeOpException( 'Claim has already a qualifier with hash ' . $this->snak->getHash() ); + throw new ChangeOpException( 'The statement has already a qualifier with hash ' . $this->snak->getHash() ); } $qualifiers->addSnak( $this->snak ); //TODO: add the mainsnak as autocomment-arg & change messages @@ -131,7 +135,7 @@ throw new ChangeOpException( "Qualifier with hash $this->snakHash does not exist" ); } if ( $qualifiers->hasSnak( $this->snak ) ) { - throw new ChangeOpException( 'Claim has already a qualifier with hash ' . $this->snak->getHash() ); + throw new ChangeOpException( 'The statement has already a qualifier with hash ' . $this->snak->getHash() ); } $qualifiers->removeSnakHash( $this->snakHash ); $qualifiers->addSnak( $this->snak ); diff --git a/repo/includes/ChangeOp/ChangeOpQualifierRemove.php b/repo/includes/ChangeOp/ChangeOpQualifierRemove.php index b495312..5d3535c 100644 --- a/repo/includes/ChangeOp/ChangeOpQualifierRemove.php +++ b/repo/includes/ChangeOp/ChangeOpQualifierRemove.php @@ -4,10 +4,10 @@ use InvalidArgumentException; use ValueValidators\Result; -use Wikibase\DataModel\Claim\Claims; use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Snak\Snak; use Wikibase\DataModel\Snak\SnakList; +use Wikibase\DataModel\Statement\StatementListHolder; use Wikibase\Summary; /** @@ -24,7 +24,7 @@ * * @var string */ - protected $claimGuid; + protected $statementGuid; /** * @since 0.5 @@ -38,21 +38,21 @@ * * @since 0.5 * - * @param string $claimGuid + * @param string $statementGuid * @param string $snakHash * * @throws InvalidArgumentException */ - public function __construct( $claimGuid, $snakHash ) { - if ( !is_string( $claimGuid ) || $claimGuid === '' ) { - throw new InvalidArgumentException( '$claimGuid needs to be a string and must not be empty' ); + public function __construct( $statementGuid, $snakHash ) { + if ( !is_string( $statementGuid ) || $statementGuid === '' ) { + throw new InvalidArgumentException( '$statementGuid needs to be a string and must not be empty' ); } if ( !is_string( $snakHash ) || $snakHash === '' ) { throw new InvalidArgumentException( '$snakHash needs to be a string and must not be empty' ); } - $this->claimGuid = $claimGuid; + $this->statementGuid = $statementGuid; $this->snakHash = $snakHash; } @@ -60,19 +60,23 @@ * @see ChangeOp::apply() */ public function apply( Entity $entity, Summary $summary = null ) { - $claims = new Claims( $entity->getClaims() ); - $claim = $claims->getClaimWithGuid( $this->claimGuid ); - - if ( $claim === null ) { - throw new ChangeOpException( "Entity does not have claim with GUID $this->claimGuid" ); + if ( !( $entity instanceof StatementListHolder ) ) { + throw new InvalidArgumentException( '$entity must be a StatementListHolder' ); } - $qualifiers = $claim->getQualifiers(); + $statements = $entity->getStatements(); + $statement = $statements->getFirstStatementWithGuid( $this->statementGuid ); + + if ( $statement === null ) { + throw new ChangeOpException( "Entity does not have a statement with GUID $this->statementGuid" ); + } + + $qualifiers = $statement->getQualifiers(); $this->removeQualifier( $qualifiers, $summary ); - $claim->setQualifiers( $qualifiers ); - $entity->setClaims( $claims ); + $statement->setQualifiers( $qualifiers ); + $entity->setStatements( $statements ); return true; } -- To view, visit https://gerrit.wikimedia.org/r/220509 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8d4546e0668324fecb86ff785974a0f403715c55 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Bene <benestar.wikime...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits