EBernhardson has uploaded a new change for review.

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

Change subject: Add an AbstractListener base class
......................................................................

Add an AbstractListener base class

Most of these listeners have some unimplemented methods that they
don't need.  Instead of having all these empty methods, and adding
new empty methods for any new events, just inherit from a base class.

Change-Id: I9da02f2667d5d85d1c28443f87e08e53aa0628c6
---
M autoload.php
M includes/Collection/CollectionCache.php
A includes/Data/Listener/AbstractListener.php
M includes/Data/Listener/EditCountListener.php
M includes/Data/Listener/ModerationLoggingListener.php
M includes/Data/Listener/NotificationListener.php
M includes/Data/Listener/OccupationListener.php
M includes/Data/Listener/RecentChangesListener.php
M includes/Data/Listener/ReferenceRecorder.php
M includes/Data/Listener/UrlGenerationListener.php
M includes/Data/Listener/UserNameListener.php
M includes/Data/Listener/WatchTopicListener.php
M includes/Data/Listener/WorkflowTopicListListener.php
13 files changed, 56 insertions(+), 101 deletions(-)


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

diff --git a/autoload.php b/autoload.php
index 314947b..0fccd6b 100644
--- a/autoload.php
+++ b/autoload.php
@@ -65,6 +65,7 @@
        'Flow\\Data\\Index\\TopicHistoryIndex' => __DIR__ . 
'/includes/Data/Index/TopicHistoryIndex.php',
        'Flow\\Data\\Index\\UniqueFeatureIndex' => __DIR__ . 
'/includes/Data/Index/UniqueFeatureIndex.php',
        'Flow\\Data\\LifecycleHandler' => __DIR__ . 
'/includes/Data/LifecycleHandler.php',
+       'Flow\\Data\\Listener\\AbstractListener' => __DIR__ . 
'/includes/Data/Listener/AbstractListener.php',
        'Flow\\Data\\Listener\\AbstractTopicInsertListener' => __DIR__ . 
'/includes/Data/Listener/WatchTopicListener.php',
        'Flow\\Data\\Listener\\DeferredInsertLifecycleHandler' => __DIR__ . 
'/includes/Data/Listener/DeferredInsertLifecycleHandler.php',
        'Flow\\Data\\Listener\\EditCountListener' => __DIR__ . 
'/includes/Data/Listener/EditCountListener.php',
diff --git a/includes/Collection/CollectionCache.php 
b/includes/Collection/CollectionCache.php
index b05b95b..58089ef 100644
--- a/includes/Collection/CollectionCache.php
+++ b/includes/Collection/CollectionCache.php
@@ -2,7 +2,7 @@
 
 namespace Flow\Collection;
 
-use Flow\Data\LifecycleHandler;
+use Flow\Data\Listener\AbstractListener;
 use Flow\Model\AbstractRevision;
 use MapCacheLRU;
 
@@ -11,7 +11,7 @@
  * insert/update/remove to keep the internal cache up to date and reduce
  * requests deeper into the stack.
  */
-class CollectionCache implements LifecycleHandler {
+class CollectionCache extends AbstractListener {
 
        /**
         * Max to cache collection's last revision
@@ -57,8 +57,6 @@
        protected function getLastRevCacheKey( AbstractRevision $revision ) {
                return $revision->getCollectionId()->getAlphadecimal() . '-' . 
$revision->getRevisionType() . '-last-rev';
        }
-
-       public function onAfterLoad( $object, array $row ) {}
 
        public function onAfterInsert( $object, array $new, array $metadata ) {
                if ( $object instanceof AbstractRevision ) {
diff --git a/includes/Data/Listener/AbstractListener.php 
b/includes/Data/Listener/AbstractListener.php
new file mode 100644
index 0000000..62637b0
--- /dev/null
+++ b/includes/Data/Listener/AbstractListener.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Flow\Data\Listener;
+
+use Closure;
+use Flow\Container;
+use Flow\Data\LifecycleHandler;
+use Flow\Data\Utils\RecentChangeFactory;
+use Flow\FlowActions;
+use Flow\Formatter\IRCLineUrlFormatter;
+use Flow\Model\AbstractRevision;
+use Flow\Model\Workflow;
+use Flow\Repository\UserNameBatch;
+
+/**
+ * Inserts mw recentchange rows for flow AbstractRevision instances.
+ */
+class AbstractListener implements LifecycleHandler {
+
+       /**
+        * {@inheritDoc}
+        */
+       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function onAfterRemove( $object, array $old, array $metadata ) {
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function onAfterLoad( $object, array $row ) {
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function onAfterInsert( $revision, array $row, array $metadata ) 
{
+       }
+}
diff --git a/includes/Data/Listener/EditCountListener.php 
b/includes/Data/Listener/EditCountListener.php
index e7f40fe..8beac6d 100644
--- a/includes/Data/Listener/EditCountListener.php
+++ b/includes/Data/Listener/EditCountListener.php
@@ -2,12 +2,11 @@
 
 namespace Flow\Data\Listener;
 
-use Flow\Data\LifecycleHandler;
 use Flow\Exception\InvalidDataException;
 use Flow\FlowActions;
 use Flow\Model\AbstractRevision;
 
-class EditCountListener implements LifecycleHandler {
+class EditCountListener extends AbstractListener {
        /**
         * @var FlowActions
         */
@@ -15,10 +14,6 @@
 
        public function __construct( FlowActions $actions ) {
                $this->actions = $actions;
-       }
-
-       public function onAfterLoad( $object, array $old ) {
-               // Nuthin
        }
 
        public function onAfterInsert( $revision, array $new, array $metadata ) 
{
@@ -32,13 +27,5 @@
                if ( $increase ) {
                        $revision->getUser()->incEditCount();
                }
-       }
-
-       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
-               // Nuthin
-       }
-
-       public function onAfterRemove( $object, array $old, array $metadata ) {
-               // Nuthin
        }
 }
diff --git a/includes/Data/Listener/ModerationLoggingListener.php 
b/includes/Data/Listener/ModerationLoggingListener.php
index a243a96..3748ca9 100644
--- a/includes/Data/Listener/ModerationLoggingListener.php
+++ b/includes/Data/Listener/ModerationLoggingListener.php
@@ -2,13 +2,12 @@
 
 namespace Flow\Data\Listener;
 
-use Flow\Data\LifecycleHandler;
 use Flow\Log\ModerationLogger;
 use Flow\Model\AbstractRevision;
 use Flow\Model\PostRevision;
 use Flow\Model\Workflow;
 
-class ModerationLoggingListener implements LifecycleHandler {
+class ModerationLoggingListener extends AbstractListener {
 
        /**
         * @var ModerationLogger
@@ -28,18 +27,6 @@
                if ( $object instanceof PostRevision ) {
                        $this->log( $object, $metadata['workflow'] );
                }
-       }
-
-       function onAfterLoad( $object, array $old ) {
-                // You don't need to see my identification
-       }
-
-       function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
-               // These aren't the droids you're looking for
-       }
-
-       function onAfterRemove( $object, array $old, array $metadata ) {
-               // Move along
        }
 
        protected function log( PostRevision $post, Workflow $workflow ) {
diff --git a/includes/Data/Listener/NotificationListener.php 
b/includes/Data/Listener/NotificationListener.php
index 6c266d1..8414133 100644
--- a/includes/Data/Listener/NotificationListener.php
+++ b/includes/Data/Listener/NotificationListener.php
@@ -2,13 +2,12 @@
 
 namespace Flow\Data\Listener;
 
-use Flow\Data\LifecycleHandler;
 use Flow\Exception\InvalidDataException;
 use Flow\Model\AbstractRevision;
 use Flow\Model\Workflow;
 use Flow\NotificationController;
 
-class NotificationListener implements LifecycleHandler {
+class NotificationListener extends AbstractListener {
 
        /**
         * @var NotificationController
@@ -92,8 +91,4 @@
                        'topic-title' => $metadata['topic-title'],
                ) );
        }
-
-       public function onAfterLoad( $object, array $row ) {}
-       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {}
-       public function onAfterRemove( $object, array $row, array $metadata ) {}
 }
diff --git a/includes/Data/Listener/OccupationListener.php 
b/includes/Data/Listener/OccupationListener.php
index 80618af..3c6e269 100644
--- a/includes/Data/Listener/OccupationListener.php
+++ b/includes/Data/Listener/OccupationListener.php
@@ -3,7 +3,6 @@
 namespace Flow\Data\Listener;
 
 use Article;
-use Flow\Data\LifecycleHandler;
 use Flow\Exception\FlowException;
 use Flow\Model\Workflow;
 use Flow\OccupationController;
@@ -13,7 +12,7 @@
  * Ensures that a given workflow is occupied.  This will be unnecssary
  * once we deprecate the OccupationController white list.
  */
-class OccupationListener implements LifecycleHandler {
+class OccupationListener extends AbstractListener {
        /** @var OccupationController **/
        protected $occupationController;
 
@@ -88,13 +87,5 @@
                                );
                        } );
                }
-       }
-
-       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
-               // Nothing
-       }
-
-       public function onAfterRemove( $object, array $old, array $metadata ) {
-               // Nothing
        }
 }
diff --git a/includes/Data/Listener/RecentChangesListener.php 
b/includes/Data/Listener/RecentChangesListener.php
index b839850..468b63a 100644
--- a/includes/Data/Listener/RecentChangesListener.php
+++ b/includes/Data/Listener/RecentChangesListener.php
@@ -4,7 +4,6 @@
 
 use Closure;
 use Flow\Container;
-use Flow\Data\LifecycleHandler;
 use Flow\Data\Utils\RecentChangeFactory;
 use Flow\FlowActions;
 use Flow\Formatter\IRCLineUrlFormatter;
@@ -15,7 +14,7 @@
 /**
  * Inserts mw recentchange rows for flow AbstractRevision instances.
  */
-class RecentChangesListener implements LifecycleHandler {
+class RecentChangesListener extends AbstractListener {
 
        // Value used in rc_source field of recentchanges to identify flow 
specific changes
        const SRC_FLOW = "flow";
@@ -56,19 +55,6 @@
                $this->usernames = $usernames;
                $this->rcFactory = $rcFactory;
                $this->ircFormatter = $ircFormatter;
-       }
-
-       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
-               // Moderation.  Doesn't need to log anything because all 
moderation also inserts
-               // a new null revision to track who and when.
-       }
-
-       public function onAfterRemove( $object, array $old, array $metadata ) {
-               // Deletion. Not kinda-sorta deleted, like 100% GONE. Should 
never happen.
-       }
-
-       public function onAfterLoad( $object, array $row ) {
-               // nothing to do
        }
 
        /**
diff --git a/includes/Data/Listener/ReferenceRecorder.php 
b/includes/Data/Listener/ReferenceRecorder.php
index e260d6a..f4e47ef 100644
--- a/includes/Data/Listener/ReferenceRecorder.php
+++ b/includes/Data/Listener/ReferenceRecorder.php
@@ -5,7 +5,6 @@
 use Flow\Exception\FlowException;
 use Flow\Exception\InvalidDataException;
 use Flow\LinksTableUpdater;
-use Flow\Data\LifecycleHandler;
 use Flow\Data\ManagerGroup;
 use Flow\Model\AbstractRevision;
 use Flow\Model\PostRevision;
@@ -21,7 +20,7 @@
  * references(URLs, images, etc) between this new version and the previous
  * revision. Uses calculated difference to update links tables to match the 
new revision.
  */
-class ReferenceRecorder implements LifecycleHandler {
+class ReferenceRecorder extends AbstractListener {
        /**
         * @var ReferenceExtractor
         */
@@ -291,13 +290,5 @@
                }
 
                return array( $addReferences, $removeReferences );
-       }
-
-       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
-               // Nuthin
-       }
-
-       public function onAfterRemove( $object, array $old, array $metadata ) {
-               // Nuthin
        }
 }
diff --git a/includes/Data/Listener/UrlGenerationListener.php 
b/includes/Data/Listener/UrlGenerationListener.php
index d8ce241..706341d 100644
--- a/includes/Data/Listener/UrlGenerationListener.php
+++ b/includes/Data/Listener/UrlGenerationListener.php
@@ -2,7 +2,6 @@
 
 namespace Flow\Data\Listener;
 
-use Flow\Data\LifecycleHandler;
 use Flow\Model\Workflow;
 use Flow\UrlGenerator;
 
@@ -10,7 +9,7 @@
  * The url generator needs to know about loaded workflow instances so it
  * can generate urls pointing to the correct pages.
  */
-class UrlGenerationListener implements LifecycleHandler {
+class UrlGenerationListener extends AbstractListener {
        /**
         * @var UrlGenerator
         */
@@ -33,13 +32,5 @@
                if ( $object instanceof Workflow ) {
                        $this->urlGenerator->withWorkflow( $object );
                }
-       }
-
-       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
-               // Nothing
-       }
-
-       public function onAfterRemove( $object, array $old, array $metadata ) {
-               // Nothing
        }
 }
diff --git a/includes/Data/Listener/UserNameListener.php 
b/includes/Data/Listener/UserNameListener.php
index 5d36652..abb70c9 100644
--- a/includes/Data/Listener/UserNameListener.php
+++ b/includes/Data/Listener/UserNameListener.php
@@ -5,14 +5,13 @@
  */
 namespace Flow\Data\Listener;
 
-use Flow\Data\LifecycleHandler;
 use Flow\Repository\UserNameBatch;
 
 /**
  * Listen for loaded objects and pre-load their user id fields into
  * a batch username loader.
  */
-class UserNameListener implements LifecycleHandler {
+class UserNameListener extends AbstractListener {
        protected $batch;
        protected $keys;
        protected $wikiKey;
@@ -58,8 +57,4 @@
                        }
                }
        }
-
-       public function onAfterInsert( $object, array $new, array $metadata ) {}
-       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {}
-       public function onAfterRemove( $object, array $old, array $metadata ) {}
 }
diff --git a/includes/Data/Listener/WatchTopicListener.php 
b/includes/Data/Listener/WatchTopicListener.php
index db93f6a..db8833b 100644
--- a/includes/Data/Listener/WatchTopicListener.php
+++ b/includes/Data/Listener/WatchTopicListener.php
@@ -3,7 +3,6 @@
 namespace Flow\Data\Listener;
 
 use Flow\Container;
-use Flow\Data\LifecycleHandler;
 use Flow\Exception\InvalidDataException;
 use Flow\FlowActions;
 use Flow\Model\PostRevision;
@@ -17,7 +16,7 @@
  * Auto-watch topics when the user performs one of the actions specified
  * in the constructor.
  */
-abstract class AbstractTopicInsertListener implements LifecycleHandler {
+abstract class AbstractTopicInsertListener extends AbstractListener {
        /**
         * @param string $changeType
         * @param Workflow $workflow
@@ -85,11 +84,6 @@
 
                return $users;
        }
-
-       // do nothing
-       public function onAfterLoad( $object, array $new ) {}
-       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {}
-       public function onAfterRemove( $object, array $old, array $metadata ) {}
 }
 
 /**
diff --git a/includes/Data/Listener/WorkflowTopicListListener.php 
b/includes/Data/Listener/WorkflowTopicListListener.php
index b1cff74..39e593d 100644
--- a/includes/Data/Listener/WorkflowTopicListListener.php
+++ b/includes/Data/Listener/WorkflowTopicListListener.php
@@ -3,7 +3,6 @@
 namespace Flow\Data\Listener;
 
 use Flow\Data\Index\TopKIndex;
-use Flow\Data\LifecycleHandler;
 use Flow\Data\ObjectManager;
 use Flow\Model\TopicListEntry;
 
@@ -13,7 +12,7 @@
  * passes that updated timestamp along to the topic list last updated index
  * so that it can reorder any lists this workflow is in.
  */
-class WorkflowTopicListListener implements LifecycleHandler {
+class WorkflowTopicListListener extends AbstractListener {
 
        /**
         * @param ObjectManager
@@ -75,7 +74,4 @@
                        );
                }
        }
-
-       public function onAfterLoad( $object, array $row ) {}
-       public function onAfterRemove( $object, array $old, array $metadata ) {}
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9da02f2667d5d85d1c28443f87e08e53aa0628c6
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