Improve events handling
This commit is contained in:
@@ -21,7 +21,7 @@ Features
|
|||||||
|
|
||||||
- Multiple boards/projects
|
- Multiple boards/projects
|
||||||
- Boards customization, rename or add columns
|
- Boards customization, rename or add columns
|
||||||
- Tasks with different colors, Markdown support for the description
|
- Tasks with different colors, categories, sub-tasks, attachments, Markdown support for the description
|
||||||
- Automatic actions
|
- Automatic actions
|
||||||
- Users management with a basic privileges separation (administrator or regular user)
|
- Users management with a basic privileges separation (administrator or regular user)
|
||||||
- External authentication: Google Account and LDAP/ActiveDirectory
|
- External authentication: Google Account and LDAP/ActiveDirectory
|
||||||
|
|||||||
@@ -67,13 +67,16 @@ class Event
|
|||||||
*/
|
*/
|
||||||
public function trigger($eventName, array $data)
|
public function trigger($eventName, array $data)
|
||||||
{
|
{
|
||||||
$this->lastEvent = $eventName;
|
if (! $this->isEventTriggered($eventName)) {
|
||||||
$this->events[] = $eventName;
|
|
||||||
|
|
||||||
if (isset($this->listeners[$eventName])) {
|
$this->lastEvent = $eventName;
|
||||||
foreach ($this->listeners[$eventName] as $listener) {
|
$this->events[] = $eventName;
|
||||||
if ($listener->execute($data)) {
|
|
||||||
$this->lastListener = get_class($listener);
|
if (isset($this->listeners[$eventName])) {
|
||||||
|
foreach ($this->listeners[$eventName] as $listener) {
|
||||||
|
if ($listener->execute($data)) {
|
||||||
|
$this->lastListener = get_class($listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,6 +115,18 @@ class Event
|
|||||||
return $this->events;
|
return $this->events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an event have been triggered
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $eventName Event name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isEventTriggered($eventName)
|
||||||
|
{
|
||||||
|
return in_array($eventName, $this->events);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a listener bind to an event
|
* Check if a listener bind to an event
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -359,12 +359,10 @@ class Task extends Base
|
|||||||
// Trigger events
|
// Trigger events
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
|
||||||
$events = array();
|
$events = array(
|
||||||
|
self::EVENT_CREATE_UPDATE,
|
||||||
if (! in_array($this->event->getLastTriggeredEvent(), array(self::EVENT_CREATE_UPDATE))) {
|
self::EVENT_UPDATE,
|
||||||
$events[] = self::EVENT_CREATE_UPDATE;
|
);
|
||||||
$events[] = self::EVENT_UPDATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($values['column_id']) && $original_task['column_id'] != $values['column_id']) {
|
if (isset($values['column_id']) && $original_task['column_id'] != $values['column_id']) {
|
||||||
$events[] = self::EVENT_MOVE_COLUMN;
|
$events[] = self::EVENT_MOVE_COLUMN;
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ class ActionTest extends Base
|
|||||||
// We move our task
|
// We move our task
|
||||||
$task->move(1, 4, 1);
|
$task->move(1, 4, 1);
|
||||||
|
|
||||||
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||||
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_UPDATE));
|
||||||
|
|
||||||
// Our task should be closed
|
// Our task should be closed
|
||||||
$t1 = $task->getById(1);
|
$t1 = $task->getById(1);
|
||||||
$this->assertEquals(4, $t1['column_id']);
|
$this->assertEquals(4, $t1['column_id']);
|
||||||
@@ -109,15 +112,16 @@ class ActionTest extends Base
|
|||||||
'owner_id' => 1,
|
'owner_id' => 1,
|
||||||
'color_id' => 'red',
|
'color_id' => 'red',
|
||||||
'column_id' => 1,
|
'column_id' => 1,
|
||||||
|
'category_id' => 1,
|
||||||
)));
|
)));
|
||||||
|
|
||||||
// We create a new action, when the category_id=2 then the color_id should be green
|
// We create a new action, when the category_id=2 then the color_id should be green
|
||||||
$this->assertTrue($action->create(array(
|
$this->assertTrue($action->create(array(
|
||||||
'project_id' => 1,
|
'project_id' => 1,
|
||||||
'event_name' => Task::EVENT_MOVE_POSITION,
|
'event_name' => Task::EVENT_MOVE_POSITION,
|
||||||
'action_name' => 'TaskClose',
|
'action_name' => 'TaskAssignColorCategory',
|
||||||
'params' => array(
|
'params' => array(
|
||||||
'column_id' => 1,
|
'category_id' => 1,
|
||||||
'color_id' => 'green',
|
'color_id' => 'green',
|
||||||
)
|
)
|
||||||
)));
|
)));
|
||||||
@@ -125,21 +129,24 @@ class ActionTest extends Base
|
|||||||
// We bind events
|
// We bind events
|
||||||
$action->attachEvents();
|
$action->attachEvents();
|
||||||
|
|
||||||
$this->assertTrue($this->event->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskClose'));
|
$this->assertTrue($this->event->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskAssignColorCategory'));
|
||||||
|
|
||||||
// Our task should have the color red and position=0
|
// Our task should have the color red and position=0
|
||||||
$t1 = $task->getById(1);
|
$t1 = $task->getById(1);
|
||||||
$this->assertEquals(0, $t1['position']);
|
$this->assertEquals(0, $t1['position']);
|
||||||
$this->assertEquals(1, $t1['is_active']);
|
$this->assertEquals(1, $t1['is_active']);
|
||||||
|
$this->assertEquals('red', $t1['color_id']);
|
||||||
|
|
||||||
// We move our task
|
// We move our task
|
||||||
$task->move(1, 1, 2);
|
$task->move(1, 1, 2);
|
||||||
$this->assertEquals(Task::EVENT_CLOSE, $this->event->getLastTriggeredEvent());
|
|
||||||
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||||
|
|
||||||
// Our task should be green and have the position 2
|
// Our task should be green and have the position 2
|
||||||
$t1 = $task->getById(1);
|
$t1 = $task->getById(1);
|
||||||
$this->assertEquals(2, $t1['position']);
|
$this->assertEquals(2, $t1['position']);
|
||||||
$this->assertEquals(0, $t1['is_active']);
|
$this->assertEquals(1, $t1['is_active']);
|
||||||
|
$this->assertEquals('green', $t1['color_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExecuteMultipleActions()
|
public function testExecuteMultipleActions()
|
||||||
@@ -197,7 +204,9 @@ class ActionTest extends Base
|
|||||||
|
|
||||||
// We move our task
|
// We move our task
|
||||||
$task->move(1, 4, 1);
|
$task->move(1, 4, 1);
|
||||||
$this->assertEquals(Task::EVENT_CREATE, $this->event->getLastTriggeredEvent());
|
|
||||||
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_CLOSE));
|
||||||
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||||
|
|
||||||
// Our task should be closed
|
// Our task should be closed
|
||||||
$t1 = $task->getById(1);
|
$t1 = $task->getById(1);
|
||||||
@@ -212,6 +221,4 @@ class ActionTest extends Base
|
|||||||
$this->assertEquals(2, $t2['project_id']);
|
$this->assertEquals(2, $t2['project_id']);
|
||||||
$this->assertEquals('unit_test', $t2['title']);
|
$this->assertEquals('unit_test', $t2['title']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class TaskTest extends Base
|
|||||||
|
|
||||||
// We duplicate our task
|
// We duplicate our task
|
||||||
$this->assertEquals(2, $t->duplicate(1));
|
$this->assertEquals(2, $t->duplicate(1));
|
||||||
$this->assertEquals(Task::EVENT_CREATE, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE));
|
||||||
|
|
||||||
// Check the values of the duplicated task
|
// Check the values of the duplicated task
|
||||||
$task = $t->getById(2);
|
$task = $t->getById(2);
|
||||||
@@ -136,7 +136,7 @@ class TaskTest extends Base
|
|||||||
|
|
||||||
// We duplicate our task to the 2nd project
|
// We duplicate our task to the 2nd project
|
||||||
$this->assertEquals(2, $t->duplicateToAnotherProject(1, 2));
|
$this->assertEquals(2, $t->duplicateToAnotherProject(1, 2));
|
||||||
$this->assertEquals(Task::EVENT_CREATE, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE));
|
||||||
|
|
||||||
// Check the values of the duplicated task
|
// Check the values of the duplicated task
|
||||||
$task = $t->getById(2);
|
$task = $t->getById(2);
|
||||||
@@ -157,30 +157,31 @@ class TaskTest extends Base
|
|||||||
|
|
||||||
// We create task
|
// We create task
|
||||||
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
||||||
$this->assertEquals(Task::EVENT_CREATE, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE));
|
||||||
|
|
||||||
// We update a task
|
// We update a task
|
||||||
$this->assertTrue($t->update(array('title' => 'test2', 'id' => 1)));
|
$this->assertTrue($t->update(array('title' => 'test2', 'id' => 1)));
|
||||||
$this->assertEquals(Task::EVENT_UPDATE, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_UPDATE));
|
||||||
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE_UPDATE));
|
||||||
|
|
||||||
// We close our task
|
// We close our task
|
||||||
$this->assertTrue($t->close(1));
|
$this->assertTrue($t->close(1));
|
||||||
$this->assertEquals(Task::EVENT_CLOSE, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_CLOSE));
|
||||||
|
|
||||||
// We open our task
|
// We open our task
|
||||||
$this->assertTrue($t->open(1));
|
$this->assertTrue($t->open(1));
|
||||||
$this->assertEquals(Task::EVENT_OPEN, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_OPEN));
|
||||||
|
|
||||||
// We change the column of our task
|
// We change the column of our task
|
||||||
$this->assertTrue($t->move(1, 2, 1));
|
$this->assertTrue($t->move(1, 2, 1));
|
||||||
$this->assertEquals(Task::EVENT_MOVE_COLUMN, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||||
|
|
||||||
// We change the position of our task
|
// We change the position of our task
|
||||||
$this->assertTrue($t->move(1, 2, 2));
|
$this->assertTrue($t->move(1, 2, 2));
|
||||||
$this->assertEquals(Task::EVENT_MOVE_POSITION, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||||
|
|
||||||
// We change the column and the position of our task
|
// We change the column and the position of our task
|
||||||
$this->assertTrue($t->move(1, 1, 3));
|
$this->assertTrue($t->move(1, 1, 3));
|
||||||
$this->assertEquals(Task::EVENT_MOVE_COLUMN, $this->event->getLastTriggeredEvent());
|
$this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user