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 21, 2022
1 parent 187ddde commit 92e0b7a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
22 changes: 19 additions & 3 deletions model/dao/TaskDAO/PostgreSQLTaskDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected function setValues($row)
$taskVO->setPhase($row['phase']);
$taskVO->setUserId($row['usrid']);
$taskVO->setProjectId($row['projectid']);
$taskVO->setUpdatedAt($row['updated_at']);

return $taskVO;
}
Expand Down Expand Up @@ -699,7 +700,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 +900,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 +924,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
9 changes: 9 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,14 @@ public function getProjectId() {
return $this->projectId;
}

public function setUpdatedAt($updated_at) {
$this->updated_at = $updated_at ? new DateTime($updated_at) : NULL;
}

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

/**#@-*/

/**
Expand Down

0 comments on commit 92e0b7a

Please sign in to comment.