From 145670acdeb190ed3016855f63e1d92545cb4152 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 13 Apr 2017 22:00:29 +0700 Subject: [PATCH 1/9] Build sources instead of 'Manual' word. --- src/PHPCensor/Command/CreateBuildCommand.php | 3 +- .../Command/ScheduleBuildCommand.php | 2 +- .../Controller/ProjectController.php | 19 +++-- .../Controller/WebhookController.php | 2 + src/PHPCensor/Languages/lang.en.php | 7 ++ src/PHPCensor/Languages/lang.ru.php | 7 ++ .../20151015124825_convert_errors.php | 7 +- ...256_added_source_column_to_build_table.php | 33 ++++++++ src/PHPCensor/Model/Build.php | 80 +++++++++++++++++-- src/PHPCensor/Model/Build/BitbucketBuild.php | 18 ++--- src/PHPCensor/Model/Build/GithubBuild.php | 13 +-- src/PHPCensor/Model/Build/GogsBuild.php | 6 +- src/PHPCensor/Model/Build/MercurialBuild.php | 9 ++- src/PHPCensor/Model/Build/RemoteGitBuild.php | 20 +++-- src/PHPCensor/Model/Build/SubversionBuild.php | 2 +- src/PHPCensor/Service/BuildService.php | 17 ++-- src/PHPCensor/Store/BuildMetaStore.php | 2 +- src/PHPCensor/Store/BuildStore.php | 28 +++++++ src/PHPCensor/View/Build/view.phtml | 8 +- src/PHPCensor/View/BuildStatus/view.phtml | 10 +-- src/PHPCensor/View/Home/ajax-timeline.phtml | 28 +++---- src/PHPCensor/View/Home/index.phtml | 30 +++---- src/PHPCensor/View/Project/ajax-builds.phtml | 15 ++-- src/PHPCensor/View/Project/view.phtml | 1 + tests/PHPCensor/Service/BuildServiceTest.php | 8 +- 25 files changed, 266 insertions(+), 109 deletions(-) create mode 100644 src/PHPCensor/Migrations/20170413131256_added_source_column_to_build_table.php diff --git a/src/PHPCensor/Command/CreateBuildCommand.php b/src/PHPCensor/Command/CreateBuildCommand.php index e92cf947..28b97592 100644 --- a/src/PHPCensor/Command/CreateBuildCommand.php +++ b/src/PHPCensor/Command/CreateBuildCommand.php @@ -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('Failed'); diff --git a/src/PHPCensor/Command/ScheduleBuildCommand.php b/src/PHPCensor/Command/ScheduleBuildCommand.php index 69d89270..1f76df63 100644 --- a/src/PHPCensor/Command/ScheduleBuildCommand.php +++ b/src/PHPCensor/Command/ScheduleBuildCommand.php @@ -90,7 +90,7 @@ class ScheduleBuildCommand extends Command } 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('Failed'); diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index 4b782e0c..e78317b1 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -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) @@ -175,11 +177,12 @@ class ProjectController extends PHPCensor\Controller $build = $this->buildService->createBuild( $project, $environment, - null, + '', $branch, null, $email, null, + Build::SOURCE_MANUAL_WEB, $extra ); @@ -187,7 +190,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 +206,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; @@ -324,7 +327,7 @@ class ProjectController extends PHPCensor\Controller $project = $this->projectService->createProject($title, $type, $reference, $options); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL.'project/view/' . $project->getId()); return $response; @@ -393,7 +396,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; diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index 61f5de01..4e040bbf 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -665,6 +665,7 @@ class WebhookController extends Controller $tag, $committer, $commitMessage, + Build::SOURCE_WEBHOOK, $extra ); @@ -702,6 +703,7 @@ class WebhookController extends Controller $tag, $committer, $commitMessage, + Build::SOURCE_WEBHOOK, $extra ); diff --git a/src/PHPCensor/Languages/lang.en.php b/src/PHPCensor/Languages/lang.en.php index 5fa56d22..f42e5987 100644 --- a/src/PHPCensor/Languages/lang.en.php +++ b/src/PHPCensor/Languages/lang.en.php @@ -145,6 +145,13 @@ PHP Censor', 'next_link' => 'Next »', '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 diff --git a/src/PHPCensor/Languages/lang.ru.php b/src/PHPCensor/Languages/lang.ru.php index b125d28d..23d7d552 100644 --- a/src/PHPCensor/Languages/lang.ru.php +++ b/src/PHPCensor/Languages/lang.ru.php @@ -142,6 +142,13 @@ PHP Censor', 'next_link' => 'След. »', '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 ниже в качестве нового хука в разделе настроек Webhooks diff --git a/src/PHPCensor/Migrations/20151015124825_convert_errors.php b/src/PHPCensor/Migrations/20151015124825_convert_errors.php index 2051de60..37751b69 100644 --- a/src/PHPCensor/Migrations/20151015124825_convert_errors.php +++ b/src/PHPCensor/Migrations/20151015124825_convert_errors.php @@ -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); diff --git a/src/PHPCensor/Migrations/20170413131256_added_source_column_to_build_table.php b/src/PHPCensor/Migrations/20170413131256_added_source_column_to_build_table.php new file mode 100644 index 00000000..a63a3a17 --- /dev/null +++ b/src/PHPCensor/Migrations/20170413131256_added_source_column_to_build_table.php @@ -0,0 +1,33 @@ +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(); + } + } +} diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index 54d7d29e..818b5000 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -25,6 +25,12 @@ class Build extends Model const STATUS_RUNNING = 1; const STATUS_SUCCESS = 2; const STATUS_FAILED = 3; + + const SOURCE_UNKNOWN = 0; + const SOURCE_MANUAL_WEB = 1; + const SOURCE_MANUAL_CONSOLE = 2; + const SOURCE_PERIODICAL = 3; + const SOURCE_WEBHOOK = 4; /** * @var array @@ -59,6 +65,7 @@ class Build extends Model 'commit_message' => null, 'extra' => null, 'environment' => null, + 'source' => Build::SOURCE_UNKNOWN, ]; /** @@ -80,6 +87,7 @@ class Build extends Model 'commit_message' => 'getCommitMessage', 'extra' => 'getExtra', 'environment' => 'getEnvironment', + 'source' => 'getSource', // Foreign key getters: 'Project' => 'getProject', @@ -104,6 +112,7 @@ class Build extends Model 'commit_message' => 'setCommitMessage', 'extra' => 'setExtra', 'environment' => 'setEnvironment', + 'source' => 'setSource', // Foreign key setters: 'Project' => 'setProject', @@ -182,10 +191,15 @@ class Build extends Model 'default' => null, ], 'environment' => [ - 'type' => 'varchar', - 'length' => 250, + 'type' => 'varchar', + 'length' => 250, 'default' => null, ], + 'source' => [ + 'type' => 'int', + 'length' => 11, + 'default' => Build::SOURCE_UNKNOWN, + ], ]; /** @@ -213,25 +227,25 @@ class Build extends Model /** * Get the value of Id / id. * - * @return int + * @return integer */ public function getId() { $rtn = $this->data['id']; - return $rtn; + return (integer)$rtn; } /** * Get the value of ProjectId / project_id. * - * @return int + * @return integer */ public function getProjectId() { $rtn = $this->data['project_id']; - return $rtn; + return (integer)$rtn; } /** @@ -249,13 +263,13 @@ class Build extends Model /** * Get the value of Status / status. * - * @return int + * @return integer */ public function getStatus() { $rtn = $this->data['status']; - return $rtn; + return (integer)$rtn; } /** @@ -1032,6 +1046,36 @@ class Build extends Model $this->setModified('tag'); } + /** + * Get the value of source. + * + * @return string + */ + public function getSource() + { + $rtn = $this->data['source']; + + return (integer)$rtn; + } + + /** + * Set the value of source. + * + * @param $value integer + */ + public function setSource($value) + { + $this->validateInt('Source', $value); + + if ($this->data['source'] === $value) { + return; + } + + $this->data['source'] = $value; + + $this->setModified('source'); + } + /** * Get the value of Environment / environment. * @@ -1107,4 +1151,24 @@ OUT; return $wrapperFile; } + + /** + * @return string + */ + public function getSourceHumanize() + { + switch ($this->getSource()) { + case Build::SOURCE_WEBHOOK: + return 'source_webhook'; + case Build::SOURCE_MANUAL_WEB: + return 'source_manual_web'; + case Build::SOURCE_MANUAL_CONSOLE: + return 'source_manual_console'; + case Build::SOURCE_PERIODICAL: + return 'source_periodical'; + case Build::SOURCE_UNKNOWN: + default: + return 'source_unknown'; + } + } } diff --git a/src/PHPCensor/Model/Build/BitbucketBuild.php b/src/PHPCensor/Model/Build/BitbucketBuild.php index 3b602fbf..77102950 100644 --- a/src/PHPCensor/Model/Build/BitbucketBuild.php +++ b/src/PHPCensor/Model/Build/BitbucketBuild.php @@ -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; } diff --git a/src/PHPCensor/Model/Build/GithubBuild.php b/src/PHPCensor/Model/Build/GithubBuild.php index 54f026ca..d160704a 100644 --- a/src/PHPCensor/Model/Build/GithubBuild.php +++ b/src/PHPCensor/Model/Build/GithubBuild.php @@ -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; } diff --git a/src/PHPCensor/Model/Build/GogsBuild.php b/src/PHPCensor/Model/Build/GogsBuild.php index a5f08413..cab9ad54 100644 --- a/src/PHPCensor/Model/Build/GogsBuild.php +++ b/src/PHPCensor/Model/Build/GogsBuild.php @@ -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(); } /** diff --git a/src/PHPCensor/Model/Build/MercurialBuild.php b/src/PHPCensor/Model/Build/MercurialBuild.php index bcc8ed4a..17976207 100644 --- a/src/PHPCensor/Model/Build/MercurialBuild.php +++ b/src/PHPCensor/Model/Build/MercurialBuild.php @@ -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()); } diff --git a/src/PHPCensor/Model/Build/RemoteGitBuild.php b/src/PHPCensor/Model/Build/RemoteGitBuild.php index 68a4c018..93301100 100644 --- a/src/PHPCensor/Model/Build/RemoteGitBuild.php +++ b/src/PHPCensor/Model/Build/RemoteGitBuild.php @@ -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; diff --git a/src/PHPCensor/Model/Build/SubversionBuild.php b/src/PHPCensor/Model/Build/SubversionBuild.php index 431b5459..68a2ff7d 100644 --- a/src/PHPCensor/Model/Build/SubversionBuild.php +++ b/src/PHPCensor/Model/Build/SubversionBuild.php @@ -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 { diff --git a/src/PHPCensor/Service/BuildService.php b/src/PHPCensor/Service/BuildService.php index e4e0a67c..af2e3284 100644 --- a/src/PHPCensor/Service/BuildService.php +++ b/src/PHPCensor/Service/BuildService.php @@ -36,11 +36,12 @@ 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 string|null $extra * * @return \PHPCensor\Model\Build @@ -48,11 +49,12 @@ class BuildService public function createBuild( Project $project, $environment, - $commitId = null, + $commitId = '', $branch = null, $tag = null, $committerEmail = null, $commitMessage = null, + $source = Build::SOURCE_UNKNOWN, $extra = null ) { $build = new Build(); @@ -64,12 +66,8 @@ 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->setCommitId((string)$commitId); if (!empty($branch)) { $build->setBranch($branch); @@ -94,8 +92,7 @@ class BuildService } /** @var Build $build */ - $build = $this->buildStore->save($build); - + $build = $this->buildStore->save($build); $buildId = $build->getId(); if (!empty($buildId)) { diff --git a/src/PHPCensor/Store/BuildMetaStore.php b/src/PHPCensor/Store/BuildMetaStore.php index 4c6e11ad..c69782e9 100644 --- a/src/PHPCensor/Store/BuildMetaStore.php +++ b/src/PHPCensor/Store/BuildMetaStore.php @@ -118,7 +118,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); diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 15c0a82d..895ad872 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -117,6 +117,34 @@ 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 diff --git a/src/PHPCensor/View/Build/view.phtml b/src/PHPCensor/View/Build/view.phtml index 60ba7d30..7bba273b 100644 --- a/src/PHPCensor/View/Build/view.phtml +++ b/src/PHPCensor/View/Build/view.phtml @@ -78,10 +78,16 @@
+ + + + diff --git a/src/PHPCensor/View/BuildStatus/view.phtml b/src/PHPCensor/View/BuildStatus/view.phtml index c7c80576..7a30b624 100644 --- a/src/PHPCensor/View/BuildStatus/view.phtml +++ b/src/PHPCensor/View/BuildStatus/view.phtml @@ -75,7 +75,7 @@ Branch: getBranch(); ?>
Committer: getCommitterEmail(); ?> - getCommitId() != 'Manual'): ?> + getCommitId())): ?>
Commit: getCommitId(); ?>

@@ -145,15 +145,15 @@ diff --git a/src/PHPCensor/View/Home/ajax-timeline.phtml b/src/PHPCensor/View/Home/ajax-timeline.phtml index ed9d1cf2..4071721a 100644 --- a/src/PHPCensor/View/Home/ajax-timeline.phtml +++ b/src/PHPCensor/View/Home/ajax-timeline.phtml @@ -74,7 +74,7 @@ use PHPCensor\Model\Build; Build #getId(); ?> — - + getSourceHumanize()); ?>
@@ -85,21 +85,21 @@ use PHPCensor\Model\Build; - — getCommitId() !== 'Manual') { - print sprintf( - '%s (%s)', - $build->getCommitLink(), - substr($build->getCommitId(), 0, 7), - $build->getCommitterEmail() - ); - } else { - print Lang::get('manual_build'); - } + if (!empty($build->getCommitId())) { + echo ' — '; + echo sprintf( + '%s %s', + $build->getCommitLink(), + substr($build->getCommitId(), 0, 7), + $build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : '' + ); + if (!empty($build->getCommitMessage())) { + echo ' — '; + print $build->getCommitMessage(); + } + } ?> - — - getCommitMessage(); ?>
diff --git a/src/PHPCensor/View/Home/index.phtml b/src/PHPCensor/View/Home/index.phtml index cc5b9abc..d55301c3 100644 --- a/src/PHPCensor/View/Home/index.phtml +++ b/src/PHPCensor/View/Home/index.phtml @@ -104,8 +104,8 @@ use PHPCensor\Model\Build; Build #getId(); ?> - — - + — + getSourceHumanize()); ?>
@@ -116,21 +116,21 @@ use PHPCensor\Model\Build; - — getCommitId() !== 'Manual') { - print sprintf( - '%s (%s)', - $build->getCommitLink(), - substr($build->getCommitId(), 0, 7), - $build->getCommitterEmail() - ); - } else { - print Lang::get('manual_build'); - } + if (!empty($build->getCommitId())) { + echo ' — '; + echo sprintf( + '%s %s', + $build->getCommitLink(), + substr($build->getCommitId(), 0, 7), + $build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : '' + ); + if (!empty($build->getCommitMessage())) { + echo ' — '; + print $build->getCommitMessage(); + } + } ?> - — - getCommitMessage(); ?>
diff --git a/src/PHPCensor/View/Project/ajax-builds.phtml b/src/PHPCensor/View/Project/ajax-builds.phtml index a67a52f6..0aacd198 100644 --- a/src/PHPCensor/View/Project/ajax-builds.phtml +++ b/src/PHPCensor/View/Project/ajax-builds.phtml @@ -40,20 +40,21 @@ switch($build->getStatus()) $branches = $build->getExtra('branches'); ?> - - - + + + + diff --git a/src/PHPCensor/View/Project/view.phtml b/src/PHPCensor/View/Project/view.phtml index b1da5007..805b6631 100644 --- a/src/PHPCensor/View/Project/view.phtml +++ b/src/PHPCensor/View/Project/view.phtml @@ -103,6 +103,7 @@ + diff --git a/tests/PHPCensor/Service/BuildServiceTest.php b/tests/PHPCensor/Service/BuildServiceTest.php index f4c64501..42759f66 100644 --- a/tests/PHPCensor/Service/BuildServiceTest.php +++ b/tests/PHPCensor/Service/BuildServiceTest.php @@ -65,12 +65,13 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase $this->assertNull($returnValue->getStarted()); $this->assertNull($returnValue->getFinished()); $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->assertEquals('', $returnValue->getCommitId()); + $this->assertEquals(Build::SOURCE_UNKNOWN, $returnValue->getSource()); } public function testExecute_CreateBuildWithOptions() @@ -120,11 +121,12 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase $returnValue = $this->testedService->createBuild( $project, null, + '', null, null, null, null, - null, + Build::SOURCE_UNKNOWN, ['item1' => 1001] ); From 9e57de043e725a729f514784b0fdb80c0f4bf3c0 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 15 Oct 2017 00:48:53 +0700 Subject: [PATCH 2/9] Removed useless 'project_id' column from 'build_meta' table. --- ...348_removed_project_id_from_build_meta.php | 28 +++++ src/PHPCensor/Model/Build.php | 2 +- src/PHPCensor/Model/BuildMeta.php | 107 ------------------ src/PHPCensor/Model/Project.php | 12 -- src/PHPCensor/Plugin/Util/Executor.php | 2 +- src/PHPCensor/Store/BuildMetaStore.php | 32 ------ src/PHPCensor/Store/BuildStore.php | 13 +-- 7 files changed, 36 insertions(+), 160 deletions(-) create mode 100644 src/PHPCensor/Migrations/20171014173348_removed_project_id_from_build_meta.php diff --git a/src/PHPCensor/Migrations/20171014173348_removed_project_id_from_build_meta.php b/src/PHPCensor/Migrations/20171014173348_removed_project_id_from_build_meta.php new file mode 100644 index 00000000..873aba78 --- /dev/null +++ b/src/PHPCensor/Migrations/20171014173348_removed_project_id_from_build_meta.php @@ -0,0 +1,28 @@ +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(); + } + } +} diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index 818b5000..ade8e1cc 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -775,7 +775,7 @@ class Build extends Model public function storeMeta($key, $value) { $value = json_encode($value); - Factory::getStore('Build')->setMeta($this->getProjectId(), $this->getId(), $key, $value); + Factory::getStore('Build')->setMeta($this->getId(), $key, $value); } /** diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index 656f81b5..14e8e035 100644 --- a/src/PHPCensor/Model/BuildMeta.php +++ b/src/PHPCensor/Model/BuildMeta.php @@ -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,12 +38,10 @@ 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', ]; @@ -54,12 +51,10 @@ 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', ]; @@ -74,11 +69,6 @@ class BuildMeta extends Model 'auto_increment' => true, 'default' => null, ], - 'project_id' => [ - 'type' => 'int', - 'length' => 11, - 'default' => null, - ], 'build_id' => [ 'type' => 'int', 'length' => 11, @@ -101,20 +91,12 @@ class BuildMeta extends Model 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', @@ -136,18 +118,6 @@ class BuildMeta extends Model 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. * @@ -204,26 +174,6 @@ class BuildMeta extends Model $this->setModified('id'); } - /** - * 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. * @@ -284,63 +234,6 @@ 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. * diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 9e20d91d..406df493 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -660,18 +660,6 @@ 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 diff --git a/src/PHPCensor/Plugin/Util/Executor.php b/src/PHPCensor/Plugin/Util/Executor.php index 18bd2ebb..03f3ce76 100644 --- a/src/PHPCensor/Plugin/Util/Executor.php +++ b/src/PHPCensor/Plugin/Util/Executor.php @@ -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)); } } diff --git a/src/PHPCensor/Store/BuildMetaStore.php b/src/PHPCensor/Store/BuildMetaStore.php index c69782e9..2909d7f3 100644 --- a/src/PHPCensor/Store/BuildMetaStore.php +++ b/src/PHPCensor/Store/BuildMetaStore.php @@ -44,38 +44,6 @@ 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. * @return array diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 895ad872..79c28bdf 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -269,8 +269,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: @@ -318,20 +317,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 */ - 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); From 508465fc7474534fff250e5058359e66bc8ff60d Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 15 Oct 2017 01:29:29 +0700 Subject: [PATCH 3/9] Code style fixes + phpdocs. --- src/PHPCensor/Store/BuildErrorStore.php | 45 ++++++++--- src/PHPCensor/Store/BuildErrorWriter.php | 62 +++++++-------- src/PHPCensor/Store/BuildMetaStore.php | 40 +++++++--- src/PHPCensor/Store/BuildStore.php | 93 +++++++++++++++-------- src/PHPCensor/Store/EnvironmentStore.php | 37 +++++---- src/PHPCensor/Store/ProjectGroupStore.php | 31 ++++---- src/PHPCensor/Store/ProjectStore.php | 60 ++++++++++----- src/PHPCensor/Store/UserStore.php | 72 ++++++++++-------- 8 files changed, 274 insertions(+), 166 deletions(-) diff --git a/src/PHPCensor/Store/BuildErrorStore.php b/src/PHPCensor/Store/BuildErrorStore.php index 1dbc7fea..f716fc70 100644 --- a/src/PHPCensor/Store/BuildErrorStore.php +++ b/src/PHPCensor/Store/BuildErrorStore.php @@ -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) diff --git a/src/PHPCensor/Store/BuildErrorWriter.php b/src/PHPCensor/Store/BuildErrorWriter.php index e0dc89de..272604c8 100644 --- a/src/PHPCensor/Store/BuildErrorWriter.php +++ b/src/PHPCensor/Store/BuildErrorWriter.php @@ -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 = []; } } diff --git a/src/PHPCensor/Store/BuildMetaStore.php b/src/PHPCensor/Store/BuildMetaStore.php index 2909d7f3..74b40f62 100644 --- a/src/PHPCensor/Store/BuildMetaStore.php +++ b/src/PHPCensor/Store/BuildMetaStore.php @@ -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)) { @@ -46,18 +57,25 @@ class BuildMetaStore extends Store /** * 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()) { diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 79c28bdf..b69d9bbb 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -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()) { @@ -147,8 +164,10 @@ class BuildStore extends Store /** * 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) @@ -183,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) @@ -237,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) @@ -257,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) @@ -318,11 +343,11 @@ class BuildStore extends Store /** * Set a metadata value for a given project and build ID. * - * @param $buildId - * @param $key - * @param $value + * @param integer $buildId + * @param string $key + * @param string $value * - * @return bool + * @return boolean */ public function setMeta($buildId, $key, $value) { @@ -343,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) { diff --git a/src/PHPCensor/Store/EnvironmentStore.php b/src/PHPCensor/Store/EnvironmentStore.php index 54f48bed..c88bf0ed 100644 --- a/src/PHPCensor/Store/EnvironmentStore.php +++ b/src/PHPCensor/Store/EnvironmentStore.php @@ -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); diff --git a/src/PHPCensor/Store/ProjectGroupStore.php b/src/PHPCensor/Store/ProjectGroupStore.php index 790a9134..1580d085 100644 --- a/src/PHPCensor/Store/ProjectGroupStore.php +++ b/src/PHPCensor/Store/ProjectGroupStore.php @@ -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)) { diff --git a/src/PHPCensor/Store/ProjectStore.php b/src/PHPCensor/Store/ProjectStore.php index bc58d7f0..70330f73 100644 --- a/src/PHPCensor/Store/ProjectStore.php +++ b/src/PHPCensor/Store/ProjectStore.php @@ -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); diff --git a/src/PHPCensor/Store/UserStore.php b/src/PHPCensor/Store/UserStore.php index d8f892c9..029195dd 100644 --- a/src/PHPCensor/Store/UserStore.php +++ b/src/PHPCensor/Store/UserStore.php @@ -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()) { From 58b23fe89d508a486540d791f3ab0ca9df03bbdf Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 15 Oct 2017 20:05:33 +0700 Subject: [PATCH 4/9] Removed useless code from models + code style fixes. --- ...2_added_language_and_per_page_for_user.php | 16 ++- .../20170321131931_add_environment.php | 24 +++- ...142131_added_tag_column_to_build_table.php | 8 +- ...20170828142020_added_remember_me_login.php | 8 +- ...170913141438_added_default_branch_only.php | 16 ++- src/PHPCensor/Model/Build.php | 106 ---------------- src/PHPCensor/Model/BuildError.php | 76 ----------- src/PHPCensor/Model/BuildMeta.php | 62 ++------- src/PHPCensor/Model/Environment.php | 76 ++--------- src/PHPCensor/Model/Project.php | 120 ++---------------- src/PHPCensor/Model/ProjectGroup.php | 38 +----- src/PHPCensor/Model/User.php | 78 ------------ 12 files changed, 85 insertions(+), 543 deletions(-) diff --git a/src/PHPCensor/Migrations/20170103163312_added_language_and_per_page_for_user.php b/src/PHPCensor/Migrations/20170103163312_added_language_and_per_page_for_user.php index b6352b19..befc77fd 100644 --- a/src/PHPCensor/Migrations/20170103163312_added_language_and_per_page_for_user.php +++ b/src/PHPCensor/Migrations/20170103163312_added_language_and_per_page_for_user.php @@ -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(); } } } diff --git a/src/PHPCensor/Migrations/20170321131931_add_environment.php b/src/PHPCensor/Migrations/20170321131931_add_environment.php index 890ac635..5d2b860d 100644 --- a/src/PHPCensor/Migrations/20170321131931_add_environment.php +++ b/src/PHPCensor/Migrations/20170321131931_add_environment.php @@ -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(); } } } diff --git a/src/PHPCensor/Migrations/20170420142131_added_tag_column_to_build_table.php b/src/PHPCensor/Migrations/20170420142131_added_tag_column_to_build_table.php index cc5f80e5..39b752ad 100644 --- a/src/PHPCensor/Migrations/20170420142131_added_tag_column_to_build_table.php +++ b/src/PHPCensor/Migrations/20170420142131_added_tag_column_to_build_table.php @@ -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(); } } } diff --git a/src/PHPCensor/Migrations/20170828142020_added_remember_me_login.php b/src/PHPCensor/Migrations/20170828142020_added_remember_me_login.php index 0dc4e075..da88adc7 100644 --- a/src/PHPCensor/Migrations/20170828142020_added_remember_me_login.php +++ b/src/PHPCensor/Migrations/20170828142020_added_remember_me_login.php @@ -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(); } } } diff --git a/src/PHPCensor/Migrations/20170913141438_added_default_branch_only.php b/src/PHPCensor/Migrations/20170913141438_added_default_branch_only.php index 64352cee..af125714 100644 --- a/src/PHPCensor/Migrations/20170913141438_added_default_branch_only.php +++ b/src/PHPCensor/Migrations/20170913141438_added_default_branch_only.php @@ -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(); } } } diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index ade8e1cc..4c62d4c3 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -118,112 +118,6 @@ class Build extends Model 'Project' => 'setProject', ]; - /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'project_id' => [ - 'type' => 'int', - 'length' => 11, - 'default' => null, - ], - 'commit_id' => [ - 'type' => 'varchar', - 'length' => 50, - 'default' => null, - ], - 'status' => [ - 'type' => 'int', - 'length' => 11, - 'default' => null, - ], - 'log' => [ - 'type' => 'mediumtext', - 'nullable' => true, - 'default' => null, - ], - 'branch' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => 'master', - ], - 'tag' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'created' => [ - 'type' => 'datetime', - 'nullable' => true, - 'default' => null, - ], - 'started' => [ - 'type' => 'datetime', - 'nullable' => true, - 'default' => null, - ], - 'finished' => [ - 'type' => 'datetime', - 'nullable' => true, - 'default' => null, - ], - 'committer_email' => [ - 'type' => 'varchar', - 'length' => 512, - 'nullable' => true, - 'default' => null, - ], - 'commit_message' => [ - 'type' => 'text', - 'nullable' => true, - 'default' => null, - ], - 'extra' => [ - 'type' => 'text', - 'nullable' => true, - 'default' => null, - ], - 'environment' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'source' => [ - 'type' => 'int', - 'length' => 11, - 'default' => Build::SOURCE_UNKNOWN, - ], - ]; - - /** - * @var array - */ - public $indexes = [ - 'PRIMARY' => ['unique' => true, 'columns' => 'id'], - 'project_id' => ['columns' => 'project_id'], - 'idx_status' => ['columns' => 'status'], - ]; - - /** - * @var array - */ - public $foreignKeys = [ - 'build_ibfk_1' => [ - 'local_col' => 'project_id', - 'update' => 'CASCADE', - 'delete' => 'CASCADE', - 'table' => 'project', - 'col' => 'id' - ], - ]; - /** * Get the value of Id / id. * diff --git a/src/PHPCensor/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index 7a1f70a6..135aeecc 100644 --- a/src/PHPCensor/Model/BuildError.php +++ b/src/PHPCensor/Model/BuildError.php @@ -75,82 +75,6 @@ class BuildError extends Model '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. * diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index 14e8e035..7ef1475e 100644 --- a/src/PHPCensor/Model/BuildMeta.php +++ b/src/PHPCensor/Model/BuildMeta.php @@ -41,8 +41,9 @@ class BuildMeta extends Model 'build_id' => 'getBuildId', 'meta_key' => 'getMetaKey', 'meta_value' => 'getMetaValue', + // Foreign key getters: - 'Build' => 'getBuild', + 'Build' => 'getBuild', ]; /** @@ -54,56 +55,9 @@ class BuildMeta extends Model 'build_id' => 'setBuildId', 'meta_key' => 'setMetaKey', 'meta_value' => 'setMetaValue', + // Foreign key setters: - 'Build' => 'setBuild', - ]; - - /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 10, - 'primary_key' => true, - 'auto_increment' => true, - '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'], - ]; - - /** - * @var array - */ - public $foreignKeys = [ - 'fk_meta_build_id' => [ - 'local_col' => 'build_id', - 'update' => 'CASCADE', - 'delete' => 'CASCADE', - 'table' => 'build', - 'col' => 'id' - ], + 'Build' => 'setBuild', ]; /** @@ -113,7 +67,7 @@ class BuildMeta extends Model */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } @@ -125,7 +79,7 @@ class BuildMeta extends Model */ public function getBuildId() { - $rtn = $this->data['build_id']; + $rtn = $this->data['build_id']; return $rtn; } @@ -137,7 +91,7 @@ class BuildMeta extends Model */ public function getMetaKey() { - $rtn = $this->data['meta_key']; + $rtn = $this->data['meta_key']; return $rtn; } @@ -149,7 +103,7 @@ class BuildMeta extends Model */ public function getMetaValue() { - $rtn = $this->data['meta_value']; + $rtn = $this->data['meta_value']; return $rtn; } diff --git a/src/PHPCensor/Model/Environment.php b/src/PHPCensor/Model/Environment.php index 4645010c..ece87a98 100644 --- a/src/PHPCensor/Model/Environment.php +++ b/src/PHPCensor/Model/Environment.php @@ -25,82 +25,30 @@ 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: - ]; - - /** - * @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' - ], + 'id' => 'setId', + 'project_id' => 'setProjectId', + 'name' => 'setName', + 'branches' => 'setBranches', ]; /** @@ -110,7 +58,7 @@ class Environment extends Model */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } @@ -134,7 +82,7 @@ class Environment extends Model */ public function getName() { - $rtn = $this->data['name']; + $rtn = $this->data['name']; return $rtn; } diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 406df493..9276d0ee 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -68,8 +68,9 @@ class Project extends Model 'allow_public_status' => 'getAllowPublicStatus', 'archived' => 'getArchived', 'group_id' => 'getGroupId', + // Foreign key getters: - 'Group' => 'getGroup', + 'Group' => 'getGroup', ]; /** @@ -91,108 +92,9 @@ class Project extends Model 'allow_public_status' => 'setAllowPublicStatus', 'archived' => 'setArchived', 'group_id' => 'setGroupId', + // Foreign key setters: - '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' - ], + 'Group' => 'setGroup', ]; /** @@ -202,7 +104,7 @@ class Project extends Model */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } @@ -214,7 +116,7 @@ class Project extends Model */ public function getTitle() { - $rtn = $this->data['title']; + $rtn = $this->data['title']; return $rtn; } @@ -226,7 +128,7 @@ class Project extends Model */ public function getReference() { - $rtn = $this->data['reference']; + $rtn = $this->data['reference']; return $rtn; } @@ -238,7 +140,7 @@ class Project extends Model */ public function getSshPrivateKey() { - $rtn = $this->data['ssh_private_key']; + $rtn = $this->data['ssh_private_key']; return $rtn; } @@ -250,7 +152,7 @@ class Project extends Model */ public function getType() { - $rtn = $this->data['type']; + $rtn = $this->data['type']; return $rtn; } @@ -262,7 +164,7 @@ class Project extends Model */ public function getLastCommit() { - $rtn = $this->data['last_commit']; + $rtn = $this->data['last_commit']; return $rtn; } @@ -286,7 +188,7 @@ class Project extends Model */ public function getSshPublicKey() { - $rtn = $this->data['ssh_public_key']; + $rtn = $this->data['ssh_public_key']; return $rtn; } diff --git a/src/PHPCensor/Model/ProjectGroup.php b/src/PHPCensor/Model/ProjectGroup.php index 3d5adf16..904f1e81 100644 --- a/src/PHPCensor/Model/ProjectGroup.php +++ b/src/PHPCensor/Model/ProjectGroup.php @@ -34,52 +34,18 @@ class ProjectGroup extends Model * @var array */ protected $getters = [ - // Direct property getters: 'id' => 'getId', 'title' => 'getTitle', - // Foreign key getters: ]; /** * @var array */ protected $setters = [ - // Direct property setters: 'id' => 'setId', 'title' => 'setTitle', - // Foreign key setters: ]; - /** - * @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. * @@ -87,7 +53,7 @@ class ProjectGroup extends Model */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } @@ -99,7 +65,7 @@ class ProjectGroup extends Model */ public function getTitle() { - $rtn = $this->data['title']; + $rtn = $this->data['title']; return $rtn; } diff --git a/src/PHPCensor/Model/User.php b/src/PHPCensor/Model/User.php index 204d81fd..fc466743 100644 --- a/src/PHPCensor/Model/User.php +++ b/src/PHPCensor/Model/User.php @@ -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,83 +71,8 @@ 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. * From 4ec6d854c2f71a908110918806029ea1384aa304 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 15 Oct 2017 21:58:36 +0700 Subject: [PATCH 5/9] Added 'user_id' column to 'build' table (created by) + Renamed columns 'created' -> 'create_date', 'started' -> 'start_date' and 'finished' -> 'finish_date' + Code style fixes. --- public/assets/js/build.js | 4 +- src/B8Framework/Model.php | 18 +- src/PHPCensor/Builder.php | 4 +- src/PHPCensor/Command/RunCommand.php | 6 +- .../Command/ScheduleBuildCommand.php | 2 +- src/PHPCensor/Controller/BuildController.php | 18 +- .../Controller/ProjectController.php | 6 +- .../Controller/WebhookController.php | 2 + ...0171015123827_added_additional_columns.php | 68 ++ src/PHPCensor/Model/Build.php | 847 +++++++++--------- src/PHPCensor/Model/BuildError.php | 86 +- src/PHPCensor/Model/BuildMeta.php | 46 +- src/PHPCensor/Model/Environment.php | 34 +- src/PHPCensor/Model/Project.php | 129 +-- src/PHPCensor/Model/ProjectGroup.php | 20 +- src/PHPCensor/Model/User.php | 76 +- src/PHPCensor/Service/BuildService.php | 7 +- src/PHPCensor/Service/BuildStatusService.php | 2 +- src/PHPCensor/View/Build/header-row.phtml | 15 +- src/PHPCensor/View/Build/view.phtml | 19 +- src/PHPCensor/View/BuildStatus/view.phtml | 2 +- .../View/Home/ajax-dashboard-project.phtml | 18 +- src/PHPCensor/View/Home/ajax-timeline.phtml | 14 +- .../View/Home/dashboard-projects.phtml | 18 +- src/PHPCensor/View/Home/index.phtml | 14 +- src/PHPCensor/View/Project/ajax-builds.phtml | 2 +- src/PHPCensor/Worker/BuildWorker.php | 2 +- tests/PHPCensor/Service/BuildServiceTest.php | 16 +- .../Service/BuiltStatusServiceTest.php | 4 +- 29 files changed, 694 insertions(+), 805 deletions(-) create mode 100644 src/PHPCensor/Migrations/20171015123827_added_additional_columns.php diff --git a/public/assets/js/build.js b/public/assets/js/build.js index bfe55494..9229a512 100644 --- a/public/assets/js/build.js +++ b/public/assets/js/build.js @@ -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); diff --git a/src/B8Framework/Model.php b/src/B8Framework/Model.php index d7eb3497..929a8ed3 100644 --- a/src/B8Framework/Model.php +++ b/src/B8Framework/Model.php @@ -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.'); } } diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index 37e8496e..09fe5233 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -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) { diff --git a/src/PHPCensor/Command/RunCommand.php b/src/PHPCensor/Command/RunCommand.php index 1ae13d51..2ff7f563 100644 --- a/src/PHPCensor/Command/RunCommand.php +++ b/src/PHPCensor/Command/RunCommand.php @@ -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; diff --git a/src/PHPCensor/Command/ScheduleBuildCommand.php b/src/PHPCensor/Command/ScheduleBuildCommand.php index 1f76df63..57c02f9f 100644 --- a/src/PHPCensor/Command/ScheduleBuildCommand.php +++ b/src/PHPCensor/Command/ScheduleBuildCommand.php @@ -83,7 +83,7 @@ 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; } diff --git a/src/PHPCensor/Controller/BuildController.php b/src/PHPCensor/Controller/BuildController.php index 297aa138..d8435d17 100644 --- a/src/PHPCensor/Controller/BuildController.php +++ b/src/PHPCensor/Controller/BuildController.php @@ -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()); diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index e78317b1..96299a42 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -173,16 +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, '', $branch, null, - $email, + $user->getEmail(), null, Build::SOURCE_MANUAL_WEB, + $user->getId(), $extra ); diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index 4e040bbf..afa43337 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -666,6 +666,7 @@ class WebhookController extends Controller $committer, $commitMessage, Build::SOURCE_WEBHOOK, + 0, $extra ); @@ -704,6 +705,7 @@ class WebhookController extends Controller $committer, $commitMessage, Build::SOURCE_WEBHOOK, + 0, $extra ); diff --git a/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php b/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php new file mode 100644 index 00000000..8cf3454b --- /dev/null +++ b/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php @@ -0,0 +1,68 @@ +table('build'); + + if (!$table->hasColumn('user_id')) { + $table + ->addColumn('user_id', 'integer', ['default' => 0]) + ->save(); + } + + $table = $this->table('build'); + + 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(); + } + + $table = $this->table('build'); + + 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(); + } + } +} diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index 4c62d4c3..f2aadc90 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -21,10 +21,10 @@ class Build extends Model const STAGE_FIXED = 'fixed'; const STAGE_BROKEN = 'broken'; - const STATUS_PENDING = 0; - const STATUS_RUNNING = 1; - const STATUS_SUCCESS = 2; - const STATUS_FAILED = 3; + const STATUS_PENDING = 0; + const STATUS_RUNNING = 1; + const STATUS_SUCCESS = 2; + const STATUS_FAILED = 3; const SOURCE_UNKNOWN = 0; const SOURCE_MANUAL_WEB = 1; @@ -58,14 +58,15 @@ class Build extends Model 'log' => null, 'branch' => null, 'tag' => null, - 'created' => null, - 'started' => null, - 'finished' => null, + 'create_date' => null, + 'start_date' => null, + 'finish_date' => null, 'committer_email' => null, 'commit_message' => null, 'extra' => null, 'environment' => null, 'source' => Build::SOURCE_UNKNOWN, + 'user_id' => 0, ]; /** @@ -80,14 +81,15 @@ class Build extends Model 'log' => 'getLog', 'branch' => 'getBranch', 'tag' => 'getTag', - 'created' => 'getCreated', - 'started' => 'getStarted', - 'finished' => 'getFinished', + 'create_date' => 'getCreateDate', + 'start_date' => 'getStartDate', + 'finish_date' => 'getFinishDate', 'committer_email' => 'getCommitterEmail', 'commit_message' => 'getCommitMessage', 'extra' => 'getExtra', 'environment' => 'getEnvironment', 'source' => 'getSource', + 'user_id' => 'getUserId', // Foreign key getters: 'Project' => 'getProject', @@ -105,22 +107,21 @@ class Build extends Model 'log' => 'setLog', 'branch' => 'setBranch', 'setTag' => 'setTag', - 'created' => 'setCreated', - 'started' => 'setStarted', - 'finished' => 'setFinished', + 'create_date' => 'setCreateDate', + 'start_date' => 'setStartDate', + 'finish_date' => 'setFinishDate', 'committer_email' => 'setCommitterEmail', 'commit_message' => 'setCommitMessage', 'extra' => 'setExtra', 'environment' => 'setEnvironment', 'source' => 'setSource', + 'user_id' => 'setUserId', // Foreign key setters: 'Project' => 'setProject', ]; /** - * Get the value of Id / id. - * * @return integer */ public function getId() @@ -131,134 +132,12 @@ class Build extends Model } /** - * Get the value of ProjectId / project_id. - * - * @return integer - */ - public function getProjectId() - { - $rtn = $this->data['project_id']; - - return (integer)$rtn; - } - - /** - * Get the value of CommitId / commit_id. - * - * @return string - */ - public function getCommitId() - { - $rtn = $this->data['commit_id']; - - return $rtn; - } - - /** - * Get the value of Status / status. - * - * @return integer - */ - public function getStatus() - { - $rtn = $this->data['status']; - - return (integer)$rtn; - } - - /** - * Get the value of Log / log. - * - * @return string - */ - public function getLog() - { - $rtn = $this->data['log']; - - return $rtn; - } - - /** - * Get the value of Branch / branch. - * - * @return string - */ - public function getBranch() - { - $rtn = $this->data['branch']; - - return $rtn; - } - - /** - * Get the value of Created / created. - * - * @return \DateTime - */ - public function getCreated() - { - $rtn = $this->data['created']; - - if (!empty($rtn)) { - $rtn = new \DateTime($rtn); - } - - return $rtn; - } - - /** - * Get the value of Started / started. - * - * @return \DateTime - */ - public function getStarted() - { - $rtn = $this->data['started']; - - if (!empty($rtn)) { - $rtn = new \DateTime($rtn); - } - - return $rtn; - } - - /** - * Get the value of Finished / finished. - * - * @return \DateTime - */ - public function getFinished() - { - $rtn = $this->data['finished']; - - if (!empty($rtn)) { - $rtn = new \DateTime($rtn); - } - - return $rtn; - } - - /** - * Get the value of CommitterEmail / committer_email. - * - * @return string - */ - public function getCommitterEmail() - { - $rtn = $this->data['committer_email']; - - 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; @@ -270,14 +149,22 @@ class Build extends Model } /** - * Set the value of ProjectId / project_id. Must not be null. - * + * @return integer + */ + public function getProjectId() + { + $rtn = $this->data['project_id']; + + return (integer)$rtn; + } + + /** * @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; @@ -289,14 +176,22 @@ class Build extends Model } /** - * Set the value of CommitId / commit_id. Must not be null. - * + * @return string + */ + public function getCommitId() + { + $rtn = $this->data['commit_id']; + + return $rtn; + } + + /** * @param $value string */ public function setCommitId($value) { - $this->validateNotNull('CommitId', $value); - $this->validateString('CommitId', $value); + $this->validateNotNull('commit_id', $value); + $this->validateString('commit_id', $value); if ($this->data['commit_id'] === $value) { return; @@ -308,14 +203,22 @@ class Build extends Model } /** - * Set the value of Status / status. Must not be null. - * + * @return integer + */ + public function getStatus() + { + $rtn = $this->data['status']; + + return (integer)$rtn; + } + + /** * @param $value int */ public function setStatus($value) { - $this->validateNotNull('Status', $value); - $this->validateInt('Status', $value); + $this->validateNotNull('status', $value); + $this->validateInt('status', $value); if ($this->data['status'] === $value) { return; @@ -327,15 +230,315 @@ class Build extends Model } /** - * Set the value of Status / status only if it synced with db. Must not be null. + * @return string + */ + public function getLog() + { + $rtn = $this->data['log']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setLog($value) + { + $this->validateString('log', $value); + + if ($this->data['log'] === $value) { + return; + } + + $this->data['log'] = $value; + + $this->setModified('log'); + } + + /** + * @return string + */ + public function getBranch() + { + $rtn = $this->data['branch']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setBranch($value) + { + $this->validateNotNull('branch', $value); + $this->validateString('branch', $value); + + if ($this->data['branch'] === $value) { + return; + } + + $this->data['branch'] = $value; + + $this->setModified('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 \DateTime + */ + public function getStartDate() + { + $rtn = $this->data['start_date']; + + if (!empty($rtn)) { + $rtn = new \DateTime($rtn); + } + + return $rtn; + } + + /** + * @param $value \DateTime + */ + public function setStartDate($value) + { + $this->validateDate('start_date', $value); + + if ($this->data['start_date'] === $value) { + return; + } + + $this->data['start_date'] = $value; + + $this->setModified('start_date'); + } + + /** + * @return \DateTime + */ + public function getFinishDate() + { + $rtn = $this->data['finish_date']; + + if (!empty($rtn)) { + $rtn = new \DateTime($rtn); + } + + return $rtn; + } + + /** + * @param $value \DateTime + */ + public function setFinishDate($value) + { + $this->validateDate('finish_date', $value); + + if ($this->data['finish_date'] === $value) { + return; + } + + $this->data['finish_date'] = $value; + + $this->setModified('finish_date'); + } + + /** + * @return string + */ + public function getCommitterEmail() + { + $rtn = $this->data['committer_email']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setCommitterEmail($value) + { + $this->validateString('committer_email', $value); + + if ($this->data['committer_email'] === $value) { + return; + } + + $this->data['committer_email'] = $value; + + $this->setModified('committer_email'); + } + + /** + * @return string + */ + public function getCommitMessage() + { + $rtn = htmlspecialchars($this->data['commit_message']); + + return $rtn; + } + + /** + * @param $value string + */ + public function setCommitMessage($value) + { + $this->validateString('commit_message', $value); + + if ($this->data['commit_message'] === $value) { + return; + } + + $this->data['commit_message'] = $value; + + $this->setModified('commit_message'); + } + + /** + * @return string + */ + public function getTag() + { + $rtn = $this->data['tag']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setTag($value) + { + $this->validateString('tag', $value); + + if ($this->data['tag'] === $value) { + return; + } + + $this->data['tag'] = $value; + + $this->setModified('tag'); + } + + /** + * @return string + */ + public function getSource() + { + $rtn = $this->data['source']; + + return (integer)$rtn; + } + + /** + * @param $value integer + */ + public function setSource($value) + { + $this->validateInt('source', $value); + + if ($this->data['source'] === $value) { + return; + } + + $this->data['source'] = $value; + + $this->setModified('source'); + } + + /** + * @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'); + } + + /** + * @return string + */ + public function getEnvironment() + { + $rtn = $this->data['environment']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setEnvironment($value) + { + $this->validateString('environment', $value); + + if ($this->data['environment'] === $value) { + return; + } + + $this->data['environment'] = $value; + + $this->setModified('environment'); + } + + /** + * Set the value of status only if it synced with db. Must not be null. * * @param $value int * @return bool */ public function setStatusSync($value) { - $this->validateNotNull('Status', $value); - $this->validateInt('Status', $value); + $this->validateNotNull('status', $value); + $this->validateInt('status', $value); if ($this->data['status'] !== $value) { $store = Factory::getStore('Build'); @@ -347,185 +550,11 @@ class Build extends Model return false; } - /** - * Set the value of Log / log. - * - * @param $value string - */ - public function setLog($value) - { - $this->validateString('Log', $value); - - if ($this->data['log'] === $value) { - return; - } - - $this->data['log'] = $value; - - $this->setModified('log'); - } - - /** - * 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); - - if ($this->data['branch'] === $value) { - return; - } - - $this->data['branch'] = $value; - - $this->setModified('branch'); - } - - /** - * Set the value of Created / created. - * - * @param $value \DateTime - */ - public function setCreated($value) - { - $this->validateDate('Created', $value); - - if ($this->data['created'] === $value) { - return; - } - - $this->data['created'] = $value; - - $this->setModified('created'); - } - - /** - * Set the value of Started / started. - * - * @param $value \DateTime - */ - public function setStarted($value) - { - $this->validateDate('Started', $value); - - if ($this->data['started'] === $value) { - return; - } - - $this->data['started'] = $value; - - $this->setModified('started'); - } - - /** - * Set the value of Finished / finished. - * - * @param $value \DateTime - */ - public function setFinished($value) - { - $this->validateDate('Finished', $value); - - if ($this->data['finished'] === $value) { - return; - } - - $this->data['finished'] = $value; - - $this->setModified('finished'); - } - - /** - * Set the value of CommitterEmail / committer_email. - * - * @param $value string - */ - public function setCommitterEmail($value) - { - $this->validateString('CommitterEmail', $value); - - if ($this->data['committer_email'] === $value) { - return; - } - - $this->data['committer_email'] = $value; - - $this->setModified('committer_email'); - } - - /** - * Set the value of CommitMessage / commit_message. - * - * @param $value string - */ - public function setCommitMessage($value) - { - $this->validateString('CommitMessage', $value); - - if ($this->data['commit_message'] === $value) { - return; - } - - $this->data['commit_message'] = $value; - - $this->setModified('commit_message'); - } - - /** - * Set the value of Extra / extra. - * - * @param $value string - */ - public function setExtra($value) - { - $this->validateString('Extra', $value); - - if ($this->data['extra'] === $value) { - return; - } - - $this->data['extra'] = $value; - - $this->setModified('extra'); - } - - /** - * Set the value of Extra / extra. - * - * @param $name string - * @param $value mixed - */ - public function setExtraValue($name, $value) - { - $extra = json_decode($this->data['extra'], true); - if ($extra === false) { - $extra = []; - } - $extra[$name] = $value; - $this->setExtra(json_encode($extra)); - } - - /** - * Set the values of Extra / extra. - * - * @param $values mixed - */ - public function setExtraValues($values) - { - $extra = json_decode($this->data['extra'], true); - if ($extra === false) { - $extra = []; - } - $extra = array_replace($extra, $values); - $this->setExtra(json_encode($extra)); - } - /** * Return a value from the build's "extra" JSON array. + * * @param null $key + * * @return mixed|null|string */ public function getExtra($key = null) @@ -543,6 +572,53 @@ class Build extends Model return $rtn; } + /** + * @param $value string + */ + public function setExtra($value) + { + $this->validateString('extra', $value); + + if ($this->data['extra'] === $value) { + return; + } + + $this->data['extra'] = $value; + + $this->setModified('extra'); + } + + /** + * Set the value of extra. + * + * @param $name string + * @param $value mixed + */ + public function setExtraValue($name, $value) + { + $extra = json_decode($this->data['extra'], true); + if ($extra === false) { + $extra = []; + } + $extra[$name] = $value; + $this->setExtra(json_encode($extra)); + } + + /** + * Set the values of extra. + * + * @param $values mixed + */ + public function setExtraValues($values) + { + $extra = json_decode($this->data['extra'], true); + if ($extra === false) { + $extra = []; + } + $extra = array_replace($extra, $values); + $this->setExtra(json_encode($extra)); + } + /** * Get the Project model for this Build by Id. * @@ -764,17 +840,6 @@ class Build extends Model return $config; } - /** - * Returns the commit message for this build. - * @return string - */ - public function getCommitMessage() - { - $rtn = htmlspecialchars($this->data['commit_message']); - - return $rtn; - } - /** * Allows specific build types (e.g. Github) to report violations back to their respective services. * @param Builder $builder @@ -852,17 +917,18 @@ class Build extends Model /** * Get the number of seconds a build has been running for. + * * @return int */ public function getDuration() { - $start = $this->getStarted(); + $start = $this->getStartDate(); if (empty($start)) { return 0; } - $end = $this->getFinished(); + $end = $this->getFinishDate(); if (empty($end)) { $end = new \DateTime(); @@ -873,15 +939,16 @@ class Build extends Model /** * get time a build has been running for in hour/minute/seconds format (e.g. 1h 21m 45s) + * * @return string */ public function getPrettyDuration() { - $start = $this->getStarted(); + $start = $this->getStartDate(); if (!$start) { $start = new \DateTime(); } - $end = $this->getFinished(); + $end = $this->getFinishDate(); if (!$end) { $end = new \DateTime(); } @@ -910,96 +977,6 @@ class Build extends Model return false; } - /** - * Get the value of Tag / tag. - * - * @return string - */ - public function getTag() - { - $rtn = $this->data['tag']; - - return $rtn; - } - - /** - * Set the value of Tag / tag. - * - * @param $value string - */ - public function setTag($value) - { - $this->validateString('Tag', $value); - - if ($this->data['tag'] === $value) { - return; - } - - $this->data['tag'] = $value; - - $this->setModified('tag'); - } - - /** - * Get the value of source. - * - * @return string - */ - public function getSource() - { - $rtn = $this->data['source']; - - return (integer)$rtn; - } - - /** - * Set the value of source. - * - * @param $value integer - */ - public function setSource($value) - { - $this->validateInt('Source', $value); - - if ($this->data['source'] === $value) { - return; - } - - $this->data['source'] = $value; - - $this->setModified('source'); - } - - /** - * Get the value of Environment / environment. - * - * @return string - */ - public function getEnvironment() - { - $rtn = $this->data['environment']; - - return $rtn; - } - - /** - * Set the value of Environment / environment. - * - * @param $value string - */ - public function setEnvironment($value) - { - $this->validateString('Environment', $value); - - if ($this->data['environment'] === $value) { - return; - } - - $this->data['environment'] = $value; - - $this->setModified('environment'); - } - /** * Create an SSH key file on disk for this build. * diff --git a/src/PHPCensor/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index 135aeecc..a24ca754 100644 --- a/src/PHPCensor/Model/BuildError.php +++ b/src/PHPCensor/Model/BuildError.php @@ -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 */ @@ -76,8 +81,6 @@ class BuildError extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -88,8 +91,6 @@ class BuildError extends Model } /** - * Get the value of BuildId / build_id. - * * @return int */ public function getBuildId() @@ -100,8 +101,6 @@ class BuildError extends Model } /** - * Get the value of Plugin / plugin. - * * @return string */ public function getPlugin() @@ -112,8 +111,6 @@ class BuildError extends Model } /** - * Get the value of File / file. - * * @return string */ public function getFile() @@ -124,8 +121,6 @@ class BuildError extends Model } /** - * Get the value of LineStart / line_start. - * * @return int */ public function getLineStart() @@ -136,8 +131,6 @@ class BuildError extends Model } /** - * Get the value of LineEnd / line_end. - * * @return int */ public function getLineEnd() @@ -148,8 +141,6 @@ class BuildError extends Model } /** - * Get the value of Severity / severity. - * * @return int */ public function getSeverity() @@ -160,8 +151,6 @@ class BuildError extends Model } /** - * Get the value of Message / message. - * * @return string */ public function getMessage() @@ -172,8 +161,6 @@ class BuildError extends Model } /** - * Get the value of CreatedDate / created_date. - * * @return \DateTime */ public function getCreatedDate() @@ -188,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; @@ -208,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; @@ -228,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; @@ -248,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; @@ -266,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; @@ -284,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; @@ -302,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; @@ -322,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; @@ -342,15 +308,12 @@ class BuildError extends Model } /** - * Set the value of CreatedDate / created_date. - * - * Must not be null. * @param $value \DateTime */ public function setCreatedDate($value) { - $this->validateNotNull('CreatedDate', $value); - $this->validateDate('CreatedDate', $value); + $this->validateNotNull('created_date', $value); + $this->validateDate('created_date', $value); if ($this->data['created_date'] === $value) { return; @@ -364,8 +327,6 @@ class BuildError extends Model /** * 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() @@ -418,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() @@ -446,6 +403,7 @@ class BuildError extends Model /** * Get the class to apply to HTML elements representing this error. + * * @return string */ public function getSeverityClass() diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index 7ef1475e..0efa761c 100644 --- a/src/PHPCensor/Model/BuildMeta.php +++ b/src/PHPCensor/Model/BuildMeta.php @@ -61,8 +61,6 @@ class BuildMeta extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -73,8 +71,6 @@ class BuildMeta extends Model } /** - * Get the value of BuildId / build_id. - * * @return int */ public function getBuildId() @@ -85,8 +81,6 @@ class BuildMeta extends Model } /** - * Get the value of MetaKey / meta_key. - * * @return string */ public function getMetaKey() @@ -97,8 +91,6 @@ class BuildMeta extends Model } /** - * Get the value of MetaValue / meta_value. - * * @return string */ public function getMetaValue() @@ -109,15 +101,12 @@ class BuildMeta extends Model } /** - * 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; @@ -129,15 +118,12 @@ class BuildMeta extends Model } /** - * 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; @@ -149,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; @@ -169,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; @@ -191,8 +171,6 @@ class BuildMeta extends Model /** * 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() @@ -203,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); diff --git a/src/PHPCensor/Model/Environment.php b/src/PHPCensor/Model/Environment.php index ece87a98..e70da4ee 100644 --- a/src/PHPCensor/Model/Environment.php +++ b/src/PHPCensor/Model/Environment.php @@ -52,8 +52,6 @@ class Environment extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -64,8 +62,6 @@ class Environment extends Model } /** - * Get the value of Id / id. - * * @return int */ public function getProjectId() @@ -76,8 +72,6 @@ class Environment extends Model } /** - * Get the value of Title / title. - * * @return string */ public function getName() @@ -88,8 +82,6 @@ class Environment extends Model } /** - * Get the value of Title / title. - * * @return array */ public function getBranches() @@ -100,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; @@ -120,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; @@ -140,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; @@ -160,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) { diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 9276d0ee..9696e61f 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -98,8 +98,6 @@ class Project extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -110,8 +108,6 @@ class Project extends Model } /** - * Get the value of Title / title. - * * @return string */ public function getTitle() @@ -122,8 +118,6 @@ class Project extends Model } /** - * Get the value of Reference / reference. - * * @return string */ public function getReference() @@ -134,8 +128,6 @@ class Project extends Model } /** - * Get the value of SshPrivateKey / ssh_private_key. - * * @return string */ public function getSshPrivateKey() @@ -146,8 +138,6 @@ class Project extends Model } /** - * Get the value of Type / type. - * * @return string */ public function getType() @@ -158,8 +148,6 @@ class Project extends Model } /** - * Get the value of LastCommit / last_commit. - * * @return string */ public function getLastCommit() @@ -170,8 +158,6 @@ class Project extends Model } /** - * Get the value of BuildConfig / build_config. - * * @return string */ public function getBuildConfig() @@ -182,8 +168,6 @@ class Project extends Model } /** - * Get the value of SshPublicKey / ssh_public_key. - * * @return string */ public function getSshPublicKey() @@ -194,8 +178,6 @@ class Project extends Model } /** - * Get the value of AllowPublicStatus / allow_public_status. - * * @return int */ public function getAllowPublicStatus() @@ -206,8 +188,6 @@ class Project extends Model } /** - * Get the value of Archived / archived. - * * @return int */ public function getArchived() @@ -218,8 +198,6 @@ class Project extends Model } /** - * Get the value of GroupId / group_id. - * * @return int */ public function getGroupId() @@ -230,8 +208,6 @@ class Project extends Model } /** - * Get the value of DefaultBranchOnly / default_branch_only. - * * @return int */ public function getDefaultBranchOnly() @@ -242,15 +218,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; @@ -262,15 +235,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; @@ -282,15 +252,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; @@ -302,15 +269,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; @@ -322,15 +286,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; @@ -342,13 +303,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; @@ -360,15 +319,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; @@ -380,13 +336,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; @@ -398,13 +352,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; @@ -416,13 +368,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; @@ -434,15 +384,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; @@ -454,15 +401,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; @@ -474,15 +418,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; @@ -496,8 +437,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() @@ -508,11 +447,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); } @@ -553,8 +492,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() @@ -564,8 +501,10 @@ class Project extends Model /** * 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) @@ -592,7 +531,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') @@ -613,7 +554,6 @@ class Project extends Model } /** - * Store this project's access_information data * @param string|array $value */ public function setAccessInformation($value) @@ -622,7 +562,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; @@ -635,7 +575,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) @@ -661,7 +603,7 @@ class Project extends Model } /** - * Get the value of Branch / branch. + * Get the value of branch. * * @return string */ @@ -688,6 +630,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() @@ -740,7 +683,7 @@ class Project extends Model if (empty($rtn)) { $store = $this->getEnvironmentStore(); - $rtn = $store->getByProjectId($key); + $rtn = $store->getByProjectId($key); $this->cache->set($cacheKey, $rtn); } diff --git a/src/PHPCensor/Model/ProjectGroup.php b/src/PHPCensor/Model/ProjectGroup.php index 904f1e81..2457b8b5 100644 --- a/src/PHPCensor/Model/ProjectGroup.php +++ b/src/PHPCensor/Model/ProjectGroup.php @@ -47,8 +47,6 @@ class ProjectGroup extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -59,8 +57,6 @@ class ProjectGroup extends Model } /** - * Get the value of Title / title. - * * @return string */ public function getTitle() @@ -71,15 +67,12 @@ class ProjectGroup 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; @@ -91,15 +84,12 @@ class ProjectGroup 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; @@ -113,8 +103,6 @@ class ProjectGroup extends Model /** * Get Project models by GroupId for this ProjectGroup. * - * @uses \PHPCensor\Store\ProjectStore::getByGroupId() - * @uses \PHPCensor\Model\Project * @return \PHPCensor\Model\Project[] */ public function getGroupProjects() diff --git a/src/PHPCensor/Model/User.php b/src/PHPCensor/Model/User.php index fc466743..d49c7472 100644 --- a/src/PHPCensor/Model/User.php +++ b/src/PHPCensor/Model/User.php @@ -74,8 +74,6 @@ class User extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -86,8 +84,6 @@ class User extends Model } /** - * Get the value of Email / email. - * * @return string */ public function getEmail() @@ -98,8 +94,6 @@ class User extends Model } /** - * Get the value of Hash / hash. - * * @return string */ public function getHash() @@ -110,8 +104,6 @@ class User extends Model } /** - * Get the value of Name / name. - * * @return string */ public function getName() @@ -122,8 +114,6 @@ class User extends Model } /** - * Get the value of IsAdmin / is_admin. - * * @return int */ public function getIsAdmin() @@ -134,8 +124,6 @@ class User extends Model } /** - * Get the value of ProviderKey / provider_key. - * * @return string */ public function getProviderKey() @@ -146,8 +134,6 @@ class User extends Model } /** - * Get the value of ProviderData / provider_data. - * * @return string */ public function getProviderData() @@ -158,8 +144,6 @@ class User extends Model } /** - * Get the value of RememberKey / remember_key. - * * @return string */ public function getRememberKey() @@ -170,8 +154,6 @@ class User extends Model } /** - * Get the value of Language / language. - * * @return string */ public function getLanguage() @@ -182,8 +164,6 @@ class User extends Model } /** - * Get the value of PerPage / per_page. - * * @return string */ public function getPerPage() @@ -194,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; @@ -214,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; @@ -234,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; @@ -254,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; @@ -274,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; @@ -294,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; @@ -314,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; @@ -332,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; @@ -350,9 +308,6 @@ class User extends Model } /** - * Set the value of Language / language. - * - * Must not be null. * @param $value string */ public function setLanguage($value) @@ -367,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) diff --git a/src/PHPCensor/Service/BuildService.php b/src/PHPCensor/Service/BuildService.php index af2e3284..1922540f 100644 --- a/src/PHPCensor/Service/BuildService.php +++ b/src/PHPCensor/Service/BuildService.php @@ -42,6 +42,7 @@ class BuildService * @param string|null $committerEmail * @param string|null $commitMessage * @param integer $source + * @param integer $userId * @param string|null $extra * * @return \PHPCensor\Model\Build @@ -55,10 +56,11 @@ class BuildService $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); @@ -67,6 +69,7 @@ class BuildService $build->setExtraValue('branches', $branches); $build->setSource($source); + $build->setUserId($userId); $build->setCommitId((string)$commitId); if (!empty($branch)) { @@ -121,7 +124,7 @@ class BuildService $build = new Build(); $build->setValues($data); - $build->setCreated(new \DateTime()); + $build->setCreateDate(new \DateTime()); $build->setStatus(Build::STATUS_PENDING); /** @var Build $build */ diff --git a/src/PHPCensor/Service/BuildStatusService.php b/src/PHPCensor/Service/BuildStatusService.php index 8a323d18..d3a53d6e 100644 --- a/src/PHPCensor/Service/BuildStatusService.php +++ b/src/PHPCensor/Service/BuildStatusService.php @@ -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 ''; } diff --git a/src/PHPCensor/View/Build/header-row.phtml b/src/PHPCensor/View/Build/header-row.phtml index 7bb8f4d0..b2038c4d 100644 --- a/src/PHPCensor/View/Build/header-row.phtml +++ b/src/PHPCensor/View/Build/header-row.phtml @@ -1,4 +1,13 @@ - +
  • getCommitterEmail()): ?> @@ -11,9 +20,9 @@ getProject()->getTitle(); ?> getStatus() == \PHPCensor\Model\Build::STATUS_PENDING): ?> - getCreated()->format('H:i')); ?> + getCreateDate()->format('H:i')); ?> getStatus() == \PHPCensor\Model\Build::STATUS_RUNNING): ?> - getStarted()->format('H:i')); ?> + getStartDate()->format('H:i')); ?>

    getBranch()); ?>

    diff --git a/src/PHPCensor/View/Build/view.phtml b/src/PHPCensor/View/Build/view.phtml index 7bba273b..8288fd5a 100644 --- a/src/PHPCensor/View/Build/view.phtml +++ b/src/PHPCensor/View/Build/view.phtml @@ -1,4 +1,13 @@ - +
    @@ -124,28 +133,28 @@
  • + getSourceHumanize()); ?> +
    - + getCommitId(), 0, 7); ?> getCreated()->format('Y-m-d H:i:s'); ?> getCommitId() !== 'Manual') { + if (!empty($build->getCommitId())) { print sprintf( - '%s (%s)', + '%s %s', $build->getCommitLink(), substr($build->getCommitId(), 0, 7), - $build->getCommitterEmail() + $build->getCommitterEmail() ? ('(' . $build->getCommitterEmail() . ')') : '' ); } else { - print 'Manual'; + print '—'; } ?>
    #getId(), 6, '0', STR_PAD_LEFT); ?>getCreated()->format('Y-m-d H:i:s'); ?>#getId(), 6, '0', STR_PAD_LEFT); ?>getCreated()->format('Y-m-d H:i:s'); ?>getSourceHumanize()); ?>
    - getCreated() ? $build->getCreated()->format('Y-m-d H:i:s') : ''; ?> + getCreateDate() ? $build->getCreateDate()->format('Y-m-d H:i:s') : ''); ?>
    - getStarted() ? $build->getStarted()->format('Y-m-d H:i:s') : ''; ?> + getStartDate() ? $build->getStartDate()->format('Y-m-d H:i:s') : ''); ?>
    - getFinished() ? $build->getFinished()->format('Y-m-d H:i:s') : ''; ?> + getFinishDate() ? $build->getFinishDate()->format('Y-m-d H:i:s') : ''); ?>
    - getDuration(); ?> + getDuration(); ?>
    diff --git a/src/PHPCensor/View/BuildStatus/view.phtml b/src/PHPCensor/View/BuildStatus/view.phtml index 7a30b624..856f7dad 100644 --- a/src/PHPCensor/View/BuildStatus/view.phtml +++ b/src/PHPCensor/View/BuildStatus/view.phtml @@ -142,7 +142,7 @@ - getCreated()->format('Y-m-d H:i:s'); ?> + getCreateDate()->format('Y-m-d H:i:s'); ?> getCommitId())) { diff --git a/src/PHPCensor/View/Home/ajax-dashboard-project.phtml b/src/PHPCensor/View/Home/ajax-dashboard-project.phtml index 3daec637..1f00e379 100644 --- a/src/PHPCensor/View/Home/ajax-dashboard-project.phtml +++ b/src/PHPCensor/View/Home/ajax-dashboard-project.phtml @@ -1,5 +1,11 @@ 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'); } diff --git a/src/PHPCensor/View/Home/ajax-timeline.phtml b/src/PHPCensor/View/Home/ajax-timeline.phtml index 4071721a..b9037810 100644 --- a/src/PHPCensor/View/Home/ajax-timeline.phtml +++ b/src/PHPCensor/View/Home/ajax-timeline.phtml @@ -3,6 +3,10 @@ use PHPCensor\Helper\Lang; use PHPCensor\Model\Build; +/** + * @var Build[] $builds + */ + ?>
      @@ -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; diff --git a/src/PHPCensor/View/Home/dashboard-projects.phtml b/src/PHPCensor/View/Home/dashboard-projects.phtml index b884c679..1b046bac 100644 --- a/src/PHPCensor/View/Home/dashboard-projects.phtml +++ b/src/PHPCensor/View/Home/dashboard-projects.phtml @@ -1,5 +1,11 @@ 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'); } diff --git a/src/PHPCensor/View/Home/index.phtml b/src/PHPCensor/View/Home/index.phtml index d55301c3..873bc86b 100644 --- a/src/PHPCensor/View/Home/index.phtml +++ b/src/PHPCensor/View/Home/index.phtml @@ -3,6 +3,10 @@ use PHPCensor\Helper\Lang; use PHPCensor\Model\Build; +/** + * @var Build[] $builds + */ + ?>