Daniel Kinzler has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/392679 )
Change subject: Remove the need for EntityDocument::isEmpty.
......................................................................
Remove the need for EntityDocument::isEmpty.
We'll keep isEmpty in Item and Property for now.
Change-Id: I4086017352e2fee7f1841c5e4ded5a2c8ffae285
---
M repo/includes/Content/EntityContent.php
M repo/includes/Content/ItemContent.php
M repo/includes/Content/PropertyContent.php
M repo/includes/Interactors/ItemMergeInteractor.php
M repo/includes/Interactors/RedirectCreationInteractor.php
5 files changed, 45 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/79/392679/1
diff --git a/repo/includes/Content/EntityContent.php
b/repo/includes/Content/EntityContent.php
index 230a062..ce57e4f 100644
--- a/repo/includes/Content/EntityContent.php
+++ b/repo/includes/Content/EntityContent.php
@@ -583,7 +583,7 @@
$redirAfterPatch = $this->getPatchedRedirect(
$patch->getRedirectDiff() );
- if ( $redirAfterPatch !== null && !$entityAfterPatch->isEmpty()
) {
+ if ( $redirAfterPatch !== null && !$this->isEntityEmpty(
$entityAfterPatch ) ) {
throw new PatcherException( 'EntityContent must not
contain Entity data as well as'
. ' a redirect after applying the patch!' );
} elseif ( $redirAfterPatch ) {
@@ -636,7 +636,7 @@
}
$holder = $this->getEntityHolder();
- return $holder === null || $holder->getEntity()->isEmpty();
+ return $holder === null || $this->isEntityEmpty(
$holder->getEntity() );
}
/**
@@ -740,4 +740,16 @@
return [];
}
+ /**
+ * Determines whether the Entity is empty. This implementations always
returns false.
+ * Subclasses should override this with the appropriate logic.
+ *
+ * @param EntityDocument $entity
+ * @return bool
+ */
+ protected function isEntityEmpty( EntityDocument $entity ) {
+ // XXX: this could perhaps live in EntityHandler and subclasses
instead!
+ return false;
+ }
+
}
diff --git a/repo/includes/Content/ItemContent.php
b/repo/includes/Content/ItemContent.php
index baf8af2..d385cd0 100644
--- a/repo/includes/Content/ItemContent.php
+++ b/repo/includes/Content/ItemContent.php
@@ -9,6 +9,7 @@
use Title;
use Wikibase\Content\EntityHolder;
use Wikibase\Content\EntityInstanceHolder;
+use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\EntityRedirect;
use Wikibase\DataModel\Entity\Item;
use Wikibase\Repo\ItemSearchTextGenerator;
@@ -227,4 +228,9 @@
return $properties;
}
+ protected function isEntityEmpty( EntityDocument $entity ) {
+ /** @var Item $entity */
+ return $entity->isEmpty();
+ }
+
}
diff --git a/repo/includes/Content/PropertyContent.php
b/repo/includes/Content/PropertyContent.php
index 6732997..da6efda 100644
--- a/repo/includes/Content/PropertyContent.php
+++ b/repo/includes/Content/PropertyContent.php
@@ -6,6 +6,7 @@
use LogicException;
use Wikibase\Content\EntityHolder;
use Wikibase\Content\EntityInstanceHolder;
+use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\Property;
/**
@@ -135,4 +136,9 @@
return !$this->isRedirect() && $this->getProperty()->isEmpty();
}
+ protected function isEntityEmpty( EntityDocument $entity ) {
+ /** @var Property $entity */
+ return $entity->isEmpty();
+ }
+
}
diff --git a/repo/includes/Interactors/ItemMergeInteractor.php
b/repo/includes/Interactors/ItemMergeInteractor.php
index 686943c..e1187ce 100644
--- a/repo/includes/Interactors/ItemMergeInteractor.php
+++ b/repo/includes/Interactors/ItemMergeInteractor.php
@@ -14,6 +14,7 @@
use Wikibase\EntityContent;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Lib\Store\EntityStore;
+use Wikibase\Repo\Content\EntityContentFactory;
use Wikibase\Repo\Store\EntityTitleStoreLookup;
use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
use Wikibase\Lib\Store\StorageException;
@@ -70,6 +71,11 @@
*/
private $entityTitleLookup;
+ /**
+ * @var EntityContentFactory
+ */
+ private $entityContentFactory;
+
public function __construct(
MergeChangeOpsFactory $changeOpFactory,
EntityRevisionLookup $entityRevisionLookup,
@@ -88,6 +94,7 @@
$this->user = $user;
$this->interactorRedirect = $interactorRedirect;
$this->entityTitleLookup = $entityTitleLookup;
+ $this->entityContentFactory = ...;
}
/**
@@ -181,7 +188,9 @@
* @return bool
*/
private function isEmpty( ItemId $itemId ) {
- return $this->loadEntity( $itemId )->isEmpty();
+ $entity = $this->loadEntity( $itemId )->isEmpty();
+ $content = $this->entityContentFactory->newFromEntity( $entity
);
+ return $content->isEmpty();
}
/**
diff --git a/repo/includes/Interactors/RedirectCreationInteractor.php
b/repo/includes/Interactors/RedirectCreationInteractor.php
index 73170e2..c81dee3 100644
--- a/repo/includes/Interactors/RedirectCreationInteractor.php
+++ b/repo/includes/Interactors/RedirectCreationInteractor.php
@@ -9,6 +9,7 @@
use Wikibase\DataModel\Services\Lookup\EntityRedirectLookupException;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Lib\Store\EntityStore;
+use Wikibase\Repo\Content\EntityContentFactory;
use Wikibase\Repo\Store\EntityTitleStoreLookup;
use Wikibase\Lib\Store\StorageException;
use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
@@ -67,6 +68,11 @@
*/
private $entityRedirectLookup;
+ /**
+ * @var EntityContentFactory
+ */
+ private $entityContentFactory;
+
public function __construct(
EntityRevisionLookup $entityRevisionLookup,
EntityStore $entityStore,
@@ -85,6 +91,7 @@
$this->editFilterHookRunner = $editFilterHookRunner;
$this->entityRedirectLookup = $entityRedirectLookup;
$this->entityTitleLookup = $entityTitleLookup;
+ $this->entityContentFactory = ...;
}
/**
@@ -161,7 +168,8 @@
}
} else {
$entity = $revision->getEntity();
- if ( !$entity->isEmpty() ) {
+ $content =
$this->entityContentFactory->newFromEntity( $entity );
+ if ( !$content->isEmpty() ) {
throw new RedirectCreationException(
"Can't create redirect on non
empty item $entityId",
'origin-not-empty'
--
To view, visit https://gerrit.wikimedia.org/r/392679
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4086017352e2fee7f1841c5e4ded5a2c8ffae285
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits