Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/247626
Change subject: Ignore site link uniqueness conflicts of from-item during merge
[WIP]
......................................................................
Ignore site link uniqueness conflicts of from-item during merge [WIP]
needs tests and perhaps polish the code some...
Bug: T115892
Change-Id: I4cb518f54f6dd045f81e6e79390e320a0cd8895d
---
M repo/includes/WikibaseRepo.php
M repo/includes/api/MergeItems.php
M repo/includes/specials/SpecialMergeItems.php
M repo/includes/store/sql/SqlSiteLinkConflictLookup.php
4 files changed, 97 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/26/247626/1
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index d0bcbb4..889aab6 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -68,6 +68,7 @@
use Wikibase\Repo\Content\ItemHandler;
use Wikibase\Repo\Content\PropertyHandler;
use Wikibase\Repo\Hooks\EditFilterHookRunner;
+use Wikibase\Repo\Interactors\ItemMergeInteractor;
use Wikibase\Repo\Interactors\RedirectCreationInteractor;
use Wikibase\Repo\LinkedData\EntityDataFormatProvider;
use Wikibase\Repo\Localizer\ChangeOpValidationExceptionLocalizer;
@@ -82,6 +83,7 @@
use Wikibase\Repo\Notifications\DatabaseChangeTransmitter;
use Wikibase\Repo\Notifications\HookChangeTransmitter;
use Wikibase\Repo\Store\EntityPermissionChecker;
+use Wikibase\Repo\Store\SiteLinkConflictLookup;
use Wikibase\Repo\Validators\EntityConstraintProvider;
use Wikibase\Repo\Validators\SnakValidator;
use Wikibase\Repo\Validators\TermValidatorFactory;
@@ -199,6 +201,11 @@
private $monolingualTextLanguages = null;
/**
+ * @var SiteLinkConflictLookup|null
+ */
+ private $siteLinkConflictLookup = null;
+
+ /**
* @var DataTypeDefinitions
*/
private $dataTypeDefinitions;
@@ -207,6 +214,7 @@
* @var Language
*/
private $defaultLanguage;
+
/**
* Returns the default instance constructed using newInstance().
@@ -948,7 +956,7 @@
public function getEntityConstraintProvider() {
return new EntityConstraintProvider(
$this->getLabelDescriptionDuplicateDetector(),
- $this->getStore()->getSiteLinkConflictLookup()
+ $this->getSiteLinkConflictLookup()
);
}
@@ -1387,4 +1395,30 @@
return new WikibaseHtmlSnakFormatterFactory(
$this->getSnakFormatterFactory() );
}
+ private function getSiteLinkConflictLookup() {
+ if ( $this->siteLinkConflictLookup === null ) {
+ $this->siteLinkConflictLookup =
$this->store->getSiteLinkConflictLookup();
+ }
+
+ return $this->siteLinkConflictLookup;
+ }
+
+ /**
+ * @return ItemMergeInteractor
+ */
+ public function newItemMergeInteractor( User $user, IContextSource
$context ) {
+ $entityStore = $this->getEntityStore();
+ $entityStore->registerWatcher(
$this->getSiteLinkConflictLookup() );
+
+ return new ItemMergeInteractor(
+
$this->getChangeOpFactoryProvider()->getMergeChangeOpFactory(),
+ $this->getEntityRevisionLookup( 'uncached' ),
+ $entityStore,
+ $this->getEntityPermissionChecker(),
+ $this->getSummaryFormatter(),
+ $user,
+ $this->newRedirectCreationInteractor( $user, $context )
+ );
+ }
+
}
diff --git a/repo/includes/api/MergeItems.php b/repo/includes/api/MergeItems.php
index 677fd66..6ca1a22 100644
--- a/repo/includes/api/MergeItems.php
+++ b/repo/includes/api/MergeItems.php
@@ -65,14 +65,9 @@
$wikibaseRepo->getEntityIdParser(),
$apiHelperFactory->getErrorReporter( $this ),
$apiHelperFactory->getResultBuilder( $this ),
- new ItemMergeInteractor(
-
$wikibaseRepo->getChangeOpFactoryProvider()->getMergeChangeOpFactory(),
- $wikibaseRepo->getEntityRevisionLookup(
'uncached' ),
- $wikibaseRepo->getEntityStore(),
- $wikibaseRepo->getEntityPermissionChecker(),
- $wikibaseRepo->getSummaryFormatter(),
+ $wikibaseRepo->newItemMergeInteractor(
$this->getUser(),
- $wikibaseRepo->newRedirectCreationInteractor(
$this->getUser(), $this->getContext() )
+ $this->getContext()
)
);
}
diff --git a/repo/includes/specials/SpecialMergeItems.php
b/repo/includes/specials/SpecialMergeItems.php
index 47ec779..5d228fd 100644
--- a/repo/includes/specials/SpecialMergeItems.php
+++ b/repo/includes/specials/SpecialMergeItems.php
@@ -59,14 +59,9 @@
new TokenCheckInteractor(
$this->getUser()
),
- new ItemMergeInteractor(
-
$wikibaseRepo->getChangeOpFactoryProvider()->getMergeChangeOpFactory(),
- $wikibaseRepo->getEntityRevisionLookup(
'uncached' ),
- $wikibaseRepo->getEntityStore(),
- $wikibaseRepo->getEntityPermissionChecker(),
- $wikibaseRepo->getSummaryFormatter(),
+ $wikibaseRepo->newItemMergeInteractor(
$this->getUser(),
- $wikibaseRepo->newRedirectCreationInteractor(
$this->getUser(), $this->getContext() )
+ $this->getContext()
)
);
}
diff --git a/repo/includes/store/sql/SqlSiteLinkConflictLookup.php
b/repo/includes/store/sql/SqlSiteLinkConflictLookup.php
index ee830cd..0c3bc94 100644
--- a/repo/includes/store/sql/SqlSiteLinkConflictLookup.php
+++ b/repo/includes/store/sql/SqlSiteLinkConflictLookup.php
@@ -4,8 +4,13 @@
use DatabaseBase;
use DBAccessBase;
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\EntityRedirect;
use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\SiteLink;
+use Wikibase\EntityRevision;
+use Wikibase\Lib\Store\EntityStoreWatcher;
use Wikibase\Repo\Store\SiteLinkConflictLookup;
/**
@@ -19,7 +24,13 @@
* @author Daniel Kinzler
* @author Katie Filbert < [email protected] >
*/
-class SqlSiteLinkConflictLookup extends DBAccessBase implements
SiteLinkConflictLookup {
+class SqlSiteLinkConflictLookup extends DBAccessBase implements
SiteLinkConflictLookup,
+ EntityStoreWatcher {
+
+ /**
+ * @var ItemId[]
+ */
+ private $itemConflictsToIgnore = array();
/**
* @see SiteLinkConflictLookup::getConflictsForItem
@@ -75,11 +86,15 @@
$conflicts = array();
foreach ( $conflictingLinks as $link ) {
- $conflicts[] = array(
- 'siteId' => $link->ips_site_id,
- 'itemId' => (int)$link->ips_item_id,
- 'sitePage' => $link->ips_site_page,
- );
+ $numericId = (int)$link->ips_item_id;
+
+ if ( !array_key_exists( $numericId,
$this->itemConflictsToIgnore ) ) {
+ $conflicts[] = array(
+ 'siteId' => $link->ips_site_id,
+ 'itemId' => $numericId,
+ 'sitePage' => $link->ips_site_page,
+ );
+ }
}
if ( !$db ) {
@@ -89,4 +104,41 @@
return $conflicts;
}
+ /**
+ * @see EntityStoreWatcher::entityDeleted
+ *
+ * @param EntityId $entityId
+ */
+ public function entityDeleted( EntityId $entityId ) {
+ // no-op
+ }
+
+ /**
+ * @see EntityStoreWatcher::entityDeleted
+ *
+ * @param EntityRevision $entityRevision
+ */
+ public function entityUpdated( EntityRevision $entityRevision ) {
+ $entity = $entityRevision->getEntity();
+
+ if ( $entity instanceof Item ) {
+ $itemId = $entity->getId();
+
+ if ( $itemId instanceof ItemId ) {
+ $numericId = $itemId->getNumericId();
+ $this->itemConflictsToIgnore[$numericId] =
$itemId;
+ }
+ }
+ }
+
+ /**
+ * @see EntityStoreWatcher::redirectUpdated
+ *
+ * @param EntityRedirect $entityRedirect
+ * @param int $revisionId
+ */
+ public function redirectUpdated( EntityRedirect $entityRedirect,
$revisionId ) {
+ // no-op
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/247626
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4cb518f54f6dd045f81e6e79390e320a0cd8895d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits