summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Event/ProjectModificationDate.php3
-rw-r--r--app/Model/Project.php9
-rw-r--r--tests/units/ProjectTest.php45
3 files changed, 52 insertions, 5 deletions
diff --git a/app/Event/ProjectModificationDate.php b/app/Event/ProjectModificationDate.php
index d0d1e846..1b0b3736 100644
--- a/app/Event/ProjectModificationDate.php
+++ b/app/Event/ProjectModificationDate.php
@@ -55,8 +55,7 @@ class ProjectModificationDate implements Listener
public function execute(array $data)
{
if (isset($data['project_id'])) {
- $this->project->updateModificationDate($data['project_id']);
- return true;
+ return $this->project->updateModificationDate($data['project_id']);
}
return false;
diff --git a/app/Model/Project.php b/app/Model/Project.php
index f8df1ae1..3edd82c5 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -489,6 +489,7 @@ class Project extends Base
$this->db->startTransaction();
$values['token'] = '';
+ $values['last_modified'] = time();
if (! $this->db->table(self::TABLE)->save($values)) {
$this->db->cancelTransaction();
@@ -539,7 +540,7 @@ class Project extends Base
*/
public function updateModificationDate($project_id)
{
- return $this->db->table(self::TABLE)->eq('id', $project_id)->save(array(
+ return $this->db->table(self::TABLE)->eq('id', $project_id)->update(array(
'last_modified' => time()
));
}
@@ -730,10 +731,12 @@ class Project extends Base
public function attachEvents()
{
$events = array(
- Task::EVENT_UPDATE,
- Task::EVENT_CREATE,
+ Task::EVENT_CREATE_UPDATE,
Task::EVENT_CLOSE,
Task::EVENT_OPEN,
+ Task::EVENT_MOVE_COLUMN,
+ Task::EVENT_MOVE_POSITION,
+ Task::EVENT_ASSIGNEE_CHANGE,
);
$listener = new ProjectModificationDate($this);
diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php
index 95894172..dc71d5ae 100644
--- a/tests/units/ProjectTest.php
+++ b/tests/units/ProjectTest.php
@@ -20,9 +20,54 @@ class ProjectTest extends Base
$this->assertNotEmpty($project);
$this->assertEquals(1, $project['is_active']);
$this->assertEquals(0, $project['is_public']);
+ $this->assertEquals(time(), $project['last_modified']);
$this->assertEmpty($project['token']);
}
+ public function testUpdateLastModifiedDate()
+ {
+ $p = new Project($this->registry);
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+
+ $now = time();
+
+ $project = $p->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals($now, $project['last_modified']);
+
+ sleep(1);
+ $this->assertTrue($p->updateModificationDate(1));
+
+ $project = $p->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals($now + 1, $project['last_modified']);
+ }
+
+ public function testIsLastModified()
+ {
+ $p = new Project($this->registry);
+ $t = new Task($this->registry);
+
+ $now = time();
+ $p->attachEvents();
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+
+ $project = $p->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals($now, $project['last_modified']);
+
+ sleep(1);
+
+ $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertEquals('Event\ProjectModificationDate', $this->registry->shared('event')->getLastListenerExecuted());
+
+ $project = $p->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertTrue($p->isModifiedSince(1, $now));
+ }
+
public function testRemove()
{
$p = new Project($this->registry);