Merge branch 'feature-build-source'

This commit is contained in:
Dmitry Khomutov 2017-10-19 22:33:39 +07:00
commit 9d07b577c5
63 changed files with 1593 additions and 1782 deletions

View file

@ -30,8 +30,8 @@ var Build = Class.extend({
if (self.buildData) {
$('.build-duration').html(self.buildData.duration ? (self.buildData.duration + ' ' + Lang.get('seconds')) : ('0 ' + Lang.get('seconds')));
$('.build-started').html(self.buildData.started ? self.buildData.started : '');
$('.build-finished').html(self.buildData.finished ? self.buildData.finished : '');
$('.build-started').html(self.buildData.start_date ? self.buildData.start_date : '');
$('.build-finished').html(self.buildData.finish_date ? self.buildData.finish_date : '');
$('#log pre').html(self.buildData.log);
$('.errors-table tbody').html(self.buildData.error_html);

View file

@ -76,8 +76,9 @@ class Model
$rtn = $childArray;
} else {
$rtn = (is_string($value) && !mb_check_encoding($value, 'UTF-8')) ? mb_convert_encoding($value,
'UTF-8') : $value;
$rtn = (is_string($value) && !mb_check_encoding($value, 'UTF-8'))
? mb_convert_encoding($value, 'UTF-8')
: $value;
}
}
@ -121,7 +122,7 @@ class Model
protected function validateString($name, $value)
{
if (!is_string($value) && !is_null($value)) {
throw new HttpException\ValidationException($name . ' must be a string.');
throw new HttpException\ValidationException('Column "', $name . '" must be a string.');
}
}
@ -132,7 +133,7 @@ class Model
}
if (!is_numeric($value) && !is_null($value)) {
throw new HttpException\ValidationException($name . ' must be an integer.');
throw new HttpException\ValidationException('Column "', $name . '" must be an integer.');
}
if (!is_int($value) && !is_null($value)) {
@ -143,7 +144,7 @@ class Model
protected function validateFloat($name, &$value)
{
if (!is_numeric($value) && !is_null($value)) {
throw new HttpException\ValidationException($name . ' must be a float.');
throw new HttpException\ValidationException('Column "', $name . '" must be a float.');
}
if (!is_float($value) && !is_null($value)) {
@ -158,17 +159,16 @@ class Model
}
if ((!is_object($value) || !($value instanceof \DateTime)) && !is_null($value)) {
throw new HttpException\ValidationException($name . ' must be a date object.');
throw new HttpException\ValidationException('Column "', $name . '" must be a date object.');
}
$value = empty($value) ? null : $value->format('Y-m-d H:i:s');
}
protected function validateNotNull($name, &$value)
protected function validateNotNull($name, $value)
{
if (is_null($value)) {
throw new HttpException\ValidationException($name . ' must not be null.');
throw new HttpException\ValidationException('Column "', $name . '" must not be null.');
}
}

View file

@ -185,7 +185,7 @@ class Builder implements LoggerAwareInterface
}
// Update the build in the database, ping any external services.
$this->build->setStarted(new \DateTime());
$this->build->setStartDate(new \DateTime());
$this->store->save($this->build);
$this->build->sendStatusPostback();
$success = true;
@ -256,7 +256,7 @@ class Builder implements LoggerAwareInterface
// Update the build in the database, ping any external services, etc.
$this->build->sendStatusPostback();
$this->build->setFinished(new \DateTime());
$this->build->setFinishDate(new \DateTime());
$removeBuilds = (bool)Config::getInstance()->get('php-censor.build.remove_builds', true);
if ($removeBuilds) {

View file

@ -2,6 +2,7 @@
namespace PHPCensor\Command;
use PHPCensor\Model\Build;
use PHPCensor\Service\BuildService;
use PHPCensor\Store\ProjectStore;
use Symfony\Component\Console\Command\Command;
@ -72,7 +73,7 @@ class CreateBuildCommand extends Command
}
try {
$this->buildService->createBuild($project, $environment, $commitId, $branch, null, $ciEmail, $ciMessage);
$this->buildService->createBuild($project, $environment, $commitId, $branch, null, $ciEmail, $ciMessage, Build::SOURCE_MANUAL_CONSOLE);
$output->writeln('Build Created');
} catch (\Exception $e) {
$output->writeln('<error>Failed</error>');

View file

@ -526,6 +526,8 @@ class InstallCommand extends Command
$group = new ProjectGroup();
$group->setTitle('Projects');
$group->setCreateDate(new \DateTime());
$group->setUserId(0);
Factory::getStore('ProjectGroup')->save($group);

View file

@ -114,7 +114,7 @@ class RunCommand extends Command
$this->logger->addError($ex->getMessage());
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$build->setFinishDate(new \DateTime());
$build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage());
$buildStore->save($build);
$build->sendStatusPostback();
@ -154,12 +154,12 @@ class RunCommand extends Command
$build = BuildFactory::getBuild($build);
$now = time();
$start = $build->getStarted()->getTimestamp();
$start = $build->getStartDate()->getTimestamp();
if (($now - $start) > $timeout) {
$this->logger->addInfo(sprintf('Build %d marked as failed due to timeout.', $build->getId()));
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$build->setFinishDate(new \DateTime());
$store->save($build);
$build->removeBuildDirectory();
continue;

View file

@ -83,14 +83,14 @@ class ScheduleBuildCommand extends Command
// If it's running or just created, we don't want to reschedule already.
continue;
}
if ($date < $build->getFinished()) {
if ($date < $build->getFinishDate()) {
// If finished date is newer then the specified since days, we don't want to reschedule
continue;
}
}
try {
$this->buildService->createBuild($project, null);
$this->buildService->createBuild($project, null, '', null, null, null, null, Build::SOURCE_PERIODICAL);
$output->writeln("Build Created for {$project->getTitle()}");
} catch (\Exception $e) {
$output->writeln('<error>Failed</error>');

View file

@ -125,20 +125,20 @@ class BuildController extends Controller
*/
protected function getBuildData(Build $build)
{
$data = [];
$data['status'] = (int)$build->getStatus();
$data['log'] = $this->cleanLog($build->getLog());
$data['created'] = !is_null($build->getCreated()) ? $build->getCreated()->format('Y-m-d H:i:s') : null;
$data['started'] = !is_null($build->getStarted()) ? $build->getStarted()->format('Y-m-d H:i:s') : null;
$data['finished'] = !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : null;
$data['duration'] = $build->getDuration();
$data = [];
$data['status'] = (int)$build->getStatus();
$data['log'] = $this->cleanLog($build->getLog());
$data['create_date'] = !is_null($build->getCreateDate()) ? $build->getCreateDate()->format('Y-m-d H:i:s') : null;
$data['start_date'] = !is_null($build->getStartDate()) ? $build->getStartDate()->format('Y-m-d H:i:s') : null;
$data['finish_date'] = !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : null;
$data['duration'] = $build->getDuration();
/** @var \PHPCensor\Store\BuildErrorStore $errorStore */
$errorStore = b8\Store\Factory::getStore('BuildError');
$errors = $errorStore->getErrorsForBuild($build->getId());
$errorView = new b8\View('Build/errors');
$errorView->build = $build;
$errorView = new b8\View('Build/errors');
$errorView->build = $build;
$errorView->errors = $errors;
$data['errors'] = $errorStore->getErrorTotalForBuild($build->getId());

View file

@ -7,6 +7,7 @@ use b8\Form;
use PHPCensor\Controller;
use PHPCensor\Model\ProjectGroup;
use PHPCensor\Helper\Lang;
use PHPCensor\Model\User;
/**
* Project Controller - Allows users to create, edit and view projects.
@ -71,10 +72,19 @@ class GroupController extends Controller
if ($this->request->getMethod() == 'POST') {
$group->setTitle($this->getParam('title'));
if (is_null($groupId)) {
/** @var User $user */
$user = $_SESSION['php-censor-user'];
$group->setCreateDate(new \DateTime());
$group->setUserId($user->getId());
}
$this->groupStore->save($group);
$response = new b8\Http\Response\RedirectResponse();
$response->setHeader('Location', APP_URL.'group');
return $response;
}

View file

@ -3,8 +3,8 @@
namespace PHPCensor\Controller;
use b8;
use b8\Form;
use b8\Exception\HttpException\NotFoundException;
use b8\Form;
use b8\Store;
use PHPCensor;
use PHPCensor\BuildFactory;
@ -13,6 +13,8 @@ use PHPCensor\Helper\Lang;
use PHPCensor\Helper\SshKey;
use PHPCensor\Service\BuildService;
use PHPCensor\Service\ProjectService;
use PHPCensor\Model\Build;
use b8\Http\Response\RedirectResponse;
/**
* Project Controller - Allows users to create, edit and view projects.
@ -96,7 +98,7 @@ class ProjectController extends PHPCensor\Controller
$pages = $builds[1] == 0 ? 1 : ceil($builds[1] / $perPage);
if ($page > $pages) {
$response = new b8\Http\Response\RedirectResponse();
$response = new RedirectResponse();
$response->setHeader('Location', APP_URL . 'project/view/' . $projectId);
return $response;
@ -132,7 +134,7 @@ class ProjectController extends PHPCensor\Controller
*
* @throws NotFoundException
*
* @return b8\Http\Response\RedirectResponse
* @return RedirectResponse
*
*/
public function build($projectId)
@ -171,15 +173,18 @@ class ProjectController extends PHPCensor\Controller
];
}
$email = $_SESSION['php-censor-user']->getEmail();
/** @var PHPCensor\Model\User $user */
$user = $_SESSION['php-censor-user'];
$build = $this->buildService->createBuild(
$project,
$environment,
null,
'',
$branch,
null,
$email,
$user->getEmail(),
null,
Build::SOURCE_MANUAL_WEB,
$user->getId(),
$extra
);
@ -187,7 +192,7 @@ class ProjectController extends PHPCensor\Controller
$_SESSION['global_error'] = Lang::get('add_to_queue_failed');
}
$response = new b8\Http\Response\RedirectResponse();
$response = new RedirectResponse();
$response->setHeader('Location', APP_URL.'build/view/' . $build->getId());
return $response;
@ -203,7 +208,7 @@ class ProjectController extends PHPCensor\Controller
$project = $this->projectStore->getById($projectId);
$this->projectService->deleteProject($project);
$response = new b8\Http\Response\RedirectResponse();
$response = new RedirectResponse();
$response->setHeader('Location', APP_URL);
return $response;
@ -322,9 +327,11 @@ class ProjectController extends PHPCensor\Controller
'environments' => $this->getParam('environments', null),
];
$project = $this->projectService->createProject($title, $type, $reference, $options);
/** @var PHPCensor\Model\User $user */
$user = $_SESSION['php-censor-user'];
$project = $this->projectService->createProject($title, $type, $reference, $user->getId(), $options);
$response = new b8\Http\Response\RedirectResponse();
$response = new RedirectResponse();
$response->setHeader('Location', APP_URL.'project/view/' . $project->getId());
return $response;
@ -393,7 +400,7 @@ class ProjectController extends PHPCensor\Controller
$project = $this->projectService->updateProject($project, $title, $type, $reference, $options);
$response = new b8\Http\Response\RedirectResponse();
$response = new RedirectResponse();
$response->setHeader('Location', APP_URL.'project/view/' . $project->getId());
return $response;

View file

@ -665,6 +665,8 @@ class WebhookController extends Controller
$tag,
$committer,
$commitMessage,
Build::SOURCE_WEBHOOK,
0,
$extra
);
@ -702,6 +704,8 @@ class WebhookController extends Controller
$tag,
$committer,
$commitMessage,
Build::SOURCE_WEBHOOK,
0,
$extra
);

View file

@ -145,6 +145,13 @@ PHP Censor',
'next_link' => 'Next &raquo;',
'public_key' => 'Public Key',
'delete_build' => 'Delete Build',
'build_source' => 'Build source',
'source_unknown' => 'Unknown',
'source_manual_web' => 'Manual (from Web)',
'source_manual_console' => 'Manual (from CLI)',
'source_periodical' => 'Periodical',
'source_webhook' => 'Webhook',
'webhooks' => 'Webhooks',
'webhooks_help_github' => 'To automatically build this project when new commits are pushed, add the URL below

View file

@ -142,6 +142,13 @@ PHP Censor',
'next_link' => 'След. &raquo;',
'public_key' => 'Публичный ключ',
'delete_build' => 'Удалить сборку',
'build_source' => 'Источник сборки',
'source_unknown' => 'Неизвестный',
'source_manual_web' => 'Вручную (Через Web)',
'source_manual_console' => 'Вручную (Через CLI)',
'source_periodical' => 'Переодический',
'source_webhook' => 'Webhook',
'webhooks' => 'Webhooks',
'webhooks_help_github' => 'Чтобы Автоматически собирать этот проект при публикации новых коммитов, добавьте URL ниже в качестве нового хука в разделе настроек <a href="https://github.com/%s/settings/hooks">Webhooks

View file

@ -3,6 +3,7 @@
use Phinx\Migration\AbstractMigration;
use PHPCensor\Model\BuildMeta;
use PHPCensor\Model\BuildError;
use b8\Store\Factory;
class ConvertErrors extends AbstractMigration
{
@ -20,10 +21,10 @@ class ConvertErrors extends AbstractMigration
{
$count = 100;
$this->metaStore = \b8\Store\Factory::getStore('BuildMeta');
$this->errorStore = \b8\Store\Factory::getStore('BuildError');
$this->metaStore = Factory::getStore('BuildMeta');
$this->errorStore = Factory::getStore('BuildError');
while ($count == 100) {
while ($count === 100) {
$data = $this->metaStore->getErrorsForUpgrade(100);
$count = count($data);
@ -65,7 +66,7 @@ class ConvertErrors extends AbstractMigration
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_mess_detector');
$buildError->setCreatedDate(new \DateTime());
$buildError->setCreateDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line_start']);
$buildError->setLineEnd($error['line_end']);
@ -86,7 +87,7 @@ class ConvertErrors extends AbstractMigration
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_code_sniffer');
$buildError->setCreatedDate(new \DateTime());
$buildError->setCreateDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line']);
$buildError->setLineEnd($error['line']);
@ -116,7 +117,7 @@ class ConvertErrors extends AbstractMigration
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_docblock_checker');
$buildError->setCreatedDate(new \DateTime());
$buildError->setCreateDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line']);
$buildError->setLineEnd($error['line']);
@ -147,7 +148,7 @@ class ConvertErrors extends AbstractMigration
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_cpd');
$buildError->setCreatedDate(new \DateTime());
$buildError->setCreateDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line_start']);
$buildError->setLineEnd($error['line_end']);
@ -168,7 +169,7 @@ class ConvertErrors extends AbstractMigration
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('technical_debt');
$buildError->setCreatedDate(new \DateTime());
$buildError->setCreateDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line']);
$buildError->setSeverity(BuildError::SEVERITY_NORMAL);

View file

@ -9,11 +9,15 @@ class AddedLanguageAndPerPageForUser extends AbstractMigration
$table = $this->table('user');
if (!$table->hasColumn('language')) {
$table->addColumn('language', 'string', ['limit' => 5, 'null' => true])->save();
$table
->addColumn('language', 'string', ['limit' => 5, 'null' => true])
->save();
}
if (!$table->hasColumn('per_page')) {
$table->addColumn('per_page', 'integer', ['null' => true])->save();
$table
->addColumn('per_page', 'integer', ['null' => true])
->save();
}
}
@ -22,11 +26,15 @@ class AddedLanguageAndPerPageForUser extends AbstractMigration
$table = $this->table('user');
if ($table->hasColumn('language')) {
$table->removeColumn('language')->save();
$table
->removeColumn('language')
->save();
}
if ($table->hasColumn('per_page')) {
$table->removeColumn('per_page')->save();
$table
->removeColumn('per_page')
->save();
}
}
}

View file

@ -13,25 +13,35 @@ class AddEnvironment extends AbstractMigration
}
if (!$table->hasColumn('project_id')) {
$table->addColumn('project_id', 'integer')->save();
$table
->addColumn('project_id', 'integer')
->save();
}
if (!$table->hasColumn('name')) {
$table->addColumn('name', 'string', ['limit' => 250])->save();
$table
->addColumn('name', 'string', ['limit' => 250])
->save();
}
if (!$table->hasColumn('branches')) {
$table->addColumn('branches', 'text')->save();
$table
->addColumn('branches', 'text')
->save();
}
if (!$table->hasIndex(['project_id', 'name'])) {
$table->addIndex(['project_id', 'name'])->save();
$table
->addIndex(['project_id', 'name'])
->save();
}
$table = $this->table('build');
if (!$table->hasColumn('environment')) {
$table->addColumn('environment', 'string', ['limit' => 250])->save();
$table
->addColumn('environment', 'string', ['limit' => 250])
->save();
}
}
@ -46,7 +56,9 @@ class AddEnvironment extends AbstractMigration
$table = $this->table('build');
if ($table->hasColumn('environment')) {
$table->removeColumn('environment')->save();
$table
->removeColumn('environment')
->save();
}
}
}

View file

@ -0,0 +1,33 @@
<?php
use Phinx\Migration\AbstractMigration;
use PHPCensor\Model\Build;
class AddedSourceColumnToBuildTable extends AbstractMigration
{
public function up()
{
$table = $this->table('build');
if (!$table->hasColumn('source')) {
$table
->addColumn('source', 'integer', ['default' => Build::SOURCE_UNKNOWN])
->save();
$this->execute("UPDATE build SET source = 4");
$this->execute("UPDATE build SET source = 1, commit_id = '', commit_message = '' WHERE commit_id = 'Manual'");
$this->execute("UPDATE build SET source = 1, commit_message = '' WHERE commit_message = 'Manual'");
}
}
public function down()
{
$table = $this->table('build');
if ($table->hasColumn('source')) {
$table
->removeColumn('source')
->save();
}
}
}

View file

@ -9,7 +9,9 @@ class AddedTagColumnToBuildTable extends AbstractMigration
$table = $this->table('build');
if (!$table->hasColumn('tag')) {
$table->addColumn('tag', 'string', ['limit' => 250, 'null' => true])->save();
$table
->addColumn('tag', 'string', ['limit' => 250, 'null' => true])
->save();
}
}
@ -18,7 +20,9 @@ class AddedTagColumnToBuildTable extends AbstractMigration
$table = $this->table('build');
if ($table->hasColumn('tag')) {
$table->removeColumn('tag')->save();
$table
->removeColumn('tag')
->save();
}
}
}

View file

@ -9,7 +9,9 @@ class AddedRememberMeLogin extends AbstractMigration
$table = $this->table('user');
if (!$table->hasColumn('remember_key')) {
$table->addColumn('remember_key', 'string', ['limit' => 32, 'null' => true])->save();
$table
->addColumn('remember_key', 'string', ['limit' => 32, 'null' => true])
->save();
}
}
@ -18,7 +20,9 @@ class AddedRememberMeLogin extends AbstractMigration
$table = $this->table('user');
if ($table->hasColumn('remember_key')) {
$table->removeColumn('remember_key')->save();
$table
->removeColumn('remember_key')
->save();
}
}
}

View file

@ -6,19 +6,23 @@ class AddedDefaultBranchOnly extends AbstractMigration
{
public function up()
{
$project = $this->table('project');
$table = $this->table('project');
if (!$project->hasColumn('default_branch_only')) {
$project->addColumn('default_branch_only', 'integer', ['default' => 0])->save();
if (!$table->hasColumn('default_branch_only')) {
$table
->addColumn('default_branch_only', 'integer', ['default' => 0])
->save();
}
}
public function down()
{
$project = $this->table('project');
$table = $this->table('project');
if ($project->hasColumn('default_branch_only')) {
$project->removeColumn('default_branch_only')->save();
if ($table->hasColumn('default_branch_only')) {
$table
->removeColumn('default_branch_only')
->save();
}
}
}

View file

@ -0,0 +1,28 @@
<?php
use Phinx\Migration\AbstractMigration;
class RemovedProjectIdFromBuildMeta extends AbstractMigration
{
public function up()
{
$table = $this->table('build_meta');
if ($table->hasColumn('project_id')) {
$table
->removeColumn('project_id')
->save();
}
}
public function down()
{
$table = $this->table('build_meta');
if (!$table->hasColumn('project_id')) {
$table
->addColumn('project_id', 'integer', ['default' => 0])
->save();
}
}
}

View file

@ -0,0 +1,64 @@
<?php
use Phinx\Migration\AbstractMigration;
class AddedAdditionalColumns extends AbstractMigration
{
public function up()
{
$table = $this->table('build');
if (!$table->hasColumn('user_id')) {
$table
->addColumn('user_id', 'integer', ['default' => 0])
->save();
}
if ($table->hasColumn('created')) {
$table
->renameColumn('created', 'create_date')
->save();
}
if ($table->hasColumn('started')) {
$table
->renameColumn('started', 'start_date')
->save();
}
if ($table->hasColumn('finished')) {
$table
->renameColumn('finished', 'finish_date')
->save();
}
}
public function down()
{
$table = $this->table('build');
if ($table->hasColumn('user_id')) {
$table
->removeColumn('user_id')
->save();
}
if ($table->hasColumn('create_date')) {
$table
->renameColumn('create_date', 'created')
->save();
}
if ($table->hasColumn('start_date')) {
$table
->renameColumn('start_date', 'started')
->save();
}
if ($table->hasColumn('finish_date')) {
$table
->renameColumn('finish_date', 'finished')
->save();
}
}
}

View file

@ -0,0 +1,40 @@
<?php
use Phinx\Migration\AbstractMigration;
class AddedAdditionalColumns2 extends AbstractMigration
{
public function up()
{
$table = $this->table('project_group');
if (!$table->hasColumn('create_date')) {
$table
->addColumn('create_date', 'datetime', ['null' => true])
->save();
}
if (!$table->hasColumn('user_id')) {
$table
->addColumn('user_id', 'integer', ['default' => 0])
->save();
}
}
public function down()
{
$table = $this->table('project_group');
if ($table->hasColumn('create_date')) {
$table
->removeColumn('create_date')
->save();
}
if ($table->hasColumn('user_id')) {
$table
->removeColumn('user_id')
->save();
}
}
}

View file

@ -0,0 +1,56 @@
<?php
use Phinx\Migration\AbstractMigration;
class AddedAdditionalColumns3 extends AbstractMigration
{
public function up()
{
$table = $this->table('build_error');
if ($table->hasColumn('created_date') && !$table->hasColumn('create_date')) {
$table
->renameColumn('created_date', 'create_date')
->save();
}
$table = $this->table('project');
if (!$table->hasColumn('create_date')) {
$table
->addColumn('create_date', 'datetime', ['null' => true])
->save();
}
if (!$table->hasColumn('user_id')) {
$table
->addColumn('user_id', 'integer', ['default' => 0])
->save();
}
}
public function down()
{
$table = $this->table('build_error');
if ($table->hasColumn('create_date') && !$table->hasColumn('created_date')) {
$table
->renameColumn('create_date', 'created_date')
->save();
}
$table = $this->table('project');
if ($table->hasColumn('create_date')) {
$table
->removeColumn('create_date')
->save();
}
if ($table->hasColumn('user_id')) {
$table
->removeColumn('user_id')
->save();
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -7,6 +7,7 @@ use PHPCensor\Builder;
use PHPCensor\Helper\Bitbucket;
use PHPCensor\Helper\Diff;
use b8\Config;
use PHPCensor\Model\Build;
use PHPCensor\Model\BuildError;
/**
@ -47,17 +48,16 @@ class BitbucketBuild extends RemoteGitBuild
*/
public function sendStatusPostback()
{
if ('Manual' === $this->getCommitId()) {
if (Build::SOURCE_WEBHOOK !== $this->getSource()) {
return false;
}
$project = $this->getProject();
$project = $this->getProject();
if (empty($project)) {
return false;
}
$username = Config::getInstance()->get('php-censor.bitbucket.username');
$username = Config::getInstance()->get('php-censor.bitbucket.username');
$appPassword = Config::getInstance()->get('php-censor.bitbucket.app_password');
if (empty($username) || empty($appPassword) || empty($this->data['id'])) {
@ -261,18 +261,18 @@ class BitbucketBuild extends RemoteGitBuild
*/
protected function getDiffLineNumber(Builder $builder, $file, $line)
{
$line = (integer)$line;
$builder->logExecOutput(false);
$line = (integer)$line;
$prNumber = $this->getExtra('pull_request_number');
$path = $builder->buildPath;
$path = $builder->buildPath;
if (!empty($prNumber)) {
$builder->executeCommand('cd %s && git diff origin/%s "%s"', $path, $this->getBranch(), $file);
} else {
$commitId = $this->getCommitId();
$compare = $commitId == 'Manual' ? 'HEAD' : $commitId;
$compare = empty($commitId) ? 'HEAD' : $commitId;
$builder->executeCommand('cd %s && git diff %s^^ "%s"', $path, $compare, $file);
}
@ -281,7 +281,7 @@ class BitbucketBuild extends RemoteGitBuild
$diff = $builder->getLastOutput();
$helper = new Diff();
$lines = $helper->getLinePositions($diff);
$lines = $helper->getLinePositions($diff);
return isset($lines[$line]) ? $lines[$line] : null;
}

View file

@ -7,6 +7,7 @@ use PHPCensor\Builder;
use PHPCensor\Helper\Diff;
use PHPCensor\Helper\Github;
use b8\Config;
use PHPCensor\Model\Build;
use PHPCensor\Model\BuildError;
/**
@ -45,7 +46,7 @@ class GithubBuild extends RemoteGitBuild
*/
public function sendStatusPostback()
{
if ('Manual' === $this->getCommitId()) {
if (Build::SOURCE_WEBHOOK !== $this->getSource()) {
return false;
}
@ -246,18 +247,18 @@ class GithubBuild extends RemoteGitBuild
*/
protected function getDiffLineNumber(Builder $builder, $file, $line)
{
$line = (integer)$line;
$builder->logExecOutput(false);
$line = (integer)$line;
$prNumber = $this->getExtra('pull_request_number');
$path = $builder->buildPath;
$path = $builder->buildPath;
if (!empty($prNumber)) {
$builder->executeCommand('cd %s && git diff origin/%s "%s"', $path, $this->getBranch(), $file);
} else {
$commitId = $this->getCommitId();
$compare = $commitId == 'Manual' ? 'HEAD' : $commitId;
$compare = empty($commitId) ? 'HEAD' : $commitId;
$builder->executeCommand('cd %s && git diff %s^^ "%s"', $path, $compare, $file);
}
@ -266,7 +267,7 @@ class GithubBuild extends RemoteGitBuild
$diff = $builder->getLastOutput();
$helper = new Diff();
$lines = $helper->getLinePositions($diff);
$lines = $helper->getLinePositions($diff);
return isset($lines[$line]) ? $lines[$line] : null;
}

View file

@ -12,11 +12,7 @@ class GogsBuild extends RemoteGitBuild
*/
public function getCommitLink()
{
if ($this->getCommitId() !== 'manual'){
return $this->getProject()->getReference() . '/commit/' . $this->getCommitId();
}
return parent::getCommitLink();
return $this->getProject()->getReference() . '/commit/' . $this->getCommitId();
}
/**

View file

@ -35,6 +35,7 @@ class MercurialBuild extends Build
if (!$success) {
$builder->logFailure('Failed to clone remote hg repository.');
return false;
}
@ -84,12 +85,12 @@ class MercurialBuild extends Build
*/
protected function postCloneSetup(Builder $builder, $cloneTo, array $extra = null)
{
$success = true;
$commit = $this->getCommitId();
$success = true;
$commitId = $this->getCommitId();
// Allow switching to a specific branch:
if (!empty($commit) && $commit != 'Manual') {
$cmd = 'cd "%s" && hg checkout %s';
if (!empty($commitId)) {
$cmd = 'cd "%s" && hg checkout %s';
$success = $builder->executeCommand($cmd, $cloneTo, $this->getBranch());
}

View file

@ -137,18 +137,24 @@ class RemoteGitBuild extends Build
*/
protected function postCloneSetup(Builder $builder, $cloneTo, array $extra = null)
{
$success = true;
$commit = $this->getCommitId();
$chdir = 'cd "%s"';
$success = true;
$commitId = $this->getCommitId();
$chdir = 'cd "%s"';
if (empty($this->getEnvironment()) && !empty($commit) && $commit != 'Manual') {
$cmd = $chdir . ' && git checkout %s --quiet';
$success = $builder->executeCommand($cmd, $cloneTo, $commit);
if (empty($this->getEnvironment()) && !empty($commitId)) {
$cmd = $chdir . ' && git checkout %s --quiet';
$success = $builder->executeCommand($cmd, $cloneTo, $commitId);
}
// Always update the commit hash with the actual HEAD hash
if ($builder->executeCommand($chdir . ' && git rev-parse HEAD', $cloneTo)) {
$this->setCommitId(trim($builder->getLastOutput()));
$commitId = trim($builder->getLastOutput());
$this->setCommitId($commitId);
if ($builder->executeCommand($chdir . ' && git log -1 --pretty=format:%%s %s', $cloneTo, $commitId)) {
$this->setCommitMessage(trim($builder->getLastOutput()));
}
}
return $success;

View file

@ -95,7 +95,7 @@ class SubversionBuild extends Build
{
$cmd = $this->svnCommand;
if ($this->getCommitId() != 'Manual') {
if (!empty($this->getCommitId())) {
$cmd .= ' -r %s %s "%s"';
$success = $builder->executeCommand($cmd, $this->getCommitId(), $this->getCloneUrl(), $cloneTo);
} else {

View file

@ -7,6 +7,11 @@ use b8\Store\Factory;
class BuildError extends Model
{
const SEVERITY_CRITICAL = 0;
const SEVERITY_HIGH = 1;
const SEVERITY_NORMAL = 2;
const SEVERITY_LOW = 3;
/**
* @var array
*/
@ -34,7 +39,7 @@ class BuildError extends Model
'line_end' => null,
'severity' => null,
'message' => null,
'created_date' => null,
'create_date' => null,
];
/**
@ -50,7 +55,7 @@ class BuildError extends Model
'line_end' => 'getLineEnd',
'severity' => 'getSeverity',
'message' => 'getMessage',
'created_date' => 'getCreatedDate',
'create_date' => 'getCreateDate',
// Foreign key getters:
'Build' => 'getBuild',
@ -69,91 +74,13 @@ class BuildError extends Model
'line_end' => 'setLineEnd',
'severity' => 'setSeverity',
'message' => 'setMessage',
'created_date' => 'setCreatedDate',
'create_date' => 'setCreateDate',
// Foreign key setters:
'Build' => 'setBuild',
];
/**
* @var array
*/
public $columns = [
'id' => [
'type' => 'int',
'length' => 11,
'primary_key' => true,
'auto_increment' => true,
'default' => null,
],
'build_id' => [
'type' => 'int',
'length' => 11,
'default' => null,
],
'plugin' => [
'type' => 'varchar',
'length' => 100,
'default' => null,
],
'file' => [
'type' => 'varchar',
'length' => 250,
'nullable' => true,
'default' => null,
],
'line_start' => [
'type' => 'int',
'length' => 11,
'nullable' => true,
'default' => null,
],
'line_end' => [
'type' => 'int',
'length' => 11,
'nullable' => true,
'default' => null,
],
'severity' => [
'type' => 'tinyint',
'length' => 3,
'default' => null,
],
'message' => [
'type' => 'varchar',
'length' => 250,
'default' => null,
],
'created_date' => [
'type' => 'datetime',
'default' => null,
],
];
/**
* @var array
*/
public $indexes = [
'PRIMARY' => ['unique' => true, 'columns' => 'id'],
'build_id' => ['columns' => 'build_id, created_date'],
];
/**
* @var array
*/
public $foreignKeys = [
'build_error_ibfk_1' => [
'local_col' => 'build_id',
'update' => 'CASCADE',
'delete' => 'CASCADE',
'table' => 'build',
'col' => 'id'
],
];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
@ -164,8 +91,6 @@ class BuildError extends Model
}
/**
* Get the value of BuildId / build_id.
*
* @return int
*/
public function getBuildId()
@ -176,8 +101,6 @@ class BuildError extends Model
}
/**
* Get the value of Plugin / plugin.
*
* @return string
*/
public function getPlugin()
@ -188,8 +111,6 @@ class BuildError extends Model
}
/**
* Get the value of File / file.
*
* @return string
*/
public function getFile()
@ -200,8 +121,6 @@ class BuildError extends Model
}
/**
* Get the value of LineStart / line_start.
*
* @return int
*/
public function getLineStart()
@ -212,8 +131,6 @@ class BuildError extends Model
}
/**
* Get the value of LineEnd / line_end.
*
* @return int
*/
public function getLineEnd()
@ -224,8 +141,6 @@ class BuildError extends Model
}
/**
* Get the value of Severity / severity.
*
* @return int
*/
public function getSeverity()
@ -236,8 +151,6 @@ class BuildError extends Model
}
/**
* Get the value of Message / message.
*
* @return string
*/
public function getMessage()
@ -248,13 +161,11 @@ class BuildError extends Model
}
/**
* Get the value of CreatedDate / created_date.
*
* @return \DateTime
*/
public function getCreatedDate()
public function getCreateDate()
{
$rtn = $this->data['created_date'];
$rtn = $this->data['create_date'];
if (!empty($rtn)) {
$rtn = new \DateTime($rtn);
@ -264,15 +175,12 @@ class BuildError extends Model
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->validateNotNull('Id', $value);
$this->validateInt('Id', $value);
$this->validateNotNull('id', $value);
$this->validateInt('id', $value);
if ($this->data['id'] === $value) {
return;
@ -284,15 +192,12 @@ class BuildError extends Model
}
/**
* Set the value of BuildId / build_id.
*
* Must not be null.
* @param $value int
*/
public function setBuildId($value)
{
$this->validateNotNull('BuildId', $value);
$this->validateInt('BuildId', $value);
$this->validateNotNull('build_id', $value);
$this->validateInt('build_id', $value);
if ($this->data['build_id'] === $value) {
return;
@ -304,15 +209,12 @@ class BuildError extends Model
}
/**
* Set the value of Plugin / plugin.
*
* Must not be null.
* @param $value string
*/
public function setPlugin($value)
{
$this->validateNotNull('Plugin', $value);
$this->validateString('Plugin', $value);
$this->validateNotNull('plugin', $value);
$this->validateString('plugin', $value);
if ($this->data['plugin'] === $value) {
return;
@ -324,13 +226,11 @@ class BuildError extends Model
}
/**
* Set the value of File / file.
*
* @param $value string
*/
public function setFile($value)
{
$this->validateString('File', $value);
$this->validateString('file', $value);
if ($this->data['file'] === $value) {
return;
@ -342,13 +242,11 @@ class BuildError extends Model
}
/**
* Set the value of LineStart / line_start.
*
* @param $value int
*/
public function setLineStart($value)
{
$this->validateInt('LineStart', $value);
$this->validateInt('line_start', $value);
if ($this->data['line_start'] === $value) {
return;
@ -360,13 +258,11 @@ class BuildError extends Model
}
/**
* Set the value of LineEnd / line_end.
*
* @param $value int
*/
public function setLineEnd($value)
{
$this->validateInt('LineEnd', $value);
$this->validateInt('line_end', $value);
if ($this->data['line_end'] === $value) {
return;
@ -378,15 +274,12 @@ class BuildError extends Model
}
/**
* Set the value of Severity / severity.
*
* Must not be null.
* @param $value int
*/
public function setSeverity($value)
{
$this->validateNotNull('Severity', $value);
$this->validateInt('Severity', $value);
$this->validateNotNull('severity', $value);
$this->validateInt('severity', $value);
if ($this->data['severity'] === $value) {
return;
@ -398,15 +291,12 @@ class BuildError extends Model
}
/**
* Set the value of Message / message.
*
* Must not be null.
* @param $value string
*/
public function setMessage($value)
{
$this->validateNotNull('Message', $value);
$this->validateString('Message', $value);
$this->validateNotNull('message', $value);
$this->validateString('message', $value);
if ($this->data['message'] === $value) {
return;
@ -418,30 +308,25 @@ class BuildError extends Model
}
/**
* Set the value of CreatedDate / created_date.
*
* Must not be null.
* @param $value \DateTime
*/
public function setCreatedDate($value)
public function setCreateDate($value)
{
$this->validateNotNull('CreatedDate', $value);
$this->validateDate('CreatedDate', $value);
$this->validateNotNull('create_date', $value);
$this->validateDate('create_date', $value);
if ($this->data['created_date'] === $value) {
if ($this->data['create_date'] === $value) {
return;
}
$this->data['created_date'] = $value;
$this->data['create_date'] = $value;
$this->setModified('created_date');
$this->setModified('create_date');
}
/**
* Get the Build model for this BuildError by Id.
*
* @uses \PHPCensor\Store\BuildStore::getById()
* @uses \PHPCensor\Model\Build
* @return \PHPCensor\Model\Build
*/
public function getBuild()
@ -494,13 +379,9 @@ class BuildError extends Model
return $this->setBuildId($value->getId());
}
const SEVERITY_CRITICAL = 0;
const SEVERITY_HIGH = 1;
const SEVERITY_NORMAL = 2;
const SEVERITY_LOW = 3;
/**
* Get the language string key for this error's severity level.
*
* @return string
*/
public function getSeverityString()
@ -522,6 +403,7 @@ class BuildError extends Model
/**
* Get the class to apply to HTML elements representing this error.
*
* @return string
*/
public function getSeverityClass()

View file

@ -27,7 +27,6 @@ class BuildMeta extends Model
*/
protected $data = [
'id' => null,
'project_id' => null,
'build_id' => null,
'meta_key' => null,
'meta_value' => null,
@ -39,13 +38,12 @@ class BuildMeta extends Model
protected $getters = [
// Direct property getters:
'id' => 'getId',
'project_id' => 'getProjectId',
'build_id' => 'getBuildId',
'meta_key' => 'getMetaKey',
'meta_value' => 'getMetaValue',
// Foreign key getters:
'Project' => 'getProject',
'Build' => 'getBuild',
'Build' => 'getBuild',
];
/**
@ -54,146 +52,61 @@ class BuildMeta extends Model
protected $setters = [
// Direct property setters:
'id' => 'setId',
'project_id' => 'setProjectId',
'build_id' => 'setBuildId',
'meta_key' => 'setMetaKey',
'meta_value' => 'setMetaValue',
// Foreign key setters:
'Project' => 'setProject',
'Build' => 'setBuild',
'Build' => 'setBuild',
];
/**
* @var array
*/
public $columns = [
'id' => [
'type' => 'int',
'length' => 10,
'primary_key' => true,
'auto_increment' => true,
'default' => null,
],
'project_id' => [
'type' => 'int',
'length' => 11,
'default' => null,
],
'build_id' => [
'type' => 'int',
'length' => 11,
'default' => null,
],
'meta_key' => [
'type' => 'varchar',
'length' => 250,
'default' => null,
],
'meta_value' => [
'type' => 'mediumtext',
'default' => null,
],
];
/**
* @var array
*/
public $indexes = [
'PRIMARY' => ['unique' => true, 'columns' => 'id'],
'idx_meta_id' => ['unique' => true, 'columns' => 'build_id, meta_key'],
'project_id' => ['columns' => 'project_id'],
];
/**
* @var array
*/
public $foreignKeys = [
'build_meta_ibfk_1' => [
'local_col' => 'project_id',
'update' => 'CASCADE',
'delete' => 'CASCADE',
'table' => 'project',
'col' => 'id'
],
'fk_meta_build_id' => [
'local_col' => 'build_id',
'update' => 'CASCADE',
'delete' => 'CASCADE',
'table' => 'build',
'col' => 'id'
],
];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->data['id'];
$rtn = $this->data['id'];
return $rtn;
}
/**
* Get the value of ProjectId / project_id.
*
* @return int
*/
public function getProjectId()
{
$rtn = $this->data['project_id'];
return $rtn;
}
/**
* Get the value of BuildId / build_id.
*
* @return int
*/
public function getBuildId()
{
$rtn = $this->data['build_id'];
$rtn = $this->data['build_id'];
return $rtn;
}
/**
* Get the value of MetaKey / meta_key.
*
* @return string
*/
public function getMetaKey()
{
$rtn = $this->data['meta_key'];
$rtn = $this->data['meta_key'];
return $rtn;
}
/**
* Get the value of MetaValue / meta_value.
*
* @return string
*/
public function getMetaValue()
{
$rtn = $this->data['meta_value'];
$rtn = $this->data['meta_value'];
return $rtn;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
* @param int $value
*/
public function setId($value)
{
$this->validateNotNull('Id', $value);
$this->validateInt('Id', $value);
$this->validateNotNull('id', $value);
$this->validateInt('id', $value);
if ($this->data['id'] === $value) {
return;
@ -205,35 +118,12 @@ class BuildMeta extends Model
}
/**
* Set the value of ProjectId / project_id.
*
* Must not be null.
* @param $value int
*/
public function setProjectId($value)
{
$this->validateNotNull('ProjectId', $value);
$this->validateInt('ProjectId', $value);
if ($this->data['project_id'] === $value) {
return;
}
$this->data['project_id'] = $value;
$this->setModified('project_id');
}
/**
* Set the value of BuildId / build_id.
*
* Must not be null.
* @param $value int
* @param int $value
*/
public function setBuildId($value)
{
$this->validateNotNull('BuildId', $value);
$this->validateInt('BuildId', $value);
$this->validateNotNull('build_id', $value);
$this->validateInt('build_id', $value);
if ($this->data['build_id'] === $value) {
return;
@ -245,15 +135,12 @@ class BuildMeta extends Model
}
/**
* Set the value of MetaKey / meta_key.
*
* Must not be null.
* @param $value string
*/
public function setMetaKey($value)
{
$this->validateNotNull('MetaKey', $value);
$this->validateString('MetaKey', $value);
$this->validateNotNull('meta_key', $value);
$this->validateString('meta_key', $value);
if ($this->data['meta_key'] === $value) {
return;
@ -265,15 +152,12 @@ class BuildMeta extends Model
}
/**
* Set the value of MetaValue / meta_value.
*
* Must not be null.
* @param $value string
*/
public function setMetaValue($value)
{
$this->validateNotNull('MetaValue', $value);
$this->validateString('MetaValue', $value);
$this->validateNotNull('meta_value', $value);
$this->validateString('meta_value', $value);
if ($this->data['meta_value'] === $value) {
return;
@ -284,68 +168,9 @@ class BuildMeta extends Model
$this->setModified('meta_value');
}
/**
* Get the Project model for this BuildMeta by Id.
*
* @uses \PHPCensor\Store\ProjectStore::getById()
* @uses \PHPCensor\Model\Project
* @return \PHPCensor\Model\Project
*/
public function getProject()
{
$key = $this->getProjectId();
if (empty($key)) {
return null;
}
$cacheKey = 'Cache.Project.' . $key;
$rtn = $this->cache->get($cacheKey, null);
if (empty($rtn)) {
$rtn = Factory::getStore('Project', 'PHPCensor')->getById($key);
$this->cache->set($cacheKey, $rtn);
}
return $rtn;
}
/**
* Set Project - Accepts an ID, an array representing a Project or a Project model.
*
* @param $value mixed
*/
public function setProject($value)
{
// Is this an instance of Project?
if ($value instanceof Project) {
return $this->setProjectObject($value);
}
// Is this an array representing a Project item?
if (is_array($value) && !empty($value['id'])) {
return $this->setProjectId($value['id']);
}
// Is this a scalar value representing the ID of this foreign key?
return $this->setProjectId($value);
}
/**
* Set Project - Accepts a Project model.
*
* @param $value Project
*/
public function setProjectObject(Project $value)
{
return $this->setProjectId($value->getId());
}
/**
* Get the Build model for this BuildMeta by Id.
*
* @uses \PHPCensor\Store\BuildStore::getById()
* @uses \PHPCensor\Model\Build
* @return \PHPCensor\Model\Build
*/
public function getBuild()
@ -356,8 +181,8 @@ class BuildMeta extends Model
return null;
}
$cacheKey = 'Cache.Build.' . $key;
$rtn = $this->cache->get($cacheKey, null);
$cacheKey = 'Cache.Build.' . $key;
$rtn = $this->cache->get($cacheKey, null);
if (empty($rtn)) {
$rtn = Factory::getStore('Build', 'PHPCensor')->getById($key);

View file

@ -25,99 +25,43 @@ class Environment extends Model
* @var array
*/
protected $data = [
'id' => null,
'id' => null,
'project_id' => null,
'name' => null,
'branches' => null,
'name' => null,
'branches' => null,
];
/**
* @var array
*/
protected $getters = [
// Direct property getters:
'id' => 'getId',
'id' => 'getId',
'project_id' => 'getProjectId',
'name' => 'getName',
'branches' => 'getBranches',
// Foreign key getters:
'name' => 'getName',
'branches' => 'getBranches',
];
/**
* @var array
*/
protected $setters = [
// Direct property setters:
'id' => 'setId',
'project_id' => 'setProjectId',
'name' => 'setName',
'branches' => 'setBranches',
// Foreign key setters:
'id' => 'setId',
'project_id' => 'setProjectId',
'name' => 'setName',
'branches' => 'setBranches',
];
/**
* @var array
*/
public $columns = [
'id' => [
'type' => 'int',
'length' => 11,
'primary_key' => true,
'auto_increment' => true,
'default' => null,
],
'project_id' => [
'type' => 'int',
'length' => 11,
'primary_key' => true,
'default' => null,
],
'name' => [
'type' => 'varchar',
'length' => 250,
'default' => null,
],
'branches' => [
'type' => 'text',
'default' => '',
],
];
/**
* @var array
*/
public $indexes = [
'PRIMARY' => ['unique' => true, 'columns' => 'project_id, name'],
];
/**
* @var array
*/
public $foreignKeys = [
'environment_ibfk_1' => [
'local_col' => 'project_id',
'update' => 'CASCADE',
'delete' => '',
'table' => 'project',
'col' => 'id'
],
];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->data['id'];
$rtn = $this->data['id'];
return $rtn;
}
/**
* Get the value of Id / id.
*
* @return int
*/
public function getProjectId()
@ -128,20 +72,16 @@ class Environment extends Model
}
/**
* Get the value of Title / title.
*
* @return string
*/
public function getName()
{
$rtn = $this->data['name'];
$rtn = $this->data['name'];
return $rtn;
}
/**
* Get the value of Title / title.
*
* @return array
*/
public function getBranches()
@ -152,15 +92,12 @@ class Environment extends Model
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->validateNotNull('Id', $value);
$this->validateInt('Id', $value);
$this->validateNotNull('id', $value);
$this->validateInt('id', $value);
if ($this->data['id'] === $value) {
return;
@ -172,15 +109,12 @@ class Environment extends Model
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setProjectId($value)
{
$this->validateNotNull('ProjectId', $value);
$this->validateInt('ProjectId', $value);
$this->validateNotNull('project_id', $value);
$this->validateInt('project_id', $value);
if ($this->data['project_id'] === $value) {
return;
@ -192,15 +126,12 @@ class Environment extends Model
}
/**
* Set the value of Name / name
*
* Must not be null.
* @param $value string
*/
public function setName($value)
{
$this->validateNotNull('Name', $value);
$this->validateString('Name', $value);
$this->validateNotNull('name', $value);
$this->validateString('name', $value);
if ($this->data['name'] === $value) {
return;
@ -212,14 +143,11 @@ class Environment extends Model
}
/**
* Set the value of Branches / branches
*
* Must not be null.
* @param $value array
*/
public function setBranches($value)
{
$this->validateNotNull('Branches', $value);
$this->validateNotNull('branches', $value);
$value = implode("\n", $value);
if ($this->data['branches'] === $value) {

View file

@ -47,6 +47,8 @@ class Project extends Model
'allow_public_status' => null,
'archived' => null,
'group_id' => null,
'create_date' => null,
'user_id' => 0,
];
/**
@ -68,8 +70,11 @@ class Project extends Model
'allow_public_status' => 'getAllowPublicStatus',
'archived' => 'getArchived',
'group_id' => 'getGroupId',
'create_date' => 'getCreateDate',
'user_id' => 'getUserId',
// Foreign key getters:
'Group' => 'getGroup',
'Group' => 'getGroup',
];
/**
@ -91,185 +96,74 @@ class Project extends Model
'allow_public_status' => 'setAllowPublicStatus',
'archived' => 'setArchived',
'group_id' => 'setGroupId',
'create_date' => 'setCreateDate',
'user_id' => 'setUserId',
// Foreign key setters:
'Group' => 'setGroup',
'Group' => 'setGroup',
];
/**
* @var array
*/
public $columns = [
'id' => [
'type' => 'int',
'length' => 11,
'primary_key' => true,
'auto_increment' => true,
'default' => null,
],
'title' => [
'type' => 'varchar',
'length' => 250,
'default' => null,
],
'reference' => [
'type' => 'varchar',
'length' => 250,
'default' => null,
],
'branch' => [
'type' => 'varchar',
'length' => 250,
'default' => 'master',
],
'default_branch_only' => [
'type' => 'int',
'length' => 11,
],
'ssh_private_key' => [
'type' => 'text',
'nullable' => true,
'default' => null,
],
'type' => [
'type' => 'varchar',
'length' => 50,
'default' => null,
],
'access_information' => [
'type' => 'varchar',
'length' => 250,
'nullable' => true,
'default' => null,
],
'last_commit' => [
'type' => 'varchar',
'length' => 250,
'nullable' => true,
'default' => null,
],
'build_config' => [
'type' => 'text',
'nullable' => true,
'default' => null,
],
'ssh_public_key' => [
'type' => 'text',
'nullable' => true,
'default' => null,
],
'allow_public_status' => [
'type' => 'int',
'length' => 11,
],
'archived' => [
'type' => 'tinyint',
'length' => 1,
'default' => null,
],
'group_id' => [
'type' => 'int',
'length' => 11,
'default' => 1,
],
];
/**
* @var array
*/
public $indexes = [
'PRIMARY' => ['unique' => true, 'columns' => 'id'],
'idx_project_title' => ['columns' => 'title'],
'group_id' => ['columns' => 'group_id'],
];
/**
* @var array
*/
public $foreignKeys = [
'project_ibfk_1' => [
'local_col' => 'group_id',
'update' => 'CASCADE',
'delete' => '',
'table' => 'project_group',
'col' => 'id'
],
];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->data['id'];
$rtn = $this->data['id'];
return $rtn;
}
/**
* Get the value of Title / title.
*
* @return string
*/
public function getTitle()
{
$rtn = $this->data['title'];
$rtn = $this->data['title'];
return $rtn;
}
/**
* Get the value of Reference / reference.
*
* @return string
*/
public function getReference()
{
$rtn = $this->data['reference'];
$rtn = $this->data['reference'];
return $rtn;
}
/**
* Get the value of SshPrivateKey / ssh_private_key.
*
* @return string
*/
public function getSshPrivateKey()
{
$rtn = $this->data['ssh_private_key'];
$rtn = $this->data['ssh_private_key'];
return $rtn;
}
/**
* Get the value of Type / type.
*
* @return string
*/
public function getType()
{
$rtn = $this->data['type'];
$rtn = $this->data['type'];
return $rtn;
}
/**
* Get the value of LastCommit / last_commit.
*
* @return string
*/
public function getLastCommit()
{
$rtn = $this->data['last_commit'];
$rtn = $this->data['last_commit'];
return $rtn;
}
/**
* Get the value of BuildConfig / build_config.
*
* @return string
*/
public function getBuildConfig()
@ -280,20 +174,16 @@ class Project extends Model
}
/**
* Get the value of SshPublicKey / ssh_public_key.
*
* @return string
*/
public function getSshPublicKey()
{
$rtn = $this->data['ssh_public_key'];
$rtn = $this->data['ssh_public_key'];
return $rtn;
}
/**
* Get the value of AllowPublicStatus / allow_public_status.
*
* @return int
*/
public function getAllowPublicStatus()
@ -304,8 +194,6 @@ class Project extends Model
}
/**
* Get the value of Archived / archived.
*
* @return int
*/
public function getArchived()
@ -316,8 +204,6 @@ class Project extends Model
}
/**
* Get the value of GroupId / group_id.
*
* @return int
*/
public function getGroupId()
@ -328,8 +214,6 @@ class Project extends Model
}
/**
* Get the value of DefaultBranchOnly / default_branch_only.
*
* @return int
*/
public function getDefaultBranchOnly()
@ -340,15 +224,12 @@ class Project extends Model
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->validateNotNull('Id', $value);
$this->validateInt('Id', $value);
$this->validateNotNull('id', $value);
$this->validateInt('id', $value);
if ($this->data['id'] === $value) {
return;
@ -360,15 +241,12 @@ class Project extends Model
}
/**
* Set the value of Title / title.
*
* Must not be null.
* @param $value string
*/
public function setTitle($value)
{
$this->validateNotNull('Title', $value);
$this->validateString('Title', $value);
$this->validateNotNull('title', $value);
$this->validateString('title', $value);
if ($this->data['title'] === $value) {
return;
@ -380,15 +258,12 @@ class Project extends Model
}
/**
* Set the value of Reference / reference.
*
* Must not be null.
* @param $value string
*/
public function setReference($value)
{
$this->validateNotNull('Reference', $value);
$this->validateString('Reference', $value);
$this->validateNotNull('reference', $value);
$this->validateString('reference', $value);
if ($this->data['reference'] === $value) {
return;
@ -400,15 +275,12 @@ class Project extends Model
}
/**
* Set the value of Branch / branch.
*
* Must not be null.
* @param $value string
*/
public function setBranch($value)
{
$this->validateNotNull('Branch', $value);
$this->validateString('Branch', $value);
$this->validateNotNull('branch', $value);
$this->validateString('branch', $value);
if ($this->data['branch'] === $value) {
return;
@ -420,15 +292,12 @@ class Project extends Model
}
/**
* Set the value of DefaultBranchOnly / default_branch_only.
*
* Must not be null.
* @param $value int
*/
public function setDefaultBranchOnly($value)
{
$this->validateNotNull('DefaultBranchOnly', $value);
$this->validateInt('DefaultBranchOnly', $value);
$this->validateNotNull('default_branch_only', $value);
$this->validateInt('default_branch_only', $value);
if ($this->data['default_branch_only'] === $value) {
return;
@ -440,13 +309,11 @@ class Project extends Model
}
/**
* Set the value of SshPrivateKey / ssh_private_key.
*
* @param $value string
*/
public function setSshPrivateKey($value)
{
$this->validateString('SshPrivateKey', $value);
$this->validateString('ssh_private_key', $value);
if ($this->data['ssh_private_key'] === $value) {
return;
@ -458,15 +325,12 @@ class Project extends Model
}
/**
* Set the value of Type / type.
*
* Must not be null.
* @param $value string
*/
public function setType($value)
{
$this->validateNotNull('Type', $value);
$this->validateString('Type', $value);
$this->validateNotNull('type', $value);
$this->validateString('type', $value);
if ($this->data['type'] === $value) {
return;
@ -478,13 +342,11 @@ class Project extends Model
}
/**
* Set the value of LastCommit / last_commit.
*
* @param $value string
*/
public function setLastCommit($value)
{
$this->validateString('LastCommit', $value);
$this->validateString('last_commit', $value);
if ($this->data['last_commit'] === $value) {
return;
@ -496,13 +358,11 @@ class Project extends Model
}
/**
* Set the value of BuildConfig / build_config.
*
* @param $value string
*/
public function setBuildConfig($value)
{
$this->validateString('BuildConfig', $value);
$this->validateString('build_config', $value);
if ($this->data['build_config'] === $value) {
return;
@ -514,13 +374,11 @@ class Project extends Model
}
/**
* Set the value of SshPublicKey / ssh_public_key.
*
* @param $value string
*/
public function setSshPublicKey($value)
{
$this->validateString('SshPublicKey', $value);
$this->validateString('ssh_public_key', $value);
if ($this->data['ssh_public_key'] === $value) {
return;
@ -532,15 +390,12 @@ class Project extends Model
}
/**
* Set the value of AllowPublicStatus / allow_public_status.
*
* Must not be null.
* @param $value int
*/
public function setAllowPublicStatus($value)
{
$this->validateNotNull('AllowPublicStatus', $value);
$this->validateInt('AllowPublicStatus', $value);
$this->validateNotNull('allow_public_status', $value);
$this->validateInt('allow_public_status', $value);
if ($this->data['allow_public_status'] === $value) {
return;
@ -552,15 +407,12 @@ class Project extends Model
}
/**
* Set the value of Archived / archived.
*
* Must not be null.
* @param $value int
*/
public function setArchived($value)
{
$this->validateNotNull('Archived', $value);
$this->validateInt('Archived', $value);
$this->validateNotNull('archived', $value);
$this->validateInt('archived', $value);
if ($this->data['archived'] === $value) {
return;
@ -572,15 +424,12 @@ class Project extends Model
}
/**
* Set the value of GroupId / group_id.
*
* Must not be null.
* @param $value int
*/
public function setGroupId($value)
{
$this->validateNotNull('GroupId', $value);
$this->validateInt('GroupId', $value);
$this->validateNotNull('group_id', $value);
$this->validateInt('group_id', $value);
if ($this->data['group_id'] === $value) {
return;
@ -594,8 +443,6 @@ class Project extends Model
/**
* Get the ProjectGroup model for this Project by Id.
*
* @uses \PHPCensor\Store\ProjectGroupStore::getById()
* @uses \PHPCensor\Model\ProjectGroup
* @return \PHPCensor\Model\ProjectGroup
*/
public function getGroup()
@ -606,11 +453,11 @@ class Project extends Model
return null;
}
$cacheKey = 'Cache.ProjectGroup.' . $key;
$rtn = $this->cache->get($cacheKey, null);
$cacheKey = 'Cache.ProjectGroup.' . $key;
$rtn = $this->cache->get($cacheKey, null);
if (empty($rtn)) {
$rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key);
$rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key);
$this->cache->set($cacheKey, $rtn);
}
@ -651,8 +498,6 @@ class Project extends Model
/**
* Get Build models by ProjectId for this Project.
*
* @uses \PHPCensor\Store\BuildStore::getByProjectId()
* @uses \PHPCensor\Model\Build
* @return \PHPCensor\Model\Build[]
*/
public function getProjectBuilds()
@ -660,22 +505,12 @@ class Project extends Model
return Factory::getStore('Build', 'PHPCensor')->getByProjectId($this->getId());
}
/**
* Get BuildMeta models by ProjectId for this Project.
*
* @uses \PHPCensor\Store\BuildMetaStore::getByProjectId()
* @uses \PHPCensor\Model\BuildMeta
* @return \PHPCensor\Model\BuildMeta[]
*/
public function getProjectBuildMetas()
{
return Factory::getStore('BuildMeta', 'PHPCensor')->getByProjectId($this->getId());
}
/**
* Return the latest build from a specific branch, of a specific status, for this project.
*
* @param string $branch
* @param null $status
* @param null $status
*
* @return mixed|null
*/
public function getLatestBuild($branch = 'master', $status = null)
@ -702,7 +537,9 @@ class Project extends Model
/**
* Return the previous build from a specific branch, for this project.
*
* @param string $branch
*
* @return mixed|null
*/
public function getPreviousBuild($branch = 'master')
@ -723,7 +560,6 @@ class Project extends Model
}
/**
* Store this project's access_information data
* @param string|array $value
*/
public function setAccessInformation($value)
@ -732,7 +568,7 @@ class Project extends Model
$value = json_encode($value);
}
$this->validateString('AccessInformation', $value);
$this->validateString('access_information', $value);
if ($this->data['access_information'] === $value) {
return;
@ -745,7 +581,9 @@ class Project extends Model
/**
* Get this project's access_information data. Pass a specific key or null for all data.
*
* @param string|null $key
*
* @return mixed|null|string
*/
public function getAccessInformation($key = null)
@ -771,7 +609,64 @@ class Project extends Model
}
/**
* Get the value of Branch / branch.
* @return \DateTime
*/
public function getCreateDate()
{
$rtn = $this->data['create_date'];
if (!empty($rtn)) {
$rtn = new \DateTime($rtn);
}
return $rtn;
}
/**
* @param $value \DateTime
*/
public function setCreateDate($value)
{
$this->validateDate('create_date', $value);
if ($this->data['create_date'] === $value) {
return;
}
$this->data['create_date'] = $value;
$this->setModified('create_date');
}
/**
* @return string
*/
public function getUserId()
{
$rtn = $this->data['user_id'];
return (integer)$rtn;
}
/**
* @param $value integer
*/
public function setUserId($value)
{
$this->validateNotNull('user_id', $value);
$this->validateInt('user_id', $value);
if ($this->data['user_id'] === $value) {
return;
}
$this->data['user_id'] = $value;
$this->setModified('user_id');
}
/**
* Get the value of branch.
*
* @return string
*/
@ -798,6 +693,7 @@ class Project extends Model
/**
* Return the name of a FontAwesome icon to represent this project, depending on its type.
*
* @return string
*/
public function getIcon()
@ -850,7 +746,7 @@ class Project extends Model
if (empty($rtn)) {
$store = $this->getEnvironmentStore();
$rtn = $store->getByProjectId($key);
$rtn = $store->getByProjectId($key);
$this->cache->set($cacheKey, $rtn);
}

View file

@ -26,94 +26,49 @@ class ProjectGroup extends Model
* @var array
*/
protected $data = [
'id' => null,
'title' => null,
'id' => null,
'title' => null,
'create_date' => null,
'user_id' => 0,
];
/**
* @var array
*/
protected $getters = [
// Direct property getters:
'id' => 'getId',
'title' => 'getTitle',
// Foreign key getters:
'id' => 'getId',
'title' => 'getTitle',
'create_date' => 'getCreateDate',
'user_id' => 'getUserId',
];
/**
* @var array
*/
protected $setters = [
// Direct property setters:
'id' => 'setId',
'title' => 'setTitle',
// Foreign key setters:
'id' => 'setId',
'title' => 'setTitle',
'create_date' => 'setCreateDate',
'user_id' => 'setUserId',
];
/**
* @var array
*/
public $columns = [
'id' => [
'type' => 'int',
'length' => 11,
'primary_key' => true,
'auto_increment' => true,
'default' => null,
],
'title' => [
'type' => 'varchar',
'length' => 100,
'default' => null,
],
];
/**
* @var array
*/
public $indexes = [
'PRIMARY' => ['unique' => true, 'columns' => 'id'],
];
/**
* @var array
*/
public $foreignKeys = [];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->data['id'];
$rtn = $this->data['id'];
return $rtn;
}
/**
* Get the value of Title / title.
*
* @return string
*/
public function getTitle()
{
$rtn = $this->data['title'];
return $rtn;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->validateNotNull('Id', $value);
$this->validateInt('Id', $value);
$this->validateNotNull('id', $value);
$this->validateInt('id', $value);
if ($this->data['id'] === $value) {
return;
@ -125,15 +80,22 @@ class ProjectGroup extends Model
}
/**
* Set the value of Title / title.
*
* Must not be null.
* @return string
*/
public function getTitle()
{
$rtn = $this->data['title'];
return $rtn;
}
/**
* @param $value string
*/
public function setTitle($value)
{
$this->validateNotNull('Title', $value);
$this->validateString('Title', $value);
$this->validateNotNull('title', $value);
$this->validateString('title', $value);
if ($this->data['title'] === $value) {
return;
@ -144,11 +106,66 @@ class ProjectGroup extends Model
$this->setModified('title');
}
/**
* @return \DateTime
*/
public function getCreateDate()
{
$rtn = $this->data['create_date'];
if (!empty($rtn)) {
$rtn = new \DateTime($rtn);
}
return $rtn;
}
/**
* @param $value \DateTime
*/
public function setCreateDate($value)
{
$this->validateDate('create_date', $value);
if ($this->data['create_date'] === $value) {
return;
}
$this->data['create_date'] = $value;
$this->setModified('create_date');
}
/**
* @return string
*/
public function getUserId()
{
$rtn = $this->data['user_id'];
return (integer)$rtn;
}
/**
* @param $value integer
*/
public function setUserId($value)
{
$this->validateNotNull('user_id', $value);
$this->validateInt('user_id', $value);
if ($this->data['user_id'] === $value) {
return;
}
$this->data['user_id'] = $value;
$this->setModified('user_id');
}
/**
* Get Project models by GroupId for this ProjectGroup.
*
* @uses \PHPCensor\Store\ProjectStore::getByGroupId()
* @uses \PHPCensor\Model\Project
* @return \PHPCensor\Model\Project[]
*/
public function getGroupProjects()

View file

@ -45,7 +45,6 @@ class User extends Model
* @var array
*/
protected $getters = [
// Direct property getters:
'id' => 'getId',
'email' => 'getEmail',
'hash' => 'getHash',
@ -56,14 +55,12 @@ class User extends Model
'provider_key' => 'getProviderKey',
'provider_data' => 'getProviderData',
'remember_key' => 'getRememberKey',
// Foreign key getters:
];
/**
* @var array
*/
protected $setters = [
// Direct property setters:
'id' => 'setId',
'email' => 'setEmail',
'hash' => 'setHash',
@ -74,86 +71,9 @@ class User extends Model
'provider_key' => 'setProviderKey',
'provider_data' => 'setProviderData',
'remember_key' => 'setRememberKey',
// Foreign key setters:
];
/**
* @var array
*/
public $columns = [
'id' => [
'type' => 'int',
'length' => 11,
'primary_key' => true,
'auto_increment' => true,
'default' => null,
],
'email' => [
'type' => 'varchar',
'length' => 250,
'default' => null,
],
'hash' => [
'type' => 'varchar',
'length' => 250,
'default' => null,
],
'is_admin' => [
'type' => 'int',
'length' => 11,
],
'name' => [
'type' => 'varchar',
'length' => 250,
'default' => null,
],
'language' => [
'type' => 'varchar',
'length' => 5,
'default' => null,
],
'per_page' => [
'type' => 'int',
'length' => 11,
'default' => null,
],
'provider_key' => [
'type' => 'varchar',
'length' => 255,
'default' => 'internal',
],
'provider_data' => [
'type' => 'varchar',
'length' => 255,
'nullable' => true,
'default' => null,
],
'remember_key' => [
'type' => 'varchar',
'length' => 32,
'nullable' => true,
'default' => null,
],
];
/**
* @var array
*/
public $indexes = [
'PRIMARY' => ['unique' => true, 'columns' => 'id'],
'idx_email' => ['unique' => true, 'columns' => 'email'],
'email' => ['unique' => true, 'columns' => 'email'],
'name' => ['columns' => 'name'],
];
/**
* @var array
*/
public $foreignKeys = [];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
@ -164,8 +84,6 @@ class User extends Model
}
/**
* Get the value of Email / email.
*
* @return string
*/
public function getEmail()
@ -176,8 +94,6 @@ class User extends Model
}
/**
* Get the value of Hash / hash.
*
* @return string
*/
public function getHash()
@ -188,8 +104,6 @@ class User extends Model
}
/**
* Get the value of Name / name.
*
* @return string
*/
public function getName()
@ -200,8 +114,6 @@ class User extends Model
}
/**
* Get the value of IsAdmin / is_admin.
*
* @return int
*/
public function getIsAdmin()
@ -212,8 +124,6 @@ class User extends Model
}
/**
* Get the value of ProviderKey / provider_key.
*
* @return string
*/
public function getProviderKey()
@ -224,8 +134,6 @@ class User extends Model
}
/**
* Get the value of ProviderData / provider_data.
*
* @return string
*/
public function getProviderData()
@ -236,8 +144,6 @@ class User extends Model
}
/**
* Get the value of RememberKey / remember_key.
*
* @return string
*/
public function getRememberKey()
@ -248,8 +154,6 @@ class User extends Model
}
/**
* Get the value of Language / language.
*
* @return string
*/
public function getLanguage()
@ -260,8 +164,6 @@ class User extends Model
}
/**
* Get the value of PerPage / per_page.
*
* @return string
*/
public function getPerPage()
@ -272,15 +174,12 @@ class User extends Model
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->validateNotNull('Id', $value);
$this->validateInt('Id', $value);
$this->validateNotNull('id', $value);
$this->validateInt('id', $value);
if ($this->data['id'] === $value) {
return;
@ -292,15 +191,12 @@ class User extends Model
}
/**
* Set the value of Email / email.
*
* Must not be null.
* @param $value string
*/
public function setEmail($value)
{
$this->validateNotNull('Email', $value);
$this->validateString('Email', $value);
$this->validateNotNull('email', $value);
$this->validateString('email', $value);
if ($this->data['email'] === $value) {
return;
@ -312,15 +208,12 @@ class User extends Model
}
/**
* Set the value of Hash / hash.
*
* Must not be null.
* @param $value string
*/
public function setHash($value)
{
$this->validateNotNull('Hash', $value);
$this->validateString('Hash', $value);
$this->validateNotNull('hash', $value);
$this->validateString('hash', $value);
if ($this->data['hash'] === $value) {
return;
@ -332,15 +225,12 @@ class User extends Model
}
/**
* Set the value of Name / name.
*
* Must not be null.
* @param $value string
*/
public function setName($value)
{
$this->validateNotNull('Name', $value);
$this->validateString('Name', $value);
$this->validateNotNull('name', $value);
$this->validateString('name', $value);
if ($this->data['name'] === $value) {
return;
@ -352,15 +242,12 @@ class User extends Model
}
/**
* Set the value of IsAdmin / is_admin.
*
* Must not be null.
* @param $value int
*/
public function setIsAdmin($value)
{
$this->validateNotNull('IsAdmin', $value);
$this->validateInt('IsAdmin', $value);
$this->validateNotNull('is_admin', $value);
$this->validateInt('is_admin', $value);
if ($this->data['is_admin'] === $value) {
return;
@ -372,15 +259,12 @@ class User extends Model
}
/**
* Set the value of ProviderKey / provider_key.
*
* Must not be null.
* @param $value string
*/
public function setProviderKey($value)
{
$this->validateNotNull('ProviderKey', $value);
$this->validateString('ProviderKey', $value);
$this->validateNotNull('provider_key', $value);
$this->validateString('provider_key', $value);
if ($this->data['provider_key'] === $value) {
return;
@ -392,13 +276,11 @@ class User extends Model
}
/**
* Set the value of ProviderData / provider_data.
*
* @param $value string
*/
public function setProviderData($value)
{
$this->validateString('ProviderData', $value);
$this->validateString('provider_data', $value);
if ($this->data['provider_data'] === $value) {
return;
@ -410,13 +292,11 @@ class User extends Model
}
/**
* Set the value of RememberKey / remember_key.
*
* @param $value string
*/
public function setRememberKey($value)
{
$this->validateString('RememberKey', $value);
$this->validateString('remember_key', $value);
if ($this->data['remember_key'] === $value) {
return;
@ -428,9 +308,6 @@ class User extends Model
}
/**
* Set the value of Language / language.
*
* Must not be null.
* @param $value string
*/
public function setLanguage($value)
@ -445,9 +322,6 @@ class User extends Model
}
/**
* Set the value of PerPage / per_page.
*
* Must not be null.
* @param $value string
*/
public function setPerPage($value)

View file

@ -283,6 +283,6 @@ class Executor
{
/** @var Build $build */
$build = $this->pluginFactory->getResourceFor('PHPCensor\Model\Build');
$this->store->setMeta($build->getProjectId(), $build->getId(), 'plugin-summary', json_encode($summary));
$this->store->setMeta($build->getId(), 'plugin-summary', json_encode($summary));
}
}

View file

@ -36,11 +36,13 @@ class BuildService
/**
* @param Project $project
* @param string $environment
* @param string|null $commitId
* @param string $commitId
* @param string|null $branch
* @param string|null $tag
* @param string|null $committerEmail
* @param string|null $commitMessage
* @param integer $source
* @param integer $userId
* @param string|null $extra
*
* @return \PHPCensor\Model\Build
@ -48,15 +50,17 @@ class BuildService
public function createBuild(
Project $project,
$environment,
$commitId = null,
$commitId = '',
$branch = null,
$tag = null,
$committerEmail = null,
$commitMessage = null,
$source = Build::SOURCE_UNKNOWN,
$userId = 0,
$extra = null
) {
$build = new Build();
$build->setCreated(new \DateTime());
$build->setCreateDate(new \DateTime());
$build->setProject($project);
$build->setStatus(Build::STATUS_PENDING);
$build->setEnvironment($environment);
@ -64,12 +68,9 @@ class BuildService
$branches = $project->getBranchesByEnvironment($environment);
$build->setExtraValue('branches', $branches);
if (!empty($commitId)) {
$build->setCommitId($commitId);
} else {
$build->setCommitId('Manual');
$build->setCommitMessage('Manual');
}
$build->setSource($source);
$build->setUserId($userId);
$build->setCommitId((string)$commitId);
if (!empty($branch)) {
$build->setBranch($branch);
@ -94,8 +95,7 @@ class BuildService
}
/** @var Build $build */
$build = $this->buildStore->save($build);
$build = $this->buildStore->save($build);
$buildId = $build->getId();
if (!empty($buildId)) {
@ -119,12 +119,12 @@ class BuildService
unset($data['id']);
unset($data['status']);
unset($data['log']);
unset($data['started']);
unset($data['finished']);
unset($data['start_date']);
unset($data['finish_date']);
$build = new Build();
$build->setValues($data);
$build->setCreated(new \DateTime());
$build->setCreateDate(new \DateTime());
$build->setStatus(Build::STATUS_PENDING);
/** @var Build $build */

View file

@ -155,7 +155,7 @@ class BuildStatusService
{
$dateFormat = 'Y-m-d\\TH:i:sO';
if ($buildInfo = $this->getFinishedBuildInfo()) {
return ($buildInfo->getFinished()) ? $buildInfo->getFinished()->format($dateFormat) : '';
return ($buildInfo->getFinishDate()) ? $buildInfo->getFinishDate()->format($dateFormat) : '';
}
return '';
}

View file

@ -25,16 +25,22 @@ class ProjectService
/**
* Create a new project model and use the project store to save it.
* @param string $title
* @param string $type
* @param string $reference
* @param array $options
*
* @param string $title
* @param string $type
* @param string $reference
* @param integer $userId
* @param array $options
*
* @return \PHPCensor\Model\Project
*/
public function createProject($title, $type, $reference, $options = [])
public function createProject($title, $type, $reference, $userId, $options = [])
{
// Create base project and use updateProject() to set its properties:
$project = new Project();
$project->setCreateDate(new \DateTime());
$project->setUserId((integer)$userId);
return $this->updateProject($project, $title, $type, $reference, $options);
}

View file

@ -15,25 +15,36 @@ class BuildErrorStore extends Store
/**
* Get a BuildError by primary key (Id)
*
* @param integer $key
* @param string $useConnection
*
* @return null|BuildError
*/
public function getByPrimaryKey($value, $useConnection = 'read')
public function getByPrimaryKey($key, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
return $this->getById($key, $useConnection);
}
/**
* Get a single BuildError by Id.
*
* @param integer $id
* @param string $useConnection
*
* @return null|BuildError
*
* @throws HttpException
*/
public function getById($value, $useConnection = 'read')
public function getById($id, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($id)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build_error}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
$stmt->bindValue(':id', $id);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -46,18 +57,25 @@ class BuildErrorStore extends Store
/**
* Get multiple BuildError by BuildId.
*
* @param integer $buildId
* @param integer $limit
* @param string $useConnection
*
* @return array
*
* @throws HttpException
*/
public function getByBuildId($value, $limit = 1000, $useConnection = 'read')
public function getByBuildId($buildId, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($buildId)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':build_id', $value);
$stmt->bindValue(':build_id', $buildId);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
@ -78,8 +96,10 @@ class BuildErrorStore extends Store
/**
* Get a list of errors for a given build, since a given time.
* @param $buildId
* @param string $since date string
*
* @param integer $buildId
* @param string $since date string
*
* @return array
*/
public function getErrorsForBuild($buildId, $since = null)
@ -116,8 +136,9 @@ class BuildErrorStore extends Store
/**
* Gets the total number of errors for a given build.
* @param $buildId
* @param string $since date string
*
* @param integer $buildId
*
* @return array
*/
public function getErrorTotalForBuild($buildId)

View file

@ -11,7 +11,7 @@ use b8\Database;
class BuildErrorWriter
{
/** @var int */
protected $build_id;
protected $buildId;
/** @var array */
protected $errors = [];
@ -20,17 +20,17 @@ class BuildErrorWriter
* @var int
* @see https://stackoverflow.com/questions/40361164/pdoexception-sqlstatehy000-general-error-7-number-of-parameters-must-be-bet
*/
protected $buffer_size;
protected $bufferSize;
/**
* BuildErrorWriter constructor.
*
* @param int $build_id
* @param int $buildId
*/
public function __construct($build_id)
public function __construct($buildId)
{
$this->buffer_size = (integer)Config::getInstance()->get('php-censor.build.writer_buffer_size', 500);
$this->build_id = $build_id;
$this->bufferSize = (integer)Config::getInstance()->get('php-censor.build.writer_buffer_size', 500);
$this->buildId = $buildId;
}
/**
@ -48,33 +48,33 @@ class BuildErrorWriter
* @param string $message
* @param int $severity
* @param string $file
* @param int $line_start
* @param int $line_end
* @param \DateTime $created_date
* @param int $lineStart
* @param int $lineEnd
* @param \DateTime $createdDate
*/
public function write(
$plugin,
$message,
$severity,
$file = null,
$line_start = null,
$line_end = null,
$created_date = null
$lineStart = null,
$lineEnd = null,
$createdDate = null
) {
if (is_null($created_date)) {
$created_date = new \DateTime();
if (is_null($createdDate)) {
$createdDate = new \DateTime();
}
$this->errors[] = [
'plugin' => (string)$plugin,
'message' => (string)$message,
'severity' => (int)$severity,
'file' => !is_null($file) ? (string)$file : null,
'line_start' => !is_null($line_start) ? (int)$line_start : null,
'line_end' => !is_null($line_end) ? (int)$line_end : null,
'created_date' => $created_date->format('Y-m-d H:i:s'),
'line_start' => !is_null($lineStart) ? (int)$lineStart : null,
'line_end' => !is_null($lineEnd) ? (int)$lineEnd : null,
'created_date' => $createdDate->format('Y-m-d H:i:s'),
];
if (count($this->errors) >= $this->buffer_size) {
if (count($this->errors) >= $this->bufferSize) {
$this->flush();
}
}
@ -88,10 +88,10 @@ class BuildErrorWriter
return;
}
$insert_values_placeholders = [];
$insert_values_data = [];
$insertValuesPlaceholders = [];
$insertValuesData = [];
foreach ($this->errors as $i => $error) {
$insert_values_placeholders[] = '(
$insertValuesPlaceholders[] = '(
:build_id' . $i . ',
:plugin' . $i . ',
:file' . $i . ',
@ -101,14 +101,14 @@ class BuildErrorWriter
:message' . $i . ',
:created_date' . $i . '
)';
$insert_values_data['build_id' . $i] = $this->build_id;
$insert_values_data['plugin' . $i] = $error['plugin'];
$insert_values_data['file' . $i] = $error['file'];
$insert_values_data['line_start' . $i] = $error['line_start'];
$insert_values_data['line_end' . $i] = $error['line_end'];
$insert_values_data['severity' . $i] = $error['severity'];
$insert_values_data['message' . $i] = $error['message'];
$insert_values_data['created_date' . $i] = $error['created_date'];
$insertValuesData['build_id' . $i] = $this->buildId;
$insertValuesData['plugin' . $i] = $error['plugin'];
$insertValuesData['file' . $i] = $error['file'];
$insertValuesData['line_start' . $i] = $error['line_start'];
$insertValuesData['line_end' . $i] = $error['line_end'];
$insertValuesData['severity' . $i] = $error['severity'];
$insertValuesData['message' . $i] = $error['message'];
$insertValuesData['created_date' . $i] = $error['created_date'];
}
$query = '
INSERT INTO {{build_error}} (
@ -121,10 +121,10 @@ class BuildErrorWriter
{{message}},
{{created_date}}
)
VALUES ' . join(', ', $insert_values_placeholders) . '
VALUES ' . join(', ', $insertValuesPlaceholders) . '
';
$stmt = Database::getConnection('write')->prepareCommon($query);
$stmt->execute($insert_values_data);
$stmt->execute($insertValuesData);
$this->errors = [];
}
}

View file

@ -9,31 +9,42 @@ use b8\Exception\HttpException;
class BuildMetaStore extends Store
{
protected $tableName = 'build_meta';
protected $modelName = '\PHPCensor\Model\BuildMeta';
protected $primaryKey = 'id';
protected $tableName = 'build_meta';
protected $modelName = '\PHPCensor\Model\BuildMeta';
protected $primaryKey = 'id';
/**
* Get a BuildMeta by primary key (Id)
*
* @param integer $key
* @param string $useConnection
*
* @return null|BuildMeta
*/
public function getByPrimaryKey($value, $useConnection = 'read')
public function getByPrimaryKey($key, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
return $this->getById($key, $useConnection);
}
/**
* Get a single BuildMeta by Id.
*
* @param integer $id
* @param string $useConnection
*
* @return null|BuildMeta
*
* @throws HttpException
*/
public function getById($value, $useConnection = 'read')
public function getById($id, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($id)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build_meta}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
$stmt->bindValue(':id', $id);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -44,52 +55,27 @@ class BuildMetaStore extends Store
return null;
}
/**
* Get multiple BuildMeta by ProjectId.
* @return array
*/
public function getByProjectId($value, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build_meta}} WHERE {{project_id}} = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':project_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
return new BuildMeta($item);
};
$rtn = array_map($map, $res);
$count = count($rtn);
return ['items' => $rtn, 'count' => $count];
} else {
return ['items' => [], 'count' => 0];
}
}
/**
* Get multiple BuildMeta by BuildId.
*
* @param integer $buildId
* @param integer $limit
* @param string $useConnection
*
* @return array
*
* @throws HttpException
*/
public function getByBuildId($value, $limit = 1000, $useConnection = 'read')
public function getByBuildId($buildId, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($buildId)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build_meta}} WHERE {{build_id}} = :build_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':build_id', $value);
$stmt->bindValue(':build_id', $buildId);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
@ -118,7 +104,7 @@ class BuildMetaStore extends Store
public function getErrorsForUpgrade($limit)
{
$query = 'SELECT * FROM {{build_meta}}
WHERE {{meta_key}} IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\', \'technical_debt - data\')
WHERE {{meta_key}} IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\', \'technical_debt-data\')
ORDER BY {{id}} ASC LIMIT :limit';
$stmt = Database::getConnection('read')->prepareCommon($query);

View file

@ -18,25 +18,36 @@ class BuildStore extends Store
/**
* Get a Build by primary key (Id)
*
* @param integer $key
* @param string $useConnection
*
* @return null|Build
*/
public function getByPrimaryKey($value, $useConnection = 'read')
public function getByPrimaryKey($key, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
return $this->getById($key, $useConnection);
}
/**
* Get a single Build by Id.
* @return null|Build
*
* @param integer $id
* @param string $useConnection
*
* @return Build|null
*
* @throws HttpException
*/
public function getById($value, $useConnection = 'read')
public function getById($id, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($id)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
$stmt->bindValue(':id', $id);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -49,18 +60,24 @@ class BuildStore extends Store
/**
* Get multiple Build by ProjectId.
*
* @param integer $projectId
* @param integer $limit
* @param string $useConnection
*
* @return array
*
* @throws HttpException
*/
public function getByProjectId($value, $limit = 1000, $useConnection = 'read')
public function getByProjectId($projectId, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($projectId)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build}} WHERE {{project_id}} = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':project_id', $value);
$stmt->bindValue(':project_id', $projectId);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
@ -82,23 +99,23 @@ class BuildStore extends Store
/**
* Get multiple Build by Status.
*
* @param $value
* @param int $limit
* @param string $useConnection
* @param integer $status
* @param integer $limit
* @param string $useConnection
*
* @return array
*
* @throws HttpException
*/
public function getByStatus($value, $limit = 1000, $useConnection = 'read')
public function getByStatus($status, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($status)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build}} WHERE {{status}} = :status LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':status', $value);
$stmt->bindValue(':status', $status);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
@ -117,10 +134,40 @@ class BuildStore extends Store
}
}
/**
* @param integer $limit
* @param integer $offset
*
* @return array
*/
public function getBuilds($limit = 5, $offset = 0)
{
$query = 'SELECT * FROM {{build}} ORDER BY {{id}} DESC LIMIT :limit OFFSET :offset';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
return new Build($item);
};
$rtn = array_map($map, $res);
return $rtn;
} else {
return [];
}
}
/**
* Return an array of the latest builds for a given project.
* @param null $projectId
* @param int $limit
*
* @param integer|null $projectId
* @param integer $limit
*
* @return array
*/
public function getLatestBuilds($projectId = null, $limit = 5)
@ -155,8 +202,10 @@ class BuildStore extends Store
/**
* Return the latest build for a specific project, of a specific build status.
* @param null $projectId
* @param int $status
*
* @param integer|null $projectId
* @param integer $status
*
* @return array|Build
*/
public function getLastBuildByStatus($projectId = null, $status = Build::STATUS_SUCCESS)
@ -209,8 +258,10 @@ class BuildStore extends Store
/**
* Returns all registered branches for project
*
* @param $projectId
* @param integer $projectId
*
* @return array
*
* @throws \Exception
*/
public function getBuildBranches($projectId)
@ -229,11 +280,13 @@ class BuildStore extends Store
/**
* Return build metadata by key, project and optionally build id.
* @param $key
* @param $projectId
* @param null $buildId
* @param null $branch
* @param int $numResults
*
* @param string $key
* @param integer $projectId
* @param integer|null $buildId
* @param string|null $branch
* @param integer $numResults
*
* @return array|null
*/
public function getMeta($key, $projectId, $buildId = null, $branch = null, $numResults = 1)
@ -241,8 +294,7 @@ class BuildStore extends Store
$query = 'SELECT bm.build_id, bm.meta_key, bm.meta_value
FROM {{build_meta}} AS {{bm}}
LEFT JOIN {{build}} AS {{b}} ON b.id = bm.build_id
WHERE bm.meta_key = :key
AND bm.project_id = :projectId';
WHERE bm.meta_key = :key AND b.project_id = :projectId';
// If we're getting comparative meta data, include previous builds
// otherwise just include the specified build ID:
@ -290,20 +342,20 @@ class BuildStore extends Store
/**
* Set a metadata value for a given project and build ID.
* @param $projectId
* @param $buildId
* @param $key
* @param $value
* @return bool
*
* @param integer $buildId
* @param string $key
* @param string $value
*
* @return boolean
*/
public function setMeta($projectId, $buildId, $key, $value)
public function setMeta($buildId, $key, $value)
{
$cols = '{{project_id}}, {{build_id}}, {{meta_key}}, {{meta_value}}';
$query = 'INSERT INTO {{build_meta}} ('.$cols.') VALUES (:projectId, :buildId, :key, :value)';
$cols = '{{build_id}}, {{meta_key}}, {{meta_value}}';
$query = 'INSERT INTO {{build_meta}} ('.$cols.') VALUES (:buildId, :key, :value)';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);
$stmt->bindValue(':projectId', (int)$projectId, \PDO::PARAM_INT);
$stmt->bindValue(':buildId', (int)$buildId, \PDO::PARAM_INT);
$stmt->bindValue(':value', $value, \PDO::PARAM_STR);
@ -316,9 +368,11 @@ class BuildStore extends Store
/**
* Update status only if it synced with db
* @param Build $build
* @param int $status
* @return bool
*
* @param Build $build
* @param integer $status
*
* @return boolean
*/
public function updateStatusSync($build, $status)
{

View file

@ -15,31 +15,36 @@ class EnvironmentStore extends Store
/**
* Get a Environment by primary key (Id)
* @param int $value
* @param string $useConnection
*
* @param integer $key
* @param string $useConnection
*
* @return null|Environment
*/
public function getByPrimaryKey($value, $useConnection = 'read')
public function getByPrimaryKey($key, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
return $this->getById($key, $useConnection);
}
/**
* Get a single Environment by Id.
* @param $value
* @param string $useConnection
*
* @param integer $id
* @param string $useConnection
*
* @return null|Environment
*
* @throws HttpException
*/
public function getById($value, $useConnection = 'read')
public function getById($id, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($id)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{environment}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
$stmt->bindValue(':id', $id);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -52,24 +57,24 @@ class EnvironmentStore extends Store
/**
* Get multiple Environment by Project id.
*
* @param integer $value
*
* @param integer $projectId
* @param string $useConnection
*
*
* @return array
*
*
* @throws \Exception
*/
public function getByProjectId($value, $useConnection = 'read')
public function getByProjectId($projectId, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($projectId)) {
throw new \Exception('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{environment}} WHERE {{project_id}} = :project_id';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':project_id', $value);
$stmt->bindValue(':project_id', $projectId);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);

View file

@ -9,38 +9,43 @@ use PHPCensor\Model\ProjectGroup;
class ProjectGroupStore extends Store
{
protected $tableName = 'project_group';
protected $modelName = '\PHPCensor\Model\ProjectGroup';
protected $primaryKey = 'id';
protected $tableName = 'project_group';
protected $modelName = '\PHPCensor\Model\ProjectGroup';
protected $primaryKey = 'id';
/**
* Get a ProjectGroup by primary key (Id)
*
* @param integer $key
* @param string $useConnection
*
* @return null|ProjectGroup
*/
public function getByPrimaryKey($value, $useConnection = 'read')
public function getByPrimaryKey($key, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
return $this->getById($key, $useConnection);
}
/**
* Get a single ProjectGroup by Id.
*
* @param integer $value
* @param integer $id
* @param string $useConnection
*
* @return ProjectGroup|null
*
* @throws HttpException
*/
public function getById($value, $useConnection = 'read')
public function getById($id, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($id)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{project_group}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
$stmt->bindValue(':id', $id);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -54,23 +59,23 @@ class ProjectGroupStore extends Store
/**
* Get a single ProjectGroup by title.
*
* @param integer $value
* @param integer $title
* @param string $useConnection
*
* @return ProjectGroup|null
*
* @throws HttpException
*/
public function getByTitle($value, $useConnection = 'read')
public function getByTitle($title, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($title)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{project_group}} WHERE {{title}} = :title LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':title', $value);
$stmt->bindValue(':title', $title);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {

View file

@ -12,31 +12,42 @@ use b8\Exception\HttpException;
*/
class ProjectStore extends Store
{
protected $tableName = 'project';
protected $modelName = '\PHPCensor\Model\Project';
protected $primaryKey = 'id';
protected $tableName = 'project';
protected $modelName = '\PHPCensor\Model\Project';
protected $primaryKey = 'id';
/**
* Get a Project by primary key (Id)
*
* @param integer $key
* @param string $useConnection
*
* @return null|Project
*/
public function getByPrimaryKey($value, $useConnection = 'read')
public function getByPrimaryKey($key, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
return $this->getById($key, $useConnection);
}
/**
* Get a single Project by Id.
*
* @param integer $id
* @param string $useConnection
*
* @return null|Project
*
* @throws HttpException
*/
public function getById($value, $useConnection = 'read')
public function getById($id, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($id)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{project}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
$stmt->bindValue(':id', $id);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -49,18 +60,25 @@ class ProjectStore extends Store
/**
* Get multiple Project by Title.
*
* @param string $title
* @param integer $limit
* @param string $useConnection
*
* @return array
*
* @throws HttpException
*/
public function getByTitle($value, $limit = 1000, $useConnection = 'read')
public function getByTitle($title, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($title)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{project}} WHERE {{title}} = :title LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':title', $value);
$stmt->bindValue(':title', $title);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
@ -81,7 +99,9 @@ class ProjectStore extends Store
/**
* Returns a list of all branch names PHPCI has run builds against.
*
* @param $projectId
*
* @return array
*/
public function getKnownBranches($projectId)
@ -106,9 +126,9 @@ class ProjectStore extends Store
/**
* Get a list of all projects, ordered by their title.
*
*
* @param boolean $archived
*
*
* @return array
*/
public function getAll($archived = false)
@ -139,19 +159,19 @@ class ProjectStore extends Store
/**
* Get multiple Project by GroupId.
*
* @param integer $value
*
* @param integer $groupId
* @param boolean $archived
* @param integer $limit
* @param string $useConnection
*
*
* @return array
*
*
* @throws \Exception
*/
public function getByGroupId($value, $archived = false, $limit = 1000, $useConnection = 'read')
public function getByGroupId($groupId, $archived = false, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($groupId)) {
throw new \Exception('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$archived = (integer)$archived;
@ -159,7 +179,7 @@ class ProjectStore extends Store
$query = 'SELECT * FROM {{project}} WHERE {{group_id}} = :group_id AND {{archived}} = :archived ORDER BY {{title}} LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':group_id', $value);
$stmt->bindValue(':group_id', $groupId);
$stmt->bindValue(':archived', $archived);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);

View file

@ -12,31 +12,42 @@ use PHPCensor\Model\User;
*/
class UserStore extends Store
{
protected $tableName = 'user';
protected $modelName = '\PHPCensor\Model\User';
protected $primaryKey = 'id';
protected $tableName = 'user';
protected $modelName = '\PHPCensor\Model\User';
protected $primaryKey = 'id';
/**
* Get a User by primary key (Id)
*
* @param integer $key
* @param string $useConnection
*
* @return null|User
*/
public function getByPrimaryKey($value, $useConnection = 'read')
public function getByPrimaryKey($key, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
return $this->getById($key, $useConnection);
}
/**
* Get a single User by Id.
*
* @param integer $id
* @param string $useConnection
*
* @return null|User
*
* @throws HttpException
*/
public function getById($value, $useConnection = 'read')
public function getById($id, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($id)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{user}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
$stmt->bindValue(':id', $id);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -48,25 +59,24 @@ class UserStore extends Store
}
/**
*
* Get a single User by Email.
*
* @param string $value
* @param string $email
*
* @throws HttpException
*
* @return User
*/
public function getByEmail($value)
public function getByEmail($email)
{
if (is_null($value)) {
if (is_null($email)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{user}} WHERE {{email}} = :email LIMIT 1';
$stmt = Database::getConnection()->prepareCommon($query);
$stmt->bindValue(':email', $value);
$stmt->bindValue(':email', $email);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -78,24 +88,23 @@ class UserStore extends Store
}
/**
*
* Get a single User by Email or Name.
*
* @param string $value
* @param string $emailOrName
*
* @throws HttpException
*
* @return User
*/
public function getByEmailOrName($value)
public function getByEmailOrName($emailOrName)
{
if (is_null($value)) {
if (is_null($emailOrName)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{user}} WHERE {{email}} = :value OR {{name}} = :value LIMIT 1';
$stmt = Database::getConnection()->prepareCommon($query);
$stmt->bindValue(':value', $value);
$stmt->bindValue(':value', $emailOrName);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -107,24 +116,23 @@ class UserStore extends Store
}
/**
*
* Get a single User by RememberKey.
*
* @param string $value
* @param string $rememberKey
*
* @throws HttpException
*
* @return User
*/
public function getByRememberKey($value)
public function getByRememberKey($rememberKey)
{
if (is_null($value)) {
if (is_null($rememberKey)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{user}} WHERE {{remember_key}} = :value LIMIT 1';
$query = 'SELECT * FROM {{user}} WHERE {{remember_key}} = :remember_key LIMIT 1';
$stmt = Database::getConnection()->prepareCommon($query);
$stmt->bindValue(':value', $value);
$stmt->bindValue(':remember_key', $rememberKey);
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
@ -137,20 +145,24 @@ class UserStore extends Store
/**
* Get multiple User by Name.
*
* @throws HttpException
*
*
* @param string $name
* @param integer $limit
* @param string $useConnection
*
* @return array
*
* @throws HttpException
*/
public function getByName($value, $limit = 1000, $useConnection = 'read')
public function getByName($name, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
if (is_null($name)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{user}} WHERE {{name}} = :name LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':name', $value);
$stmt->bindValue(':name', $name);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {

View file

@ -1,4 +1,13 @@
<?php use PHPCensor\Helper\Lang; ?>
<?php
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Build;
/**
* @var Build $build
*/
?>
<li>
<a href="<?php print APP_URL; ?>build/view/<?php print $build->getId(); ?>">
<?php if ($build->getCommitterEmail()): ?>
@ -11,9 +20,9 @@
<?php print $build->getProject()->getTitle(); ?>
<?php if ($build->getStatus() == \PHPCensor\Model\Build::STATUS_PENDING): ?>
<small class="pull-right"><?php Lang::out('created_x', $build->getCreated()->format('H:i')); ?></small>
<small class="pull-right"><?php Lang::out('created_x', $build->getCreateDate()->format('H:i')); ?></small>
<?php elseif ($build->getStatus() == \PHPCensor\Model\Build::STATUS_RUNNING): ?>
<small class="pull-right"><?php Lang::out('started_x', $build->getStarted()->format('H:i')); ?></small>
<small class="pull-right"><?php Lang::out('started_x', $build->getStartDate()->format('H:i')); ?></small>
<?php endif; ?>
</h4>
<p><?php Lang::out('branch_x', $build->getBranch()); ?></p>

View file

@ -1,4 +1,13 @@
<?php use PHPCensor\Helper\Lang; ?>
<?php
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Build;
/**
* @var Build $build
*/
?>
<div class="row">
<div class="col-sm-4">
@ -78,10 +87,16 @@
<div class="box-body no-padding">
<table class="table">
<tr>
<th><?php Lang::out('build_source'); ?></th>
<td style="text-align: right">
<?php Lang::out($build->getSourceHumanize()); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('commit'); ?></th>
<td style="text-align: right">
<a target="_blank" href="<?php print $build->getCommitLink(); ?>">
<a target="_blank" href="<?= $build->getCommitLink(); ?>">
<?php print substr($build->getCommitId(), 0, 7); ?>
</a>
</td>
@ -118,28 +133,28 @@
<tr>
<th><?php Lang::out('created'); ?></th>
<td style="text-align: right" class="build-created datetime">
<?php print $build->getCreated() ? $build->getCreated()->format('Y-m-d H:i:s') : ''; ?>
<?= ($build->getCreateDate() ? $build->getCreateDate()->format('Y-m-d H:i:s') : ''); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('started'); ?></th>
<td style="text-align: right" class="build-started datetime">
<?php print $build->getStarted() ? $build->getStarted()->format('Y-m-d H:i:s') : ''; ?>
<?= ($build->getStartDate() ? $build->getStartDate()->format('Y-m-d H:i:s') : ''); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('finished'); ?></th>
<td style="text-align: right" class="build-finished datetime">
<?php print $build->getFinished() ? $build->getFinished()->format('Y-m-d H:i:s') : ''; ?>
<?= ($build->getFinishDate() ? $build->getFinishDate()->format('Y-m-d H:i:s') : ''); ?>
</td>
</tr>
<tr>
<th><?php Lang::out('duration'); ?></th>
<td style="text-align: right" class="build-duration duration">
<?php print $build->getDuration(); ?> <?= Lang::get('seconds'); ?>
<?= $build->getDuration(); ?> <?= Lang::get('seconds'); ?>
</td>
</tr>
</table>

View file

@ -75,7 +75,7 @@
<strong>Branch: </strong> <?php print $latest->getBranch(); ?><br />
<strong>Committer: </strong> <?php print $latest->getCommitterEmail(); ?>
<?php if ($latest->getCommitId() != 'Manual'): ?>
<?php if (!empty($latest->getCommitId())): ?>
<br /><strong>Commit: </strong> <?php print $latest->getCommitId(); ?><br>
<?php endif; ?>
</p>
@ -142,18 +142,18 @@
<td>
<span class='label label-<?php echo $class ?>'><?php echo $status ?></span>
</td>
<td><?= $build->getCreated()->format('Y-m-d H:i:s'); ?></td>
<td><?= $build->getCreateDate()->format('Y-m-d H:i:s'); ?></td>
<td>
<?php
if ($build->getCommitId() !== 'Manual') {
if (!empty($build->getCommitId())) {
print sprintf(
'<a href="%s" target="_blank">%s (%s)</a>',
'<a href="%s" target="_blank">%s %s</a>',
$build->getCommitLink(),
substr($build->getCommitId(), 0, 7),
$build->getCommitterEmail()
$build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : ''
);
} else {
print 'Manual';
print '&mdash;';
}
?>
</td>

View file

@ -1,5 +1,11 @@
<?php
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Build;
/**
* @var Build[] $builds
*/
$statuses = [];
$failures = 0;
@ -39,12 +45,12 @@ if (count($builds)) {
break;
case 2:
$statuses[] = 'ok';
$success = is_null($success) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $success;
$success = is_null($success) && !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : $success;
break;
case 3:
$failures++;
$statuses[] = 'failed';
$failure = is_null($failure) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $failure;
$failure = is_null($failure) && !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : $failure;
break;
}
}
@ -61,8 +67,8 @@ if ($buildCount > 0) {
$shortMessage = Lang::get('x_of_x_failed_short', $failures, $buildCount);
$message = Lang::get('x_of_x_failed', $failures, $buildCount);
if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) {
$message .= Lang::get('last_successful_build', $lastSuccess->getFinished()->format('Y-m-d H:i:s'));
if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinishDate())) {
$message .= Lang::get('last_successful_build', $lastSuccess->getFinishDate()->format('Y-m-d H:i:s'));
} else {
$message .= Lang::get('never_built_successfully');
}
@ -70,8 +76,8 @@ if ($buildCount > 0) {
$message = Lang::get('all_builds_passed', $buildCount);
$shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount);
if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) {
$message .= Lang::get('last_failed_build', $lastFailure->getFinished()->format('Y-m-d H:i:s'));
if (!is_null($lastFailure) && !is_null($lastFailure->getFinishDate())) {
$message .= Lang::get('last_failed_build', $lastFailure->getFinishDate()->format('Y-m-d H:i:s'));
} else {
$message .= Lang::get('never_failed_build');
}

View file

@ -3,6 +3,10 @@
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Build;
/**
* @var Build[] $builds
*/
?>
<ul class="timeline">
<?php $last = new \DateTime('-1 Year'); ?>
@ -14,32 +18,32 @@ use PHPCensor\Model\Build;
switch ($build->getStatus()) {
case Build::STATUS_PENDING:
$updated = $build->getCreated();
$updated = $build->getCreateDate();
$label = Lang::get('pending');
$color = 'blue';
break;
case Build::STATUS_RUNNING:
$updated = $build->getStarted();
$updated = $build->getStartDate();
$label = Lang::get('running');
$color = 'yellow';
break;
case Build::STATUS_SUCCESS:
$updated = $build->getFinished();
$updated = $build->getFinishDate();
$label = Lang::get('success');
$color = 'green';
break;
case Build::STATUS_FAILED:
$updated = $build->getFinished();
$updated = $build->getFinishDate();
$label = Lang::get('failed');
$color = 'red';
break;
}
if (!$updated) {
$updated = $build->getCreated();
$updated = $build->getCreateDate();
}
if ($updated->format('Y-m-d') != $last->format('Y-m-d')): $last = $updated;
@ -74,7 +78,7 @@ use PHPCensor\Model\Build;
Build #<?= $build->getId(); ?>
</a>
&mdash;
<?php print $label; ?>
<?php Lang::out($build->getSourceHumanize()); ?>
</h3>
<div class="timeline-body">
@ -85,21 +89,21 @@ use PHPCensor\Model\Build;
<i class="fa fa-tag"></i> <?= $tag; ?>
</a>
<?php endif; ?>
&mdash;
<?php
if ($build->getCommitId() !== 'Manual') {
print sprintf(
'<a href="%s" target="_blank">%s (%s)</a>',
$build->getCommitLink(),
substr($build->getCommitId(), 0, 7),
$build->getCommitterEmail()
);
} else {
print Lang::get('manual_build');
}
if (!empty($build->getCommitId())) {
echo ' &mdash; ';
echo sprintf(
'<a href="%s" target="_blank">%s %s</a>',
$build->getCommitLink(),
substr($build->getCommitId(), 0, 7),
$build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : ''
);
if (!empty($build->getCommitMessage())) {
echo ' &mdash; ';
print $build->getCommitMessage();
}
}
?>
&mdash;
<?php print $build->getCommitMessage(); ?>
</div>
</div>
</li>

View file

@ -1,5 +1,11 @@
<?php
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Build;
/**
* @var Build[] $builds
*/
foreach($projects as $project):
$statuses = [];
@ -40,12 +46,12 @@ foreach($projects as $project):
break;
case 2:
$statuses[] = 'ok';
$success = is_null($success) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $success;
$success = is_null($success) && !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : $success;
break;
case 3:
$failures++;
$statuses[] = 'failed';
$failure = is_null($failure) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $failure;
$failure = is_null($failure) && !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : $failure;
break;
}
}
@ -62,8 +68,8 @@ foreach($projects as $project):
$shortMessage = Lang::get('x_of_x_failed_short', $failures, $buildCount);
$message = Lang::get('x_of_x_failed', $failures, $buildCount);
if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) {
$message .= Lang::get('last_successful_build', $lastSuccess->getFinished()->format('Y-m-d H:i:s'));
if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinishDate())) {
$message .= Lang::get('last_successful_build', $lastSuccess->getFinishDate()->format('Y-m-d H:i:s'));
} else {
$message .= Lang::get('never_built_successfully');
}
@ -71,8 +77,8 @@ foreach($projects as $project):
$message = Lang::get('all_builds_passed', $buildCount);
$shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount);
if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) {
$message .= Lang::get('last_failed_build', $lastFailure->getFinished()->format('Y-m-d H:i:s'));
if (!is_null($lastFailure) && !is_null($lastFailure->getFinishDate())) {
$message .= Lang::get('last_failed_build', $lastFailure->getFinishDate()->format('Y-m-d H:i:s'));
} else {
$message .= Lang::get('never_failed_build');
}

View file

@ -3,6 +3,10 @@
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Build;
/**
* @var Build[] $builds
*/
?>
<script>
var DASHBOARD = true;
@ -45,32 +49,32 @@ use PHPCensor\Model\Build;
switch ($build->getStatus()) {
case Build::STATUS_PENDING:
$updated = $build->getCreated();
$updated = $build->getCreateDate();
$label = Lang::get('pending');
$color = 'blue';
break;
case Build::STATUS_RUNNING:
$updated = $build->getStarted();
$updated = $build->getStartDate();
$label = Lang::get('running');
$color = 'yellow';
break;
case Build::STATUS_SUCCESS:
$updated = $build->getFinished();
$updated = $build->getFinishDate();
$label = Lang::get('success');
$color = 'green';
break;
case Build::STATUS_FAILED:
$updated = $build->getFinished();
$updated = $build->getFinishDate();
$label = Lang::get('failed');
$color = 'red';
break;
}
if (!$updated) {
$updated = $build->getCreated();
$updated = $build->getCreateDate();
}
if ($updated->format('Y-m-d') != $last->format('Y-m-d')): $last = $updated;
@ -104,8 +108,8 @@ use PHPCensor\Model\Build;
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>">
Build #<?= $build->getId(); ?>
</a>
&mdash;
<?= $label; ?>
&mdash;
<?php Lang::out($build->getSourceHumanize()); ?>
</h3>
<div class="timeline-body">
@ -116,21 +120,21 @@ use PHPCensor\Model\Build;
<i class="fa fa-tag"></i> <?= $tag; ?>
</a>
<?php endif; ?>
&mdash;
<?php
if ($build->getCommitId() !== 'Manual') {
print sprintf(
'<a href="%s" target="_blank">%s (%s)</a>',
$build->getCommitLink(),
substr($build->getCommitId(), 0, 7),
$build->getCommitterEmail()
);
} else {
print Lang::get('manual_build');
}
if (!empty($build->getCommitId())) {
echo ' &mdash; ';
echo sprintf(
'<a href="%s" target="_blank">%s %s</a>',
$build->getCommitLink(),
substr($build->getCommitId(), 0, 7),
$build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : ''
);
if (!empty($build->getCommitMessage())) {
echo ' &mdash; ';
print $build->getCommitMessage();
}
}
?>
&mdash;
<?php print $build->getCommitMessage(); ?>
</div>
</div>
</li>

View file

@ -40,20 +40,21 @@ switch($build->getStatus())
$branches = $build->getExtra('branches');
?>
<tr>
<td><a href="<?php echo APP_URL ?>build/view/<?php print $build->getId(); ?>">#<?php print str_pad($build->getId(), 6, '0', STR_PAD_LEFT); ?></a></td>
<td><span class='label label-<?php echo $subcls ?>'><?php echo $status ?></span></td>
<td><?php print $build->getCreated()->format('Y-m-d H:i:s'); ?></td>
<td><a href="<?= APP_URL ?>build/view/<?= $build->getId(); ?>">#<?= str_pad($build->getId(), 6, '0', STR_PAD_LEFT); ?></a></td>
<td><span class='label label-<?= $subcls ?>'><?= $status ?></span></td>
<td><?= $build->getCreateDate()->format('Y-m-d H:i:s'); ?></td>
<td><?php Lang::out($build->getSourceHumanize()); ?></td>
<td class="hidden-md hidden-sm hidden-xs">
<?php
if ($build->getCommitId() !== 'Manual') {
if (!empty($build->getCommitId())) {
print sprintf(
'<a href="%s" target="_blank">%s (%s)</a>',
'<a href="%s" target="_blank">%s %s</a>',
$build->getCommitLink(),
substr($build->getCommitId(), 0, 7),
$build->getCommitterEmail()
$build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : ''
);
} else {
print Lang::get('manual_build');
print '&mdash;';
}
?>
</td>

View file

@ -103,6 +103,7 @@
<th><?php Lang::out('id'); ?></th>
<th><?php Lang::out('status'); ?></th>
<th><?php Lang::out('date'); ?></th>
<th><?php Lang::out('build_source'); ?></th>
<th class="hidden-md hidden-sm hidden-xs"><?php Lang::out('commit'); ?></th>
<th><?php Lang::out('branch'); ?></th>
<th><?php Lang::out('environment'); ?></th>

View file

@ -118,7 +118,7 @@ class BuildWorker
$this->logger->addError($ex->getMessage());
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$build->setFinishDate(new \DateTime());
$build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage());
$buildStore->save($build);
$build->sendStatusPostback();

View file

@ -81,7 +81,7 @@ class DatabaseTest extends \PHPUnit\Framework\TestCase
['host' => 'localhost'],
],
],
'type' => 'mysql',
'type' => DB_TYPE,
'name' => 'b8_test_2',
'username' => '',
'password' => '',

View file

@ -62,15 +62,16 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(101, $returnValue->getProjectId());
$this->assertEquals(Build::STATUS_PENDING, $returnValue->getStatus());
$this->assertNull($returnValue->getStarted());
$this->assertNull($returnValue->getFinished());
$this->assertNull($returnValue->getStartDate());
$this->assertNull($returnValue->getFinishDate());
$this->assertNull($returnValue->getLog());
$this->assertEquals('Manual', $returnValue->getCommitMessage());
$this->assertEquals(null, $returnValue->getCommitMessage());
$this->assertNull($returnValue->getCommitterEmail());
$this->assertEquals(['branches' => []], $returnValue->getExtra());
$this->assertEquals('master', $returnValue->getBranch());
$this->assertInstanceOf('DateTime', $returnValue->getCreated());
$this->assertEquals('Manual', $returnValue->getCommitId());
$this->assertInstanceOf('DateTime', $returnValue->getCreateDate());
$this->assertEquals('', $returnValue->getCommitId());
$this->assertEquals(Build::SOURCE_UNKNOWN, $returnValue->getSource());
}
public function testExecute_CreateBuildWithOptions()
@ -120,11 +121,13 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
$returnValue = $this->testedService->createBuild(
$project,
null,
'',
null,
null,
null,
null,
null,
Build::SOURCE_UNKNOWN,
0,
['item1' => 1001]
);
@ -140,8 +143,8 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
$build->setStatus(Build::STATUS_FAILED);
$build->setLog('Test');
$build->setBranch('example_branch');
$build->setStarted(new \DateTime());
$build->setFinished(new \DateTime());
$build->setStartDate(new \DateTime());
$build->setFinishDate(new \DateTime());
$build->setCommitMessage('test');
$build->setCommitterEmail('test@example.com');
$build->setExtra(json_encode(['item1' => 1001]));
@ -155,9 +158,9 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(Build::STATUS_PENDING, $returnValue->getStatus());
$this->assertNull($returnValue->getLog());
$this->assertEquals($build->getBranch(), $returnValue->getBranch());
$this->assertNotEquals($build->getCreated(), $returnValue->getCreated());
$this->assertNull($returnValue->getStarted());
$this->assertNull($returnValue->getFinished());
$this->assertNotEquals($build->getCreateDate(), $returnValue->getCreateDate());
$this->assertNull($returnValue->getStartDate());
$this->assertNull($returnValue->getFinishDate());
$this->assertEquals('test', $returnValue->getCommitMessage());
$this->assertEquals('test@example.com', $returnValue->getCommitterEmail());
$this->assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1'));

View file

@ -86,10 +86,10 @@ class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase
$build->setBranch(self::BRANCH);
$build->setStatus($config[$configId]['status']);
if ($config[$configId]['finishDateTime']) {
$build->setFinished(new \DateTime($config[$configId]['finishDateTime']));
$build->setFinishDate(new \DateTime($config[$configId]['finishDateTime']));
}
if (!empty($config[$configId]['startedDate'])) {
$build->setStarted(new \DateTime('2014-10-25 21:20:02'));
$build->setStartDate(new \DateTime('2014-10-25 21:20:02'));
}
$project = $this->getProjectMock($config[$configId]['previousBuild'], $setProject);

View file

@ -35,7 +35,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
public function testExecute_CreateBasicProject()
{
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci');
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', 0);
$this->assertEquals('Test Project', $returnValue->getTitle());
$this->assertEquals('github', $returnValue->getType());
@ -53,7 +53,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
'branch' => 'testbranch',
];
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', $options);
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', 0, $options);
$this->assertEquals('private', $returnValue->getSshPrivateKey());
$this->assertEquals('public', $returnValue->getSshPublicKey());
@ -68,7 +68,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
public function testExecute_CreateGitlabProjectWithoutPort()
{
$reference = 'git@gitlab.block8.net:block8/phpci.git';
$returnValue = $this->testedService->createProject('Gitlab', 'gitlab', $reference);
$returnValue = $this->testedService->createProject('Gitlab', 'gitlab', $reference, 0);
$this->assertEquals('git', $returnValue->getAccessInformation('user'));
$this->assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain'));