EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/204677

Change subject: Use the Workflow mapper in UrlGenerator
......................................................................

Use the Workflow mapper in UrlGenerator

The UrlGenerator + Listener were building up a list of workflows
that are currently loaded, but that information is already stored
in the Workflow mapper.  Just use that instead.

Change-Id: If4877a985cf77b5588cbb12ad70b38846db6a37b
---
M autoload.php
M container.php
D includes/Data/Listener/UrlGenerationListener.php
M includes/UrlGenerator.php
4 files changed, 9 insertions(+), 57 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/77/204677/1

diff --git a/autoload.php b/autoload.php
index 0fccd6b..40e1bae 100644
--- a/autoload.php
+++ b/autoload.php
@@ -75,7 +75,6 @@
        'Flow\\Data\\Listener\\OccupationListener' => __DIR__ . 
'/includes/Data/Listener/OccupationListener.php',
        'Flow\\Data\\Listener\\RecentChangesListener' => __DIR__ . 
'/includes/Data/Listener/RecentChangesListener.php',
        'Flow\\Data\\Listener\\ReferenceRecorder' => __DIR__ . 
'/includes/Data/Listener/ReferenceRecorder.php',
-       'Flow\\Data\\Listener\\UrlGenerationListener' => __DIR__ . 
'/includes/Data/Listener/UrlGenerationListener.php',
        'Flow\\Data\\Listener\\UserNameListener' => __DIR__ . 
'/includes/Data/Listener/UserNameListener.php',
        'Flow\\Data\\Listener\\WorkflowTopicListListener' => __DIR__ . 
'/includes/Data/Listener/WorkflowTopicListListener.php',
        'Flow\\Data\\ManagerGroup' => __DIR__ . 
'/includes/Data/ManagerGroup.php',
diff --git a/container.php b/container.php
index fc101ae..b008320 100644
--- a/container.php
+++ b/container.php
@@ -43,13 +43,8 @@
 };
 
 $c['url_generator'] = function( $c ) {
-       return new Flow\UrlGenerator();
-};
-// listener is attached to storage.workflow, it
-// notifies the url generator about all loaded workflows.
-$c['listener.url_generator'] = function( $c ) {
-       return new Flow\Data\Listener\UrlGenerationListener(
-               $c['url_generator']
+       return new Flow\UrlGenerator(
+               $c['storage.workflow.mapper']
        );
 };
 
@@ -207,7 +202,6 @@
 $c['storage.workflow.listeners'] = function( $c ) {
        return array(
                'listener.occupation' => $c['listener.occupation'],
-               'listener.url_generator' => $c['listener.url_generator'],
                'storage.workflow.listeners.topiclist' => 
$c['storage.workflow.listeners.topiclist'],
        );
 };
diff --git a/includes/Data/Listener/UrlGenerationListener.php 
b/includes/Data/Listener/UrlGenerationListener.php
deleted file mode 100644
index 706341d..0000000
--- a/includes/Data/Listener/UrlGenerationListener.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-namespace Flow\Data\Listener;
-
-use Flow\Model\Workflow;
-use Flow\UrlGenerator;
-
-/**
- * The url generator needs to know about loaded workflow instances so it
- * can generate urls pointing to the correct pages.
- */
-class UrlGenerationListener extends AbstractListener {
-       /**
-        * @var UrlGenerator
-        */
-       protected $urlGenerator;
-
-       /**
-        * @param UrlGenerator $urlGenerator
-        */
-       public function __construct( UrlGenerator $urlGenerator ) {
-               $this->urlGenerator = $urlGenerator;
-       }
-
-       public function onAfterLoad( $object, array $old ) {
-               if ( $object instanceof Workflow ) {
-                       $this->urlGenerator->withWorkflow( $object );
-               }
-       }
-
-       public function onAfterInsert( $object, array $new, array $metadata ) {
-               if ( $object instanceof Workflow ) {
-                       $this->urlGenerator->withWorkflow( $object );
-               }
-       }
-}
diff --git a/includes/UrlGenerator.php b/includes/UrlGenerator.php
index 4bcb8d2..5304e73 100644
--- a/includes/UrlGenerator.php
+++ b/includes/UrlGenerator.php
@@ -23,16 +23,9 @@
  * Anchor instances..
  */
 class UrlGenerator {
-       /**
-        * @var Workflow[] Map from alphadecimal workflow id to Workflow 
instance
-        */
-       protected $workflows = array();
 
-       /**
-        * @param Workflow $workflow
-        */
-       public function withWorkflow( Workflow $workflow ) {
-               $this->workflows[$workflow->getId()->getAlphadecimal()] = 
$workflow;
+       public function __construct( CachingObjectMapper $workflowMapper ) {
+               $this->workflowMapper = $workflowMapper;
        }
 
        /**
@@ -50,11 +43,13 @@
                }
 
                $alpha = $workflowId->getAlphadecimal();
-               if ( !isset( $this->workflows[$alpha] ) ) {
+               $workflow = $this->workflowMapper->get( array(
+                       'workflow_id' => $alpha,
+               ) );
+               if ( $workflow === null ) {
                        throw new InvalidInputException( 'Unloaded workflow:' . 
$alpha, 'invalid-workflow' );
                }
-
-               return $this->workflows[$alpha]->getArticleTitle();
+               return $workflow->getArticleTitle();
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If4877a985cf77b5588cbb12ad70b38846db6a37b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

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

Reply via email to