From 336d8c1faa330a7eacbaa121843553bf88d1cb38 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 29 Oct 2014 10:50:09 +0000 Subject: [PATCH] Add "threadCreate" event --- src/mibew/libs/classes/Mibew/EventDispatcher/Events.php | 9 +++++++++ src/mibew/libs/classes/Mibew/Thread.php | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php index 0032d7f4..3231504f 100644 --- a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php +++ b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php @@ -319,6 +319,15 @@ final class Events */ const THREAD_FUNCTION_CALL = 'threadFunctionCall'; + /** + * A thread is created. + * + * This event is triggered after a thread has been created. An associative + * array with the following items is passed to the event handlers: + * - "thread": an instance of {@link \Mibew\Thread}. + */ + const THREAD_CREATE = 'threadCreate'; + /** * Thread is updated. * diff --git a/src/mibew/libs/classes/Mibew/Thread.php b/src/mibew/libs/classes/Mibew/Thread.php index 2346dfbf..69acba02 100644 --- a/src/mibew/libs/classes/Mibew/Thread.php +++ b/src/mibew/libs/classes/Mibew/Thread.php @@ -601,7 +601,8 @@ class Thread /** * Save the thread to the database * - * Triggers {@link \Mibew\EventDispatcher\Events::THREAD_UPDATE} event. + * Triggers {@link \Mibew\EventDispatcher\Events::THREAD_UPDATE} and + * {@link \Mibew\EventDispatcher\Events::THREAD_CREATE} events. * * @param boolean $update_revision Indicates if last modified time and last * revision should be updated. @@ -660,6 +661,9 @@ class Thread ) ); $this->id = $db->insertedId(); + + $args = array('thread' => $this); + EventDispatcher::getInstance()->triggerEvent(Events::THREAD_CREATE, $args); } else { // Get the original state of the thread to trigger event later. $original_thread = Thread::load($this->id);