summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-07-25 17:07:07 -0400
committerFrederic Guillot <fred@kanboard.net>2015-07-25 17:07:07 -0400
commit7f33cf6ef5f3fbe576c3d56813447eed91de75bd (patch)
tree71e8a9ea45ccd5a67ce36126f39bb4f41fd87137 /app/Model
parentc5481618a723599dea8f0686d2714a842e5ebb45 (diff)
Fix bug: avoid the creation of multiple subtask timer for the same task and user
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/SubtaskTimeTracking.php23
1 files changed, 19 insertions, 4 deletions
diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php
index 51743198..9f17ee3f 100644
--- a/app/Model/SubtaskTimeTracking.php
+++ b/app/Model/SubtaskTimeTracking.php
@@ -29,7 +29,7 @@ class SubtaskTimeTracking extends Base
public function getTimerQuery($user_id)
{
return sprintf(
- "SELECT %s FROM %s WHERE %s='%d' AND %s='0' AND %s=%s",
+ "SELECT %s FROM %s WHERE %s='%d' AND %s='0' AND %s=%s LIMIT 1",
$this->db->escapeIdentifier('start'),
$this->db->escapeIdentifier(self::TABLE),
$this->db->escapeIdentifier('user_id'),
@@ -227,6 +227,19 @@ class SubtaskTimeTracking extends Base
}
/**
+ * Return true if a timer is started for this use and subtask
+ *
+ * @access public
+ * @param integer $subtask_id
+ * @param integer $user_id
+ * @return boolean
+ */
+ public function hasTimer($subtask_id, $user_id)
+ {
+ return $this->db->table(self::TABLE)->eq('subtask_id', $subtask_id)->eq('user_id', $user_id)->eq('end', 0)->exists();
+ }
+
+ /**
* Log start time
*
* @access public
@@ -236,9 +249,11 @@ class SubtaskTimeTracking extends Base
*/
public function logStartTime($subtask_id, $user_id)
{
- return $this->db
- ->table(self::TABLE)
- ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time(), 'end' => 0));
+ return
+ ! $this->hasTimer($subtask_id, $user_id) &&
+ $this->db
+ ->table(self::TABLE)
+ ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time(), 'end' => 0));
}
/**