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

Change subject: Don't load existing workflows for deleted boards, create new 
workflow instead
......................................................................


Don't load existing workflows for deleted boards, create new workflow instead

Instead of loading workflow based on ns/title, it'll load based on
workflow ID associated with the page.
If it fails to find that workflow id, a new workflow will be created.

Bug: T90974
Change-Id: I0bc7f2cb909dab1cc8f6d5fd76a994c47833a109
---
M includes/WorkflowLoaderFactory.php
1 file changed, 19 insertions(+), 29 deletions(-)

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

Objections:
  Matthias Mullie: There's a problem with this change, please improve



diff --git a/includes/WorkflowLoaderFactory.php 
b/includes/WorkflowLoaderFactory.php
index d335f10..1766f92 100644
--- a/includes/WorkflowLoaderFactory.php
+++ b/includes/WorkflowLoaderFactory.php
@@ -2,12 +2,12 @@
 
 namespace Flow;
 
+use Flow\Content\BoardContent;
 use Flow\Model\UUID;
 use Flow\Model\Workflow;
 use Flow\Data\ManagerGroup;
 use Flow\Exception\CrossWikiException;
 use Flow\Exception\InvalidInputException;
-use Flow\Exception\InvalidDataException;
 use Flow\Exception\InvalidTopicUuidException;
 use Flow\Exception\UnknownWorkflowIdException;
 use Title;
@@ -76,13 +76,26 @@
                        throw new CrossWikiException( 'Interwiki to ' . 
$pageTitle->getInterwiki() . ' not implemented ', 'default' );
                }
 
-               if ( $pageTitle->getNamespace() === NS_TOPIC ) {
-                       $workflowId = self::uuidFromTitle( $pageTitle );
+               // @todo: ideally, workflowId is always set and this stuff is 
done in the places that call this
+               if ( $workflowId === null ) {
+                       if ( $pageTitle->getNamespace() === NS_TOPIC ) {
+                               // topic page: workflow UUID is page title
+                               $workflowId = self::uuidFromTitle( $pageTitle );
+                       } else {
+                               // board page: workflow UUID is inside content 
model
+                               $page = \WikiPage::factory( $pageTitle );
+                               $content = $page->getContent();
+                               if ( $content instanceof BoardContent ) {
+                                       $workflowId = $content->getWorkflowId();
+                               }
+                       }
                }
-               if ( $workflowId !== null ) {
-                       $workflow = $this->loadWorkflowById( $pageTitle, 
$workflowId );
+
+               if ( $workflowId === null ) {
+                       // no existing workflow found, create new one
+                       $workflow = Workflow::create( 
$this->defaultWorkflowName, $pageTitle );
                } else {
-                       $workflow = $this->loadWorkflow( $pageTitle );
+                       $workflow = $this->loadWorkflowById( $pageTitle, 
$workflowId );
                }
 
                return new WorkflowLoader(
@@ -90,29 +103,6 @@
                        $this->blockFactory->createBlocks( $workflow ),
                        $this->submissionHandler
                );
-       }
-
-       /**
-        * @param Title $title
-        * @return Workflow
-        * @throws InvalidDataException
-        */
-       protected function loadWorkflow( \Title $title ) {
-               $storage = $this->storage->getStorage( 'Workflow' );
-
-               $found = $storage->find( array(
-                       'workflow_type' => $this->defaultWorkflowName,
-                       'workflow_wiki' => $title->isLocal() ? wfWikiId() : 
$title->getTransWikiID(),
-                       'workflow_namespace' => $title->getNamespace(),
-                       'workflow_title_text' => $title->getDBkey(),
-               ) );
-               if ( $found ) {
-                       $workflow = reset( $found );
-               } else {
-                       $workflow = Workflow::create( 
$this->defaultWorkflowName, $title );
-               }
-
-               return $workflow;
        }
 
        /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0bc7f2cb909dab1cc8f6d5fd76a994c47833a109
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org>
Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org>
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