jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/335161 )

Change subject: Inject SetQualifier dependencies
......................................................................


Inject SetQualifier dependencies

Bug: T156688
Change-Id: Icb9a958b155ef4157606cab1f48f5bfbbda1c0da
---
M repo/Wikibase.php
M repo/includes/Api/SetQualifier.php
2 files changed, 57 insertions(+), 20 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, but someone else must approve
  WMDE-leszek: Looks good to me, but someone else must approve
  Ladsgroup: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index ec6618c..2fe90c5 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -236,7 +236,38 @@
        $wgAPIModules['wbremovereferences'] = 
Wikibase\Repo\Api\RemoveReferences::class;
        $wgAPIModules['wbsetclaim'] = Wikibase\Repo\Api\SetClaim::class;
        $wgAPIModules['wbremovequalifiers'] = 
Wikibase\Repo\Api\RemoveQualifiers::class;
-       $wgAPIModules['wbsetqualifier'] = Wikibase\Repo\Api\SetQualifier::class;
+       $wgAPIModules['wbsetqualifier'] = [
+               'class' => Wikibase\Repo\Api\SetQualifier::class,
+               'factory' => function( ApiMain $mainModule, $moduleName ) {
+                       $wikibaseRepo = 
\Wikibase\Repo\WikibaseRepo::getDefaultInstance();
+                       $apiHelperFactory = $wikibaseRepo->getApiHelperFactory( 
$mainModule->getContext() );
+                       $changeOpFactoryProvider = 
$wikibaseRepo->getChangeOpFactoryProvider();
+
+                       $modificationHelper = new 
\Wikibase\Repo\Api\StatementModificationHelper(
+                               $wikibaseRepo->getSnakFactory(),
+                               $wikibaseRepo->getEntityIdParser(),
+                               $wikibaseRepo->getStatementGuidValidator(),
+                               $apiHelperFactory->getErrorReporter( 
$mainModule )
+                       );
+
+                       return new Wikibase\Repo\Api\SetQualifier(
+                               $mainModule,
+                               $moduleName,
+                               function ( $module ) use ( $apiHelperFactory ) {
+                                       return 
$apiHelperFactory->getErrorReporter( $module );
+                               },
+                               
$changeOpFactoryProvider->getStatementChangeOpFactory(),
+                               $modificationHelper,
+                               $wikibaseRepo->getStatementGuidParser(),
+                               function ( $module ) use ( $apiHelperFactory ) {
+                                       return 
$apiHelperFactory->getResultBuilder( $module );
+                               },
+                               function ( $module ) use ( $apiHelperFactory ) {
+                                       return 
$apiHelperFactory->getEntitySavingHelper( $module );
+                               }
+                       );
+               }
+       ];
        $wgAPIModules['wbmergeitems'] = Wikibase\Repo\Api\MergeItems::class;
        $wgAPIModules['wbformatvalue'] = [
                'class' => Wikibase\Repo\Api\FormatSnakValue::class,
diff --git a/repo/includes/Api/SetQualifier.php 
b/repo/includes/Api/SetQualifier.php
index 975c1d5..d861f6b 100644
--- a/repo/includes/Api/SetQualifier.php
+++ b/repo/includes/Api/SetQualifier.php
@@ -54,28 +54,34 @@
        /**
         * @param ApiMain $mainModule
         * @param string $moduleName
-        * @param string $modulePrefix
+        * @param callable $errorReporterInstantiator
+        * @param StatementChangeOpFactory $statementChangeOpFactory
+        * @param StatementModificationHelper $modificationHelper
+        * @param StatementGuidParser $guidParser
+        * @param callable $resultBuilderInstantiator
+        * @param callable $entitySavingHelperInstantiator
+        *
+        * @note Using callable for several arguments because of circular 
dependency and unability to inject object to constructor
         */
-       public function __construct( ApiMain $mainModule, $moduleName, 
$modulePrefix = '' ) {
-               parent::__construct( $mainModule, $moduleName, $modulePrefix );
+       public function __construct(
+               ApiMain $mainModule,
+               $moduleName,
+               callable $errorReporterInstantiator,
+               StatementChangeOpFactory $statementChangeOpFactory,
+               StatementModificationHelper $modificationHelper,
+               StatementGuidParser $guidParser,
+               callable $resultBuilderInstantiator,
+               callable $entitySavingHelperInstantiator
+       ) {
+               parent::__construct( $mainModule, $moduleName );
 
-               $wikibaseRepo = WikibaseRepo::getDefaultInstance();
-               $apiHelperFactory = $wikibaseRepo->getApiHelperFactory( 
$this->getContext() );
-               $changeOpFactoryProvider = 
$wikibaseRepo->getChangeOpFactoryProvider();
+               $this->errorReporter = $errorReporterInstantiator( $this );
+               $this->statementChangeOpFactory = $statementChangeOpFactory;
 
-               $this->errorReporter = $apiHelperFactory->getErrorReporter( 
$this );
-               $this->statementChangeOpFactory = 
$changeOpFactoryProvider->getStatementChangeOpFactory();
-
-               $this->modificationHelper = new StatementModificationHelper(
-                       $wikibaseRepo->getSnakFactory(),
-                       $wikibaseRepo->getEntityIdParser(),
-                       $wikibaseRepo->getStatementGuidValidator(),
-                       $apiHelperFactory->getErrorReporter( $this )
-               );
-
-               $this->guidParser = $wikibaseRepo->getStatementGuidParser();
-               $this->resultBuilder = $apiHelperFactory->getResultBuilder( 
$this );
-               $this->entitySavingHelper = 
$apiHelperFactory->getEntitySavingHelper( $this );
+               $this->modificationHelper = $modificationHelper;
+               $this->guidParser = $guidParser;
+               $this->resultBuilder = $resultBuilderInstantiator( $this );
+               $this->entitySavingHelper = $entitySavingHelperInstantiator( 
$this );
        }
 
        /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Icb9a958b155ef4157606cab1f48f5bfbbda1c0da
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to