/** * Prepare the response. * * @return void * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $user = $application->getUser(); $project = $application->getProject(); if (!$user->check('edit')) { throw new \Exception('You are not allowed to alter this item.'); } $issueId = $application->input->getUint('issueId'); if (!$issueId) { throw new \Exception('No issue ID received.'); } $this->dispatcher = $application->getDispatcher(); $this->addEventListener('tests'); $this->setProjectGitHubBot($project); $data = new \stdClass(); $result = new \stdClass(); $result->user = $application->input->getUsername('user'); $result->value = $application->input->getUint('result'); $issueModel = new IssueModel($this->getContainer()->get('db')); $data->testResults = $issueModel->saveTest($issueId, $result->user, $result->value); $issueNumber = $issueModel->getIssueNumberById($issueId); $event = (new ActivityModel($this->getContainer()->get('db')))->addActivityEvent('alter_testresult', 'now', $user->username, $project->project_id, $issueNumber, null, json_encode($result)); $this->triggerEvent('onTestAfterSubmit', ['issueNumber' => $issueNumber, 'data' => $data->testResults]); $data->event = new \stdClass(); foreach ($event as $k => $v) { $data->event->{$k} = $v; } $data->event->text = json_decode($data->event->text); $this->response->data = json_encode($data); $this->response->message = g11n3t('Test successfully added'); }
/** * Prepare the response. * * @return void * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { if (false == $this->getContainer()->get('app')->getUser()->check('manage')) { throw new \Exception('You are not authorized'); } $input = $this->getContainer()->get('app')->input; $db = $this->getContainer()->get('db'); $user = $input->getCmd('user'); $groupId = $input->getInt('group_id'); $assign = $input->getInt('assign'); if (!$groupId) { throw new \Exception('Missing group id'); } $tableUsers = new TableUsers($this->getContainer()->get('db')); $tableUsers->loadByUserName($user); if (!$tableUsers->id) { throw new \Exception('User not found'); } $check = $db->setQuery($db->getQuery(true)->from($db->quoteName('#__user_accessgroup_map', 'm'))->select('COUNT(*)')->where($db->quoteName('group_id') . ' = ' . (int) $groupId)->where($db->quoteName('user_id') . ' = ' . (int) $tableUsers->id))->loadResult(); if ($assign) { if ($check) { throw new \Exception('The user is already assigned to this group.'); } $this->assign($tableUsers->id, $groupId); $this->response->data->message = g11n3t('The user has been assigned.'); } else { if (!$check) { throw new \Exception('The user is not assigned to this group.'); } $this->unAssign($tableUsers->id, $groupId); $this->response->data->message = g11n3t('The user has been unassigned.'); } }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $table = new GroupsTable($this->getContainer()->get('db')); $table->load($this->getContainer()->get('app')->input->getInt('group_id'))->delete(); $this->getContainer()->get('app')->enqueueMessage(g11n3t('The group has been deleted.'), 'success'); return parent::execute(); }
/** * Execute the controller. * * @return string The rendered view. * * @since 1.0 * @throws \UnexpectedValueException */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $id = $application->input->getUint('id'); if (!$id) { throw new \UnexpectedValueException('No id given'); } if (!$application->getUser()->check('admin')) { if ($application->getUser()->id != $id) { $application->enqueueMessage(g11n3t('You are not authorized to refresh this user.'), 'error')->redirect($application->get('uri.base.path') . 'user/' . $id); } } /* @type \Joomla\Github\Github $github */ $gitHub = $this->getContainer()->get('gitHub'); $loginHelper = new GitHubLoginHelper($this->getContainer()); $gitHubUser = $gitHub->users->getAuthenticatedUser(); $user = new GithubUser($application->getProject(), $this->getContainer()->get('db')); $user->loadGitHubData($gitHubUser)->loadByUserName($user->username); // Refresh the avatar $loginHelper->refreshAvatar($user->username); try { $loginHelper->setEmail($user->id, $gitHubUser->email); } catch (\RuntimeException $e) { $application->enqueueMessage(g11n3t('An error has occurred during email refresh.'), 'error'); } $application->enqueueMessage(g11n3t('The profile has been refreshed.'), 'success')->redirect($application->get('uri.base.path') . 'user/' . $id); return parent::execute(); }
/** * Method to render the view. * * @return string The rendered view. * * @since 1.0 * @throws \UnexpectedValueException */ public function render() { $type = $this->getLogType(); switch ($type) { case 'php': $path = $this->getDebugger()->getLogPath('php'); break; case '403': case '404': case '500': case 'app': case 'cron': case 'database': case 'error': case 'github_issues': case 'github_comments': case 'github_pulls': $path = $this->getDebugger()->getLogPath('root') . '/' . $type . '.log'; break; default: throw new \UnexpectedValueException('Invalid log type'); break; } $log = realpath($path) ? $this->processLog($type, $path) : [sprintf(g11n3t('No %s log file found.'), $type)]; $this->renderer->set('log', $log); $this->renderer->set('log_type', $type); return parent::render(); }
/** * Prepare the response. * * @return void * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $user = $application->getUser(); $project = $application->getProject(); if (!$user->id) { throw new \Exception('You are not allowed to test this item.'); } $issueId = $application->input->getUint('issueId'); $result = $application->input->getUint('result'); if (!$issueId) { throw new \Exception('No issue ID received.'); } $issueModel = new IssueModel($this->getContainer()->get('db')); $data = new \stdClass(); $data->testResults = $issueModel->saveTest($issueId, $user->username, $result); $event = (new ActivityModel($this->getContainer()->get('db')))->addActivityEvent('test_item', 'now', $user->username, $project->project_id, $issueModel->getIssueNumberById($issueId), null, json_encode($result)); $data->event = new \stdClass(); foreach ($event as $k => $v) { $data->event->{$k} = $v; } $data->event->text = json_decode($data->event->text); $this->response->data = json_encode($data); $this->response->message = g11n3t('Test successfully added'); }
/** * Prepare the response. * * @return mixed * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { // Verify the user has permissions to perform this action if (!$this->getContainer()->get('app')->getUser()->authorize('view')) { throw new \Exception('Anonymous votes are not allowed.'); } /* @type Input $input */ $input = $this->getContainer()->get('app')->input; $issue = $input->getUint('issueId'); $experienced = $input->getInt('experienced'); $importance = $input->getInt('importance'); $userID = $this->getContainer()->get('app')->getUser()->id; if (!$issue) { throw new \Exception('No issue ID received.'); } if (!$importance) { throw new \Exception('Issue importance not received'); } $model = new IssueModel($this->getContainer()->get('db')); $data = $model->vote($issue, $experienced, $importance, $userID); // Add the new score $data->importanceScore = $data->score / $data->votes; $this->response->data = $data; $this->response->message = g11n3t('Vote successfully added'); }
/** * Fetch Tags. * * @param array $packages List of installed packages * @param boolean $allTags Fetch all tags or only the "most recent". * * @return $this * * @since 1.0 */ private function fetchTags(array $packages, $allTags = false) { foreach ($packages as $package) { $this->out($package->name); if (!preg_match('|https://github.com/([A-z0-9\\-]+)/([A-z0-9\\-\\.]+).git|', $package->source->url, $matches)) { $this->out('CAN NOT PARSE: ' . $package->source->url); continue; } $owner = $matches[1]; $repo = $matches[2]; $tags = $this->github->repositories->getListTags($owner, $repo); $found = false; foreach ($tags as $tag) { if ($tag->name == $package->version) { $this->out($tag->name . ' <= ' . g11n3t('Installed')); $found = true; if (!$allTags) { break; } } else { $this->out($tag->name); } } if (!$found) { $this->out(sprintf(g11n3t('Installed: %s'), $package->version)); } $this->out(); } return $this; }
/** * Prepare the response. * * @return mixed * * @since 1.0 */ protected function prepareResponse() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $files = $application->input->files->get('files'); if (!empty($files)) { $file = new File($application); // Prepare response data $host = $application->get('uri')->base->host; $destName = md5(time() . $file->getName()) . '.' . $file->getExtension(); $destDir = $application->getProject()->project_id; $fullPath = $host . '/' . $application->get('system.upload_dir') . '/' . $destDir . '/' . $destName; $data = array(array('url' => $fullPath, 'thumbnailUrl' => $fullPath, 'name' => $file->getName(), 'type' => $file->getMimetype(), 'size' => $file->getSize(), 'alt' => 'screen shot ' . date('Y-m-d') . ' at ' . date('H i s'), 'deleteUrl' => '/upload/delete/?file=' . $destName, 'deleteType' => "POST", 'editorId' => $application->input->get('editorId'))); // Try to upload file try { $file->upload($destName); } catch (\Exception $e) { $errors = array(); foreach ($file->getErrors() as $error) { $errors[] = g11n3t($error); } $data = array(array('error' => $errors)); } $this->response->files = $data; } }
/** * Execute the command. * * @return void * * @since 1.0 */ public function execute() { $this->getApplication()->outputTitle(g11n3t('Get Translations')); $this->languages = $this->getApplication()->get('languages'); // Remove English from the language array unset($this->languages[0]); $this->logOut(g11n3t('Start fetching translations.'))->setupTransifex()->fetchTranslations()->out()->logOut(g11n3t('Finished.')); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $app = $this->getContainer()->get('app'); $app->getUser()->authorize('admin'); $table = new ArticlesTable($this->getContainer()->get('db')); $table->delete($app->input->getInt('id')); $app->enqueueMessage(g11n3t('The article has been deleted.'), 'success'); $this->getContainer()->get('app')->input->set('view', 'articles'); return parent::execute(); }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { $app = $this->getContainer()->get('app'); $app->getUser()->authorize('admin'); $table = new ArticlesTable($this->getContainer()->get('db')); /* @type \Joomla\Github\Github $gitHub */ $table->setGitHub($this->getContainer()->get('gitHub')); $table->save($app->input->get('article', array(), 'array')); $app->enqueueMessage(g11n3t('The article has been saved.'), 'success'); return parent::execute(); }
/** * Execute the controller. * * @return void * * @since 1.0 */ public function execute() { $application = $this->getContainer()->get('app'); try { g11n::cleanCache(); $application->enqueueMessage(g11n3t('The cache has been cleared.'), 'success'); } catch (\Exception $e) { $application->enqueueMessage($e->getMessage(), 'error'); } $application->redirect('/'); }
/** * Prepare the response. * * @return void * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $user = $application->getUser(); $project = $application->getProject(); if (!$user->id) { throw new \Exception('You are not allowed to test this item.'); } $issueId = $application->input->getUint('issueId'); $result = $application->input->getUint('result'); $userComment = $application->input->get('comment', '', 'raw'); $sha = $application->input->getCmd('sha'); if (!$issueId) { throw new \Exception('No issue ID received.'); } $this->dispatcher = $application->getDispatcher(); $this->addEventListener('tests'); $this->setProjectGitHubBot($project); $issueModel = new IssueModel($this->getContainer()->get('db')); $data = new \stdClass(); $data->testResults = $issueModel->saveTest($issueId, $user->username, $result, $sha); $issueNumber = $issueModel->getIssueNumberById($issueId); $event = (new ActivityModel($this->getContainer()->get('db')))->addActivityEvent('test_item', 'now', $user->username, $project->project_id, $issueNumber, null, json_encode($result)); $this->triggerEvent('onTestAfterSubmit', ['issueNumber' => $issueNumber, 'data' => $data->testResults]); $data->event = new \stdClass(); foreach ($event as $k => $v) { $data->event->{$k} = $v; } $data->event->text = json_decode($data->event->text); $gitHubHelper = new GitHubHelper($this->getContainer()->get('gitHub')); // Create a comment to submitted on GitHub. switch ($result) { case 0: $comment = 'I have not tested this item.'; break; case 1: $comment = 'I have tested this item :white_check_mark: successfully on ' . $sha; break; case 2: $comment = 'I have tested this item :red_circle: unsuccessfully on ' . $sha; break; default: throw new \UnexpectedValueException('Unexpected test result value.'); break; } $comment .= $userComment ? '<br /><br />' . $userComment : ''; $comment .= $gitHubHelper->getApplicationComment($application, $project, $issueNumber); $data->comment = $gitHubHelper->addComment($project, $issueNumber, $comment, $user->username, $this->getContainer()->get('db')); $this->response->data = json_encode($data); $this->response->message = g11n3t('Test successfully added'); }
/** * Prepare the response. * * @return mixed * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { $this->getContainer()->get('app')->getUser()->authorize('create'); $comment = $this->getContainer()->get('app')->input->get('text', '', 'raw'); $issue_number = $this->getContainer()->get('app')->input->getInt('issue_number'); if (!$issue_number) { throw new \Exception('No issue number received.'); } if (!$comment) { throw new \Exception('You should write a comment first...'); } // @todo removeMe :( $comment .= sprintf('<br /><br />*This comment was created with the <a href="%1$s">%2$s Application</a> at <a href="%3$s">%4$s</a>.*', 'https://github.com/joomla/jissues', 'J!Tracker', $this->getContainer()->get('app')->get('uri')->base->full, $this->getContainer()->get('app')->get('uri')->base->full); $project = $this->getContainer()->get('app')->getProject(); /* @type \Joomla\Github\Github $github */ $github = $this->getContainer()->get('gitHub'); $data = new \stdClass(); $db = $this->getContainer()->get('db'); if ($project->gh_user && $project->gh_project) { $gitHubResponse = $github->issues->comments->create($project->gh_user, $project->gh_project, $issue_number, $comment); if (!isset($gitHubResponse->id)) { throw new \Exception('Invalid response from GitHub'); } $data->created_at = $gitHubResponse->created_at; $data->opened_by = $gitHubResponse->user->login; $data->comment_id = $gitHubResponse->id; $data->text_raw = $gitHubResponse->body; $data->text = $github->markdown->render($comment, 'gfm', $project->gh_user . '/' . $project->gh_project); } else { $date = new Date(); $data->created_at = $date->format($db->getDateFormat()); $data->opened_by = $this->getContainer()->get('app')->getUser()->username; $data->comment_id = '???'; $data->text_raw = $comment; $data->text = $github->markdown->render($comment, 'markdown'); } $table = new ActivitiesTable($db); $table->event = 'comment'; $table->created_date = $data->created_at; $table->project_id = $project->project_id; $table->issue_number = $issue_number; $table->gh_comment_id = $data->comment_id; $table->user = $data->opened_by; $table->text = $data->text; $table->text_raw = $data->text_raw; $table->store(); $data->activities_id = $table->activities_id; $this->response->data = $data; $this->response->message = g11n3t('Your comment has been submitted'); }
/** * Method to perform sanity checks on the AbstractDatabaseTable instance properties to ensure * they are safe to store in the database. * * @return $this Method allows chaining * * @since 1.0 * @throws \InvalidArgumentException */ public function check() { $errors = array(); if (trim($this->issue_id) == '') { $errors[] = g11n3t('Issue id is needed'); } if (trim($this->category_id) == '') { $errors[] = g11n3t('Category ID is needed.'); } if ($errors) { throw new \InvalidArgumentException(implode("\n", $errors)); } return $this; }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $model = new CategoryModel($this->getContainer()->get('db')); try { $model->delete($application->input->get('id')); $application->enqueueMessage(g11n3t('The category has been deleted'), 'success'); } catch (\Exception $exception) { $application->enqueueMessage($exception->getMessage(), 'error'); } $application->redirect($application->get('uri.base.path') . 'category/' . $application->getProject()->alias); return parent::execute(); }
/** * Get an item. * * @param integer $id The id of the category * * @return CategoryTable * * @throws \RuntimeException * * @since 1.0 */ public function getItem($id) { if ($id == null) { throw new \RuntimeException(g11n3t('Missing ID')); } $db = $this->getDb(); $query = $db->getQuery(true); $table = new CategoryTable($db); $item = $db->setQuery($query->select('*')->from($db->quoteName($table->getTableName()))->where($db->quoteName('id') . '=' . (int) $id))->loadObject(); if (!$item) { throw new \RuntimeException(g11n3t('Invalid Category')); } return $item; }
/** * Method to perform sanity checks on the AbstractDatabaseTable instance properties to ensure * they are safe to store in the database. * * @return $this Method allows chaining * * @since 1.0 * @throws \UnexpectedValueException */ public function check() { if (!$this->title) { throw new \UnexpectedValueException(g11n3t('A title is required')); } if (!$this->short_title) { throw new \UnexpectedValueException(g11n3t('A short title is required')); } if (!$this->alias) { $this->alias = $this->title; } $this->alias = $this->stringURLSafe($this->alias); return $this; }
/** * Prepare the response. * * @return void * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { // Only registered users are able to use the preview using their credentials. if (!$this->getContainer()->get('app')->getUser()->id) { throw new \Exception('not auth..'); } $text = $this->getContainer()->get('app')->input->get('text', '', 'raw'); if (!$text) { throw new \Exception(g11n3t('Nothing to preview...')); } $project = $this->getContainer()->get('app')->getProject(); /* @type \Joomla\Github\Github $github */ $github = $this->getContainer()->get('gitHub'); $this->response->data = $github->markdown->render($text, 'gfm', $project->gh_user . '/' . $project->gh_project); }
/** * Execute the controller. * * @return string * * @since 1.0 * @throws \RuntimeException * @throws \UnexpectedValueException */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $application->getUser()->authorize('admin'); $config = $this->cleanArray($application->input->get('config', array(), 'array')); if (!$config) { throw new \UnexpectedValueException('No config to save...'); } $type = trim(getenv('JTRACKER_ENVIRONMENT')); $fileName = $type ? 'config.' . $type . '.json' : 'config.json'; if (!file_put_contents(JPATH_ROOT . '/etc/' . $fileName, json_encode($config, JSON_PRETTY_PRINT))) { throw new \RuntimeException('Could not write the configuration data to file /etc/' . $fileName); } $application->enqueueMessage(g11n3t('The configuration file has been saved.'), 'success')->redirect('/'); }
/** * Prepare the response. * * @return mixed * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $application->getUser()->authorize('create'); $comment = $application->input->get('text', '', 'raw'); $issue_number = $application->input->getInt('issue_number'); $project = $application->getProject(); if (!$issue_number) { throw new \Exception('No issue number received.'); } if (!$comment) { throw new \Exception('You should write a comment first...'); } // @todo removeMe :( $comment .= sprintf('<hr /><sub>This comment was created with the <a href="%1$s">%2$s Application</a> at <a href="%3$s">%4$s</a>.</sub>', 'https://github.com/joomla/jissues', 'J!Tracker', $application->get('uri')->base->full . 'tracker/' . $project->alias . '/' . $issue_number, str_replace(['http://', 'https://'], '', $application->get('uri')->base->full) . $project->alias . '/' . $issue_number); /* @type \Joomla\Github\Github $github */ $github = $this->getContainer()->get('gitHub'); $data = new \stdClass(); /* @type \Joomla\Database\DatabaseDriver $db */ $db = $this->getContainer()->get('db'); if ($project->gh_user && $project->gh_project) { $gitHubResponse = $github->issues->comments->create($project->gh_user, $project->gh_project, $issue_number, $comment); if (!isset($gitHubResponse->id)) { throw new \Exception('Invalid response from GitHub'); } $data->created_at = $gitHubResponse->created_at; $data->opened_by = $gitHubResponse->user->login; $data->comment_id = $gitHubResponse->id; $data->text_raw = $gitHubResponse->body; $data->text = $github->markdown->render($comment, 'gfm', $project->gh_user . '/' . $project->gh_project); } else { $date = new Date(); $data->created_at = $date->format($db->getDateFormat()); $data->opened_by = $application->getUser()->username; $data->comment_id = '???'; $data->text_raw = $comment; $data->text = $github->markdown->render($comment, 'markdown'); } (new ActivityModel($db))->addActivityEvent('comment', $data->created_at, $data->opened_by, $project->project_id, $issue_number, $data->comment_id, $data->text, $data->text_raw); $data->activities_id = $db->insertid(); $date = new Date($data->created_at); $data->created_at = $date->format('j M Y'); $this->response->data = $data; $this->response->message = g11n3t('Your comment has been submitted'); }
/** * Prepare the response. * * @return void * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $user = $application->getUser(); if (!$user->id) { throw new \Exception('You are not allowed to test this item.'); } $issueId = $application->input->getUint('issueId'); $result = $application->input->getUint('result'); if (!$issueId) { throw new \Exception('No issue ID received.'); } $model = new IssueModel($this->getContainer()->get('db')); $this->response->data = json_encode($model->saveTest($issueId, $user->username, $result)); $this->response->message = g11n3t('Test successfully added'); }
/** * Initialize the controller. * * This will set up default model and view classes. * * @return $this Method allows chaining * * @since 1.0 * @throws \UnexpectedValueException */ public function initialize() { parent::initialize(); /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $id = $application->input->getUint('id'); if (!$id) { throw new \UnexpectedValueException('No id given'); } if (!$application->getUser()->check('admin')) { if ($application->getUser()->id != $id) { $application->enqueueMessage(g11n3t('You are not authorized to edit this user.'), 'error'); $application->redirect($application->get('uri.base.path') . 'users'); } } $this->view->id = $id; $this->model->setProject($this->getContainer()->get('app')->getProject()); }
/** * Prepare the response. * * @return mixed * * @since 1.0 * @throws \Exception */ protected function prepareResponse() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $application->getUser()->authorize('create'); $comment = $application->input->get('text', '', 'raw'); $issueNumber = $application->input->getInt('issue_number'); $project = $application->getProject(); if (!$issueNumber) { throw new \Exception('No issue number received.'); } if (!$comment) { throw new \Exception('You should write a comment first...'); } $gitHubHelper = new GitHubHelper($this->getContainer()->get('gitHub')); $comment .= $gitHubHelper->getApplicationComment($application, $project, $issueNumber); $this->response->data = $gitHubHelper->addComment($project, $issueNumber, $comment, $application->getUser()->username, $this->getContainer()->get('db')); $this->response->message = g11n3t('Your comment has been submitted'); }
/** * Method to perform sanity checks on the AbstractDatabaseTable instance properties to ensure * they are safe to store in the database. * * @return $this Method allows chaining * * @since 1.0 * @throws \InvalidArgumentException */ public function check() { $errors = array(); if (trim($this->alias) == '') { if (trim($this->title)) { $this->alias = trim($this->title); } else { $errors[] = g11n3t('An alias or a title is required.'); } } if (trim($this->text_md) == '') { $errors[] = g11n3t('Some text is required.'); } $this->alias = OutputFilter::stringURLUnicodeSlug($this->alias); if ($errors) { throw new \InvalidArgumentException(implode("\n", $errors)); } return $this; }
/** * Execute the command. * * @return void * * @since 1.0 * @throws AbortException * @throws \RuntimeException */ public function execute() { $this->getApplication()->outputTitle('Update Server'); $this->logOut('Beginning git update'); if ($this->getApplication()->input->getBool('version', false)) { $version = $this->getApplication()->input->getString('version'); // Fetch from remote sources and checkout the specified version tag $this->execCommand('cd ' . JPATH_ROOT . ' && git fetch && git checkout ' . $version . ' 2>&1'); // Update the Composer installation $this->execCommand('cd ' . JPATH_ROOT . ' && composer install --no-dev --optimize-autoloader 2>&1'); /* * If a SQL diff exists for the version requested, then process it. It is assumed that the person * updating will not be skipping versions with this implementation, but if need be, that can be supported. */ $sqlFile = JPATH_CONFIGURATION . '/updates/' . $version . '.sql'; if (file_exists($sqlFile)) { $queries = file_get_contents($sqlFile); if ($queries === false) { throw new AbortException(sprintf(g11n3t('Could not read data from the %s SQL file, please update the database manually.'), $sqlFile)); } /** @var \Joomla\Database\DatabaseDriver $db */ $db = $this->getContainer()->get('db'); $dbQueries = $db->splitSql($queries); foreach ($dbQueries as $query) { try { $db->setQuery($query)->execute(); } catch (\RuntimeException $e) { throw new AbortException(sprintf(g11n3t('SQL query failed, please verify the database structure and finish the update ' . 'manually. The database error message is: %s'), $e->getMessage())); } } } $this->logOut(sprintf('Update to version %s successful', $version)); } else { // Perform a git pull on the active branch $this->execCommand('cd ' . JPATH_ROOT . ' && git pull 2>&1'); $this->logOut('Git update Finished'); } (new Repoinfo())->setContainer($this->getContainer())->execute(); $this->logOut('Update Finished'); }
/** * Method to perform sanity checks on the AbstractDatabaseTable instance properties to ensure * they are safe to store in the database. * * @return $this Method allows chaining * * @since 1.0 * @throws \InvalidArgumentException */ public function check() { $errors = array(); if (trim($this->title) == '') { $errors[] = g11n3t('A name is required for the category.'); } if (strlen($this->title) > 150) { $errors[] = g11n3t('The length of the name can not exceed 150 characters.'); } if (trim($this->alias) == '') { $errors[] = g11n3t('An alias is required for the category.'); } if (strlen($this->alias) > 150) { $errors[] = g11n3t('The length of the alias can not exceed 150 characters.'); } if (strlen($this->color) != 6) { $errors[] = g11n3t('Color should be the hex value.'); } if ($errors) { throw new \InvalidArgumentException(implode("\n", $errors)); } return $this; }
/** * Execute the controller. * * @return string The rendered view. * * @since 1.0 * @throws \UnexpectedValueException */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $src = $application->input->get('item', array(), 'array'); if (!$src['id']) { throw new \UnexpectedValueException('No id given'); } if (!$application->getUser()->check('admin')) { if ($application->getUser()->id != $src['id']) { $application->enqueueMessage(g11n3t('You are not authorized to edit this user.'), 'error'); $application->redirect($application->get('uri.base.path') . 'user/' . $src['id']); } } try { // Save the record. (new UserModel($this->getContainer()->get('db')))->save($src); $application->enqueueMessage(g11n3t('The changes have been saved.'), 'success'); } catch (\Exception $e) { $application->enqueueMessage($e->getMessage(), 'error'); } $application->redirect($application->get('uri.base.path') . 'user/' . $src['id'] . '/edit'); parent::execute(); }
/** * Method to process the list of issues and inject into the database as needed * * @return $this * * @since 1.0 * @throws \RuntimeException */ protected function processData() { $ghIssues = $this->issues; $dbIssues = $this->getDbIssues(); if (!$ghIssues) { throw new \UnexpectedValueException('No issues received...'); } $added = 0; $updated = 0; $milestones = $this->getMilestones(); $this->out(g11n3t('Adding issues to the database...'), false); $progressBar = $this->getProgressBar(count($ghIssues)); $this->usePBar ? $this->out() : null; // Start processing the pulls now foreach ($ghIssues as $count => $ghIssue) { $this->usePBar ? $progressBar->update($count + 1) : $this->out($ghIssue->number . '...', false); if (!$this->checkInRange($ghIssue->number)) { // Not in range $this->usePBar ? null : $this->out('NiR ', false); continue; } $id = 0; foreach ($dbIssues as $dbIssue) { if ($ghIssue->number == $dbIssue->issue_number) { if ($this->force) { // Force update $this->usePBar ? null : $this->out('F ', false); $id = $dbIssue->id; break; } $d1 = new Date($ghIssue->updated_at); $d2 = new Date($dbIssue->modified_date); if ($d1 == $d2) { // No update required $this->usePBar ? null : $this->out('- ', false); continue 2; } $id = $dbIssue->id; break; } } // Store the item in the database $table = new IssuesTable($this->getContainer()->get('db')); if ($id) { $table->load($id); } $table->issue_number = $ghIssue->number; $table->title = $ghIssue->title; if ($table->description_raw != $ghIssue->body) { $table->description = $this->github->markdown->render($ghIssue->body, 'gfm', $this->project->gh_user . '/' . $this->project->gh_project); $this->checkGitHubRateLimit($this->github->markdown->getRateLimitRemaining()); $table->description_raw = $ghIssue->body; } $statusTable = new StatusTable($this->getContainer()->get('db')); // Get the list of status IDs based on the GitHub issue state $state = $ghIssue->state == 'open' ? false : true; $stateIds = $statusTable->getStateStatusIds($state); // Check if the issue status is in the array; if it is, then the item didn't change open state and we don't need to change the status if (!in_array($table->status, $stateIds)) { $table->status = $state ? 10 : 1; } $table->opened_date = (new Date($ghIssue->created_at))->format('Y-m-d H:i:s'); $table->opened_by = $ghIssue->user->login; $table->modified_date = (new Date($ghIssue->updated_at))->format('Y-m-d H:i:s'); $table->modified_by = $ghIssue->user->login; $table->project_id = $this->project->project_id; $table->milestone_id = $ghIssue->milestone && isset($milestones[$ghIssue->milestone->number]) ? $milestones[$ghIssue->milestone->number] : null; // If the issue has a diff URL, it is a pull request. if (isset($ghIssue->pull_request->diff_url)) { $table->has_code = 1; // Get the pull request corresponding to an issue. $this->debugOut('Get PR for the issue'); $pullRequest = $this->github->pulls->get($this->project->gh_user, $this->project->gh_project, $ghIssue->number); $table->pr_head_ref = $pullRequest->head->ref; $status = $this->GetMergeStatus($pullRequest); if (!$status->state) { // No status found. Let's create one! $status->state = 'pending'; $status->targetUrl = 'http://issues.joomla.org/gagaga'; $status->description = 'JTracker Bug Squad working on it...'; $status->context = 'jtracker'; // @todo Project based status messages // @$this->createStatus($ghIssue, 'pending', 'http://issues.joomla.org/gagaga', 'JTracker Bug Squad working on it...', 'CI/JTracker'); } else { // Save the merge status to database $table->merge_state = $status->state; $table->gh_merge_status = json_encode($status); } // Get commits $table->commits = json_encode($this->getCommits($pullRequest)); } // Add the closed date if the status is closed if ($ghIssue->closed_at) { $table->closed_date = (new Date($ghIssue->closed_at))->format('Y-m-d H:i:s'); } // If the title has a [# in it, assume it's a JoomlaCode Tracker ID if (preg_match('/\\[#([0-9]+)\\]/', $ghIssue->title, $matches)) { $table->foreign_number = $matches[1]; } elseif (preg_match('/tracker_item_id=([0-9]+)/', $ghIssue->body, $matches)) { $table->foreign_number = $matches[1]; } $table->labels = implode(',', $this->getLabelIds($ghIssue->labels)); $table->store(true); if (!$table->id) { // Bad coder :( - @todo when does this happen ?? throw new \RuntimeException(sprintf('Invalid issue id for issue: %1$d in project id %2$s', $ghIssue->number, $this->project->project_id)); } /* @todo see issue #194 Add an open record to the activity table $activity = new ActivitiesTable($db); $activity->project_id = $this->project->project_id; $activity->issue_number = (int) $table->issue_number; $activity->user = $issue->user->login; $activity->event = 'open'; $activity->created_date = $table->opened_date; $activity->store(); / Add a close record to the activity table if the status is closed if ($issue->closed_at) { $activity = new ActivitiesTable($db); $activity->project_id = $this->project->project_id; $activity->issue_number = (int) $table->issue_number; $activity->event = 'close'; $activity->created_date = $issue->closed_at; $activity->store(); } */ // Store was successful, update status if ($id) { ++$updated; } else { ++$added; } $this->changedIssueNumbers[] = $ghIssue->number; } // Output the final result $this->out()->logOut(sprintf(g11n3t('<ok>%1$d added, %2$d updated.</ok>'), $added, $updated)); return $this; }