From e52bb347ab7bc22b5a92b038a7e76c6db7b50329 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Tue, 20 Sep 2011 23:55:57 +0200 Subject: [PATCH] Implement correct project deletion --- application/controllers/projects.php | 25 ++++++++++++++++++------- application/models/project.php | 15 +++++++++++++-- application/views/projects/list.php | 10 +++++++++- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/application/controllers/projects.php b/application/controllers/projects.php index a9077cc..d4dce7f 100644 --- a/application/controllers/projects.php +++ b/application/controllers/projects.php @@ -78,7 +78,7 @@ class Projects extends MY_Controller { if ($this->upload->do_upload('defaultmodel')) { $default = $this->upload->data(); - $this->project->update($data['project_id'], array('default_model' => $default['file_name'])); + $this->project->update(array('default_model' => $default['file_name']), $data['project_id']); } else { $this->messages->add(_('The default model could not be uploaded.'), 'error'); } @@ -118,16 +118,19 @@ class Projects extends MY_Controller { show_404(); } - if (!$this->_checkAccess($id)) { // check if the user has access + if (!$this->_checkAccess($project['id'])) { // check if the user has access show_error(_("Sorry, you don't have access to this project."), 403); } + // mark a shared project as seen + $this->share->markSeen($project['id']); + $this->load->helper('typography'); $data['project'] = $project; - $data['experiments'] = $this->experiment->getByProjectId($id); - $data['jobs'] = $this->job->getRecent($id); - $data['shares'] = $this->share->getByProjectId($id); + $data['experiments'] = $this->experiment->getByProjectId($project['id']); + $data['jobs'] = $this->job->getRecent($project['id']); + $data['shares'] = $this->share->getByProjectId($project['id']); $this->load->view('projects/detail', $data); } @@ -182,8 +185,16 @@ class Projects extends MY_Controller { * @param string $id */ public function delete($id) { - if (!$this->_checkAccess($id)) { // check if the user has access - show_error(_("Sorry, you don't have access to this project."), 403); + $project = $this->project->getById($id); + if (!$project || $project['owner'] != $this->session->userdata('user_id')) { + show_404(); + } + + $this->load->helper('file'); + + $projectPath = FCPATH . 'uploads/' . $id; + if (delete_files($projectPath, true)) { + rmdir($projectPath); } if ($this->project->delete($id)) { diff --git a/application/models/project.php b/application/models/project.php index a2d7d3e..1ebd204 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -190,7 +190,7 @@ class Project extends CI_Model { public function create($data) { $this->load->helper(array('hash', 'date')); - $data['owner'] = '215cd70f310ae6ae'; //$this->session->userdata('user_id'); + $data['owner'] = $this->session->userdata('user_id'); $data['created'] = mysql_now(); $data['last_access'] = mysql_now(); @@ -225,7 +225,18 @@ class Project extends CI_Model { * @param integer $projectId The ID of the project to delete */ public function delete($projectId) { - return $this->db->delete('projects', array('id' => $projectId)); + $this->db->delete('shares', array('project_id' => $projectId)); + + $experiments = $this->db->get_where('experiments', array('project_id' => $projectId))->result_array(); + foreach ($experiments as $experiment) { + $this->db->delete('experiments_parameters', array('experiment_id' => $experiment['id'])); + $this->db->delete('jobs', array('experiment_id' => $experiment['id'])); + $this->db->delete('experiments', array('id' => $experiment['id'])); + } + + $this->db->delete('projects', array('id' => $projectId)); + + return $this->db->affected_rows() > 0; } } diff --git a/application/views/projects/list.php b/application/views/projects/list.php index 532dbc9..1b29dc4 100644 --- a/application/views/projects/list.php +++ b/application/views/projects/list.php @@ -37,7 +37,15 @@ ?> - | + + +access->profile()->id): +?> + | +