From ead24da1a5f29a2194260dc61c82242cfcb414df Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Mon, 22 Dec 2014 15:48:35 +0000 Subject: [PATCH] Hopefully re-greening the build. --- PHPCI/Application.php | 42 ++++++++++++++----------- PHPCI/Controller/SettingsController.php | 6 ++-- PHPCI/Controller/WebhookController.php | 4 +-- PHPCI/Store/BuildStore.php | 8 +++-- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 821c8199..88380c87 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -47,24 +47,7 @@ class Application extends b8\Application return false; }; - // Check settings for disable_authentication enabled and user_id - $skipAuth = function () { - $config = b8\Config::getInstance(); - $state = (bool)$config->get('phpci.authentication_settings.state', false); - $id = $config->get('phpci.authentication_settings.user_id', 0); - - if (false !== $state && 0 != (int)$id) { - $user = b8\Store\Factory::getStore('User') - ->getByPrimaryKey($id); - - if ($user) { - $_SESSION['phpci_user'] = $user; - return true; - } - } - - return false; - }; + $skipAuth = [$this, 'shouldSkipAuth']; // Handler for the route we're about to register, checks for a valid session where necessary: $routeHandler = function (&$route, Response &$response) use (&$request, $validateSession, $skipAuth) { @@ -152,4 +135,27 @@ class Application extends b8\Application $projectStore = b8\Store\Factory::getStore('Project'); $layout->projects = $projectStore->getAll(); } + + /** + * Check whether we should skip auth (because it is disabled) + * @return bool + */ + protected function shouldSkipAuth() + { + $config = b8\Config::getInstance(); + $state = (bool)$config->get('phpci.authentication_settings.state', false); + $userId = $config->get('phpci.authentication_settings.user_id', 0); + + if (false !== $state && 0 != (int)$userId) { + $user = b8\Store\Factory::getStore('User') + ->getByPrimaryKey($userId); + + if ($user) { + $_SESSION['phpci_user'] = $user; + return true; + } + } + + return false; + } } diff --git a/PHPCI/Controller/SettingsController.php b/PHPCI/Controller/SettingsController.php index 3056d203..a764b7e4 100644 --- a/PHPCI/Controller/SettingsController.php +++ b/PHPCI/Controller/SettingsController.php @@ -62,16 +62,16 @@ class SettingsController extends Controller $buildSettings = $this->settings['phpci']['build']; } - $authenticationSettings = array(); + $authSettings = array(); if (isset($this->settings['phpci']['authentication_settings'])) { - $authenticationSettings = $this->settings['phpci']['authentication_settings']; + $authSettings = $this->settings['phpci']['authentication_settings']; } $this->view->github = $this->getGithubForm(); $this->view->emailSettings = $this->getEmailForm($emailSettings); $this->view->buildSettings = $this->getBuildForm($buildSettings); $this->view->isWriteable = $this->canWriteConfig(); - $this->view->authenticationSettings = $this->getAuthenticationForm($authenticationSettings); + $this->view->authenticationSettings = $this->getAuthenticationForm($authSettings); if (!empty($this->settings['phpci']['github']['token'])) { $this->view->githubUser = $this->getGithubUser($this->settings['phpci']['github']['token']); diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index 56ac0bff..a7652971 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -260,13 +260,13 @@ class WebhookController extends \PHPCI\Controller // build on merge request events if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') { $attributes = $payload['object_attributes']; - if ( $attributes['state'] == 'opened' || $attributes['state'] == 'reopened') { + if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') { $branch = $attributes['source_branch']; $commit = $attributes['last_commit']; $committer = $commit['author']['email']; - $this->createBuild($project, $commit['id'], $branch, $committer, $commit['message'] ); + $this->createBuild($project, $commit['id'], $branch, $committer, $commit['message']); } } diff --git a/PHPCI/Store/BuildStore.php b/PHPCI/Store/BuildStore.php index 4f849fa6..39ff7c78 100644 --- a/PHPCI/Store/BuildStore.php +++ b/PHPCI/Store/BuildStore.php @@ -123,11 +123,13 @@ class BuildStore extends BuildStoreBase $select = '`bm`.`build_id`, `bm`.`meta_key`, `bm`.`meta_value`'; $and = $numResults > 1 ? ' AND (`bm`.`build_id` <= :buildId) ' : ' AND (`bm`.`build_id` = :buildId) '; $where = '`bm`.`meta_key` = :key AND `bm`.`project_id` = :projectId ' . $and; - $from = ' `build_meta` AS `bm`'; - if($branch !== null) { + $from = ' `build_meta` AS `bm`'; + + if ($branch !== null) { $where .= ' AND `b`.`branch` = :branch AND `b`.`id`= `bm`.`build_id` '; $from .= ', `build` AS `b`'; - } + } + $query = 'SELECT '.$select.' FROM '.$from.' WHERE '.$where.' ORDER BY `bm`.id DESC LIMIT :numResults'; $stmt = Database::getConnection('read')->prepare($query);