public function runUpload(framework\Request $request) { $apc_exists = framework\Request::CanGetUploadStatus(); if ($apc_exists && !$request['APC_UPLOAD_PROGRESS']) { $request->setParameter('APC_UPLOAD_PROGRESS', $request['upload_id']); } $this->getResponse()->setDecoration(\thebuggenie\core\framework\Response::DECORATE_NONE); $canupload = false; if ($request['mode'] == 'issue') { $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']); $canupload = (bool) ($issue instanceof entities\Issue && $issue->hasAccess() && $issue->canAttachFiles()); } elseif ($request['mode'] == 'article') { $article = \thebuggenie\modules\publish\entities\Article::getByID($request['article_id']); $canupload = (bool) ($article instanceof \thebuggenie\modules\publish\entities\Article && $article->canEdit()); } else { $event = \thebuggenie\core\framework\Event::createNew('core', 'upload', $request['mode']); $event->triggerUntilProcessed(); $canupload = $event->isProcessed() ? (bool) $event->getReturnValue() : true; } if ($canupload) { try { $file = framework\Context::getRequest()->handleUpload('uploader_file'); if ($file instanceof entities\File) { switch ($request['mode']) { case 'issue': if (!$issue instanceof entities\Issue) { break; } $issue->attachFile($file, $request->getRawParameter('comment'), $request['uploader_file_description']); $issue->save(); break; case 'article': if (!$article instanceof \thebuggenie\modules\publish\entities\Article) { break; } $article->attachFile($file); break; } if ($apc_exists) { return $this->renderText('ok'); } } $this->error = framework\Context::getI18n()->__('An unhandled error occured with the upload'); } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); $this->error = $e->getMessage(); } } else { $this->error = framework\Context::getI18n()->__('You are not allowed to attach files here'); } if (!$apc_exists) { switch ($request['mode']) { case 'issue': if (!$issue instanceof entities\Issue) { break; } $this->forward(framework\Context::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo()))); break; case 'article': if (!$article instanceof \thebuggenie\modules\publish\entities\Article) { break; } $this->forward(framework\Context::getRouting()->generate('publish_article_attachments', array('article_id' => $article->getID()))); break; } } framework\Logging::log('marking upload ' . $request['APC_UPLOAD_PROGRESS'] . ' as completed with error ' . $this->error); $request->markUploadAsFinishedWithError($request['APC_UPLOAD_PROGRESS'], $this->error); return $this->renderText($request['APC_UPLOAD_PROGRESS'] . ': ' . $this->error); }