Add "threadCreate" event

This commit is contained in:
Dmitriy Simushev 2014-10-29 10:50:09 +00:00
parent ab942731e6
commit 336d8c1faa
2 changed files with 14 additions and 1 deletions

View File

@ -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.
*

View File

@ -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);