Implement correct project deletion
This commit is contained in:
@@ -78,7 +78,7 @@ class Projects extends MY_Controller {
|
|||||||
|
|
||||||
if ($this->upload->do_upload('defaultmodel')) {
|
if ($this->upload->do_upload('defaultmodel')) {
|
||||||
$default = $this->upload->data();
|
$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 {
|
} else {
|
||||||
$this->messages->add(_('The default model could not be uploaded.'), 'error');
|
$this->messages->add(_('The default model could not be uploaded.'), 'error');
|
||||||
}
|
}
|
||||||
@@ -118,16 +118,19 @@ class Projects extends MY_Controller {
|
|||||||
show_404();
|
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);
|
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');
|
$this->load->helper('typography');
|
||||||
|
|
||||||
$data['project'] = $project;
|
$data['project'] = $project;
|
||||||
$data['experiments'] = $this->experiment->getByProjectId($id);
|
$data['experiments'] = $this->experiment->getByProjectId($project['id']);
|
||||||
$data['jobs'] = $this->job->getRecent($id);
|
$data['jobs'] = $this->job->getRecent($project['id']);
|
||||||
$data['shares'] = $this->share->getByProjectId($id);
|
$data['shares'] = $this->share->getByProjectId($project['id']);
|
||||||
|
|
||||||
$this->load->view('projects/detail', $data);
|
$this->load->view('projects/detail', $data);
|
||||||
}
|
}
|
||||||
@@ -182,8 +185,16 @@ class Projects extends MY_Controller {
|
|||||||
* @param string $id
|
* @param string $id
|
||||||
*/
|
*/
|
||||||
public function delete($id) {
|
public function delete($id) {
|
||||||
if (!$this->_checkAccess($id)) { // check if the user has access
|
$project = $this->project->getById($id);
|
||||||
show_error(_("Sorry, you don't have access to this project."), 403);
|
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)) {
|
if ($this->project->delete($id)) {
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ class Project extends CI_Model {
|
|||||||
public function create($data) {
|
public function create($data) {
|
||||||
$this->load->helper(array('hash', 'date'));
|
$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['created'] = mysql_now();
|
||||||
$data['last_access'] = 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
|
* @param integer $projectId The ID of the project to delete
|
||||||
*/
|
*/
|
||||||
public function delete($projectId) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,15 @@
|
|||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
<td><span class="active"><?=_('Successfully finished');?></span></td>
|
<td><span class="active"><?=_('Successfully finished');?></span></td>
|
||||||
<td><a href="#"><?=_('Show results');?></a> | <?=anchor('projects/delete/' . $project['id'], _('Delete'));?>
|
<td>
|
||||||
|
<a href="#"><?=_('Show results');?></a>
|
||||||
|
<?php
|
||||||
|
if ($project['owner'] == $this->access->profile()->id):
|
||||||
|
?>
|
||||||
|
| <?=anchor('projects/delete/' . $project['id'], _('Delete'));?>
|
||||||
|
<?php
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
Reference in New Issue
Block a user