Fix bug: avoid the creation of multiple subtask timer for the same task and user
This commit is contained in:
@@ -13,6 +13,7 @@ Official website: <http://kanboard.net>
|
|||||||
- Super simple installation
|
- Super simple installation
|
||||||
- Translated in 19 languages
|
- Translated in 19 languages
|
||||||
- [List of features are available on the website](http://kanboard.net/features)
|
- [List of features are available on the website](http://kanboard.net/features)
|
||||||
|
- [ChangeLog](ChangeLog)
|
||||||
|
|
||||||
[](https://travis-ci.org/fguillot/kanboard)
|
[](https://travis-ci.org/fguillot/kanboard)
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class SubtaskTimeTracking extends Base
|
|||||||
public function getTimerQuery($user_id)
|
public function getTimerQuery($user_id)
|
||||||
{
|
{
|
||||||
return sprintf(
|
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('start'),
|
||||||
$this->db->escapeIdentifier(self::TABLE),
|
$this->db->escapeIdentifier(self::TABLE),
|
||||||
$this->db->escapeIdentifier('user_id'),
|
$this->db->escapeIdentifier('user_id'),
|
||||||
@@ -226,6 +226,19 @@ class SubtaskTimeTracking extends Base
|
|||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Log start time
|
||||||
*
|
*
|
||||||
@@ -236,9 +249,11 @@ class SubtaskTimeTracking extends Base
|
|||||||
*/
|
*/
|
||||||
public function logStartTime($subtask_id, $user_id)
|
public function logStartTime($subtask_id, $user_id)
|
||||||
{
|
{
|
||||||
return $this->db
|
return
|
||||||
->table(self::TABLE)
|
! $this->hasTimer($subtask_id, $user_id) &&
|
||||||
->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time(), 'end' => 0));
|
$this->db
|
||||||
|
->table(self::TABLE)
|
||||||
|
->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time(), 'end' => 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,6 +13,25 @@ use Core\Session;
|
|||||||
|
|
||||||
class SubtaskTimeTrackingTest extends Base
|
class SubtaskTimeTrackingTest extends Base
|
||||||
{
|
{
|
||||||
|
public function testHasTimer()
|
||||||
|
{
|
||||||
|
$tc = new TaskCreation($this->container);
|
||||||
|
$s = new Subtask($this->container);
|
||||||
|
$st = new SubtaskTimeTracking($this->container);
|
||||||
|
$p = new Project($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||||
|
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||||
|
$this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
|
||||||
|
|
||||||
|
$this->assertFalse($st->hasTimer(1, 1));
|
||||||
|
$this->assertTrue($st->logStartTime(1, 1));
|
||||||
|
$this->assertTrue($st->hasTimer(1, 1));
|
||||||
|
$this->assertFalse($st->logStartTime(1, 1));
|
||||||
|
$this->assertTrue($st->logEndTime(1, 1));
|
||||||
|
$this->assertFalse($st->hasTimer(1, 1));
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetTimerStatus()
|
public function testGetTimerStatus()
|
||||||
{
|
{
|
||||||
$tc = new TaskCreation($this->container);
|
$tc = new TaskCreation($this->container);
|
||||||
|
|||||||
Reference in New Issue
Block a user