[MediaWiki-commits] [Gerrit] Check for non-existing EntityRevision in MergeItems api module - change (mediawiki...Wikibase)

2014-05-22 Thread Aude (Code Review)
Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/134874

Change subject: Check for non-existing EntityRevision in MergeItems api module
..

Check for non-existing EntityRevision in MergeItems api module

Bug: 65646
Change-Id: I4583a495ab9c62f42714afe173fa261f19fae93b
---
M repo/includes/api/MergeItems.php
M repo/tests/phpunit/includes/api/MergeItemsTest.php
2 files changed, 15 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/74/134874/1

diff --git a/repo/includes/api/MergeItems.php b/repo/includes/api/MergeItems.php
index a7eb427..2714d34 100644
--- a/repo/includes/api/MergeItems.php
+++ b/repo/includes/api/MergeItems.php
@@ -70,6 +70,10 @@
$fromEntityRevision = $this->getEntityRevisionFromIdString( 
$params['fromid'] );
$toEntityRevision = $this->getEntityRevisionFromIdString( 
$params['toid'] );
 
+   if ( !$fromEntityRevision || !$toEntityRevision ) {
+   $this->dieUsage( 'Item not found.', 'no-such-entity' );
+   }
+
$fromEntity = $fromEntityRevision->getEntity();
$toEntity = $toEntityRevision->getEntity();
 
diff --git a/repo/tests/phpunit/includes/api/MergeItemsTest.php 
b/repo/tests/phpunit/includes/api/MergeItemsTest.php
index 9794466..9a47c9f 100644
--- a/repo/tests/phpunit/includes/api/MergeItemsTest.php
+++ b/repo/tests/phpunit/includes/api/MergeItemsTest.php
@@ -369,6 +369,17 @@
$this->doTestQueryExceptions( $params, $expected['exception'] );
}
 
+   public function testMergeNonExistingItem() {
+   $params = array(
+   'action' => 'wbmergeitems',
+   'fromid' => 'Q60457977',
+   'toid' => 'Q60457978'
+   );
+
+   $expectedException = array( 'type' => 'UsageException', 'code' 
=> 'no-such-entity' );
+   $this->doTestQueryExceptions( $params, $expectedException );
+   }
+
/**
 * Applies self::$idMap to all data in the given data structure, 
recursively.
 *

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4583a495ab9c62f42714afe173fa261f19fae93b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Check for non-existing EntityRevision in MergeItems api module - change (mediawiki...Wikibase)

2014-05-23 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Check for non-existing EntityRevision in MergeItems api module
..


Check for non-existing EntityRevision in MergeItems api module

Bug: 65646
Change-Id: I4583a495ab9c62f42714afe173fa261f19fae93b
---
M repo/includes/api/MergeItems.php
M repo/tests/phpunit/includes/api/MergeItemsTest.php
2 files changed, 17 insertions(+), 6 deletions(-)

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



diff --git a/repo/includes/api/MergeItems.php b/repo/includes/api/MergeItems.php
index a7eb427..7cb3f74 100644
--- a/repo/includes/api/MergeItems.php
+++ b/repo/includes/api/MergeItems.php
@@ -70,6 +70,10 @@
$fromEntityRevision = $this->getEntityRevisionFromIdString( 
$params['fromid'] );
$toEntityRevision = $this->getEntityRevisionFromIdString( 
$params['toid'] );
 
+   if ( !$fromEntityRevision || !$toEntityRevision ) {
+   $this->dieError( 'Item not found for ID.', 
'no-such-entity' );
+   }
+
$fromEntity = $fromEntityRevision->getEntity();
$toEntity = $toEntityRevision->getEntity();
 
@@ -131,14 +135,10 @@
}
 
/**
-* @param Entity|null $fromEntity
-* @param Entity|null $toEntity
+* @param Entity $fromEntity
+* @param Entity $toEntity
 */
private function validateEntity( $fromEntity, $toEntity) {
-   if( $fromEntity === null || $toEntity === null ){
-   $this->dieUsage( 'One of more of the ids provided do 
not exist' , 'no-such-entity-id' );
-   }
-
if ( !( $fromEntity instanceof Item && $toEntity instanceof 
Item ) ) {
$this->dieUsage( 'One or more of the entities are not 
items', 'not-item' );
}
diff --git a/repo/tests/phpunit/includes/api/MergeItemsTest.php 
b/repo/tests/phpunit/includes/api/MergeItemsTest.php
index 9794466..9a47c9f 100644
--- a/repo/tests/phpunit/includes/api/MergeItemsTest.php
+++ b/repo/tests/phpunit/includes/api/MergeItemsTest.php
@@ -369,6 +369,17 @@
$this->doTestQueryExceptions( $params, $expected['exception'] );
}
 
+   public function testMergeNonExistingItem() {
+   $params = array(
+   'action' => 'wbmergeitems',
+   'fromid' => 'Q60457977',
+   'toid' => 'Q60457978'
+   );
+
+   $expectedException = array( 'type' => 'UsageException', 'code' 
=> 'no-such-entity' );
+   $this->doTestQueryExceptions( $params, $expectedException );
+   }
+
/**
 * Applies self::$idMap to all data in the given data structure, 
recursively.
 *

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4583a495ab9c62f42714afe173fa261f19fae93b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude 
Gerrit-Reviewer: Addshore 
Gerrit-Reviewer: Aude 
Gerrit-Reviewer: Daniel Kinzler 
Gerrit-Reviewer: Hoo man 
Gerrit-Reviewer: Thiemo Mättig (WMDE) 
Gerrit-Reviewer: WikidataJenkins 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits