Merge branch 'master' into fixes-for-windows

This commit is contained in:
Corpsee 2014-05-09 23:50:16 +07:00
commit 37bdffbbdd
20 changed files with 220 additions and 112 deletions

View file

@ -10,6 +10,7 @@
namespace PHPCI;
use b8;
use b8\Exception\HttpException;
use b8\Http\Response;
use b8\Http\Response\RedirectResponse;
use b8\View;
@ -51,6 +52,7 @@ class Application extends b8\Application
$response->setResponseCode(401);
$response->setContent('');
} else {
$_SESSION['login_redirect'] = substr($request->getPath(), 1);
$response = new RedirectResponse($response);
$response->setHeader('Location', PHPCI_URL.'session/login');
}
@ -69,7 +71,25 @@ class Application extends b8\Application
*/
public function handleRequest()
{
$this->response = parent::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');

View file

@ -21,11 +21,16 @@ class BuildFactory
/**
* @param $buildId
* @return Build
* @throws \Exception
*/
public static function getBuildById($buildId)
{
$build = Factory::getStore('Build')->getById($buildId);
if (empty($build)) {
throw new \Exception('Build ID ' . $buildId . ' does not exist.');
}
return self::getBuild($build);
}

View file

@ -10,6 +10,7 @@
namespace PHPCI\Controller;
use b8;
use b8\Exception\HttpException\NotFoundException;
use PHPCI\BuildFactory;
use PHPCI\Model\Build;
@ -36,7 +37,16 @@ class BuildController extends \PHPCI\Controller
*/
public function view($buildId)
{
$build = BuildFactory::getBuildById($buildId);
try {
$build = BuildFactory::getBuildById($buildId);
} catch (\Exception $ex) {
$build = null;
}
if (empty($build)) {
throw new NotFoundException('Build with ID: ' . $buildId . ' does not exist.');
}
$this->view->plugins = $this->getUiPlugins();
$this->view->build = $build;
$this->view->data = $this->getBuildData($build);
@ -110,6 +120,10 @@ class BuildController extends \PHPCI\Controller
{
$copy = BuildFactory::getBuildById($buildId);
if (empty($copy)) {
throw new NotFoundException('Build with ID: ' . $buildId . ' does not exist.');
}
$build = new Build();
$build->setProjectId($copy->getProjectId());
$build->setCommitId($copy->getCommitId());
@ -134,11 +148,10 @@ class BuildController extends \PHPCI\Controller
throw new \Exception('You do not have permission to do that.');
}
$build = BuildFactory::getBuildById($buildId);
$build = BuildFactory::getBuildById($buildId);
if (!$build) {
$this->response->setResponseCode(404);
return '404 - Not Found';
if (empty($build)) {
throw new NotFoundException('Build with ID: ' . $buildId . ' does not exist.');
}
$this->buildStore->delete($build);

View file

@ -65,7 +65,8 @@ class BuildStatusController extends \PHPCI\Controller
public function view($projectId)
{
$project = $this->projectStore->getById($projectId);
if (!$project) {
if (empty($project)) {
throw new NotFoundException('Project with id: ' . $projectId . ' not found');
}

View file

@ -9,17 +9,17 @@
namespace PHPCI\Controller;
use b8;
use b8\Controller;
use b8\Form;
use b8\Exception\HttpException\ForbiddenException;
use b8\Exception\HttpException\NotFoundException;
use b8\Store;
use PHPCI\BuildFactory;
use PHPCI\Helper\Github;
use PHPCI\Helper\SshKey;
use PHPCI\Model\Build;
use PHPCI\Model\Project;
use b8;
use b8\Config;
use b8\Controller;
use b8\Store;
use b8\Form;
use b8\Exception\HttpException\NotFoundException;
/**
* Project Controller - Allows users to create, edit and view projects.
@ -41,8 +41,8 @@ class ProjectController extends \PHPCI\Controller
public function init()
{
$this->buildStore = Store\Factory::getStore('Build');
$this->projectStore = Store\Factory::getStore('Project');
$this->buildStore = Store\Factory::getStore('Build');
$this->projectStore = Store\Factory::getStore('Project');
}
/**
@ -51,17 +51,18 @@ class ProjectController extends \PHPCI\Controller
public function view($projectId)
{
$project = $this->projectStore->getById($projectId);
if (!$project) {
if (empty($project)) {
throw new NotFoundException('Project with id: ' . $projectId . ' not found');
}
$page = $this->getParam('p', 1);
$builds = $this->getLatestBuildsHtml($projectId, (($page - 1) * 10));
$page = $this->getParam('p', 1);
$builds = $this->getLatestBuildsHtml($projectId, (($page - 1) * 10));
$this->view->builds = $builds[0];
$this->view->total = $builds[1];
$this->view->project = $project;
$this->view->page = $page;
$this->view->builds = $builds[0];
$this->view->total = $builds[1];
$this->view->project = $project;
$this->view->page = $page;
$this->config->set('page_title', $project->getTitle());
@ -76,6 +77,10 @@ class ProjectController extends \PHPCI\Controller
/* @var \PHPCI\Model\Project $project */
$project = $this->projectStore->getById($projectId);
if (empty($project)) {
throw new NotFoundException('Project with id: ' . $projectId . ' not found');
}
$build = new Build();
$build->setProjectId($projectId);
$build->setCommitId('Manual');
@ -96,7 +101,7 @@ class ProjectController extends \PHPCI\Controller
public function delete($projectId)
{
if (!$_SESSION['user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
throw new ForbiddenException('You do not have permission to do that.');
}
$project = $this->projectStore->getById($projectId);
@ -120,10 +125,10 @@ class ProjectController extends \PHPCI\Controller
*/
protected function getLatestBuildsHtml($projectId, $start = 0)
{
$criteria = array('project_id' => $projectId);
$order = array('id' => 'DESC');
$builds = $this->buildStore->getWhere($criteria, 10, $start, array(), $order);
$view = new b8\View('BuildsTable');
$criteria = array('project_id' => $projectId);
$order = array('id' => 'DESC');
$builds = $this->buildStore->getWhere($criteria, 10, $start, array(), $order);
$view = new b8\View('BuildsTable');
foreach ($builds['items'] as &$build) {
$build = BuildFactory::getBuild($build);
@ -142,7 +147,7 @@ class ProjectController extends \PHPCI\Controller
$this->config->set('page_title', 'Add Project');
if (!$_SESSION['user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
throw new ForbiddenException('You do not have permission to do that.');
}
$method = $this->request->getMethod();
@ -210,31 +215,33 @@ class ProjectController extends \PHPCI\Controller
public function edit($projectId)
{
if (!$_SESSION['user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
throw new ForbiddenException('You do not have permission to do that.');
}
$method = $this->request->getMethod();
$project = $this->projectStore->getById($projectId);
$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['git_key'];
$values['pubkey'] = $values['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();
} else {
$values = $project->getDataArray();
$values['key'] = $values['git_key'];
$values['pubkey'] = $values['public_key'];
if ($values['type'] == "gitlab") {
$accessInfo = $project->getAccessInformation();
$reference = $accessInfo["user"].'@'.$accessInfo["domain"].':' . $project->getReference().".git";
$values['reference'] = $reference;
}
}
$form = $this->projectForm($values, 'edit/' . $projectId);
$form = $this->projectForm($values, 'edit/' . $projectId);
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
$view = new b8\View('ProjectForm');

View file

@ -43,7 +43,7 @@ class SessionController extends \PHPCI\Controller
if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
$_SESSION['user_id'] = $user->getId();
header('Location: ' . PHPCI_URL);
header('Location: ' . $this->getLoginRedirect());
die;
} else {
$isLoginFailure = true;
@ -159,4 +159,16 @@ MSG;
return $this->view->render();
}
protected function getLoginRedirect()
{
$rtn = PHPCI_URL;
if (!empty($_SESSION['login_redirect'])) {
$rtn .= $_SESSION['login_redirect'];
$_SESSION['login_redirect'] = null;
}
return $rtn;
}
}

View file

@ -10,6 +10,8 @@
namespace PHPCI\Controller;
use b8;
use b8\Exception\HttpException\ForbiddenException;
use b8\Exception\HttpException\NotFoundException;
use b8\Form;
use PHPCI\Controller;
use PHPCI\Model\User;
@ -106,12 +108,11 @@ class UserController extends Controller
public function add()
{
if (!$_SESSION['user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
throw new ForbiddenException('You do not have permission to do that.');
}
$this->config->set('page_title', 'Add User');
$method = $this->request->getMethod();
if ($method == 'POST') {
@ -132,7 +133,6 @@ class UserController extends Controller
}
$values = $form->getValues();
$values['is_admin'] = $values['admin'] ? 1 : 0;
$values['hash'] = password_hash($values['password'], PASSWORD_DEFAULT);
$user = new User();
@ -150,42 +150,40 @@ class UserController extends Controller
public function edit($userId)
{
if (!$_SESSION['user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
throw new ForbiddenException('You do not have permission to do that.');
}
$method = $this->request->getMethod();
$user = $this->userStore->getById($userId);
$method = $this->request->getMethod();
$user = $this->userStore->getById($userId);
$this->config->set('page_title', 'Edit: ' . $user->getName());
if ($method == 'POST') {
$values = $this->getParams();
} else {
$values = $user->getDataArray();
$values['admin'] = $values['is_admin'];
if (empty($user)) {
throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
}
$form = $this->userForm($values, 'edit/' . $userId);
$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;
$view = new b8\View('UserForm');
$view->type = 'edit';
$view->user = $user;
$view->form = $form;
return $view->render();
}
$values = $form->getValues();
$values['is_admin'] = $values['admin'] ? 1 : 0;
if (!empty($values['password'])) {
$values['hash'] = password_hash($values['password'], PASSWORD_DEFAULT);
}
$user->setValues($values);
$user = $this->userStore->save($user);
$isAdmin = $this->getParam('is_admin');
if (empty($isAdmin)) {
$user->setIsAdmin(0);
}
$this->userStore->save($user);
header('Location: '.PHPCI_URL.'user');
die;
@ -216,13 +214,20 @@ class UserController extends Controller
$form->addField($field);
$field = new Form\Element\Password('password');
$field->setRequired(true);
$field->setLabel('Password' . ($type == 'edit' ? ' (leave blank to keep current password)' : ''));
if ($type == 'add') {
$field->setRequired(true);
$field->setLabel('Password');
} else {
$field->setRequired(false);
$field->setLabel('Password (leave blank to keep current password)');
}
$field->setClass('form-control');
$field->setContainerClass('form-group');
$form->addField($field);
$field = new Form\Element\Checkbox('admin');
$field = new Form\Element\Checkbox('is_admin');
$field->setRequired(false);
$field->setCheckedValue(1);
$field->setLabel('Is this user an administrator?');
@ -244,10 +249,15 @@ class UserController extends Controller
public function delete($userId)
{
if (!$_SESSION['user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
throw new ForbiddenException('You do not have permission to do that.');
}
$user = $this->userStore->getById($userId);
if (empty($user)) {
throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
}
$this->userStore->delete($user);
header('Location: '.PHPCI_URL.'user');

View file

@ -89,13 +89,7 @@ class PhpDocblockChecker implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
*/
public function execute()
{
$ignore = '';
if (count($this->ignore)) {
$ignore = ' --exclude="' . implode(',', $this->ignore) . '"';
}
var_dump($ignore);
// Check that the binary exists:
$checker = $this->phpci->findBinary('phpdoccheck');
if (!$checker) {
@ -103,9 +97,25 @@ class PhpDocblockChecker implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
return false;
}
$path = $this->phpci->buildPath . $this->path;
// Build ignore string:
$ignore = '';
if (count($this->ignore)) {
$ignore = ' --exclude="' . implode(',', $this->ignore) . '"';
}
$cmd = $checker . ' --json --directory="%s"%s%s%s';
// Are we skipping any checks?
$add = '';
if ($this->skipClasses) {
$add .= ' --skip-classes';
}
if ($this->skipMethods) {
$add .= ' --skip-methods';
}
// Build command string:
$path = $this->phpci->buildPath . $this->path;
$cmd = $checker . ' --json --directory="%s"%s%s';
// Disable exec output logging, as we don't want the XML report in the log:
$this->phpci->logExecOutput(false);
@ -115,8 +125,7 @@ class PhpDocblockChecker implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
$cmd,
$path,
$ignore,
($this->skipClasses ? ' --skip-classes' : ''),
($this->skipMethods ? ' --skip-methods' : '')
$add
);
// Re-enable exec output logging:

View file

@ -58,7 +58,7 @@ class PhpSpec implements PHPCI\Plugin
return false;
}
$success = $this->phpci->executeCommand($phpspec . ' --format=pretty --no-code-generation');
$success = $this->phpci->executeCommand($phpspec . ' --format=pretty --no-code-generation run');
chdir($curdir);

View file

@ -0,0 +1,9 @@
<div class="panel panel-danger">
<div class="panel-heading">
<h2 class="panel-title">Sorry, there was a problem</h2>
</div>
<div class="panel-body">
<?php print $exception->getMessage(); ?>
</div>
</div>

View file

@ -59,8 +59,10 @@ if (!file_exists(dirname(__FILE__) . '/vendor/autoload.php') && defined('PHPCI_I
// Load Composer autoloader:
require_once(dirname(__FILE__) . '/vendor/autoload.php');
$loggerConfig = LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php");
Handler::register($loggerConfig->getFor('_'));
if (defined('PHPCI_IS_CONSOLE') && PHPCI_IS_CONSOLE) {
$loggerConfig = LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php");
Handler::register($loggerConfig->getFor('_'));
}
// Load configuration if present:
$conf = array();

View file

@ -23,7 +23,7 @@
},
"require": {
"php": ">=5.3.3",
"php": ">=5.3.8",
"ext-mcrypt": "*",
"ext-pdo": "*",
"ext-pdo_mysql": "*",

4
composer.lock generated
View file

@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "0692857385ac27090b3000cbc680ced8",
"hash": "07244b4e81274ba07fdb9f0166c73678",
"packages": [
{
"name": "block8/b8framework",
@ -885,7 +885,7 @@
],
"platform": {
"php": ">=5.3.3",
"php": ">=5.3.8",
"ext-mcrypt": "*",
"ext-pdo": "*",
"ext-pdo_mysql": "*"

View file

@ -4,6 +4,7 @@ var locPlugin = PHPCI.UiPlugin.extend({
title: 'Lines of Code',
lastData: null,
displayOnUpdate: false,
rendered: false,
register: function() {
var self = this;
@ -14,8 +15,7 @@ var locPlugin = PHPCI.UiPlugin.extend({
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
self.displayOnUpdate = true;
if (data.queryData.status > 1 && !self.rendered) {
query();
}
});
@ -29,10 +29,7 @@ var locPlugin = PHPCI.UiPlugin.extend({
onUpdate: function(e) {
this.lastData = e.queryData;
if (this.displayOnUpdate) {
this.displayChart();
}
this.displayChart();
},
displayChart: function() {
@ -42,6 +39,8 @@ var locPlugin = PHPCI.UiPlugin.extend({
return;
}
this.rendered = true;
$('#phploc-lines').empty().animate({height: '275px'});
var titles = ['Build', 'Lines', 'Comment Lines', 'Non-Comment Lines', 'Logical Lines'];

View file

@ -3,8 +3,8 @@ var phpcsPlugin = PHPCI.UiPlugin.extend({
css: 'col-lg-12 col-md-12 col-sm-12 col-xs-12',
title: 'PHP Code Sniffer',
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
@ -14,16 +14,14 @@ var phpcsPlugin = PHPCI.UiPlugin.extend({
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
self.displayOnUpdate = true;
$(window).on('build-updated', function() {
if (!self.rendered) {
query();
}
});
},
render: function() {
return $('<table class="table table-striped" id="phpcs-data">' +
'<thead>' +
'<tr>' +
@ -35,10 +33,11 @@ var phpcsPlugin = PHPCI.UiPlugin.extend({
},
onUpdate: function(e) {
if (this.lastData && this.lastData[0]) {
if (!e.queryData) {
return;
}
this.rendered = true;
this.lastData = e.queryData;
var errors = this.lastData[0].meta_value;

View file

@ -5,6 +5,7 @@ var phpdoccheckPlugin = PHPCI.UiPlugin.extend({
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
@ -14,8 +15,8 @@ var phpdoccheckPlugin = PHPCI.UiPlugin.extend({
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
$(window).on('build-updated', function() {
if (!self.rendered) {
self.displayOnUpdate = true;
query();
}
@ -23,7 +24,6 @@ var phpdoccheckPlugin = PHPCI.UiPlugin.extend({
},
render: function() {
return $('<table class="table table-striped" id="phpdoccheck-data">' +
'<thead>' +
'<tr>' +
@ -37,10 +37,11 @@ var phpdoccheckPlugin = PHPCI.UiPlugin.extend({
},
onUpdate: function(e) {
if (this.lastData && this.lastData[0]) {
if (!e.queryData) {
return;
}
this.rendered = true;
this.lastData = e.queryData;
var errors = this.lastData[0].meta_value;

View file

@ -5,6 +5,7 @@ var phpmdPlugin = PHPCI.UiPlugin.extend({
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
@ -14,8 +15,8 @@ var phpmdPlugin = PHPCI.UiPlugin.extend({
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
$(window).on('build-updated', function() {
if (!self.rendered) {
self.displayOnUpdate = true;
query();
}
@ -36,10 +37,11 @@ var phpmdPlugin = PHPCI.UiPlugin.extend({
},
onUpdate: function(e) {
if (this.lastData && this.lastData[0]) {
if (!e.queryData) {
return;
}
this.rendered = true;
this.lastData = e.queryData;
var errors = this.lastData[0].meta_value;

View file

@ -5,6 +5,7 @@ var phpunitPlugin = PHPCI.UiPlugin.extend({
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
@ -14,8 +15,8 @@ var phpunitPlugin = PHPCI.UiPlugin.extend({
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
$(window).on('build-updated', function() {
if (!self.rendered) {
self.displayOnUpdate = true;
query();
}
@ -33,10 +34,11 @@ var phpunitPlugin = PHPCI.UiPlugin.extend({
},
onUpdate: function(e) {
if (this.lastData && this.lastData[0]) {
if (!e.queryData) {
return;
}
this.rendered = true;
this.lastData = e.queryData;
var tests = this.lastData[0].meta_value;

View file

@ -12,6 +12,7 @@ var warningsPlugin = PHPCI.UiPlugin.extend({
},
data: {},
displayOnUpdate: false,
rendered: false,
register: function() {
var self = this;
@ -26,7 +27,7 @@ var warningsPlugin = PHPCI.UiPlugin.extend({
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
if (!self.rendered && data.queryData.status > 1) {
self.displayOnUpdate = true;
for (var query in queries) {
queries[query]();
@ -68,6 +69,7 @@ var warningsPlugin = PHPCI.UiPlugin.extend({
displayChart: function() {
var self = this;
self.rendered = true;
$('#build-warnings').empty().animate({height: '275px'});

View file

@ -317,8 +317,19 @@ var PHPCIObject = Class.extend({
updateInterval: null,
init: function(build) {
var self = this;
this.buildId = build;
this.registerQuery('build-updated', 10);
$(window).on('build-updated', function(data) {
// If the build has finished, stop updating every 10 seconds:
if (data.queryData.status > 1) {
self.cancelQuery('build-updated');
$(window).trigger({type: 'build-complete'});
}
});
},
registerQuery: function(name, seconds, query) {
@ -337,12 +348,16 @@ var PHPCIObject = Class.extend({
};
if (seconds != -1) {
setInterval(cb, seconds * 1000);
self.queries[name] = setInterval(cb, seconds * 1000);
}
return cb;
},
cancelQuery: function (name) {
clearInterval(this.queries[name]);
},
registerPlugin: function(plugin) {
this.plugins[plugin.id] = plugin;
plugin.register();