From 7f6a9c6513e9a3c52ecdedc701de50862374940a Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 27 Oct 2014 10:40:45 +0000 Subject: [PATCH] Add "banUpdate" event --- src/mibew/libs/classes/Mibew/Ban.php | 9 +++++++++ .../libs/classes/Mibew/EventDispatcher/Events.php | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/mibew/libs/classes/Mibew/Ban.php b/src/mibew/libs/classes/Mibew/Ban.php index 4b2d5747..b5a231c6 100644 --- a/src/mibew/libs/classes/Mibew/Ban.php +++ b/src/mibew/libs/classes/Mibew/Ban.php @@ -224,6 +224,9 @@ class Ban $args = array('ban' => $this); EventDispatcher::getInstance()->triggerEvent(Events::BAN_CREATE, $args); } else { + // Get the original state of the ban for "update" event. + $original_ban = Ban::load($this->id); + // Update existing ban $db->query( ("UPDATE {ban} SET dtmtill = :till, address = :address, " @@ -235,6 +238,12 @@ class Ban ':comment' => $this->comment, ) ); + + $args = array( + 'ban' => $this, + 'original_ban' => $original_ban, + ); + EventDispatcher::getInstance()->triggerEvent(Events::BAN_UPDATE, $args); } } diff --git a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php index 3792f77f..69f8fe4e 100644 --- a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php +++ b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php @@ -33,6 +33,18 @@ final class Events */ const BAN_CREATE = 'banCreate'; + /** + * A ban is updated. + * + * This event is triggered after a ban is saved. An associative array with + * the following items is passed to the event handlers: + * - "ban": an instance of {@link \Mibew\Ban}, the state of the ban after + * the update. + * - "original_ban": an instance of {@link \Mibew\Ban}, the state of the + * ban before the update. + */ + const BAN_UPDATE = 'banUpdate'; + /** * A ban is deleted. *