jenkins-bot has submitted this change and it was merged.

Change subject: Fix ConvertLqtPageOnLocalWiki for recent core (API) and Flow 
changes
......................................................................


Fix ConvertLqtPageOnLocalWiki for recent core (API) and Flow changes

Bug: T96325
Change-Id: I6c9056f03ae8e2770e19e5b2876a0f6c50fd8b81
(cherry picked from commit 2d92aae7437cc769563bedd033d993734201fea0)
---
M container.php
M includes/Import/Importer.php
M includes/Import/LiquidThreadsApi/Objects.php
M includes/Import/LiquidThreadsApi/Source.php
M maintenance/convertToText.php
M tests/phpunit/Import/TalkpageImportOperationTest.php
6 files changed, 38 insertions(+), 44 deletions(-)

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



diff --git a/container.php b/container.php
index 5077e4e..8e97dcb 100644
--- a/container.php
+++ b/container.php
@@ -1195,7 +1195,8 @@
                $c['factory.loader.workflow'],
                $c['memcache.buffered'],
                $c['db.factory'],
-               $c['deferred_queue']
+               $c['deferred_queue'],
+               $c['occupation_controller']
        );
 
        $importer->addPostprocessor( new 
Flow\Import\Postprocessor\SpecialLogTopic(
diff --git a/includes/Import/Importer.php b/includes/Import/Importer.php
index 20fa46f..740eeb4 100644
--- a/includes/Import/Importer.php
+++ b/includes/Import/Importer.php
@@ -2,6 +2,7 @@
 
 namespace Flow\Import;
 
+use Article;
 use DeferredUpdates;
 use Flow\Data\BufferedCache;
 use Flow\Data\ManagerGroup;
@@ -15,6 +16,7 @@
 use Flow\Model\TopicListEntry;
 use Flow\Model\UUID;
 use Flow\Model\Workflow;
+use Flow\OccupationController;
 use Flow\WorkflowLoaderFactory;
 use IP;
 use MWCryptRand;
@@ -48,13 +50,16 @@
        protected $postprocessors;
        /** @var SplQueue Callbacks for DeferredUpdate that are queue'd up by 
the commit process */
        protected $deferredQueue;
+       /** @var OccupationController */
+       protected $occupationController;
 
        public function __construct(
                ManagerGroup $storage,
                WorkflowLoaderFactory $workflowLoaderFactory,
                BufferedCache $cache,
                DbFactory $dbFactory,
-               SplQueue $deferredQueue
+               SplQueue $deferredQueue,
+               OccupationController $occupationController
        ) {
                $this->storage = $storage;
                $this->workflowLoaderFactory = $workflowLoaderFactory;
@@ -62,6 +67,7 @@
                $this->dbFactory = $dbFactory;
                $this->postprocessors = new ProcessorGroup;
                $this->deferredQueue = $deferredQueue;
+               $this->occupationController = $occupationController;
        }
 
        public function addPostprocessor( Postprocessor $proc ) {
@@ -103,8 +109,8 @@
         * @return bool True When the import completes with no failures
         */
        public function import( IImportSource $source, Title $targetPage, 
ImportSourceStore $sourceStore ) {
-               $operation = new TalkpageImportOperation( $source );
-               return $operation->import( new PageImportState(
+               $operation = new TalkpageImportOperation( $source, 
$this->occupationController );
+               $pageImportState = new PageImportState(
                        $this->workflowLoaderFactory
                                ->createWorkflowLoader( $targetPage )
                                ->getWorkflow(),
@@ -116,7 +122,8 @@
                        $this->postprocessors,
                        $this->deferredQueue,
                        $this->allowUnknownUsernames
-               ) );
+               );
+               return $operation->import( $pageImportState );
        }
 }
 
@@ -495,11 +502,15 @@
         */
        protected $importSource;
 
+       /** @var OccupationController */
+       protected $occupationController;
+
        /**
         * @param IImportSource $source
         */
-       public function __construct( IImportSource $source ) {
+       public function __construct( IImportSource $source, 
OccupationController $occupationController ) {
                $this->importSource = $source;
+               $this->occupationController = $occupationController;
        }
 
        /**
@@ -509,8 +520,17 @@
         * @throws \Exception
         */
        public function import( PageImportState $state ) {
-               $state->logger->info( 'Importing to ' . 
$state->boardWorkflow->getArticleTitle()->getPrefixedText() );
+               $destinationTitle = $state->boardWorkflow->getArticleTitle();
+               $state->logger->info( 'Importing to ' . 
$destinationTitle->getPrefixedText() );
                if ( $state->boardWorkflow->isNew() ) {
+                       $this->occupationController->allowCreation(
+                               $destinationTitle,
+                               
$this->occupationController->getTalkpageManager()
+                       );
+                       $this->occupationController->ensureFlowRevision(
+                               new Article( $destinationTitle ),
+                               $state->boardWorkflow
+                       );
                        $state->put( $state->boardWorkflow, array() );
                }
 
diff --git a/includes/Import/LiquidThreadsApi/Objects.php 
b/includes/Import/LiquidThreadsApi/Objects.php
index e3329c4..351e4ce 100644
--- a/includes/Import/LiquidThreadsApi/Objects.php
+++ b/includes/Import/LiquidThreadsApi/Objects.php
@@ -96,13 +96,9 @@
        public function getText() {
                $pageData = $this->importSource->getPageData( 
$this->apiResponse['rootid'] );
                $revision = $pageData['revisions'][0];
-               if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                       $contentKey = isset( $revision[ApiResult::META_CONTENT] 
)
-                               ? $revision[ApiResult::META_CONTENT]
-                               : '*';
-               } else {
-                       $contentKey = '*';
-               }
+               $contentKey = isset( $revision[ApiResult::META_CONTENT] )
+                       ? $revision[ApiResult::META_CONTENT]
+                       : '*';
 
                return $revision[$contentKey];
        }
@@ -264,18 +260,7 @@
         * @return string
         */
        public function getText() {
-               if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                       $contentKey = isset( 
$this->apiResponse[ApiResult::META_CONTENT] )
-                               ? $this->apiResponse[ApiResult::META_CONTENT]
-                               : '*';
-               } else {
-                       $contentKey = '*';
-               }
-
-               if ( !isset( $this->apiResponse[$contentKey] ) ) {
-                       $encoded = json_encode( $this->apiResponse );
-                       throw new ImportException( "Specified content key 
($contentKey) not available: $encoded" );
-               }
+               $contentKey = 'content';
 
                $content = $this->apiResponse[$contentKey];
 
diff --git a/includes/Import/LiquidThreadsApi/Source.php 
b/includes/Import/LiquidThreadsApi/Source.php
index 8be1cf6..0e7c344 100644
--- a/includes/Import/LiquidThreadsApi/Source.php
+++ b/includes/Import/LiquidThreadsApi/Source.php
@@ -428,11 +428,7 @@
 
                        $api = new ApiMain( $context );
                        $api->execute();
-                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                               return $api->getResult()->getResultData( null, 
array( 'Strip' => 'all' ) );
-                       } else {
-                               return $api->getResult()->getData();
-                       }
+                       return $api->getResult()->getResultData( null, array( 
'Strip' => 'all' ) );
                } catch ( UsageException $exception ) {
                        // Mimic the behaviour when called remotely
                        return array( 'error' => $exception->getMessageArray() 
);
diff --git a/maintenance/convertToText.php b/maintenance/convertToText.php
index 9021370..5a5b223 100644
--- a/maintenance/convertToText.php
+++ b/maintenance/convertToText.php
@@ -90,19 +90,11 @@
                $api = new ApiMain( $request );
                $api->execute();
 
-               if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                       $flowData = $api->getResult()->getResultData( array( 
'flow', $submodule, 'result' ) );
-                       if ( $flowData === null ) {
-                               throw new MWException( "API response has no 
Flow data" );
-                       }
-                       $flowData = ApiResult::stripMetadata( $flowData );
-               } else {
-                       $apiResponse = $api->getResult()->getData();
-                       if ( ! isset( $apiResponse['flow'] ) ) {
-                               throw new MWException( "API response has no 
Flow data" );
-                       }
-                       $flowData = $apiResponse['flow'][$submodule]['result'];
+               $flowData = $api->getResult()->getResultData( array( 'flow', 
$submodule, 'result' ) );
+               if ( $flowData === null ) {
+                       throw new MWException( "API response has no Flow data" 
);
                }
+               $flowData = ApiResult::stripMetadata( $flowData );
 
                if( $requiredBlock !== false && ! isset( 
$flowData[$requiredBlock] ) ) {
                        throw new MWException( "No $requiredBlock block in API 
response" );
diff --git a/tests/phpunit/Import/TalkpageImportOperationTest.php 
b/tests/phpunit/Import/TalkpageImportOperationTest.php
index beffdbd..86a2fdb 100644
--- a/tests/phpunit/Import/TalkpageImportOperationTest.php
+++ b/tests/phpunit/Import/TalkpageImportOperationTest.php
@@ -95,7 +95,7 @@
                        )
                );
 
-               $op = new TalkpageImportOperation( $source );
+               $op = new TalkpageImportOperation( $source, Container::get( 
'occupation_controller' ) );
                $store = new NullImportSourceStore;
                $op->import( new PageImportState(
                        $workflow,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6c9056f03ae8e2770e19e5b2876a0f6c50fd8b81
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: wmf/1.26wmf3
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to