public function runDetachFile(framework\Request $request) { try { $file = entities\File::getB2DBTable()->selectById((int) $request['file_id']); switch ($request['mode']) { case 'issue': $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']); if ($issue instanceof entities\Issue && $issue->canRemoveAttachments() && (int) $request->getParameter('file_id', 0)) { $issue->detachFile($file); return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($issue->getFiles()) + count($issue->getLinks()), 'message' => framework\Context::getI18n()->__('The attachment has been removed'))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You can not remove items from this issue'))); case 'article': $article = \thebuggenie\modules\publish\entities\Article::getByID($request['article_id']); if ($article instanceof \thebuggenie\modules\publish\entities\Article && $article->canEdit() && (int) $request->getParameter('file_id', 0)) { $article->detachFile($file); return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($article->getFiles()), 'message' => framework\Context::getI18n()->__('The attachment has been removed'))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You can not remove items from this issue'))); } } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $this->getI18n()->__('An error occurred when removing the file'))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Invalid mode'))); }
public function componentAttachedfile() { if ($this->mode == 'issue' && !isset($this->issue)) { $this->issue = entities\Issue::getB2DBTable()->selectById($this->issue_id); } elseif ($this->mode == 'article' && !isset($this->article)) { $this->article = \thebuggenie\modules\publish\entities\Article::getByID($this->article_id); } $this->file_id = $this->file->getID(); }