EBernhardson has uploaded a new change for review.

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

Change subject: Pass metadata array for ObjectManager listeners
......................................................................

Pass metadata array for ObjectManager listeners

Updates ObjectManager put and remove methods to accept an
array of metadata that will be passed on to all objects
listening for events.

This is being done to eliminate situations where we attempt to
read our own writes from the database.  This often happens
because a listener needs some extra data which isn't directly
a part of the data model like the related workflow.

This patch does not utilize the data yet, just a refactor to
start passing the data arround.

Change-Id: I8148c09c507bd86f3cfbe618f97601997c2bd746
---
M includes/Block/Header.php
M includes/Block/Topic.php
M includes/Block/TopicList.php
M includes/Block/TopicSummary.php
M includes/Data/BoardHistoryIndex.php
M includes/Data/FeatureIndex.php
M includes/Data/HeaderRecentChanges.php
M includes/Data/LifecycleHandler.php
M includes/Data/ObjectManager.php
M includes/Data/OccupationListener.php
M includes/Data/PostRevisionRecentChanges.php
M includes/Data/PostSummaryRecentChanges.php
M includes/Data/RecentChanges.php
M includes/Data/ReferenceRecorder.php
M includes/Data/TopicHistoryIndex.php
M includes/Data/UrlGenerationListener.php
M includes/Data/UserNameListener.php
M includes/Data/WorkflowTopicListListener.php
M includes/Log/PostModerationLogger.php
19 files changed, 72 insertions(+), 64 deletions(-)


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

diff --git a/includes/Block/Header.php b/includes/Block/Header.php
index 4e4ad69..87f4921 100644
--- a/includes/Block/Header.php
+++ b/includes/Block/Header.php
@@ -156,7 +156,9 @@
        public function commit() {
                switch( $this->action ) {
                        case 'edit-header':
-                               $this->storage->put( $this->newRevision );
+                               $this->storage->put( $this->newRevision, array(
+                                       'workflow' => $this->workflow,
+                               ) );
                                // Reload $this->header for renderAPI() after 
save
                                $this->header = $this->newRevision;
                                return array(
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 6c5dcc6..cf52b44 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -401,8 +401,12 @@
                                throw new FailCommitException( 'Attempt to save 
null revision', 'fail-commit' );
                        }
 
-                       $this->storage->put( $this->newRevision );
-                       $this->storage->put( $this->workflow );
+                       $metadata = array(
+                               'workflow' => $this->workflow,
+                       );
+
+                       $this->storage->put( $this->newRevision, $metadata );
+                       $this->storage->put( $this->workflow, $metadata );
                        $newRevision = $this->newRevision;
 
                        // If no context was loaded render the post in isolation
diff --git a/includes/Block/TopicList.php b/includes/Block/TopicList.php
index 9475e29..d503f34 100644
--- a/includes/Block/TopicList.php
+++ b/includes/Block/TopicList.php
@@ -142,16 +142,19 @@
                }
 
                $storage = $this->storage;
+               $metadata = array(
+                       'workflow' => $this->topicWorkflow,
+               );
 
-               $storage->put( $this->topicListEntry );
-               $storage->put( $this->topicPost );
+               $storage->put( $this->topicListEntry, $metadata );
+               $storage->put( $this->topicPost, $metadata );
                if ( $this->firstPost !== null ) {
-                       $storage->put( $this->firstPost );
+                       $storage->put( $this->firstPost, $metadata );
                }
                // must be last because this will trigger 
OccupationController::ensureFlowRevision
                // to create the page within topic namespace, that will try and 
render, so the above
                // stuff needs to be in cache at least.
-               $storage->put( $this->topicWorkflow );
+               $storage->put( $this->topicWorkflow, $metadata );
 
                $this->notificationController->subscribeToWorkflow( 
$this->user, $this->topicWorkflow );
                $this->notificationController->notifyNewTopic( array(
diff --git a/includes/Block/TopicSummary.php b/includes/Block/TopicSummary.php
index 7a45674..3430f41 100644
--- a/includes/Block/TopicSummary.php
+++ b/includes/Block/TopicSummary.php
@@ -211,7 +211,9 @@
                        throw new FailCommitException( 'Attempt to save summary 
on null revision', 'fail-commit' );
                }
 
-               $this->storage->put( $this->nextRevision );
+               $this->storage->put( $this->nextRevision, array(
+                       'workflow' => $this->workflow,
+               ) );
                // Reload the $this->formatterRow for renderAPI() after save
                $this->formatterRow = new FormatterRow();
                $this->formatterRow->revision = $this->nextRevision;
@@ -233,9 +235,6 @@
        public function commit() {
                switch( $this->action ) {
                        case 'edit-topic-summary':
-                               return $this->saveTopicSummary();
-                       break;
-
                        case 'close-open-topic':
                                return $this->saveTopicSummary();
                        break;
diff --git a/includes/Data/BoardHistoryIndex.php 
b/includes/Data/BoardHistoryIndex.php
index 22f48f5..dc435a1 100644
--- a/includes/Data/BoardHistoryIndex.php
+++ b/includes/Data/BoardHistoryIndex.php
@@ -39,7 +39,7 @@
         * @param Header|PostRevision $object
         * @param string[] $new
         */
-       public function onAfterInsert( $object, array $new ) {
+       public function onAfterInsert( $object, array $new, array $metadata ) {
                if ( $object instanceof Header ) {
                        $new['topic_list_id'] = $new['rev_type_id'];
                        parent::onAfterInsert( $object, $new );
@@ -62,7 +62,7 @@
         * @param string[] $old
         * @param string[] $new
         */
-       public function onAfterUpdate( $object, array $old, array $new ) {
+       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
                if ( $object instanceof Header ) {
                        $new['topic_list_id'] = $old['topic_list_id'] = 
$new['rev_type_id'];
                        parent::onAfterUpdate( $object, $old, $new );
@@ -84,7 +84,7 @@
         * @param Header|PostRevision $object
         * @param string[] $old
         */
-       public function onAfterRemove( $object, array $old ) {
+       public function onAfterRemove( $object, array $old, array $metadata ) {
                if ( $object instanceof Header ) {
                        $old['topic_list_id'] = $old['rev_type_id'];
                        parent::onAfterRemove( $object, $old );
diff --git a/includes/Data/FeatureIndex.php b/includes/Data/FeatureIndex.php
index 32ae1a1..ebbe254 100644
--- a/includes/Data/FeatureIndex.php
+++ b/includes/Data/FeatureIndex.php
@@ -177,7 +177,7 @@
                return 0;
        }
 
-       public function onAfterInsert( $object, array $new ) {
+       public function onAfterInsert( $object, array $new, array $metadata ) {
                $indexed = ObjectManager::splitFromRow( $new , $this->indexed );
                // is un-indexable a bail-worthy occasion? Probably not but 
makes debugging easier
                if ( !$indexed ) {
@@ -191,7 +191,7 @@
                }
        }
 
-       public function onAfterUpdate( $object, array $old, array $new ) {
+       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
                $oldIndexed = ObjectManager::splitFromRow( $old, $this->indexed 
);
                $newIndexed = ObjectManager::splitFromRow( $new, $this->indexed 
);
                if ( !$oldIndexed ) {
@@ -216,7 +216,7 @@
                }
        }
 
-       public function onAfterRemove( $object, array $old ) {
+       public function onAfterRemove( $object, array $old, array $metadata ) {
                $indexed = ObjectManager::splitFromRow( $old, $this->indexed );
                if ( !$indexed ) {
                        throw new DataModelException( 'Unindexable row: ' 
.FormatJson::encode( $old ), 'process-data' );
diff --git a/includes/Data/HeaderRecentChanges.php 
b/includes/Data/HeaderRecentChanges.php
index 6bdb131..a926ae4 100644
--- a/includes/Data/HeaderRecentChanges.php
+++ b/includes/Data/HeaderRecentChanges.php
@@ -28,7 +28,7 @@
         * @param Header $object
         * @param string[] $row
         */
-       public function onAfterInsert( $object, array $row ) {
+       public function onAfterInsert( $object, array $row, array $metadata ) {
                $workflowId = $object->getWorkflowId();
                $workflow = $this->storage->get( 'Workflow', $workflowId );
                if ( !$workflow ) {
diff --git a/includes/Data/LifecycleHandler.php 
b/includes/Data/LifecycleHandler.php
index 1cbed84..b1ee3a8 100644
--- a/includes/Data/LifecycleHandler.php
+++ b/includes/Data/LifecycleHandler.php
@@ -8,7 +8,7 @@
  */
 interface LifecycleHandler {
        function onAfterLoad( $object, array $old );
-       function onAfterInsert( $object, array $new );
-       function onAfterUpdate( $object, array $old, array $new );
-       function onAfterRemove( $object, array $old );
+       function onAfterInsert( $object, array $new, array $metadata );
+       function onAfterUpdate( $object, array $old, array $new, array 
$metadata );
+       function onAfterRemove( $object, array $old, array $metadata );
 }
diff --git a/includes/Data/ObjectManager.php b/includes/Data/ObjectManager.php
index 5cf684f..e6ef1e2 100644
--- a/includes/Data/ObjectManager.php
+++ b/includes/Data/ObjectManager.php
@@ -23,11 +23,11 @@
                $this->loaded = new SplObjectStorage;
        }
 
-       public function put( $object ) {
+       public function put( $object, array $metadata = array() ) {
                $this->multiPut( array( $object ) );
        }
 
-       public function multiPut( array $objects ) {
+       public function multiPut( array $objects, array $metadata = array() ) {
                $updateObjects = array();
                $insertObjects = array();
 
@@ -40,11 +40,11 @@
                }
 
                if ( count( $updateObjects ) ) {
-                       $this->update( $updateObjects );
+                       $this->update( $updateObjects, $metadata );
                }
 
                if ( count( $insertObjects ) ) {
-                       $this->insert( $insertObjects );
+                       $this->insert( $insertObjects, $metadata );
                }
        }
 
@@ -64,7 +64,7 @@
                }
        }
 
-       protected function insert( array $objects ) {
+       protected function insert( array $objects, array $metadata = array() ) {
                $section = new \ProfileSection( __METHOD__ );
                $rows = array_map( array( $this->mapper, 'toStorageRow' ), 
$objects );
                $storedRows = $this->storage->insert( $rows );
@@ -83,7 +83,7 @@
                        $this->mapper->fromStorageRow( $stored, $object );
 
                        foreach ( $this->lifecycleHandlers as $handler ) {
-                               $handler->onAfterInsert( $object, $stored );
+                               $handler->onAfterInsert( $object, $stored, 
$metadata );
                        }
 
                        $this->loaded[$object] = $stored;
@@ -105,17 +105,17 @@
                }
                $this->storage->update( $old, $new );
                foreach ( $this->lifecycleHandlers as $handler ) {
-                       $handler->onAfterUpdate( $object, $old, $new );
+                       $handler->onAfterUpdate( $object, $old, $new, $metadata 
);
                }
                $this->loaded[$object] = $new;
        }
 
-       public function remove( $object ) {
+       public function remove( $object, array $metadata = array() ) {
                $section = new \ProfileSection( __METHOD__ );
                $old = $this->loaded[$object];
                $this->storage->remove( $old );
                foreach ( $this->lifecycleHandlers as $handler ) {
-                       $handler->onAfterRemove( $object, $old );
+                       $handler->onAfterRemove( $object, $old, $metadata );
                }
                unset( $this->loaded[$object] );
        }
diff --git a/includes/Data/OccupationListener.php 
b/includes/Data/OccupationListener.php
index a0b38cc..5a89a17 100644
--- a/includes/Data/OccupationListener.php
+++ b/includes/Data/OccupationListener.php
@@ -28,7 +28,7 @@
                }
        }
 
-       public function onAfterInsert( $object, array $new ) {
+       public function onAfterInsert( $object, array $new, array $metadata ) {
                $this->ensureOccupation( $object );
        }
 
@@ -37,11 +37,11 @@
                $this->occupationController->ensureFlowRevision( $article, 
$workflow );
        }
 
-       public function onAfterUpdate( $object, array $old, array $new ) {
+       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
                // Nothing
        }
 
-       public function onAfterRemove( $object, array $old ) {
+       public function onAfterRemove( $object, array $old, array $metadata ) {
                // Nothing
        }
 }
diff --git a/includes/Data/PostRevisionRecentChanges.php 
b/includes/Data/PostRevisionRecentChanges.php
index aa20f64..5a78969 100644
--- a/includes/Data/PostRevisionRecentChanges.php
+++ b/includes/Data/PostRevisionRecentChanges.php
@@ -34,7 +34,7 @@
         * @param PostRevision $object
         * @param string[] $row
         */
-       public function onAfterInsert( $object, array $row ) {
+       public function onAfterInsert( $object, array $row, array $metadata ) {
                // The workflow id is the same as the root's post id
                $workflowId = $object->getRootPost()->getPostId();
                // These are likely already in the in-process cache
diff --git a/includes/Data/PostSummaryRecentChanges.php 
b/includes/Data/PostSummaryRecentChanges.php
index 3df7461..973d5f0 100644
--- a/includes/Data/PostSummaryRecentChanges.php
+++ b/includes/Data/PostSummaryRecentChanges.php
@@ -27,7 +27,7 @@
         * @param PostSummary $object
         * @param string[] $row
         */
-       public function onAfterInsert( $object, array $row ) {
+       public function onAfterInsert( $object, array $row, array $metadata ) {
                $workflowId = $object->getCollection()->getWorkflowId();
                $workflow = $this->storage->get( 'Workflow', $workflowId );
                if ( !$workflow ) {
diff --git a/includes/Data/RecentChanges.php b/includes/Data/RecentChanges.php
index 2450c35..c1d9d98 100644
--- a/includes/Data/RecentChanges.php
+++ b/includes/Data/RecentChanges.php
@@ -37,12 +37,12 @@
                $this->usernames = $usernames;
        }
 
-       public function onAfterUpdate( $object, array $old, array $new ) {
+       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 ) {
+       public function onAfterRemove( $object, array $old, array $metadata ) {
                // Deletion. Not kinda-sorta deleted, like 100% GONE. Should 
never happen.
        }
 
diff --git a/includes/Data/ReferenceRecorder.php 
b/includes/Data/ReferenceRecorder.php
index 7d4734e..9a519bc 100644
--- a/includes/Data/ReferenceRecorder.php
+++ b/includes/Data/ReferenceRecorder.php
@@ -21,7 +21,7 @@
                // Nuthin
        }
 
-       function onAfterInsert( $revision, array $new ) {
+       function onAfterInsert( $revision, array $new, array $metadata ) {
                $workflowId = $revision->getCollection()->getWorkflowId();
                $workflow = $this->storage->get( 'Workflow', $workflowId );
 
@@ -123,11 +123,11 @@
                return array( $addReferences, $removeReferences );
        }
 
-       function onAfterUpdate( $object, array $old, array $new ) {
+       function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
                // Nuthin
        }
 
-       function onAfterRemove( $object, array $old ) {
+       function onAfterRemove( $object, array $old, array $metadata ) {
                // Nuthin
        }
 }
diff --git a/includes/Data/TopicHistoryIndex.php 
b/includes/Data/TopicHistoryIndex.php
index 74a22d2..b4ff7cb 100644
--- a/includes/Data/TopicHistoryIndex.php
+++ b/includes/Data/TopicHistoryIndex.php
@@ -27,13 +27,13 @@
         * @param PostRevision $object
         * @param string[] $new
         */
-       public function onAfterInsert( $object, array $new ) {
+       public function onAfterInsert( $object, array $new, array $metadata ) {
                if ( $object instanceof PostRevision ) {
                        $new['topic_root_id'] = 
$object->getRootPost()->getPostId()->getAlphadecimal();
-                       parent::onAfterInsert( $object, $new );
+                       parent::onAfterInsert( $object, $new, $metadata );
                } elseif ( $object instanceof PostSummary ) {
                        $new['topic_root_id'] = 
$object->getCollection()->getWorkflowId()->getAlphadecimal();
-                       parent::onAfterInsert( $object, $new );
+                       parent::onAfterInsert( $object, $new, $metadata );
                }
        }
 
@@ -42,13 +42,13 @@
         * @param string[] $old
         * @param string[] $new
         */
-       public function onAfterUpdate( $object, array $old, array $new ) {
+       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
                if ( $object instanceof PostRevision ) {
                        $old['topic_root_id'] = $new['topic_root_id'] = 
$object->getRootPost()->getPostId()->getAlphadecimal();
-                       parent::onAfterUpdate( $object, $old, $new );
+                       parent::onAfterUpdate( $object, $old, $new, $metadata );
                } elseif ( $object instanceof PostSummary ) {
                        $old['topic_root_id'] = $new['topic_root_id'] = 
$object->getCollection()->getWorkflowId()->getAlphadecimal();
-                       parent::onAfterUpdate( $object, $old, $new );
+                       parent::onAfterUpdate( $object, $old, $new, $metadata );
                }
        }
 
@@ -56,13 +56,13 @@
         * @param PostRevision $object
         * @param string[] $old
         */
-       public function onAfterRemove( $object, array $old ) {
+       public function onAfterRemove( $object, array $old, array $metadata ) {
                if ( $object instanceof PostRevision ) {
                        $old['topic_root_id'] = 
$object->getRootPost()->getPostId()->getAlphadecimal();
-                       parent::onAfterRemove( $object, $old );
+                       parent::onAfterRemove( $object, $old, $metadata );
                } elseif ( $object instanceof PostSummary ) {
                        $old['topic_root_id'] = 
$object->getCollection()->getWorkflowId()->getAlphadecimal();
-                       parent::onAfterRemove( $object, $old );
+                       parent::onAfterRemove( $object, $old, $metadata );
                }
        }
 
diff --git a/includes/Data/UrlGenerationListener.php 
b/includes/Data/UrlGenerationListener.php
index 38db88c..1b38081 100644
--- a/includes/Data/UrlGenerationListener.php
+++ b/includes/Data/UrlGenerationListener.php
@@ -28,17 +28,17 @@
                }
        }
 
-       public function onAfterInsert( $object, array $new ) {
+       public function onAfterInsert( $object, array $new, array $metadata ) {
                if ( $object instanceof Workflow ) {
                        $this->urlGenerator->withWorkflow( $object );
                }
        }
 
-       public function onAfterUpdate( $object, array $old, array $new ) {
+       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
                // Nothing
        }
 
-       public function onAfterRemove( $object, array $old ) {
+       public function onAfterRemove( $object, array $old, array $metadata ) {
                // Nothing
        }
 }
diff --git a/includes/Data/UserNameListener.php 
b/includes/Data/UserNameListener.php
index bf16278..abd695e 100644
--- a/includes/Data/UserNameListener.php
+++ b/includes/Data/UserNameListener.php
@@ -56,7 +56,7 @@
                }
        }
 
-       public function onAfterInsert( $object, array $new ) {}
-       public function onAfterUpdate( $object, array $old, array $new ) {}
-       public function onAfterRemove( $object, array $old ) {}
+       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/WorkflowTopicListListener.php 
b/includes/Data/WorkflowTopicListListener.php
index d81eb7a..78d9d17 100644
--- a/includes/Data/WorkflowTopicListListener.php
+++ b/includes/Data/WorkflowTopicListListener.php
@@ -40,17 +40,17 @@
                }
        }
 
-       public function onAfterInsert( $object, array $new ) {
+       public function onAfterInsert( $object, array $new, array $metadata ) {
                $entry = $this->getTopicListEntry( $new['workflow_id'] );
                if ( $entry ) {
                        $row = array(
                                        'workflow_last_update_timestamp' => 
$new['workflow_last_update_timestamp']
                                ) + TopicListEntry::toStorageRow( $entry );
-                       $this->topicListLastUpdatedIndex->onAfterInsert( 
$entry, $row );
+                       $this->topicListLastUpdatedIndex->onAfterInsert( 
$entry, $row, $metadata );
                }
        }
 
-       public function onAfterUpdate( $object, array $old, array $new ) {
+       public function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
                $entry = $this->getTopicListEntry( $new['workflow_id'] );
                if ( $entry ) {
                        $row = TopicListEntry::toStorageRow( $entry );
@@ -61,12 +61,12 @@
                                ) + $row,
                                array(
                                        'workflow_last_update_timestamp' => 
$new['workflow_last_update_timestamp']
-                               ) + $row
+                               ) + $row,
+                               $metadata
                        );
                }
        }
 
        public function onAfterLoad( $object, array $row ) {}
-       public function onAfterRemove( $object, array $old ) {}
-
+       public function onAfterRemove( $object, array $old, array $metadata ) {}
 }
diff --git a/includes/Log/PostModerationLogger.php 
b/includes/Log/PostModerationLogger.php
index c2c85ae..20b1c51 100644
--- a/includes/Log/PostModerationLogger.php
+++ b/includes/Log/PostModerationLogger.php
@@ -21,7 +21,7 @@
         * @param PostRevision $object
         * @param array $row
         */
-       function onAfterInsert( $object, array $row ) {
+       function onAfterInsert( $object, array $row, array $metadata ) {
                if ( $object instanceof PostRevision ) {
                        $this->log( $object );
                }
@@ -31,11 +31,11 @@
                 // You don't need to see my identification
        }
 
-       function onAfterUpdate( $object, array $old, array $new ) {
+       function onAfterUpdate( $object, array $old, array $new, array 
$metadata ) {
                // These aren't the droids you're looking for
        }
 
-       function onAfterRemove( $object, array $old ) {
+       function onAfterRemove( $object, array $old, array $metadata ) {
                // Move along
        }
 

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

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