diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-05-25 18:27:18 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-05-25 18:27:18 -0400 |
commit | dbc4443bb18ab2f588b5f8e2f6dbec4332a46660 (patch) | |
tree | dd4f2e7c69120697f43afe259746a12981ed228f /app/Model/File.php | |
parent | b6c4c93fe7a8a86f9c2aca6a388cb897c6a968c5 (diff) |
Make sure that files are removed when a task is deleted
Diffstat (limited to 'app/Model/File.php')
-rw-r--r-- | app/Model/File.php | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/app/Model/File.php b/app/Model/File.php index 70b87b1b..e5aa527e 100644 --- a/app/Model/File.php +++ b/app/Model/File.php @@ -55,6 +55,22 @@ class File extends Base } /** + * 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 * * @access public @@ -144,6 +160,7 @@ class File extends Base public function upload($project_id, $task_id, $form_name) { $this->setup(); + $result = array(); if (! empty($_FILES[$form_name])) { @@ -159,7 +176,7 @@ class File extends Base if (@move_uploaded_file($uploaded_filename, self::BASE_PATH.$destination_filename)) { - return $this->create( + $result[] = $this->create( $task_id, $original_filename, $destination_filename, @@ -169,5 +186,7 @@ class File extends Base } } } + + return count(array_unique($result)) === 1; } } |