Make sure that files are removed when a task is deleted
This commit is contained in:
@@ -54,6 +54,22 @@ class File extends Base
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all files for a given task
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $task_id Task id
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function removeAll($task_id)
|
||||||
|
{
|
||||||
|
$files = $this->getAll($task_id);
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$this->remove($file['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a file entry in the database
|
* Create a file entry in the database
|
||||||
*
|
*
|
||||||
@@ -144,6 +160,7 @@ class File extends Base
|
|||||||
public function upload($project_id, $task_id, $form_name)
|
public function upload($project_id, $task_id, $form_name)
|
||||||
{
|
{
|
||||||
$this->setup();
|
$this->setup();
|
||||||
|
$result = array();
|
||||||
|
|
||||||
if (! empty($_FILES[$form_name])) {
|
if (! empty($_FILES[$form_name])) {
|
||||||
|
|
||||||
@@ -159,7 +176,7 @@ class File extends Base
|
|||||||
|
|
||||||
if (@move_uploaded_file($uploaded_filename, self::BASE_PATH.$destination_filename)) {
|
if (@move_uploaded_file($uploaded_filename, self::BASE_PATH.$destination_filename)) {
|
||||||
|
|
||||||
return $this->create(
|
$result[] = $this->create(
|
||||||
$task_id,
|
$task_id,
|
||||||
$original_filename,
|
$original_filename,
|
||||||
$destination_filename,
|
$destination_filename,
|
||||||
@@ -169,5 +186,7 @@ class File extends Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return count(array_unique($result)) === 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -441,6 +441,9 @@ class Task extends Base
|
|||||||
*/
|
*/
|
||||||
public function remove($task_id)
|
public function remove($task_id)
|
||||||
{
|
{
|
||||||
|
$file = new File($this->db, $this->event);
|
||||||
|
$file->removeAll($task_id);
|
||||||
|
|
||||||
return $this->db->table(self::TABLE)->eq('id', $task_id)->remove();
|
return $this->db->table(self::TABLE)->eq('id', $task_id)->remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user