public function do_execute() { $this->cliEcho("Importing articles ... \n", 'white', 'bold'); TBGEvent::listen('publish', 'fixture_article_loaded', array($this, 'listenPublishFixtureArticleCreated')); $overwrite = (bool) ($this->getProvidedArgument('overwrite', 'no') == 'yes'); TBGPublish::getModule()->loadFixturesArticles(TBGContext::getScope()->getID(), $overwrite); }
protected function _addListeners() { TBGEvent::listen('core', 'project_sidebar_links', array($this, 'listen_project_links')); TBGEvent::listen('core', 'breadcrumb_project_links', array($this, 'listen_breadcrumb_links')); TBGEvent::listen('core', 'get_backdrop_partial', array($this, 'listen_getcommit')); TBGEvent::listen('core', 'viewissue_left_after_attachments', array($this, 'listen_viewissue_panel')); TBGEvent::listen('core', 'config_project_tabs', array($this, 'listen_projectconfig_tab')); TBGEvent::listen('core', 'config_project_panes', array($this, 'listen_projectconfig_panel')); TBGEvent::listen('core', 'project_header_buttons', array($this, 'listen_projectheader')); TBGEvent::listen('core', '_notification_view', array($this, 'listen_notificationview')); TBGEvent::listen('core', 'TBGNotification::getTarget', array($this, 'listen_TBGNotification_getTarget')); }
protected function _addListeners() { TBGEvent::listen('core', 'user_registration', array($this, 'listen_registerUser')); TBGEvent::listen('core', 'password_reset', array($this, 'listen_forgottenPassword')); TBGEvent::listen('core', 'login_form_pane', array($this, 'listen_loginPane')); TBGEvent::listen('core', 'login_form_tab', array($this, 'listen_loginTab')); //TBGEvent::listen('core', 'TBGIssue::save', array($this, 'listen_issueSave')); TBGEvent::listen('core', 'TBGIssue::createNew', array($this, 'listen_issueCreate')); TBGEvent::listen('core', 'TBGUser::createNew', array($this, 'listen_createUser')); TBGEvent::listen('core', 'TBGComment::createNew', array($this, 'listen_TBGComment_createNew')); TBGEvent::listen('core', 'header_begins', array($this, 'listen_headerBegins')); TBGEvent::listen('core', 'viewissue', array($this, 'listen_viewissue')); }
protected function _addListeners() { TBGEvent::listen('core', 'index_left', array($this, 'listen_frontpageLeftmenu')); TBGEvent::listen('core', 'index_right_top', array($this, 'listen_frontpageArticle')); if ($this->isWikiTabsEnabled()) { TBGEvent::listen('core', 'project_overview_item_links', array($this, 'listen_projectLinks')); TBGEvent::listen('core', 'menustrip_item_links', array($this, 'listen_MenustripLinks')); TBGEvent::listen('core', 'breadcrumb_main_links', array($this, 'listen_BreadcrumbMainLinks')); TBGEvent::listen('core', 'breadcrumb_project_links', array($this, 'listen_BreadcrumbProjectLinks')); } TBGEvent::listen('core', 'TBGProject::createNew', array($this, 'listen_createNewProject')); TBGEvent::listen('core', 'upload', array($this, 'listen_upload')); TBGEvent::listen('core', 'quicksearch_dropdown_firstitems', array($this, 'listen_quicksearchDropdownFirstItems')); TBGEvent::listen('core', 'quicksearch_dropdown_founditems', array($this, 'listen_quicksearchDropdownFoundItems')); }
protected function _addListeners() { TBGEvent::listen('core', 'TBGUser::_postSave', array($this, 'listen_registerUser')); TBGEvent::listen('core', 'password_reset', array($this, 'listen_forgottenPassword')); TBGEvent::listen('core', 'login_form_pane', array($this, 'listen_loginPane')); TBGEvent::listen('core', 'login_button_container', array($this, 'listen_loginButtonContainer')); TBGEvent::listen('core', 'TBGUser::addScope', array($this, 'listen_addScope')); TBGEvent::listen('core', 'TBGIssue::createNew', array($this, 'listen_issueCreate')); TBGEvent::listen('core', 'TBGUser::_postSave', array($this, 'listen_createUser')); TBGEvent::listen('core', 'TBGIssue::save', array($this, 'listen_issueSave')); TBGEvent::listen('core', 'TBGComment::createNew', array($this, 'listen_TBGComment_createNew')); TBGEvent::listen('core', 'TBGWikiArticle::doSave', array($this, 'listen_TBGWikiArticle_doSave')); TBGEvent::listen('core', 'header_begins', array($this, 'listen_headerBegins')); TBGEvent::listen('core', 'viewissue', array($this, 'listen_viewissue')); TBGEvent::listen('core', 'issue_subscribe_user', array($this, 'listen_issueSubscribeUser')); TBGEvent::listen('core', 'user_dropdown_anon', array($this, 'listen_userDropdownAnon')); TBGEvent::listen('core', 'config_project_tabs', array($this, 'listen_projectconfig_tab')); TBGEvent::listen('core', 'config_project_panes', array($this, 'listen_projectconfig_panel')); TBGEvent::listen('core', 'account_pane_notificationsettings', array($this, 'listen_accountNotificationSettings')); TBGEvent::listen('core', 'config.createuser.email', array($this, 'listen_configCreateuserEmail')); TBGEvent::listen('core', 'config.createuser.save', array($this, 'listen_configCreateuserSave')); TBGEvent::listen('core', 'mainActions::myAccount::saveNotificationSettings', array($this, 'listen_accountSaveNotificationSettings')); TBGEvent::listen('core', 'get_backdrop_partial', array($this, 'listen_get_backdrop_partial')); }
/** * Transition an issue to the outgoing step, based on request data if available * * @param TBGIssue $issue * @param TBGRequest $request */ public function transitionIssueToOutgoingStepFromRequest(TBGIssue $issue, $request = null) { $request = $request !== null ? $request : $this->_request; $this->getOutgoingStep()->applyToIssue($issue); if ($request->hasParameter('comment_body') && trim($request->getParameter('comment_body') != '')) { $this->_request = $request; TBGEvent::listen('core', 'TBGIssue::save', array($this, 'listenIssueSaveAddComment')); } if (!empty($this->_validation_errors)) { return false; } foreach ($this->getActions() as $action) { $action->perform($issue, $request); } $issue->save(); }
public function runUpdateIssueDetails(TBGRequest $request) { $this->error = false; try { $i18n = TBGContext::getI18n(); $issue = TBGIssue::getIssueFromLink($request->getParameter('issue_no')); if ($issue->getProject()->getID() != $this->selected_project->getID()) { throw new Exception($i18n->__('This issue is not valid for this project')); } if (!$issue instanceof TBGIssue) { die; } $workflow_transition = null; if ($passed_transition = $request->getParameter('workflow_transition')) { //echo "looking for transition "; $key = str_replace(' ', '', mb_strtolower($passed_transition)); //echo $key . "\n"; foreach ($issue->getAvailableWorkflowTransitions() as $transition) { //echo str_replace(' ', '', mb_strtolower($transition->getName())) . "?"; if (strpos(str_replace(' ', '', mb_strtolower($transition->getName())), $key) !== false) { $workflow_transition = $transition; //echo "found transition " . $transition->getID(); break; } //echo "no"; } if (!$workflow_transition instanceof TBGWorkflowTransition) { throw new Exception("This transition ({$key}) is not valid"); } } $fields = $request->getRawParameter('fields', array()); $return_values = array(); if ($workflow_transition instanceof TBGWorkflowTransition) { foreach ($fields as $field_key => $field_value) { $classname = "TBG" . ucfirst($field_key); $method = "set" . ucfirst($field_key); $choices = $classname::getAll(); $found = false; foreach ($choices as $choice_key => $choice) { if (strpos(str_replace(' ', '', strtolower($choice->getName())), str_replace(' ', '', strtolower($field_value))) !== false) { $request->setParameter($field_key . '_id', $choice->getId()); break; } } } $request->setParameter('comment_body', $request->getParameter('message')); $return_values['applied_transition'] = $workflow_transition->getName(); if ($workflow_transition->validateFromRequest($request)) { $retval = $workflow_transition->transitionIssueToOutgoingStepFromRequest($issue, $request); $return_values['transition_ok'] = $retval === false ? false : true; } else { $return_values['transition_ok'] = false; $return_values['message'] = "Please pass all information required for this transition"; } } elseif ($issue->isUpdateable()) { foreach ($fields as $field_key => $field_value) { try { if (in_array($field_key, array_merge(array('title', 'state'), TBGDatatype::getAvailableFields(true)))) { switch ($field_key) { case 'state': $issue->setState($field_value == 'open' ? TBGIssue::STATE_OPEN : TBGIssue::STATE_CLOSED); break; case 'title': if ($field_value != '') { $issue->setTitle($field_value); } else { throw new Exception($i18n->__('Invalid title')); } break; case 'description': case 'reproduction_steps': $method = "set" . ucfirst($field_key); $issue->{$method}($field_value); break; case 'status': case 'resolution': case 'reproducability': case 'priority': case 'severity': case 'category': $classname = "TBG" . ucfirst($field_key); $method = "set" . ucfirst($field_key); $choices = $classname::getAll(); $found = false; foreach ($choices as $choice_key => $choice) { if (str_replace(' ', '', strtolower($choice->getName())) == str_replace(' ', '', strtolower($field_value))) { $issue->{$method}($choice); $found = true; } } if (!$found) { throw new Exception('Could not find this value'); } break; case 'percent_complete': $issue->setPercentCompleted($field_value); break; case 'owner': case 'assignee': $set_method = "set" . ucfirst($field_key); $unset_method = "un{$set_method}"; switch (strtolower($field_value)) { case 'me': $issue->{$set_method}(TBGContext::getUser()); break; case 'none': $issue->{$unset_method}(); break; default: try { $user = TBGUser::findUser(strtolower($field_value)); if ($user instanceof TBGUser) { $issue->{$set_method}($user); } } catch (Exception $e) { throw new Exception('No such user found'); } break; } break; case 'estimated_time': case 'spent_time': $set_method = "set" . ucfirst(str_replace('_', '', $field_key)); $issue->{$set_method}($field_value); break; case 'milestone': $found = false; foreach ($this->selected_project->getAllMilestones() as $milestone) { if (str_replace(' ', '', strtolower($milestone->getName())) == str_replace(' ', '', strtolower($field_value))) { $issue->setMilestone($milestone->getID()); $found = true; } } if (!$found) { throw new Exception('Could not find this milestone'); } break; default: throw new Exception($i18n->__('Invalid field')); } } $return_values[$field_key] = array('success' => true); } catch (Exception $e) { $return_values[$field_key] = array('success' => false, 'error' => $e->getMessage()); } } } TBGEvent::listen('core', 'TBGIssue::save', function (TBGEvent $event) { $comment = $event->getParameter('comment'); $comment->setContent($request->getRawParameter('message') . "\n\n" . $comment->getContent()); $comment->setSystemComment(false); $comment->save(); }); if (!$workflow_transition instanceof TBGWorkflowTransition) { $issue->getWorkflowStep()->getWorkflow()->moveIssueToMatchingWorkflowStep($issue); } if (!array_key_exists('transition_ok', $return_values) || $return_values['transition_ok']) { $issue->save(); } $this->return_values = $return_values; } catch (Exception $e) { //$this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage())); } }
protected static function setupCoreListeners() { TBGEvent::listen('core', 'TBGFile::hasAccess', 'TBGProject::listen_TBGFile_hasAccess'); TBGEvent::listen('core', 'TBGFile::hasAccess', 'TBGBuild::listen_TBGFile_hasAccess'); TBGEvent::listen('core', 'TBGFile::hasAccess', 'TBGSettings::listen_TBGFile_hasAccess'); }
protected function _addListeners() { TBGEvent::listen('core', 'project_sidebar_links_timeline', array($this, 'listen_SidebarLinks')); TBGEvent::listen('core', 'viewissue_tabs', array($this, 'listen_viewissue_tab')); TBGEvent::listen('core', 'viewissue_tab_panes_back', array($this, 'listen_viewissue_panel')); }
/** * @covers TBGEvent::listen * @covers TBGEvent::trigger * @covers TBGEvent::triggerUntilProcessed * @depends testListening */ public function testTriggeringAndProcessing(TBGEvent $event) { $this->wastriggered = false; TBGEvent::clearListeners('modulename', 'identifier'); TBGEvent::listen('modulename', 'identifier', array($this, 'listenerCallback')); $event->trigger(); $this->assertAttributeEquals(true, 'wastriggered', $this); TBGEvent::clearListeners('modulename', 'identifier'); TBGEvent::listen('modulename', 'identifier', array($this, 'listenerCallbackNonProcessingFirst')); TBGEvent::listen('modulename', 'identifier', array($this, 'listenerCallbackNonProcessingSecond')); TBGEvent::listen('modulename', 'identifier', array($this, 'listenerCallbackProcessing')); $this->wasprocessed = array(); $event->triggerUntilProcessed(); $this->assertAttributeNotEmpty('wasprocessed', $this); $this->assertAttributeContains(1, 'wasprocessed', $this); $this->assertAttributeContains(2, 'wasprocessed', $this); $this->assertAttributeNotContains(3, 'wasprocessed', $this); }
public function runAddComment(TBGRequest $request) { $i18n = TBGContext::getI18n(); $comment = null; $comment_applies_type = $request->getParameter('comment_applies_type'); try { if (!TBGContext::getUser()->canPostComments()) { throw new Exception($i18n->__('You are not allowed to do this')); } else { if ($request->getParameter('comment_body') == '') { throw new Exception($i18n->__('The comment must have some content')); } if ($comment_applies_type == TBGComment::TYPE_ISSUE && !$request->isAjaxCall()) { $this->comment_lines = array(); $this->comment = ''; TBGEvent::listen('core', 'TBGIssue::save', array($this, 'listenIssueSaveAddComment')); $issue = TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id')); $issue->save(false); } if (empty($this->comment) == false) { // prevent empty lines when only user comment $comment_body = $this->comment . "\n\n" . $request->getParameter('comment_body', null, false); } else { $comment_body = $request->getParameter('comment_body', null, false); } $comment = new TBGComment(); $comment->setTitle($i18n->__('Untitled comment')); $comment->setContent($comment_body); $comment->setPostedBy(TBGContext::getUser()->getID()); $comment->setTargetID($request->getParameter('comment_applies_id')); $comment->setTargetType($request->getParameter('comment_applies_type')); $comment->setModuleName($request->getParameter('comment_module')); $comment->setIsPublic((bool) $request->getParameter('comment_visibility')); $comment->save(); switch ($comment_applies_type) { case TBGComment::TYPE_ISSUE: $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment, 'issue' => TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id')))); break; case TBGComment::TYPE_ARTICLE: $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment)); break; default: $comment_html = 'OH NO!'; } if ($comment_applies_type == TBGComment::TYPE_ISSUE) { $issue = TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id')); TBGEvent::createNew('core', 'TBGComment::createNew', $issue, array('comment' => $comment))->trigger(); $issue->save(); } } } catch (Exception $e) { if ($request->isAjaxCall()) { return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage())); } else { TBGContext::setMessage('comment_error', $e->getMessage()); TBGContext::setMessage('comment_error_body', $request->getParameter('comment_body')); TBGContext::setMessage('comment_error_title', $request->getParameter('comment_title')); TBGContext::setMessage('comment_error_visibility', $request->getParameter('comment_visibility')); } } if ($request->isAjaxCall()) { return $this->renderJSON(array('title' => $i18n->__('Comment added!'), 'comment_data' => $comment_html, 'continue_url' => $request->getParameter('forward_url'), 'commentcount' => TBGComment::countComments($request->getParameter('comment_applies_id'), $request->getParameter('comment_applies_type')))); } if ($comment instanceof TBGComment) { $this->forward($request->getParameter('forward_url') . "#comment_{$request->getParameter('comment_applies_type')}_{$request->getParameter('comment_applies_id')}_{$comment->getID()}"); } else { $this->forward($request->getParameter('forward_url')); } }