From 297377b0fde8211af677b7dc2f6848d169617897 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 28 Oct 2014 12:43:40 +0000 Subject: [PATCH] Add "operatorUpdate" event --- .../libs/classes/Mibew/EventDispatcher/Events.php | 10 ++++++++++ src/mibew/libs/operator.php | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php index 7af4fa8d..ad641a09 100644 --- a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php +++ b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php @@ -172,6 +172,16 @@ final class Events */ const OPERATOR_CREATE = 'operatorCreate'; + /** + * An operator is updated. + * + * This event is triggered after an operator is saved. An associative array + * with the following items is passed to the event handlers: + * - "operator": array, the state of the operator after update. + * - "original_operator": array, the state of the operator before update. + */ + const OPERATOR_UPDATE = 'operatorUpdate'; + /** * An operator is deleted. * diff --git a/src/mibew/libs/operator.php b/src/mibew/libs/operator.php index 72d93f69..2d006c03 100644 --- a/src/mibew/libs/operator.php +++ b/src/mibew/libs/operator.php @@ -275,6 +275,8 @@ function operator_is_disabled($operator) /** * Update existing operator's info. * + * Triggers {@link \Mibew\EventDispatcher\Events::OPERATOR_UPDATE} event. + * * @param array $operator Associative array of operator's fields. This array * must contain the following keys: * - operatorid, @@ -300,6 +302,9 @@ function update_operator($operator) throw new \InvalidArgumentException('Not all operator fields are specified'); } + // Get the original operator to trigger the "update" event later + $original_operator = operator_by_id($operator['operatorid']); + Database::getInstance()->query( ('UPDATE {operator} SET vclogin = :login, vcpassword=:password, ' . 'vclocalename = :local_name, vccommonname = :common_name, ' @@ -325,6 +330,12 @@ function update_operator($operator) ':code' => $operator['code'], ) ); + + $args = array( + 'operator' => $operator, + 'original_operator' => $original_operator, + ); + EventDispatcher::getInstance()->triggerEvent(Events::OPERATOR_UPDATE, $args); } function update_operator_avatar($operator_id, $avatar)