示例#1
0
 public function testCleanup()
 {
     $e = new TaskHistory($this->registry);
     $t = new Task($this->registry);
     $p = new Project($this->registry);
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1)));
     $max = 15;
     $nb_events = 100;
     for ($i = 0; $i < $nb_events; $i++) {
         $this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE));
     }
     $this->assertEquals($nb_events, $this->registry->db->table('task_has_events')->count());
     $e->cleanup($max);
     $events = $e->getAllByProjectId(1);
     $this->assertNotEmpty($events);
     $this->assertTrue(is_array($events));
     $this->assertEquals($max, count($events));
     $this->assertEquals(100, $events[0]['id']);
     $this->assertEquals(99, $events[1]['id']);
     $this->assertEquals(86, $events[14]['id']);
     // Cleanup during task creation
     $nb_events = TaskHistory::MAX_EVENTS + 10;
     for ($i = 0; $i < $nb_events; $i++) {
         $this->assertTrue($e->create(1, 1, 1, Task::EVENT_CLOSE));
     }
     $this->assertEquals(TaskHistory::MAX_EVENTS, $this->registry->db->table('task_has_events')->count());
 }
 /**
  * Execute the action
  *
  * @access public
  * @param  array   $data   Event data dictionary
  * @return bool            True if the action was executed or false when not executed
  */
 public function execute(array $data)
 {
     $creator_id = $this->model->acl->getUserId();
     if ($creator_id && isset($data['task_id']) && isset($data['project_id'])) {
         $this->model->create($data['project_id'], $data['task_id'], $creator_id, $this->model->event->getLastTriggeredEvent());
     }
     return false;
 }