Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/84962
Change subject: Allow editing of claims in property groups ...................................................................... Allow editing of claims in property groups This allows output from getentites to be copied directly into editentity. Editentity now accepts both an array of claims and an array of claims grouped by property id Change-Id: I1c19bf28d2df822f082a7c9625e6f8bfd848950d --- M repo/includes/api/EditEntity.php M repo/tests/phpunit/includes/api/EditEntityTest.php 2 files changed, 46 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/62/84962/1 diff --git a/repo/includes/api/EditEntity.php b/repo/includes/api/EditEntity.php index cb48597..039052f 100644 --- a/repo/includes/api/EditEntity.php +++ b/repo/includes/api/EditEntity.php @@ -382,12 +382,22 @@ if ( !is_array( $claims ) ) { $this->dieUsage( "List of claims must be an array", 'not-recognized-array' ); } + $changeOps = array(); - //todo allow claims to be passed grouped by property rather than just an array of claims - $removeChangeops = $this->getRemoveClaimsChangeOps( $claims, $guidGenerator ); - $modifyChangeOps = $this->getModifyClaimsChangeOps( $claims, $guidGenerator ); + //check if the array is associative or in arrays by property + if( array_keys( $claims ) !== range( 0, count( $claims ) - 1 ) ){ + foreach( $claims as $subClaims ){ + $changeOps = array_merge( $changeOps, + $this->getRemoveClaimsChangeOps( $subClaims, $guidGenerator ), + $this->getModifyClaimsChangeOps( $subClaims, $guidGenerator ) ); + } + } else { + $changeOps = array_merge( $changeOps, + $this->getRemoveClaimsChangeOps( $claims, $guidGenerator ), + $this->getModifyClaimsChangeOps( $claims, $guidGenerator ) ); + } - return array_merge( $removeChangeops, $modifyChangeOps ); + return $changeOps; } /** diff --git a/repo/tests/phpunit/includes/api/EditEntityTest.php b/repo/tests/phpunit/includes/api/EditEntityTest.php index d08e354..54628a4 100644 --- a/repo/tests/phpunit/includes/api/EditEntityTest.php +++ b/repo/tests/phpunit/includes/api/EditEntityTest.php @@ -41,13 +41,20 @@ parent::setup(); $prop56 = PropertyId::newFromNumber( 56 ); + $prop72 = PropertyId::newFromNumber( 72 ); if( !isset( self::$hasSetup ) ){ $this->initTestEntities( array( 'Berlin' ) ); + $prop = PropertyContent::newEmpty(); $prop->getEntity()->setId( $prop56 ); $prop->getEntity()->setDataTypeId( 'string' ); - $prop->save( 'EditEntityTest' ); + $prop->save( 'EditEntityTestP56' ); + + $prop = PropertyContent::newEmpty(); + $prop->getEntity()->setId( $prop72 ); + $prop->getEntity()->setDataTypeId( 'string' ); + $prop->save( 'EditEntityTestP72' ); } self::$hasSetup = true; } @@ -183,6 +190,30 @@ ) ) ) ), + + array( //15 clear and add multiple claims within property groups + 'p' => array( 'clear' => '', + 'data' => '{"claims":{"P56":[{"mainsnak":{"snaktype":"value","property":"P56","datavalue":{"value":"imastring56","type":"string"}},"type":"statement","rank":"normal"}],'. + '"P72":[{"mainsnak":{"snaktype":"value","property":"P72","datavalue":{"value":"imastring72","type":"string"}},"type":"statement","rank":"normal"}]}}' ), + 'e' => array( 'claims' => array( + 'P56' => array( + 'mainsnak' => array( + 'snaktype' => 'value', 'property' => 'P56', + 'datavalue' => array( + 'value' => 'imastring56', + 'type' => 'string' ) ), + 'type' => 'statement', + 'rank' => 'normal' ), + array( + 'mainsnak' => array( + 'snaktype' => 'value', 'property' => 'P72', + 'datavalue' => array( + 'value' => 'imastring72', + 'type' => 'string' ) ), + 'type' => 'statement', + 'rank' => 'normal' ) + ) ) + ), ); } -- To view, visit https://gerrit.wikimedia.org/r/84962 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1c19bf28d2df822f082a7c9625e6f8bfd848950d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits