Example #1
0
 /**
  * Handle an incoming web request.
  */
 public function handleRequest()
 {
     try {
         $this->response = parent::handleRequest();
     } catch (HttpException $ex) {
         $this->config->set('page_title', 'Error');
         $view = new View('exception');
         $view->exception = $ex;
         $this->response->setResponseCode($ex->getErrorCode());
         $this->response->setContent($view->render());
     } catch (\Exception $ex) {
         $this->config->set('page_title', 'Error');
         $view = new View('exception');
         $view->exception = $ex;
         $this->response->setResponseCode(500);
         $this->response->setContent($view->render());
     }
     if (View::exists('layout') && $this->response->hasLayout()) {
         $view = new View('layout');
         $pageTitle = $this->config->get('page_title', null);
         if (!is_null($pageTitle)) {
             $view->title = $pageTitle;
         }
         $view->content = $this->response->getContent();
         $this->response->setContent($view->render());
     }
     return $this->response;
 }
Example #2
0
 /**
  * Connects to MySQL and runs a specified set of queries.
  */
 public function execute()
 {
     $addresses = $this->getEmailAddresses();
     // Without some email addresses in the yml file then we
     // can't do anything.
     if (count($addresses) == 0) {
         return false;
     }
     $subjectTemplate = "PHPCI - %s - %s";
     $projectName = $this->phpci->getBuildProjectTitle();
     $logText = $this->build->getLog();
     if ($this->build->isSuccessful()) {
         $sendFailures = $this->sendSeparateEmails($addresses, sprintf($subjectTemplate, $projectName, "Passing Build"), sprintf("Log Output: <br><pre>%s</pre>", $logText));
     } else {
         $view = new View('Email/failed');
         $view->build = $this->build;
         $view->project = $this->build->getProject();
         $emailHtml = $view->render();
         $sendFailures = $this->sendSeparateEmails($addresses, sprintf($subjectTemplate, $projectName, "Failing Build"), $emailHtml);
     }
     // This is a success if we've not failed to send anything.
     $this->phpci->log(sprintf("%d emails sent", count($addresses) - count($sendFailures)));
     $this->phpci->log(sprintf("%d emails failed to send", count($sendFailures)));
     return count($sendFailures) == 0;
 }
Example #3
0
 /**
  * Send a notification mail.
  */
 public function execute()
 {
     $addresses = $this->getEmailAddresses();
     // Without some email addresses in the yml file then we
     // can't do anything.
     if (count($addresses) == 0) {
         return false;
     }
     $buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
     $projectName = $this->build->getProject()->getTitle();
     try {
         $view = $this->getMailTemplate();
     } catch (Exception $e) {
         $this->phpci->log(sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']), LogLevel::WARNING);
         $view = $this->getDefaultMailTemplate();
     }
     $view->build = $this->build;
     $view->project = $this->build->getProject();
     $layout = new View('Email/layout');
     $layout->build = $this->build;
     $layout->project = $this->build->getProject();
     $layout->content = $view->render();
     $body = $layout->render();
     $sendFailures = $this->sendSeparateEmails($addresses, sprintf("PHPCI - %s - %s", $projectName, $buildStatus), $body);
     // This is a success if we've not failed to send anything.
     $this->phpci->log(sprintf("%d emails sent", count($addresses) - $sendFailures));
     $this->phpci->log(sprintf("%d emails failed to send", $sendFailures));
     return $sendFailures === 0;
 }
Example #4
0
 protected function isFunctionCall($varName)
 {
     if (preg_match('/^([a-zA-Z0-9_-]+)\\(/', $varName, $matches)) {
         $varName = substr($varName, strlen($matches[0]));
         $args = $this->template->processFunctionArguments($varName);
         return $this->template->executeTemplateFunction($matches[1], $args);
     }
     return null;
 }
Example #5
0
 public function testFormatViewHelper()
 {
     $view = new b8\View('format', dirname(__FILE__) . '/data/view/');
     $view->number = 1000000.25;
     $view->symbol = true;
     $this->assertTrue($view->render() == '£1,000,000.25');
     $view->number = 1024;
     $view->symbol = false;
     $this->assertTrue($view->render() == '1,024.00');
 }
Example #6
0
 /**
  * Get latest builds and render as a table.
  */
 protected function getLatestBuildsHtml()
 {
     $builds = $this->buildStore->getWhere(array(), 5, 0, array(), array('id' => 'DESC'));
     $view = new b8\View('BuildsTable');
     foreach ($builds['items'] as &$build) {
         $build = BuildFactory::getBuild($build);
     }
     $view->builds = $builds['items'];
     return $view->render();
 }
Example #7
0
 /**
  * Handle the incoming request.
  * @param $action
  * @param $actionParams
  * @return \b8\b8\Http\Response|Response
  */
 public function handleAction($action, $actionParams)
 {
     $this->setView($action);
     $response = parent::handleAction($action, $actionParams);
     if (is_string($response)) {
         $this->controllerView->content = $response;
     } elseif (isset($this->view)) {
         $this->controllerView->content = $this->view->render();
     }
     $this->response->setContent($this->controllerView->render());
     return $this->response;
 }
Example #8
0
 /**
  * Send a notification mail.
  */
 public function execute()
 {
     $addresses = $this->getEmailAddresses();
     // Without some email addresses in the yml file then we
     // can't do anything.
     if (count($addresses) == 0) {
         return false;
     }
     $buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
     $projectName = $this->build->getProject()->getTitle();
     $mailTemplate = $this->build->isSuccessful() ? 'Email/success' : 'Email/failed';
     $view = new View($mailTemplate);
     $view->build = $this->build;
     $view->project = $this->build->getProject();
     $body = $view->render();
     $sendFailures = $this->sendSeparateEmails($addresses, sprintf("PHPCI - %s - %s", $projectName, $buildStatus), $body);
     // This is a success if we've not failed to send anything.
     $this->phpci->log(sprintf("%d emails sent", count($addresses) - $sendFailures));
     $this->phpci->log(sprintf("%d emails failed to send", $sendFailures));
     return $sendFailures === 0;
 }
Example #9
0
 /**
  * Handle an incoming web request.
  *
  * @return b8\b8\Http\Response|Response
  */
 public function handleRequest()
 {
     try {
         $this->response = parent::handleRequest();
     } catch (HttpException $ex) {
         $this->config->set('page_title', 'Error');
         $view = new View('exception');
         $view->exception = $ex;
         $this->response->setResponseCode($ex->getErrorCode());
         $this->response->setContent($view->render());
     } catch (\Exception $ex) {
         $this->config->set('page_title', 'Error');
         $view = new View('exception');
         $view->exception = $ex;
         $this->response->setResponseCode(500);
         $this->response->setContent($view->render());
     }
     if ($this->response->hasLayout()) {
         $this->setLayoutVariables($this->controller->layout);
         $this->controller->layout->content = $this->response->getContent();
         $this->response->setContent($this->controller->layout->render());
     }
     return $this->response;
 }
Example #10
0
 /**
  * Edit a project. Handles both the form and processing.
  */
 public function edit($projectId)
 {
     $this->requireAdmin();
     $method = $this->request->getMethod();
     $project = $this->projectStore->getById($projectId);
     if (empty($project)) {
         throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
     }
     $this->layout->title = $project->getTitle();
     $this->layout->subtitle = Lang::get('edit_project');
     $values = $project->getDataArray();
     $values['key'] = $values['ssh_private_key'];
     $values['pubkey'] = $values['ssh_public_key'];
     if ($values['type'] == "gitlab") {
         $accessInfo = $project->getAccessInformation();
         $reference = $accessInfo["user"] . '@' . $accessInfo["domain"] . ':' . $accessInfo["port"] . '/' . ltrim($project->getReference(), '/') . ".git";
         $values['reference'] = $reference;
     }
     if ($method == 'POST') {
         $values = $this->getParams();
     }
     $form = $this->projectForm($values, 'edit/' . $projectId);
     if ($method != 'POST' || $method == 'POST' && !$form->validate()) {
         $view = new b8\View('ProjectForm');
         $view->type = 'edit';
         $view->project = $project;
         $view->form = $form;
         $view->key = $values['pubkey'];
         return $view->render();
     }
     $title = $this->getParam('title', Lang::get('new_project'));
     $reference = $this->getParam('reference', null);
     $type = $this->getParam('type', null);
     $options = array('ssh_private_key' => $this->getParam('key', null), 'ssh_public_key' => $this->getParam('pubkey', null), 'build_config' => $this->getParam('build_config', null), 'allow_public_status' => $this->getParam('allow_public_status', 0), 'archived' => $this->getParam('archived', 0), 'branch' => $this->getParam('branch', null), 'group' => $this->getParam('group_id', null));
     $project = $this->projectService->updateProject($project, $title, $type, $reference, $options);
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'project/view/' . $project->getId());
     return $response;
 }
Example #11
0
 /**
  * Formats a list of builds into rows suitable for the dropdowns in the PHPCI header bar.
  * @param $builds
  * @return array
  */
 protected function formatBuilds($builds)
 {
     Project::$sleepable = array('id', 'title', 'reference', 'type');
     $rtn = array('count' => $builds['count'], 'items' => array());
     foreach ($builds['items'] as $build) {
         $item = $build->toArray(1);
         $header = new b8\View('Build/header-row');
         $header->build = $build;
         $item['header_row'] = $header->render();
         $rtn['items'][$item['id']] = $item;
     }
     ksort($rtn['items']);
     return $rtn;
 }
Example #12
0
 /**
  * Edit a user - handles both form and processing.
  */
 public function edit($userId)
 {
     $this->requireAdmin();
     $method = $this->request->getMethod();
     $user = $this->userStore->getById($userId);
     if (empty($user)) {
         throw new NotFoundException(Lang::get('user_n_not_found', $userId));
     }
     $this->layout->title = $user->getName();
     $this->layout->subtitle = Lang::get('edit_user');
     $values = array_merge($user->getDataArray(), $this->getParams());
     $form = $this->userForm($values, 'edit/' . $userId);
     if ($method != 'POST' || $method == 'POST' && !$form->validate()) {
         $view = new b8\View('UserForm');
         $view->type = 'edit';
         $view->user = $user;
         $view->form = $form;
         return $view->render();
     }
     $name = $this->getParam('name', null);
     $email = $this->getParam('email', null);
     $password = $this->getParam('password', null);
     $isAdmin = (int) $this->getParam('is_admin', 0);
     $this->userService->updateUser($user, $name, $email, $password, $isAdmin);
     header('Location: ' . PHPCI_URL . 'user');
     die;
 }
Example #13
0
 /**
  * Edit a user - handles both form and processing.
  */
 public function edit($userId)
 {
     if (!$_SESSION['user']->getIsAdmin()) {
         throw new ForbiddenException('You do not have permission to do that.');
     }
     $method = $this->request->getMethod();
     $user = $this->userStore->getById($userId);
     if (empty($user)) {
         throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
     }
     $values = array_merge($user->getDataArray(), $this->getParams());
     $form = $this->userForm($values, 'edit/' . $userId);
     if ($method != 'POST' || $method == 'POST' && !$form->validate()) {
         $view = new b8\View('UserForm');
         $view->type = 'edit';
         $view->user = $user;
         $view->form = $form;
         return $view->render();
     }
     $name = $this->getParam('name', null);
     $email = $this->getParam('email', null);
     $password = $this->getParam('password', null);
     $isAdmin = (int) $this->getParam('is_admin', 0);
     $this->userService->updateUser($user, $name, $email, $password, $isAdmin);
     header('Location: ' . PHPCI_URL . 'user');
     die;
 }
Example #14
0
 /**
  * Edit a project. Handles both the form and processing.
  */
 public function edit($projectId)
 {
     if (!$_SESSION['user']->getIsAdmin()) {
         throw new ForbiddenException('You do not have permission to do that.');
     }
     $method = $this->request->getMethod();
     $project = $this->projectStore->getById($projectId);
     if (empty($project)) {
         throw new NotFoundException('Project with id: ' . $projectId . ' not found');
     }
     $this->config->set('page_title', 'Edit: ' . $project->getTitle());
     $values = $project->getDataArray();
     $values['key'] = $values['ssh_private_key'];
     $values['pubkey'] = $values['ssh_public_key'];
     if ($values['type'] == "gitlab") {
         $accessInfo = $project->getAccessInformation();
         $reference = $accessInfo["user"] . '@' . $accessInfo["domain"] . ':' . $project->getReference() . ".git";
         $values['reference'] = $reference;
     }
     if ($method == 'POST') {
         $values = $this->getParams();
     }
     $form = $this->projectForm($values, 'edit/' . $projectId);
     if ($method != 'POST' || $method == 'POST' && !$form->validate()) {
         $view = new b8\View('ProjectForm');
         $view->type = 'edit';
         $view->project = $project;
         $view->form = $form;
         $view->key = null;
         return $view->render();
     }
     $values = $form->getValues();
     $values['ssh_private_key'] = $values['key'];
     $values['ssh_public_key'] = $values['pubkey'];
     if ($values['type'] == "gitlab") {
         preg_match('`^(.*)@(.*):(.*)/(.*)\\.git`', $values['reference'], $matches);
         $info = array();
         $info["user"] = $matches[1];
         $info["domain"] = $matches[2];
         $values['access_information'] = serialize($info);
         $values['reference'] = $matches[3] . "/" . $matches[4];
     }
     $project->setValues($values);
     $project = $this->projectStore->save($project);
     header('Location: ' . PHPCI_URL . 'project/view/' . $project->getId());
     die;
 }
Example #15
0
 /**
  * Edit a user - handles both form and processing.
  */
 public function edit($userId)
 {
     if (!$_SESSION['user']->getIsAdmin()) {
         throw new ForbiddenException('You do not have permission to do that.');
     }
     $method = $this->request->getMethod();
     $user = $this->userStore->getById($userId);
     if (empty($user)) {
         throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
     }
     $values = array_merge($user->getDataArray(), $this->getParams());
     $form = $this->userForm($values, 'edit/' . $userId);
     if ($method != 'POST' || $method == 'POST' && !$form->validate()) {
         $view = new b8\View('UserForm');
         $view->type = 'edit';
         $view->user = $user;
         $view->form = $form;
         return $view->render();
     }
     if (!empty($values['password'])) {
         $values['hash'] = password_hash($values['password'], PASSWORD_DEFAULT);
     }
     $user->setValues($values);
     $isAdmin = $this->getParam('is_admin');
     if (empty($isAdmin)) {
         $user->setIsAdmin(0);
     }
     $this->userStore->save($user);
     header('Location: ' . PHPCI_URL . 'user');
     die;
 }