summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--app/Api/Procedure/TaskProcedure.php25
-rw-r--r--app/Core/Action/ActionManager.php16
-rw-r--r--app/Core/Queue/JobHandler.php14
-rw-r--r--tests/units/Base.php7
-rw-r--r--tests/units/Core/Action/ActionManagerTest.php40
6 files changed, 98 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index ff36e507..de8b69a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,4 @@
-Version 1.0.32 (unreleased)
+Version 1.0.32
--------------
New features:
@@ -17,6 +17,7 @@ New features:
Improvements:
+* Improve background worker and job handler
* New template hooks
* Removed individual column scrolling on board, columns use the height of all tasks
* Improve project page titles
diff --git a/app/Api/Procedure/TaskProcedure.php b/app/Api/Procedure/TaskProcedure.php
index 8661deef..59075b13 100644
--- a/app/Api/Procedure/TaskProcedure.php
+++ b/app/Api/Procedure/TaskProcedure.php
@@ -6,6 +6,7 @@ use Kanboard\Api\Authorization\ProjectAuthorization;
use Kanboard\Api\Authorization\TaskAuthorization;
use Kanboard\Filter\TaskProjectFilter;
use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskMetadataModel;
/**
* Task API controller
@@ -15,6 +16,30 @@ use Kanboard\Model\TaskModel;
*/
class TaskProcedure extends BaseProcedure
{
+ public function getTaskMetadata($task_id)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTask', $task_id);
+ return $this->taskMetadataModel->getAll($task_id);
+ }
+
+ public function getTaskMetadataByName($task_id, $name)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTask', $task_id);
+ return $this->taskMetadataModel->get($task_id, $name);
+ }
+
+ public function saveTaskMetadata($task_id, array $values)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTask', $task_id);
+ return $this->taskMetadataModel->save($task_id, $values);
+ }
+
+ public function removeTaskMetadata($task_id, $name)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTask', $task_id);
+ return $this->taskMetadataModel->remove($task_id, $name);
+ }
+
public function searchTasks($project_id, $query)
{
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'searchTasks', $project_id);
diff --git a/app/Core/Action/ActionManager.php b/app/Core/Action/ActionManager.php
index 1dfd820c..aec9ef02 100644
--- a/app/Core/Action/ActionManager.php
+++ b/app/Core/Action/ActionManager.php
@@ -139,4 +139,20 @@ class ActionManager extends Base
return $this;
}
+
+ /**
+ * Remove all listeners for automated actions
+ *
+ * @access public
+ */
+ public function removeEvents()
+ {
+ foreach ($this->dispatcher->getListeners() as $eventName => $listeners) {
+ foreach ($listeners as $listener) {
+ if (is_array($listener) && $listener[0] instanceof ActionBase) {
+ $this->dispatcher->removeListener($eventName, $listener);
+ }
+ }
+ }
+ }
}
diff --git a/app/Core/Queue/JobHandler.php b/app/Core/Queue/JobHandler.php
index 326f3cef..11c1fb69 100644
--- a/app/Core/Queue/JobHandler.php
+++ b/app/Core/Queue/JobHandler.php
@@ -43,8 +43,8 @@ class JobHandler extends Base
try {
$className = $payload['class'];
- $this->memoryCache->flush();
$this->prepareJobSession($payload['user_id']);
+ $this->prepareJobEnvironment();
if (DEBUG) {
$this->logger->debug(__METHOD__.' Received job => '.$className.' ('.getmypid().')');
@@ -75,4 +75,16 @@ class JobHandler extends Base
$this->userSession->initialize($user);
}
}
+
+ /**
+ * Flush in-memory caching and specific events
+ *
+ * @access protected
+ */
+ protected function prepareJobEnvironment()
+ {
+ $this->memoryCache->flush();
+ $this->actionManager->removeEvents();
+ $this->dispatcher->dispatch('app.bootstrap');
+ }
}
diff --git a/tests/units/Base.php b/tests/units/Base.php
index c471ee31..e44223ce 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -16,6 +16,11 @@ abstract class Base extends PHPUnit_Framework_TestCase
{
protected $container;
+ /**
+ * @var EventDispatcher
+ */
+ protected $dispatcher;
+
public function setUp()
{
date_default_timezone_set('UTC');
@@ -49,6 +54,8 @@ abstract class Base extends PHPUnit_Framework_TestCase
new Stopwatch
);
+ $this->dispatcher = $this->container['dispatcher'];
+
$this->container['db']->getStatementHandler()->withLogging();
$this->container['logger'] = new Logger();
diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php
index e7c2071f..4878c0c9 100644
--- a/tests/units/Core/Action/ActionManagerTest.php
+++ b/tests/units/Core/Action/ActionManagerTest.php
@@ -96,7 +96,7 @@ class ActionManagerTest extends Base
$actions = $actionManager->getAvailableActions();
$actionManager->attachEvents();
- $this->assertEmpty($this->container['dispatcher']->getListeners());
+ $this->assertEmpty($this->dispatcher->getListeners());
$this->assertEquals(1, $projectModel->create(array('name' =>'test')));
$this->assertEquals(1, $actionModel->create(array(
@@ -107,7 +107,7 @@ class ActionManagerTest extends Base
)));
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_CREATE);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
$this->assertCount(1, $listeners);
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
@@ -148,7 +148,7 @@ class ActionManagerTest extends Base
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN);
$this->assertCount(1, $listeners);
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
@@ -158,7 +158,6 @@ class ActionManagerTest extends Base
public function testThatEachListenerAreDifferentInstance()
{
$projectModel = new ProjectModel($this->container);
- $projectUserRoleModel = new ProjectUserRoleModel($this->container);
$actionModel = new ActionModel($this->container);
$actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
$actionManager = new ActionManager($this->container);
@@ -183,7 +182,7 @@ class ActionManagerTest extends Base
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN);
$this->assertCount(2, $listeners);
$this->assertFalse($listeners[0][0] === $listeners[1][0]);
@@ -193,4 +192,35 @@ class ActionManagerTest extends Base
$this->assertEquals(1, $listeners[1][0]->getParam('column_id'));
$this->assertEquals('red', $listeners[1][0]->getParam('color_id'));
}
+
+ public function testRemoveEvents()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
+ $actionManager = new ActionManager($this->container);
+ $actionManager->register($actionTaskAssignColorColumn);
+
+ $actions = $actionManager->getAvailableActions();
+
+ $this->assertEquals(1, $projectModel->create(array('name' =>'test')));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE,
+ 'action_name' => key($actions),
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $actionManager->attachEvents();
+ $this->dispatcher->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
+ $this->assertCount(2, $listeners);
+
+ $actionManager->removeEvents();
+
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
+ $this->assertCount(1, $listeners);
+ $this->assertNotInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0]);
+ }
}