Skip to content

Commit a2a96ce

Browse files
committed
Prevent calling task create without overlap check.
We make the DAO operation that creates tasks without checking overlapping private, and add a public create operation that does check that. Add internal operation for task create.
1 parent 0aeaf6e commit a2a96ce

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

model/dao/TaskDAO/PostgreSQLTaskDAO.php

+26-5
Original file line numberDiff line numberDiff line change
@@ -839,16 +839,28 @@ private function checkOverlappingTasks($tasks) {
839839
*
840840
* This function creates a new row for a Task by its {@link TaskVO}.
841841
* The internal id of <var>$taskVO</var> will be set after its creation.
842-
* WARNING: it doesn't check if task overlaps with other tasks, because that
843-
* would be very expensive to do for every task. TaskDAO::batchCreate should
844-
* be used for that purpose.
845-
* TODO: consider making private.
846842
*
847843
* @param TaskVO $taskVO the {@link TaskVO} with the data we want to insert on database.
848844
* @return int the number of rows that have been affected (it should be 1).
849845
* @throws {@link SQLQueryErrorException}, {@link SQLUniqueViolationException}
850846
*/
851847
public function create(TaskVO $taskVO) {
848+
$tasks = array($taskVO);
849+
return $this->batchCreate($tasks);
850+
}
851+
852+
/** Task creator for PostgreSQL.
853+
*
854+
* This function creates a new row for a Task by its {@link TaskVO}.
855+
* The internal id of <var>$taskVO</var> will be set after its creation.
856+
* WARNING: it doesn't check if task overlaps with other tasks.
857+
* TaskDAO::create and TaskDAO::batchCreate should be used for that purpose.
858+
*
859+
* @param TaskVO $taskVO the {@link TaskVO} with the data we want to insert on database.
860+
* @return int the number of rows that have been affected (it should be 1).
861+
* @throws {@link SQLQueryErrorException}, {@link SQLUniqueViolationException}
862+
*/
863+
private function createInternal(TaskVO $taskVO) {
852864
$affectedRows = 0;
853865

854866
$sql = "INSERT INTO task (" .
@@ -894,6 +906,15 @@ public function create(TaskVO $taskVO) {
894906

895907
}
896908

909+
/** Task batch creator.
910+
*
911+
* Equivalent to {@see create} for arrays of tasks.
912+
*
913+
* @param array $tasks array of {@link TaskVO} objects to be created.
914+
* @return int the number of rows that have been affected (it should be
915+
* equal to the size of $tasks).
916+
* @throws {@link SQLQueryErrorException}
917+
*/
897918
public function batchCreate($tasks) {
898919
if (!$this->checkOverlappingWithDBTasks($tasks)) {
899920
return 0;
@@ -902,7 +923,7 @@ public function batchCreate($tasks) {
902923
$affectedRows = 0;
903924

904925
foreach ($tasks as $task) {
905-
$affectedRows += $this->create($task);
926+
$affectedRows += $this->createInternal($task);
906927
}
907928

908929
return $affectedRows;

0 commit comments

Comments
 (0)