Skip to content

Commit

Permalink
Start storing when a user update a task
Browse files Browse the repository at this point in the history
Whenever a task is created or updated, save the current moment
in the updated_at column.
  • Loading branch information
anarute committed Jun 9, 2022
1 parent e6fbf57 commit 2f7834d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
21 changes: 18 additions & 3 deletions model/dao/TaskDAO/PostgreSQLTaskDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public function partialUpdate(DirtyTaskVO $taskVO) {
if ($last == (strlen($sql) - 2))
$sql = substr($sql, 0, -2);

$sql = $sql . " WHERE id=".$taskVO->getId();
$sql = $sql . ", updated_at=now() WHERE id=".$taskVO->getId();

$res = pg_query($this->connect, $sql);
if ($res == NULL) throw new SQLQueryErrorException(pg_last_error());
Expand Down Expand Up @@ -899,7 +899,20 @@ public function update(TaskVO $taskVO) {
public function create(TaskVO $taskVO) {
$affectedRows = 0;

$sql = "INSERT INTO task (_date, init, _end, story, telework, onsite, text, ttype, phase, usrid, projectid) VALUES(" .
$sql = "INSERT INTO task (" .
"_date, " .
"init, " .
"_end, " .
"story, " .
"telework, " .
"onsite, " .
"text, " .
"ttype, " .
"phase, " .
"usrid, " .
"projectid, " .
"updated_at " .
") VALUES(" .
DBPostgres::formatDate($taskVO->getDate()) . ", " .
DBPostgres::checkNull($taskVO->getInit()) . ", " .
DBPostgres::checkNull($taskVO->getEnd()) . ", " .
Expand All @@ -910,7 +923,9 @@ public function create(TaskVO $taskVO) {
DBPostgres::checkStringNull($taskVO->getTtype()) . ", " .
DBPostgres::checkStringNull($taskVO->getPhase()) . ", " .
DBPostgres::checkNull($taskVO->getUserId()) . ", " .
DBPostgres::checkNull($taskVO->getProjectId()) . ")";
DBPostgres::checkNull($taskVO->getProjectId()) . ", " .
"now()" .
")" ;

$res = pg_query($this->connect, $sql);

Expand Down
12 changes: 12 additions & 0 deletions model/vo/TaskVO.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TaskVO {
protected $phase = NULL;
protected $userId = NULL;
protected $projectId = NULL;
protected $updated_at = NULL;

public function setId($id) {
if (is_null($id))
Expand Down Expand Up @@ -178,6 +179,17 @@ public function getProjectId() {
return $this->projectId;
}

public function setUpdatedAt($updated_at) {
if (is_null($updated_at))
$this->updated_at = $updated_at;
else
$this->updated_at = (int) $updated_at;
}

public function getUpdatedAt() {
return $this->updated_at;
}

/**#@-*/

/**
Expand Down

0 comments on commit 2f7834d

Please sign in to comment.