summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2018-04-27 14:32:58 -0700
committerFrédéric Guillot <fred@kanboard.net>2018-04-27 14:32:58 -0700
commit2d2b50d5dca7afa8523685a682a2dcc78b602ce2 (patch)
treea77d5a9c819b754bde645256898ebf4a546da3f6 /app/Model
parentbb406d57b1c1ad2736774be18b2f7b4d31abcf63 (diff)
Remove all attachments when removing a project
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/ProjectModel.php22
1 files changed, 17 insertions, 5 deletions
diff --git a/app/Model/ProjectModel.php b/app/Model/ProjectModel.php
index 097806d8..40e92de6 100644
--- a/app/Model/ProjectModel.php
+++ b/app/Model/ProjectModel.php
@@ -5,6 +5,8 @@ namespace Kanboard\Model;
use Kanboard\Core\Base;
use Kanboard\Core\Security\Token;
use Kanboard\Core\Security\Role;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskFileModel;
/**
* Project model
@@ -470,13 +472,23 @@ class ProjectModel extends Base
*/
public function remove($project_id)
{
- $this->db->startTransaction();
+ // Remove all project attachments
+ $this->projectFileModel->removeAll($project_id);
+
+ // Remove all task attachments
+ $file_ids = $this->db
+ ->table(TaskFileModel::TABLE)
+ ->eq(TaskModel::TABLE.'.project_id', $project_id)
+ ->join(TaskModel::TABLE, 'id', 'task_id', TaskFileModel::TABLE)
+ ->findAllByColumn(TaskFileModel::TABLE.'.id');
+
+ foreach ($file_ids as $file_id) {
+ $this->taskFileModel->remove($file_id);
+ }
+ // Remove project
$this->db->table(TagModel::TABLE)->eq('project_id', $project_id)->remove();
- $result = $this->db->table(self::TABLE)->eq('id', $project_id)->remove();
-
- $this->db->closeTransaction();
- return $result;
+ return $this->db->table(self::TABLE)->eq('id', $project_id)->remove();
}
/**