diff options
| author | Teamjungla{CODE} <junglacode@gmail.com> | 2016-08-20 13:47:12 -0500 | 
|---|---|---|
| committer | Teamjungla{CODE} <junglacode@gmail.com> | 2016-08-20 13:47:12 -0500 | 
| commit | fe8e9cdcfe3afc1475c7e7f4392d2b2cc601a12b (patch) | |
| tree | 001403874e9e3716de7c6d51a9f536e9b3c3be5e /app/Model/TaskModificationModel.php | |
| parent | b1e795fc5b45369f7b9b565b1e106d2673361977 (diff) | |
| parent | 98efcf21e355ed6ac3827058b99df86ca67c75bb (diff) | |
Merge branch 'stable' of https://github.com/kanboard/kanboard
Diffstat (limited to 'app/Model/TaskModificationModel.php')
| -rw-r--r-- | app/Model/TaskModificationModel.php | 82 | 
1 files changed, 55 insertions, 27 deletions
| diff --git a/app/Model/TaskModificationModel.php b/app/Model/TaskModificationModel.php index 762af2c5..16b48f3d 100644 --- a/app/Model/TaskModificationModel.php +++ b/app/Model/TaskModificationModel.php @@ -3,7 +3,6 @@  namespace Kanboard\Model;  use Kanboard\Core\Base; -use Kanboard\Event\TaskEvent;  /**   * Task Modification @@ -23,13 +22,14 @@ class TaskModificationModel extends Base       */      public function update(array $values, $fire_events = true)      { -        $original_task = $this->taskFinderModel->getById($values['id']); +        $task = $this->taskFinderModel->getById($values['id']); +        $this->updateTags($values, $task);          $this->prepare($values); -        $result = $this->db->table(TaskModel::TABLE)->eq('id', $original_task['id'])->update($values); +        $result = $this->db->table(TaskModel::TABLE)->eq('id', $task['id'])->update($values);          if ($fire_events && $result) { -            $this->fireEvents($original_task, $values); +            $this->fireEvents($task, $values);          }          return $result; @@ -38,52 +38,65 @@ class TaskModificationModel extends Base      /**       * Fire events       * -     * @access public -     * @param  array     $task -     * @param  array     $new_values +     * @access protected +     * @param  array $task +     * @param  array $changes       */ -    public function fireEvents(array $task, array $new_values) +    protected function fireEvents(array $task, array $changes)      {          $events = array(); -        $event_data = array_merge($task, $new_values, array('task_id' => $task['id'])); - -        // Values changed -        $event_data['changes'] = array_diff_assoc($new_values, $task); -        unset($event_data['changes']['date_modification']); -        if ($this->isFieldModified('owner_id', $event_data['changes'])) { +        if ($this->isAssigneeChanged($task, $changes)) {              $events[] = TaskModel::EVENT_ASSIGNEE_CHANGE; -        } elseif (! empty($event_data['changes'])) { +        } elseif ($this->isModified($task, $changes)) {              $events[] = TaskModel::EVENT_CREATE_UPDATE;              $events[] = TaskModel::EVENT_UPDATE;          } -        foreach ($events as $event) { -            $this->logger->debug('Event fired: '.$event); -            $this->dispatcher->dispatch($event, new TaskEvent($event_data)); +        if (! empty($events)) { +            $this->queueManager->push($this->taskEventJob +                ->withParams($task['id'], $events, $changes, array(), $task) +            );          }      }      /** +     * Return true if the task have been modified +     * +     * @access protected +     * @param  array $task +     * @param  array $changes +     * @return bool +     */ +    protected function isModified(array $task, array $changes) +    { +        $diff = array_diff_assoc($changes, $task); +        unset($diff['date_modification']); +        return count($diff) > 0; +    } + +    /**       * Return true if the field is the only modified value       * -     * @access public -     * @param  string  $field -     * @param  array   $changes -     * @return boolean +     * @access protected +     * @param  array  $task +     * @param  array  $changes +     * @return bool       */ -    public function isFieldModified($field, array $changes) +    protected function isAssigneeChanged(array $task, array $changes)      { -        return isset($changes[$field]) && count($changes) === 1; +        $diff = array_diff_assoc($changes, $task); +        unset($diff['date_modification']); +        return isset($changes['owner_id']) && $task['owner_id'] != $changes['owner_id'] && count($diff) === 1;      }      /**       * Prepare data before task modification       * -     * @access public -     * @param  array    $values    Form values +     * @access protected +     * @param  array  $values       */ -    public function prepare(array &$values) +    protected function prepare(array &$values)      {          $values = $this->dateParser->convert($values, array('date_due'));          $values = $this->dateParser->convert($values, array('date_started'), true); @@ -94,4 +107,19 @@ class TaskModificationModel extends Base          $values['date_modification'] = time();      } + +    /** +     * Update tags +     * +     * @access protected +     * @param  array  $values +     * @param  array  $original_task +     */ +    protected function updateTags(array &$values, array $original_task) +    { +        if (isset($values['tags'])) { +            $this->taskTagModel->save($original_task['project_id'], $values['id'], $values['tags']); +            unset($values['tags']); +        } +    }  } | 
