Bene has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277323
Change subject: Use entity differ to diff against null versions
......................................................................
Use entity differ to diff against null versions
This removes the dependency on EntityFactory from EntityChangeFactory by
simply using the existing methods on EntityDiffer to diff against null
revisions.
Change-Id: If0a7491494cd0fdd716ebe1fa385d721b28c4315
---
M client/includes/WikibaseClient.php
M lib/includes/changes/EntityChangeFactory.php
M lib/tests/phpunit/changes/EntityChangeFactoryTest.php
M lib/tests/phpunit/changes/TestChanges.php
M repo/includes/WikibaseRepo.php
5 files changed, 31 insertions(+), 53 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/23/277323/1
diff --git a/client/includes/WikibaseClient.php
b/client/includes/WikibaseClient.php
index 18e52ab..235bb9d 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -912,7 +912,6 @@
);
return new EntityChangeFactory(
- $this->getEntityFactory(),
new EntityDiffer(),
$changeClasses
);
diff --git a/lib/includes/changes/EntityChangeFactory.php
b/lib/includes/changes/EntityChangeFactory.php
index 4e38da2..8c243c1 100644
--- a/lib/includes/changes/EntityChangeFactory.php
+++ b/lib/includes/changes/EntityChangeFactory.php
@@ -12,7 +12,6 @@
use Wikibase\DataModel\Term\FingerprintProvider;
use Wikibase\DataModel\Term\TermList;
use Wikibase\EntityChange;
-use Wikibase\EntityFactory;
/**
* Factory for EntityChange objects
@@ -25,34 +24,26 @@
class EntityChangeFactory {
/**
- * @var string[] Maps entity type IDs to subclasses of EntityChange.
- */
- private $changeClasses;
-
- /**
- * @var EntityFactory
- */
- private $entityFactory;
-
- /**
* @var EntityDiffer
*/
private $entityDiffer;
/**
- * @param EntityFactory $entityFactory
+ * @var string[] Maps entity type IDs to subclasses of EntityChange.
+ */
+ private $changeClasses;
+
+ /**
* @param EntityDiffer $entityDiffer
* @param string[] $changeClasses Maps entity type IDs to subclasses of
EntityChange.
* Entity types not mapped explicitly are assumed to use EntityChange
itself.
*/
public function __construct(
- EntityFactory $entityFactory,
EntityDiffer $entityDiffer,
array $changeClasses = array()
) {
- $this->changeClasses = $changeClasses;
- $this->entityFactory = $entityFactory;
$this->entityDiffer = $entityDiffer;
+ $this->changeClasses = $changeClasses;
}
/**
@@ -116,38 +107,21 @@
}
if ( $oldEntity === null ) {
- $oldEntity = $this->entityFactory->newEmpty(
$newEntity->getType() );
$id = $newEntity->getId();
+ $this->prepareEntity( $newEntity );
+ $diff = $this->entityDiffer->getConstructionDiff(
$newEntity );
} elseif ( $newEntity === null ) {
- $newEntity = $this->entityFactory->newEmpty(
$oldEntity->getType() );
$id = $oldEntity->getId();
+ $this->prepareEntity( $oldEntity );
+ $diff = $this->entityDiffer->getDestructionDiff(
$oldEntity );
} elseif ( $oldEntity->getType() !== $newEntity->getType() ) {
throw new MWException( 'Entity type mismatch' );
} else {
$id = $newEntity->getId();
+ $this->prepareEntity( $newEntity );
+ $this->prepareEntity( $oldEntity );
+ $diff = $this->entityDiffer->diffEntities( $oldEntity,
$newEntity );
}
-
- // HACK: don't include statements diff, since those are unused
and not helpful
- // performance-wise to the dispatcher and change handling.
- // FIXME: For a better solution, see T113468.
- if ( $oldEntity instanceof StatementListHolder ) {
- $oldEntity->setStatements( new StatementList() );
- $newEntity->setStatements( new StatementList() );
- }
-
- // Also don't include description and alias diffs.
- // FIXME: Implement T113468 and remove this.
- if ( $oldEntity instanceof FingerprintProvider ) {
- $oldFingerprint = $oldEntity->getFingerprint();
- $newFingerprint = $newEntity->getFingerprint();
-
- $oldFingerprint->setDescriptions( new TermList() );
- $oldFingerprint->setAliasGroups( new AliasGroupList() );
- $newFingerprint->setDescriptions( new TermList() );
- $newFingerprint->setAliasGroups( new AliasGroupList() );
- }
-
- $diff = $this->entityDiffer->diffEntities( $oldEntity,
$newEntity );
/** @var EntityChange $instance */
$instance = self::newForEntity( $action, $id, $fields );
@@ -156,4 +130,22 @@
return $instance;
}
+ private function prepareEntity( EntityDocument $entity ) {
+ // HACK: don't include statements diff, since those are unused
and not helpful
+ // performance-wise to the dispatcher and change handling.
+ // FIXME: For a better solution, see T113468.
+ if ( $entity instanceof StatementListHolder ) {
+ $entity->setStatements( new StatementList() );
+ }
+
+ // Also don't include description and alias diffs.
+ // FIXME: Implement T113468 and remove this.
+ if ( $entity instanceof FingerprintProvider ) {
+ $fingerprint = $entity->getFingerprint();
+
+ $fingerprint->setDescriptions( new TermList() );
+ $fingerprint->setAliasGroups( new AliasGroupList() );
+ }
+ }
+
}
diff --git a/lib/tests/phpunit/changes/EntityChangeFactoryTest.php
b/lib/tests/phpunit/changes/EntityChangeFactoryTest.php
index 0b46d18..3275e73 100644
--- a/lib/tests/phpunit/changes/EntityChangeFactoryTest.php
+++ b/lib/tests/phpunit/changes/EntityChangeFactoryTest.php
@@ -38,17 +38,11 @@
* @return EntityChangeFactory
*/
public function getEntityChangeFactory() {
- $entityClasses = array(
- Item::ENTITY_TYPE => 'Wikibase\DataModel\Entity\Item',
- Property::ENTITY_TYPE =>
'Wikibase\DataModel\Entity\Property',
- );
-
$changeClasses = array(
Item::ENTITY_TYPE => 'Wikibase\ItemChange',
);
$factory = new EntityChangeFactory(
- new EntityFactory( $entityClasses ),
new EntityDiffer(),
$changeClasses
);
diff --git a/lib/tests/phpunit/changes/TestChanges.php
b/lib/tests/phpunit/changes/TestChanges.php
index 489ce37..b10291c 100644
--- a/lib/tests/phpunit/changes/TestChanges.php
+++ b/lib/tests/phpunit/changes/TestChanges.php
@@ -59,17 +59,11 @@
* @return EntityChangeFactory
*/
public static function getEntityChangeFactory() {
- $entityClasses = array(
- Item::ENTITY_TYPE => 'Wikibase\DataModel\Entity\Item',
- Property::ENTITY_TYPE =>
'Wikibase\DataModel\Entity\Property',
- );
-
$changeClasses = array(
Item::ENTITY_TYPE => 'Wikibase\ItemChange',
);
$factory = new EntityChangeFactory(
- new EntityFactory( $entityClasses ),
new EntityDiffer(),
$changeClasses
);
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 417296c..70c9c8f 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -516,7 +516,6 @@
);
return new EntityChangeFactory(
- $this->getEntityFactory(),
new EntityDiffer(),
$changeClasses
);
--
To view, visit https://gerrit.wikimedia.org/r/277323
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If0a7491494cd0fdd716ebe1fa385d721b28c4315
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits