diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index d9ad1111fc7..70f8d998f4b 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1724,26 +1724,32 @@ class Task extends CommonObjectLine $ret = -1; } - if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration)) { - // Recalculate amount of time spent for task and update denormalized field - $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; - $sql .= " SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX."projet_task_time as ptt where ptt.fk_task = ".((int) $this->id).")"; - if (isset($this->progress)) { - $sql .= ", progress = ".((float) $this->progress); // Do not overwrite value if not provided - } - $sql .= " WHERE rowid = ".((int) $this->id); + if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) || !empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM))) { - dol_syslog(get_class($this)."::updateTimeSpent", LOG_DEBUG); - if (!$this->db->query($sql)) { - $this->error = $this->db->lasterror(); - $this->db->rollback(); - $ret = -2; + if($this->timespent_old_duration != $this->timespent_duration) { + // Recalculate amount of time spent for task and update denormalized field + $sql = "UPDATE " . MAIN_DB_PREFIX . "projet_task"; + $sql .= " SET duration_effective = (SELECT SUM(task_duration) FROM " . MAIN_DB_PREFIX . "projet_task_time as ptt where ptt.fk_task = " . ((int)$this->id) . ")"; + if (isset($this->progress)) { + $sql .= ", progress = " . ((float)$this->progress); // Do not overwrite value if not provided + } + $sql .= " WHERE rowid = " . ((int)$this->id); + + dol_syslog(get_class($this) . "::updateTimeSpent", LOG_DEBUG); + if (!$this->db->query($sql)) { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + $ret = -2; + } } // Update hourly rate of this time spent entry, but only if it was not set initialy $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time"; $sql .= " SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".((int) $this->timespent_fk_user).")"; // set average hour rate of user - $sql .= " WHERE (thm IS NULL OR thm = 0) AND rowid = ".((int) $this->timespent_id); + $sql .= " WHERE rowid = ".((int) $this->timespent_id); + if(empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM)) { // then if not empty we always update, in case of new thm for user, or change user of task time line + $sql .= " AND (thm IS NULL OR thm = 0)"; + } dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG); if (!$this->db->query($sql)) {