コード例 #1
0
ファイル: Files.php プロジェクト: nrensen/thebuggenie
 public function getUnattachedFiles()
 {
     $crit = $this->getCriteria();
     $crit->addSelectionColumn(self::ID, 'id');
     $res = $this->doSelect($crit);
     $file_ids = [];
     if ($res) {
         while ($row = $res->getNextRow()) {
             $file_ids[$row['id']] = $row['id'];
         }
     }
     $file_ids = array_diff($file_ids, IssueFiles::getTable()->getLinkedFileIds($file_ids));
     $event = framework\Event::createNew('core', 'thebuggenie\\core\\entities\\tables\\Files::getUnattachedFiles', $this, ['file_ids' => $file_ids], []);
     $event->trigger();
     if ($event->isProcessed()) {
         foreach ($event->getReturnList() as $linked_file_ids) {
             $file_ids = array_diff($file_ids, $linked_file_ids);
         }
     }
     $system_file_ids = Settings::getTable()->getFileIds();
     $file_ids = array_diff($file_ids, $system_file_ids);
     $project_file_ids = Projects::getTable()->getFileIds();
     $file_ids = array_diff($file_ids, $project_file_ids);
     return $file_ids;
 }
コード例 #2
0
ファイル: Issue.php プロジェクト: AzerothShard/thebuggenie
 /**
  * Remove a file
  *
  * @param \thebuggenie\core\entities\File $file The file to be removed
  *
  * @return boolean
  */
 public function detachFile(File $file)
 {
     tables\IssueFiles::getTable()->removeByIssueIDandFileID($this->getID(), $file->getID());
     if (is_array($this->_files) && array_key_exists($file->getID(), $this->_files)) {
         unset($this->_files[$file->getID()]);
     }
     $file->delete();
 }
コード例 #3
0
ファイル: File.php プロジェクト: founderio/thebuggenie
 public function hasAccess()
 {
     $issue_ids = tables\IssueFiles::getTable()->getIssuesByFileID($this->getID());
     foreach ($issue_ids as $issue_id) {
         $issue = new \thebuggenie\core\entities\Issue($issue_id);
         if ($issue->hasAccess()) {
             return true;
         }
     }
     $event = \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\core\\entities\\File::hasAccess', $this);
     $event->setReturnValue(false);
     $event->triggerUntilProcessed();
     return $event->getReturnValue();
 }
コード例 #4
0
ファイル: Main.php プロジェクト: nrensen/thebuggenie
 /**
  * "Report issue" page
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runReportIssue(framework\Request $request)
 {
     $i18n = framework\Context::getI18n();
     $errors = array();
     $permission_errors = array();
     $this->issue = null;
     $this->getResponse()->setPage('reportissue');
     $this->_loadSelectedProjectAndIssueTypeFromRequestForReportIssueAction($request);
     $this->forward403unless(framework\Context::getCurrentProject() instanceof entities\Project && framework\Context::getCurrentProject()->hasAccess() && $this->getUser()->canReportIssues(framework\Context::getCurrentProject()));
     if ($request->isPost()) {
         if ($this->_postIssueValidation($request, $errors, $permission_errors)) {
             try {
                 $issue = $this->_postIssue($request);
                 if ($request->hasParameter('files') && $request->hasParameter('file_description')) {
                     $files = $request['files'];
                     $file_descriptions = $request['file_description'];
                     foreach ($files as $file_id => $nothing) {
                         $file = entities\File::getB2DBTable()->selectById((int) $file_id);
                         $file->setDescription($file_descriptions[$file_id]);
                         $file->save();
                         tables\IssueFiles::getTable()->addByIssueIDandFileID($issue->getID(), $file->getID());
                     }
                 }
                 if ($request['return_format'] == 'planning') {
                     $this->_loadSelectedProjectAndIssueTypeFromRequestForReportIssueAction($request);
                     $options = array();
                     $options['selected_issuetype'] = $issue->getIssueType();
                     $options['selected_project'] = $this->selected_project;
                     $options['issuetypes'] = $this->issuetypes;
                     $options['issue'] = $issue;
                     $options['errors'] = $errors;
                     $options['permission_errors'] = $permission_errors;
                     $options['selected_milestone'] = $this->_getMilestoneFromRequest($request);
                     $options['selected_build'] = $this->_getBuildFromRequest($request);
                     $options['parent_issue'] = $this->_getParentIssueFromRequest($request);
                     $options['medium_backdrop'] = 1;
                     return $this->renderJSON(array('content' => $this->getComponentHTML('main/reportissuecontainer', $options)));
                 }
                 if ($request->getRequestedFormat() != 'json' && $issue->getProject()->getIssuetypeScheme()->isIssuetypeRedirectedAfterReporting($this->selected_issuetype)) {
                     $this->forward(framework\Context::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo())), 303);
                 } else {
                     $this->_clearReportIssueProperties();
                     $this->issue = $issue;
                 }
             } catch (\Exception $e) {
                 if ($request['return_format'] == 'planning') {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => $e->getMessage()));
                 }
                 $errors[] = $e->getMessage();
             }
         }
     }
     if ($request['return_format'] == 'planning') {
         $err_msg = array();
         foreach ($errors as $field => $value) {
             $err_msg[] = $i18n->__('Please provide a value for the %field_name field', array('%field_name' => $field));
         }
         foreach ($permission_errors as $field => $value) {
             $err_msg[] = $i18n->__("The %field_name field is marked as required, but you don't have permission to set it", array('%field_name' => $field));
         }
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $i18n->__('An error occured while creating this story: %errors', array('%errors' => '')), 'message' => join('<br>', $err_msg)));
     }
     $this->errors = $errors;
     $this->permission_errors = $permission_errors;
     $this->options = $this->getParameterHolder();
 }
コード例 #5
0
ファイル: MoveProject.php プロジェクト: founderio/thebuggenie
 protected function moveIssues($project_id, $to_scope_id)
 {
     $crit = Issues::getTable()->getCriteria();
     $crit->addWhere('issues.project_id', $project_id);
     $crit->addSelectionColumn('issues.id', 'id');
     $issue_ids = [];
     if ($res = Issues::getTable()->doSelect($crit)) {
         while ($row = $res->getNextRow()) {
             $issue_ids[] = $row['id'];
         }
     }
     $this->cliEcho("------------------\n");
     $this->cliEcho('Moving ');
     $this->cliEcho(count($issue_ids), 'white', 'bold');
     $this->cliEcho(" issues\n");
     $this->cliEcho("------------------\n");
     if (!$issue_ids) {
         return;
     }
     $this->cliEcho("Moving comments... ");
     $comments_crit = Comments::getTable()->getCriteria();
     $comments_crit->addUpdate('comments.scope', $to_scope_id);
     $comments_crit->addWhere('comments.target_id', $issue_ids, Criteria::DB_IN);
     $comments_crit->addWhere('comments.target_type', Comment::TYPE_ISSUE);
     Comments::getTable()->doUpdate($comments_crit);
     $this->cliEcho(" done\n");
     $this->cliEcho("Moving log items... ");
     $logs_crit = Log::getTable()->getCriteria();
     $logs_crit->addUpdate('log.scope', $to_scope_id);
     $logs_crit->addWhere('log.target', $issue_ids, Criteria::DB_IN);
     $logs_crit->addWhere('log.target_type', Log::TYPE_ISSUE);
     Log::getTable()->doUpdate($logs_crit);
     $this->cliEcho(" done\n");
     $this->cliEcho("Moving attachments... ");
     $file_ids_crit = IssueFiles::getTable()->getCriteria();
     $file_ids_crit->addWhere('issuefiles.issue_id', $issue_ids, Criteria::DB_IN);
     $file_ids_crit->addSelectionColumn('issuefiles.file_id', 'file_id');
     $file_ids_crit->addSelectionColumn('issuefiles.id', 'id');
     $file_ids = [];
     $issue_file_ids = [];
     if ($res = IssueFiles::getTable()->doSelect($file_ids_crit)) {
         while ($row = $res->getNextRow()) {
             $file_ids[] = $row['file_id'];
             $issue_file_ids[] = $row['id'];
         }
     }
     if (count($file_ids)) {
         $file_crit = Files::getTable()->getCriteria();
         $file_crit->addUpdate('files.scope', $to_scope_id);
         $file_crit->addWhere('files.id', $file_ids, Criteria::DB_IN);
         Files::getTable()->doUpdate($file_crit);
         $issue_file_crit = IssueFiles::getTable()->getCriteria();
         $issue_file_crit->addUpdate('issuefiles.scope', $to_scope_id);
         $issue_file_crit->addWhere('issuefiles.id', $issue_file_ids, Criteria::DB_IN);
         IssueFiles::getTable()->doUpdate($issue_file_crit);
     }
     $this->cliEcho(" done\n");
     $this->cliEcho("Moving calculations and estimations... ");
     $estimates_crit = IssueEstimates::getTable()->getCriteria();
     $estimates_crit->addUpdate('issue_estimates.scope', $to_scope_id);
     $estimates_crit->addWhere('issue_estimates.issue_id', $issue_ids, Criteria::DB_IN);
     IssueEstimates::getTable()->doUpdate($estimates_crit);
     $spent_crit = IssueSpentTimes::getTable()->getCriteria();
     $spent_crit->addUpdate('issue_spenttimes.scope', $to_scope_id);
     $spent_crit->addWhere('issue_spenttimes.issue_id', $issue_ids, Criteria::DB_IN);
     IssueSpentTimes::getTable()->doUpdate($spent_crit);
     $this->cliEcho(" done\n");
     $this->cliEcho("Moving links, related and affected items");
     $tables = ['\\thebuggenie\\core\\entities\\tables\\IssueAffectsBuild' => 'issueaffectsbuild', '\\thebuggenie\\core\\entities\\tables\\IssueAffectsComponent' => 'issueaffectscomponent', '\\thebuggenie\\core\\entities\\tables\\IssueAffectsEdition' => 'issueaffectsedition'];
     foreach ($tables as $class_name => $table_name) {
         $crit = $class_name::getTable()->getCriteria();
         $crit->addUpdate($table_name . '.scope', $to_scope_id);
         $crit->addWhere($table_name . '.issue', $issue_ids, Criteria::DB_IN);
         $class_name::getTable()->doUpdate($crit);
     }
     $links_crit = Links::getTable()->getCriteria();
     $links_crit->addUpdate('links.scope', $to_scope_id);
     $links_crit->addWhere('links.target_id', $issue_ids, Criteria::DB_IN);
     $links_crit->addWhere('links.target_type', 'issue');
     Links::getTable()->doUpdate($links_crit);
     $related_crit = IssueRelations::getTable()->getCriteria();
     $related_crit->addUpdate('issuerelations.scope', $to_scope_id);
     $ctn = $related_crit->returnCriterion('issuerelations.child_id', $issue_ids, Criteria::DB_IN);
     $ctn->addOr('issuerelations.parent_id', $issue_ids, Criteria::DB_IN);
     $related_crit->addWhere($ctn);
     $votes_crit = Votes::getTable()->getCriteria();
     $votes_crit->addUpdate('votes.scope', $to_scope_id);
     $votes_crit->addWhere('votes.target', $issue_ids, Criteria::DB_IN);
     Votes::getTable()->doUpdate($votes_crit);
     $this->cliEcho(" done\n");
     $this->cliEcho("Updating user issue bookmarks");
     $user_issues_crit = UserIssues::getTable()->getCriteria();
     $user_issues_crit->addUpdate('userissues.scope', $to_scope_id);
     $user_issues_crit->addWhere('userissues.issue', $issue_ids, Criteria::DB_IN);
     UserIssues::getTable()->doUpdate($user_issues_crit);
     $this->cliEcho(" done\n");
     $this->updateCustomFields($issue_ids, $to_scope_id);
     $crit = Issues::getTable()->getCriteria();
     $crit->addUpdate('issues.scope', $to_scope_id);
     $crit->addWhere('issues.id', $issue_ids, Criteria::DB_IN);
     Issues::getTable()->doUpdate($crit);
     $this->cliEcho("------------------\n");
     $this->cliEcho("Done moving issues\n");
     $this->cliEcho("------------------\n");
 }