/** * @see ProjectInterface::delete() * @return bool * @throws ProjectDeleteException * @throws ProjectDeleteContainsSubProjectsException * @throws ProjectDeleteFolderException * @throws ProjectDeleteItemException * @throws ProjectDeleteLinkException * @throws ProjectDeleteLogException * @throws ProjectDeletePermissionException * @throws ProjectDeleteStatusException * @throws ProjectDeleteTaskException */ public function delete() { global $transaction; if ($this->project_id) { $transaction_id = $transaction->begin(); array_push(self::$project_delete_array, $this->project_id); if ($this->exist_subproject() == true) { if ($transaction_id != null) { $transaction->rollback($transaction_id); throw new ProjectDeleteContainsSubProjectsException(); } } $tmp_project_id = $this->project_id; // Permissions $project_permission_array = ProjectPermission::list_entries_by_project_id($tmp_project_id); if (is_array($project_permission_array) and count($project_permission_array) >= 1) { foreach ($project_permission_array as $key => $value) { try { $project_permission = ProjectPermission::get_instance($value); $project_permission->delete(); } catch (ProjectPermissionException $e) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeletePermissionException(); } } } // Log Entries $project_log_array = ProjectLog::list_entries_by_project_id($tmp_project_id); if (is_array($project_log_array) and count($project_log_array) >= 1) { foreach ($project_log_array as $key => $value) { $project_log = new ProjectLog($value); try { $project_log->delete(); } catch (ProjectLogDeleteException $e) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeleteLogException(); } } } // Project Status $project_has_project_status_array = ProjectHasProjectStatus_Access::list_entries_by_project_id($tmp_project_id); if (is_array($project_has_project_status_array) and count($project_has_project_status_array) >= 1) { foreach ($project_has_project_status_array as $key => $value) { $project_has_project_status = new ProjectHasProjectStatus_Access($value); try { $project_has_project_status->delete(); } catch (ProjectStatusDeleteException $e) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeleteStatusException(); } } } // Project Links $project_link_array = ProjectLink_Access::list_entries_by_project_id($tmp_project_id); if (is_array($project_link_array) and count($project_link_array) >= 1) { foreach ($project_link_array as $key => $value) { $project_link = new ProjectLink_Access($value); if ($project_link->delete() == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeleteLinkException(); } } } // Linked Items $project_item = new ProjectItem($tmp_project_id); $item_array = $project_item->get_project_items(); if (is_array($item_array) and count($item_array) >= 1) { foreach ($item_array as $item_key => $item_value) { $project_item = new ProjectItem($tmp_project_id); $project_item->set_item_id($item_value); if ($project_item->unlink_item() == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeleteItemException(); } } } // Project Tasks $project_task_array = ProjectTask::list_tasks($tmp_project_id); if (is_array($project_task_array) and count($project_task_array) >= 1) { foreach ($project_task_array as $key => $value) { $project_task = new ProjectTask($value); if ($project_task->delete() == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeleteTaskException(); } } } // Extension Links if (ProjectHasExtensionRun_Access::delete_by_project_id($tmp_project_id) == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeleteException("Extension delete failed"); } // Project DB Entry if ($this->project->delete() == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeleteException("Database delete failed"); } else { $this->__destruct(); $project_folder_id = ProjectFolder::get_folder_by_project_id($tmp_project_id); $project_folder = new ProjectFolder($project_folder_id); if ($project_folder->delete(true, true) == false) { if ($transaction_id != null) { $transaction->rollback($transaction_id); } throw new ProjectDeleteFolderException(); } else { if ($transaction_id != null) { $transaction->commit($transaction_id); } return true; } } } else { throw new ProjectDeleteException("Project ID was missing."); } }
$_GET["projecttasks_id"] = ""; } $task = new ProjectTask(); if (isset($_POST["add"])) { $task->check(-1, CREATE, $_POST); $newID = $task->add($_POST); Event::log($task->fields['projects_id'], 'project', 4, "maintain", sprintf(__('%s adds a task'), $_SESSION["glpiname"])); if ($_SESSION['glpibackcreated']) { Html::redirect($task->getFormURL() . "?id=" . $newID); } else { Html::redirect(Project::getFormURL() . "?projects_id=" . $task->fields['projects_id']); } } else { if (isset($_POST["purge"])) { $task->check($_POST['id'], PURGE); $task->delete($_POST, 1); Event::log($task->fields['projects_id'], 'project', 4, "maintain", sprintf(__('%s purges a task'), $_SESSION["glpiname"])); Html::redirect(Project::getFormURL() . "?id=" . $task->fields['projects_id']); } else { if (isset($_POST["update"])) { $task->check($_POST["id"], UPDATE); $task->update($_POST); Event::log($task->fields['projects_id'], 'project', 4, "maintain", sprintf(__('%s updates a task'), $_SESSION["glpiname"])); Html::back(); } else { Html::header(ProjectTask::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "tools", "project"); $task->display($_GET); Html::footer(); } } }
/** * @throws ProjectTaskIDMissingException * @throws ProjectSecuriyAccessDeniedException */ public static function delete() { global $project_security; if ($_GET['id']) { if ($project_security->is_access(3, false) == true) { if ($_GET['sure'] != "true") { $template = new HTMLTemplate("project/tasks/delete.html"); $paramquery = $_GET; $paramquery['sure'] = "true"; $params = http_build_query($paramquery); $template->set_var("yes_params", $params); $paramquery = $_GET; unset($paramquery['nextpage']); $paramquery['run'] = "task_detail"; $params = http_build_query($paramquery); $template->set_var("no_params", $params); $template->output(); } else { $paramquery = $_GET; unset($paramquery['nextpage']); unset($paramquery['id']); unset($paramquery['sure']); $paramquery['run'] = "show_tasks"; $params = http_build_query($paramquery); $project_task = new ProjectTask($_GET['id']); if ($project_task->delete()) { Common_IO::step_proceed($params, "Delete Project Task", "Operation Successful", null); } else { Common_IO::step_proceed($params, "Delete Project Task", "Operation Failed", null); } } } else { throw new ProjectSecuriyAccessDeniedException(); } } else { throw new ProjectTaskIDMissingException(); } }