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/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/InstallCommand.php b/src/PHPCensor/Command/InstallCommand.php index 65506819..b7e631fa 100644 --- a/src/PHPCensor/Command/InstallCommand.php +++ b/src/PHPCensor/Command/InstallCommand.php @@ -526,6 +526,8 @@ class InstallCommand extends Command $group = new ProjectGroup(); $group->setTitle('Projects'); + $group->setCreateDate(new \DateTime()); + $group->setUserId(0); Factory::getStore('ProjectGroup')->save($group); 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 69d89270..57c02f9f 100644 --- a/src/PHPCensor/Command/ScheduleBuildCommand.php +++ b/src/PHPCensor/Command/ScheduleBuildCommand.php @@ -83,14 +83,14 @@ class ScheduleBuildCommand extends Command // If it's running or just created, we don't want to reschedule already. continue; } - if ($date < $build->getFinished()) { + if ($date < $build->getFinishDate()) { // If finished date is newer then the specified since days, we don't want to reschedule continue; } } try { - $this->buildService->createBuild($project, null); + $this->buildService->createBuild($project, null, '', null, null, null, null, Build::SOURCE_PERIODICAL); $output->writeln("Build Created for {$project->getTitle()}"); } catch (\Exception $e) { $output->writeln('Failed'); 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/GroupController.php b/src/PHPCensor/Controller/GroupController.php index cce9361f..fc54f813 100644 --- a/src/PHPCensor/Controller/GroupController.php +++ b/src/PHPCensor/Controller/GroupController.php @@ -7,6 +7,7 @@ use b8\Form; use PHPCensor\Controller; use PHPCensor\Model\ProjectGroup; use PHPCensor\Helper\Lang; +use PHPCensor\Model\User; /** * Project Controller - Allows users to create, edit and view projects. @@ -71,10 +72,19 @@ class GroupController extends Controller if ($this->request->getMethod() == 'POST') { $group->setTitle($this->getParam('title')); + if (is_null($groupId)) { + /** @var User $user */ + $user = $_SESSION['php-censor-user']; + + $group->setCreateDate(new \DateTime()); + $group->setUserId($user->getId()); + } + $this->groupStore->save($group); $response = new b8\Http\Response\RedirectResponse(); $response->setHeader('Location', APP_URL.'group'); + return $response; } diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index 4b782e0c..8276a12b 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) @@ -171,15 +173,18 @@ class ProjectController extends PHPCensor\Controller ]; } - $email = $_SESSION['php-censor-user']->getEmail(); + /** @var PHPCensor\Model\User $user */ + $user = $_SESSION['php-censor-user']; $build = $this->buildService->createBuild( $project, $environment, - null, + '', $branch, null, - $email, + $user->getEmail(), null, + Build::SOURCE_MANUAL_WEB, + $user->getId(), $extra ); @@ -187,7 +192,7 @@ class ProjectController extends PHPCensor\Controller $_SESSION['global_error'] = Lang::get('add_to_queue_failed'); } - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL.'build/view/' . $build->getId()); return $response; @@ -203,7 +208,7 @@ class ProjectController extends PHPCensor\Controller $project = $this->projectStore->getById($projectId); $this->projectService->deleteProject($project); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL); return $response; @@ -322,9 +327,11 @@ class ProjectController extends PHPCensor\Controller 'environments' => $this->getParam('environments', null), ]; - $project = $this->projectService->createProject($title, $type, $reference, $options); + /** @var PHPCensor\Model\User $user */ + $user = $_SESSION['php-censor-user']; + $project = $this->projectService->createProject($title, $type, $reference, $user->getId(), $options); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL.'project/view/' . $project->getId()); return $response; @@ -393,7 +400,7 @@ class ProjectController extends PHPCensor\Controller $project = $this->projectService->updateProject($project, $title, $type, $reference, $options); - $response = new b8\Http\Response\RedirectResponse(); + $response = new RedirectResponse(); $response->setHeader('Location', APP_URL.'project/view/' . $project->getId()); return $response; diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index 61f5de01..afa43337 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -665,6 +665,8 @@ class WebhookController extends Controller $tag, $committer, $commitMessage, + Build::SOURCE_WEBHOOK, + 0, $extra ); @@ -702,6 +704,8 @@ class WebhookController extends Controller $tag, $committer, $commitMessage, + Build::SOURCE_WEBHOOK, + 0, $extra ); 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..7cb07683 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); @@ -65,7 +66,7 @@ class ConvertErrors extends AbstractMigration $buildError = new BuildError(); $buildError->setBuildId($meta->getBuildId()); $buildError->setPlugin('php_mess_detector'); - $buildError->setCreatedDate(new \DateTime()); + $buildError->setCreateDate(new \DateTime()); $buildError->setFile($error['file']); $buildError->setLineStart($error['line_start']); $buildError->setLineEnd($error['line_end']); @@ -86,7 +87,7 @@ class ConvertErrors extends AbstractMigration $buildError = new BuildError(); $buildError->setBuildId($meta->getBuildId()); $buildError->setPlugin('php_code_sniffer'); - $buildError->setCreatedDate(new \DateTime()); + $buildError->setCreateDate(new \DateTime()); $buildError->setFile($error['file']); $buildError->setLineStart($error['line']); $buildError->setLineEnd($error['line']); @@ -116,7 +117,7 @@ class ConvertErrors extends AbstractMigration $buildError = new BuildError(); $buildError->setBuildId($meta->getBuildId()); $buildError->setPlugin('php_docblock_checker'); - $buildError->setCreatedDate(new \DateTime()); + $buildError->setCreateDate(new \DateTime()); $buildError->setFile($error['file']); $buildError->setLineStart($error['line']); $buildError->setLineEnd($error['line']); @@ -147,7 +148,7 @@ class ConvertErrors extends AbstractMigration $buildError = new BuildError(); $buildError->setBuildId($meta->getBuildId()); $buildError->setPlugin('php_cpd'); - $buildError->setCreatedDate(new \DateTime()); + $buildError->setCreateDate(new \DateTime()); $buildError->setFile($error['file']); $buildError->setLineStart($error['line_start']); $buildError->setLineEnd($error['line_end']); @@ -168,7 +169,7 @@ class ConvertErrors extends AbstractMigration $buildError = new BuildError(); $buildError->setBuildId($meta->getBuildId()); $buildError->setPlugin('technical_debt'); - $buildError->setCreatedDate(new \DateTime()); + $buildError->setCreateDate(new \DateTime()); $buildError->setFile($error['file']); $buildError->setLineStart($error['line']); $buildError->setSeverity(BuildError::SEVERITY_NORMAL); 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/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/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/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/Migrations/20171015123827_added_additional_columns.php b/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php new file mode 100644 index 00000000..b8592896 --- /dev/null +++ b/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php @@ -0,0 +1,64 @@ +table('build'); + + if (!$table->hasColumn('user_id')) { + $table + ->addColumn('user_id', 'integer', ['default' => 0]) + ->save(); + } + + if ($table->hasColumn('created')) { + $table + ->renameColumn('created', 'create_date') + ->save(); + } + + if ($table->hasColumn('started')) { + $table + ->renameColumn('started', 'start_date') + ->save(); + } + + if ($table->hasColumn('finished')) { + $table + ->renameColumn('finished', 'finish_date') + ->save(); + } + } + + public function down() + { + $table = $this->table('build'); + + if ($table->hasColumn('user_id')) { + $table + ->removeColumn('user_id') + ->save(); + } + + if ($table->hasColumn('create_date')) { + $table + ->renameColumn('create_date', 'created') + ->save(); + } + + if ($table->hasColumn('start_date')) { + $table + ->renameColumn('start_date', 'started') + ->save(); + } + + if ($table->hasColumn('finish_date')) { + $table + ->renameColumn('finish_date', 'finished') + ->save(); + } + } +} diff --git a/src/PHPCensor/Migrations/20171016143000_added_additional_columns2.php b/src/PHPCensor/Migrations/20171016143000_added_additional_columns2.php new file mode 100644 index 00000000..2516c6c3 --- /dev/null +++ b/src/PHPCensor/Migrations/20171016143000_added_additional_columns2.php @@ -0,0 +1,40 @@ +table('project_group'); + + if (!$table->hasColumn('create_date')) { + $table + ->addColumn('create_date', 'datetime', ['null' => true]) + ->save(); + } + + if (!$table->hasColumn('user_id')) { + $table + ->addColumn('user_id', 'integer', ['default' => 0]) + ->save(); + } + } + + public function down() + { + $table = $this->table('project_group'); + + if ($table->hasColumn('create_date')) { + $table + ->removeColumn('create_date') + ->save(); + } + + if ($table->hasColumn('user_id')) { + $table + ->removeColumn('user_id') + ->save(); + } + } +} diff --git a/src/PHPCensor/Migrations/20171019143346_added_additional_columns3.php b/src/PHPCensor/Migrations/20171019143346_added_additional_columns3.php new file mode 100644 index 00000000..cd305cdb --- /dev/null +++ b/src/PHPCensor/Migrations/20171019143346_added_additional_columns3.php @@ -0,0 +1,56 @@ +table('build_error'); + + if ($table->hasColumn('created_date') && !$table->hasColumn('create_date')) { + $table + ->renameColumn('created_date', 'create_date') + ->save(); + } + + $table = $this->table('project'); + + if (!$table->hasColumn('create_date')) { + $table + ->addColumn('create_date', 'datetime', ['null' => true]) + ->save(); + } + + if (!$table->hasColumn('user_id')) { + $table + ->addColumn('user_id', 'integer', ['default' => 0]) + ->save(); + } + } + + public function down() + { + $table = $this->table('build_error'); + + if ($table->hasColumn('create_date') && !$table->hasColumn('created_date')) { + $table + ->renameColumn('create_date', 'created_date') + ->save(); + } + + $table = $this->table('project'); + + if ($table->hasColumn('create_date')) { + $table + ->removeColumn('create_date') + ->save(); + } + + if ($table->hasColumn('user_id')) { + $table + ->removeColumn('user_id') + ->save(); + } + } +} diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index 54d7d29e..f2aadc90 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -21,10 +21,16 @@ 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; + const SOURCE_MANUAL_CONSOLE = 2; + const SOURCE_PERIODICAL = 3; + const SOURCE_WEBHOOK = 4; /** * @var array @@ -52,13 +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, ]; /** @@ -73,13 +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', @@ -97,260 +107,37 @@ 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', ]; /** - * @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, - ], - ]; - - /** - * @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. - * - * @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 - */ - public function getProjectId() - { - $rtn = $this->data['project_id']; - - return $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 int - */ - public function getStatus() - { - $rtn = $this->data['status']; - - return $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; @@ -362,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; @@ -381,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; @@ -400,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; @@ -419,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'); @@ -439,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) @@ -635,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. * @@ -761,7 +745,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); } /** @@ -856,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 @@ -944,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(); @@ -965,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(); } @@ -1002,66 +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 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. * @@ -1107,4 +1022,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/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index 7a1f70a6..324e2671 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 */ @@ -34,7 +39,7 @@ class BuildError extends Model 'line_end' => null, 'severity' => null, 'message' => null, - 'created_date' => null, + 'create_date' => null, ]; /** @@ -50,7 +55,7 @@ class BuildError extends Model 'line_end' => 'getLineEnd', 'severity' => 'getSeverity', 'message' => 'getMessage', - 'created_date' => 'getCreatedDate', + 'create_date' => 'getCreateDate', // Foreign key getters: 'Build' => 'getBuild', @@ -69,91 +74,13 @@ class BuildError extends Model 'line_end' => 'setLineEnd', 'severity' => 'setSeverity', 'message' => 'setMessage', - 'created_date' => 'setCreatedDate', + 'create_date' => 'setCreateDate', // Foreign key setters: 'Build' => 'setBuild', ]; /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'build_id' => [ - 'type' => 'int', - 'length' => 11, - 'default' => null, - ], - 'plugin' => [ - 'type' => 'varchar', - 'length' => 100, - 'default' => null, - ], - 'file' => [ - 'type' => 'varchar', - 'length' => 250, - 'nullable' => true, - 'default' => null, - ], - 'line_start' => [ - 'type' => 'int', - 'length' => 11, - 'nullable' => true, - 'default' => null, - ], - 'line_end' => [ - 'type' => 'int', - 'length' => 11, - 'nullable' => true, - 'default' => null, - ], - 'severity' => [ - 'type' => 'tinyint', - 'length' => 3, - 'default' => null, - ], - 'message' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'created_date' => [ - 'type' => 'datetime', - 'default' => null, - ], - ]; - - /** - * @var array - */ - public $indexes = [ - 'PRIMARY' => ['unique' => true, 'columns' => 'id'], - 'build_id' => ['columns' => 'build_id, created_date'], - ]; - - /** - * @var array - */ - public $foreignKeys = [ - 'build_error_ibfk_1' => [ - 'local_col' => 'build_id', - 'update' => 'CASCADE', - 'delete' => 'CASCADE', - 'table' => 'build', - 'col' => 'id' - ], - ]; - - /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -164,8 +91,6 @@ class BuildError extends Model } /** - * Get the value of BuildId / build_id. - * * @return int */ public function getBuildId() @@ -176,8 +101,6 @@ class BuildError extends Model } /** - * Get the value of Plugin / plugin. - * * @return string */ public function getPlugin() @@ -188,8 +111,6 @@ class BuildError extends Model } /** - * Get the value of File / file. - * * @return string */ public function getFile() @@ -200,8 +121,6 @@ class BuildError extends Model } /** - * Get the value of LineStart / line_start. - * * @return int */ public function getLineStart() @@ -212,8 +131,6 @@ class BuildError extends Model } /** - * Get the value of LineEnd / line_end. - * * @return int */ public function getLineEnd() @@ -224,8 +141,6 @@ class BuildError extends Model } /** - * Get the value of Severity / severity. - * * @return int */ public function getSeverity() @@ -236,8 +151,6 @@ class BuildError extends Model } /** - * Get the value of Message / message. - * * @return string */ public function getMessage() @@ -248,13 +161,11 @@ class BuildError extends Model } /** - * Get the value of CreatedDate / created_date. - * * @return \DateTime */ - public function getCreatedDate() + public function getCreateDate() { - $rtn = $this->data['created_date']; + $rtn = $this->data['create_date']; if (!empty($rtn)) { $rtn = new \DateTime($rtn); @@ -264,15 +175,12 @@ class BuildError extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -284,15 +192,12 @@ class BuildError extends Model } /** - * Set the value of BuildId / build_id. - * - * Must not be null. * @param $value int */ public function setBuildId($value) { - $this->validateNotNull('BuildId', $value); - $this->validateInt('BuildId', $value); + $this->validateNotNull('build_id', $value); + $this->validateInt('build_id', $value); if ($this->data['build_id'] === $value) { return; @@ -304,15 +209,12 @@ class BuildError extends Model } /** - * Set the value of Plugin / plugin. - * - * Must not be null. * @param $value string */ public function setPlugin($value) { - $this->validateNotNull('Plugin', $value); - $this->validateString('Plugin', $value); + $this->validateNotNull('plugin', $value); + $this->validateString('plugin', $value); if ($this->data['plugin'] === $value) { return; @@ -324,13 +226,11 @@ class BuildError extends Model } /** - * Set the value of File / file. - * * @param $value string */ public function setFile($value) { - $this->validateString('File', $value); + $this->validateString('file', $value); if ($this->data['file'] === $value) { return; @@ -342,13 +242,11 @@ class BuildError extends Model } /** - * Set the value of LineStart / line_start. - * * @param $value int */ public function setLineStart($value) { - $this->validateInt('LineStart', $value); + $this->validateInt('line_start', $value); if ($this->data['line_start'] === $value) { return; @@ -360,13 +258,11 @@ class BuildError extends Model } /** - * Set the value of LineEnd / line_end. - * * @param $value int */ public function setLineEnd($value) { - $this->validateInt('LineEnd', $value); + $this->validateInt('line_end', $value); if ($this->data['line_end'] === $value) { return; @@ -378,15 +274,12 @@ class BuildError extends Model } /** - * Set the value of Severity / severity. - * - * Must not be null. * @param $value int */ public function setSeverity($value) { - $this->validateNotNull('Severity', $value); - $this->validateInt('Severity', $value); + $this->validateNotNull('severity', $value); + $this->validateInt('severity', $value); if ($this->data['severity'] === $value) { return; @@ -398,15 +291,12 @@ class BuildError extends Model } /** - * Set the value of Message / message. - * - * Must not be null. * @param $value string */ public function setMessage($value) { - $this->validateNotNull('Message', $value); - $this->validateString('Message', $value); + $this->validateNotNull('message', $value); + $this->validateString('message', $value); if ($this->data['message'] === $value) { return; @@ -418,30 +308,25 @@ class BuildError extends Model } /** - * Set the value of CreatedDate / created_date. - * - * Must not be null. * @param $value \DateTime */ - public function setCreatedDate($value) + public function setCreateDate($value) { - $this->validateNotNull('CreatedDate', $value); - $this->validateDate('CreatedDate', $value); + $this->validateNotNull('create_date', $value); + $this->validateDate('create_date', $value); - if ($this->data['created_date'] === $value) { + if ($this->data['create_date'] === $value) { return; } - $this->data['created_date'] = $value; + $this->data['create_date'] = $value; - $this->setModified('created_date'); + $this->setModified('create_date'); } /** * Get the Build model for this BuildError by Id. * - * @uses \PHPCensor\Store\BuildStore::getById() - * @uses \PHPCensor\Model\Build * @return \PHPCensor\Model\Build */ public function getBuild() @@ -494,13 +379,9 @@ class BuildError extends Model return $this->setBuildId($value->getId()); } - const SEVERITY_CRITICAL = 0; - const SEVERITY_HIGH = 1; - const SEVERITY_NORMAL = 2; - const SEVERITY_LOW = 3; - /** * Get the language string key for this error's severity level. + * * @return string */ public function getSeverityString() @@ -522,6 +403,7 @@ class BuildError extends Model /** * Get the class to apply to HTML elements representing this error. + * * @return string */ public function getSeverityClass() diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index 656f81b5..0efa761c 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,13 +38,12 @@ class BuildMeta extends Model protected $getters = [ // Direct property getters: 'id' => 'getId', - 'project_id' => 'getProjectId', 'build_id' => 'getBuildId', 'meta_key' => 'getMetaKey', 'meta_value' => 'getMetaValue', + // Foreign key getters: - 'Project' => 'getProject', - 'Build' => 'getBuild', + 'Build' => 'getBuild', ]; /** @@ -54,146 +52,61 @@ class BuildMeta extends Model protected $setters = [ // Direct property setters: 'id' => 'setId', - 'project_id' => 'setProjectId', 'build_id' => 'setBuildId', 'meta_key' => 'setMetaKey', 'meta_value' => 'setMetaValue', + // Foreign key setters: - 'Project' => 'setProject', - 'Build' => 'setBuild', + 'Build' => 'setBuild', ]; /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 10, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'project_id' => [ - 'type' => 'int', - 'length' => 11, - 'default' => null, - ], - 'build_id' => [ - 'type' => 'int', - 'length' => 11, - 'default' => null, - ], - 'meta_key' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'meta_value' => [ - 'type' => 'mediumtext', - 'default' => null, - ], - ]; - - /** - * @var array - */ - public $indexes = [ - 'PRIMARY' => ['unique' => true, 'columns' => 'id'], - 'idx_meta_id' => ['unique' => true, 'columns' => 'build_id, meta_key'], - 'project_id' => ['columns' => 'project_id'], - ]; - - /** - * @var array - */ - public $foreignKeys = [ - 'build_meta_ibfk_1' => [ - 'local_col' => 'project_id', - 'update' => 'CASCADE', - 'delete' => 'CASCADE', - 'table' => 'project', - 'col' => 'id' - ], - 'fk_meta_build_id' => [ - 'local_col' => 'build_id', - 'update' => 'CASCADE', - 'delete' => 'CASCADE', - 'table' => 'build', - 'col' => 'id' - ], - ]; - - /** - * Get the value of Id / id. - * * @return int */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } /** - * Get the value of ProjectId / project_id. - * - * @return int - */ - public function getProjectId() - { - $rtn = $this->data['project_id']; - - return $rtn; - } - - /** - * Get the value of BuildId / build_id. - * * @return int */ public function getBuildId() { - $rtn = $this->data['build_id']; + $rtn = $this->data['build_id']; return $rtn; } /** - * Get the value of MetaKey / meta_key. - * * @return string */ public function getMetaKey() { - $rtn = $this->data['meta_key']; + $rtn = $this->data['meta_key']; return $rtn; } /** - * Get the value of MetaValue / meta_value. - * * @return string */ public function getMetaValue() { - $rtn = $this->data['meta_value']; + $rtn = $this->data['meta_value']; return $rtn; } /** - * Set the value of Id / id. - * - * Must not be null. - * @param $value int + * @param int $value */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -205,35 +118,12 @@ class BuildMeta extends Model } /** - * Set the value of ProjectId / project_id. - * - * Must not be null. - * @param $value int - */ - public function setProjectId($value) - { - $this->validateNotNull('ProjectId', $value); - $this->validateInt('ProjectId', $value); - - if ($this->data['project_id'] === $value) { - return; - } - - $this->data['project_id'] = $value; - - $this->setModified('project_id'); - } - - /** - * Set the value of BuildId / build_id. - * - * Must not be null. - * @param $value int + * @param int $value */ public function setBuildId($value) { - $this->validateNotNull('BuildId', $value); - $this->validateInt('BuildId', $value); + $this->validateNotNull('build_id', $value); + $this->validateInt('build_id', $value); if ($this->data['build_id'] === $value) { return; @@ -245,15 +135,12 @@ class BuildMeta extends Model } /** - * Set the value of MetaKey / meta_key. - * - * Must not be null. * @param $value string */ public function setMetaKey($value) { - $this->validateNotNull('MetaKey', $value); - $this->validateString('MetaKey', $value); + $this->validateNotNull('meta_key', $value); + $this->validateString('meta_key', $value); if ($this->data['meta_key'] === $value) { return; @@ -265,15 +152,12 @@ class BuildMeta extends Model } /** - * Set the value of MetaValue / meta_value. - * - * Must not be null. * @param $value string */ public function setMetaValue($value) { - $this->validateNotNull('MetaValue', $value); - $this->validateString('MetaValue', $value); + $this->validateNotNull('meta_value', $value); + $this->validateString('meta_value', $value); if ($this->data['meta_value'] === $value) { return; @@ -284,68 +168,9 @@ class BuildMeta extends Model $this->setModified('meta_value'); } - /** - * Get the Project model for this BuildMeta by Id. - * - * @uses \PHPCensor\Store\ProjectStore::getById() - * @uses \PHPCensor\Model\Project - * @return \PHPCensor\Model\Project - */ - public function getProject() - { - $key = $this->getProjectId(); - - if (empty($key)) { - return null; - } - - $cacheKey = 'Cache.Project.' . $key; - $rtn = $this->cache->get($cacheKey, null); - - if (empty($rtn)) { - $rtn = Factory::getStore('Project', 'PHPCensor')->getById($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; - } - - /** - * Set Project - Accepts an ID, an array representing a Project or a Project model. - * - * @param $value mixed - */ - public function setProject($value) - { - // Is this an instance of Project? - if ($value instanceof Project) { - return $this->setProjectObject($value); - } - - // Is this an array representing a Project item? - if (is_array($value) && !empty($value['id'])) { - return $this->setProjectId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setProjectId($value); - } - - /** - * Set Project - Accepts a Project model. - * - * @param $value Project - */ - public function setProjectObject(Project $value) - { - return $this->setProjectId($value->getId()); - } - /** * Get the Build model for this BuildMeta by Id. * - * @uses \PHPCensor\Store\BuildStore::getById() - * @uses \PHPCensor\Model\Build * @return \PHPCensor\Model\Build */ public function getBuild() @@ -356,8 +181,8 @@ class BuildMeta extends Model return null; } - $cacheKey = 'Cache.Build.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'Cache.Build.' . $key; + $rtn = $this->cache->get($cacheKey, null); if (empty($rtn)) { $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); diff --git a/src/PHPCensor/Model/Environment.php b/src/PHPCensor/Model/Environment.php index 4645010c..e70da4ee 100644 --- a/src/PHPCensor/Model/Environment.php +++ b/src/PHPCensor/Model/Environment.php @@ -25,99 +25,43 @@ class Environment extends Model * @var array */ protected $data = [ - 'id' => null, + 'id' => null, 'project_id' => null, - 'name' => null, - 'branches' => null, + 'name' => null, + 'branches' => null, ]; /** * @var array */ protected $getters = [ - // Direct property getters: - 'id' => 'getId', + 'id' => 'getId', 'project_id' => 'getProjectId', - 'name' => 'getName', - 'branches' => 'getBranches', - // Foreign key getters: + 'name' => 'getName', + 'branches' => 'getBranches', ]; /** * @var array */ protected $setters = [ - // Direct property setters: - 'id' => 'setId', - 'project_id' => 'setProjectId', - 'name' => 'setName', - 'branches' => 'setBranches', - // Foreign key setters: + 'id' => 'setId', + 'project_id' => 'setProjectId', + 'name' => 'setName', + 'branches' => 'setBranches', ]; /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'project_id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'default' => null, - ], - 'name' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'branches' => [ - 'type' => 'text', - 'default' => '', - ], - ]; - - /** - * @var array - */ - public $indexes = [ - 'PRIMARY' => ['unique' => true, 'columns' => 'project_id, name'], - ]; - - /** - * @var array - */ - public $foreignKeys = [ - 'environment_ibfk_1' => [ - 'local_col' => 'project_id', - 'update' => 'CASCADE', - 'delete' => '', - 'table' => 'project', - 'col' => 'id' - ], - ]; - - /** - * Get the value of Id / id. - * * @return int */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } /** - * Get the value of Id / id. - * * @return int */ public function getProjectId() @@ -128,20 +72,16 @@ class Environment extends Model } /** - * Get the value of Title / title. - * * @return string */ public function getName() { - $rtn = $this->data['name']; + $rtn = $this->data['name']; return $rtn; } /** - * Get the value of Title / title. - * * @return array */ public function getBranches() @@ -152,15 +92,12 @@ class Environment extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -172,15 +109,12 @@ class Environment extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setProjectId($value) { - $this->validateNotNull('ProjectId', $value); - $this->validateInt('ProjectId', $value); + $this->validateNotNull('project_id', $value); + $this->validateInt('project_id', $value); if ($this->data['project_id'] === $value) { return; @@ -192,15 +126,12 @@ class Environment extends Model } /** - * Set the value of Name / name - * - * Must not be null. * @param $value string */ public function setName($value) { - $this->validateNotNull('Name', $value); - $this->validateString('Name', $value); + $this->validateNotNull('name', $value); + $this->validateString('name', $value); if ($this->data['name'] === $value) { return; @@ -212,14 +143,11 @@ class Environment extends Model } /** - * Set the value of Branches / branches - * - * Must not be null. * @param $value array */ public function setBranches($value) { - $this->validateNotNull('Branches', $value); + $this->validateNotNull('branches', $value); $value = implode("\n", $value); if ($this->data['branches'] === $value) { diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 9e20d91d..bf461b7a 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -47,6 +47,8 @@ class Project extends Model 'allow_public_status' => null, 'archived' => null, 'group_id' => null, + 'create_date' => null, + 'user_id' => 0, ]; /** @@ -68,8 +70,11 @@ class Project extends Model 'allow_public_status' => 'getAllowPublicStatus', 'archived' => 'getArchived', 'group_id' => 'getGroupId', + 'create_date' => 'getCreateDate', + 'user_id' => 'getUserId', + // Foreign key getters: - 'Group' => 'getGroup', + 'Group' => 'getGroup', ]; /** @@ -91,185 +96,74 @@ class Project extends Model 'allow_public_status' => 'setAllowPublicStatus', 'archived' => 'setArchived', 'group_id' => 'setGroupId', + 'create_date' => 'setCreateDate', + 'user_id' => 'setUserId', + // Foreign key setters: - 'Group' => 'setGroup', + 'Group' => 'setGroup', ]; /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'title' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'reference' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'branch' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => 'master', - ], - 'default_branch_only' => [ - 'type' => 'int', - 'length' => 11, - ], - 'ssh_private_key' => [ - 'type' => 'text', - 'nullable' => true, - 'default' => null, - ], - 'type' => [ - 'type' => 'varchar', - 'length' => 50, - 'default' => null, - ], - 'access_information' => [ - 'type' => 'varchar', - 'length' => 250, - 'nullable' => true, - 'default' => null, - ], - 'last_commit' => [ - 'type' => 'varchar', - 'length' => 250, - 'nullable' => true, - 'default' => null, - ], - 'build_config' => [ - 'type' => 'text', - 'nullable' => true, - 'default' => null, - ], - 'ssh_public_key' => [ - 'type' => 'text', - 'nullable' => true, - 'default' => null, - ], - 'allow_public_status' => [ - 'type' => 'int', - 'length' => 11, - ], - 'archived' => [ - 'type' => 'tinyint', - 'length' => 1, - 'default' => null, - ], - 'group_id' => [ - 'type' => 'int', - 'length' => 11, - 'default' => 1, - ], - ]; - - /** - * @var array - */ - public $indexes = [ - 'PRIMARY' => ['unique' => true, 'columns' => 'id'], - 'idx_project_title' => ['columns' => 'title'], - 'group_id' => ['columns' => 'group_id'], - ]; - - /** - * @var array - */ - public $foreignKeys = [ - 'project_ibfk_1' => [ - 'local_col' => 'group_id', - 'update' => 'CASCADE', - 'delete' => '', - 'table' => 'project_group', - 'col' => 'id' - ], - ]; - - /** - * Get the value of Id / id. - * * @return int */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } /** - * Get the value of Title / title. - * * @return string */ public function getTitle() { - $rtn = $this->data['title']; + $rtn = $this->data['title']; return $rtn; } /** - * Get the value of Reference / reference. - * * @return string */ public function getReference() { - $rtn = $this->data['reference']; + $rtn = $this->data['reference']; return $rtn; } /** - * Get the value of SshPrivateKey / ssh_private_key. - * * @return string */ public function getSshPrivateKey() { - $rtn = $this->data['ssh_private_key']; + $rtn = $this->data['ssh_private_key']; return $rtn; } /** - * Get the value of Type / type. - * * @return string */ public function getType() { - $rtn = $this->data['type']; + $rtn = $this->data['type']; return $rtn; } /** - * Get the value of LastCommit / last_commit. - * * @return string */ public function getLastCommit() { - $rtn = $this->data['last_commit']; + $rtn = $this->data['last_commit']; return $rtn; } /** - * Get the value of BuildConfig / build_config. - * * @return string */ public function getBuildConfig() @@ -280,20 +174,16 @@ class Project extends Model } /** - * Get the value of SshPublicKey / ssh_public_key. - * * @return string */ public function getSshPublicKey() { - $rtn = $this->data['ssh_public_key']; + $rtn = $this->data['ssh_public_key']; return $rtn; } /** - * Get the value of AllowPublicStatus / allow_public_status. - * * @return int */ public function getAllowPublicStatus() @@ -304,8 +194,6 @@ class Project extends Model } /** - * Get the value of Archived / archived. - * * @return int */ public function getArchived() @@ -316,8 +204,6 @@ class Project extends Model } /** - * Get the value of GroupId / group_id. - * * @return int */ public function getGroupId() @@ -328,8 +214,6 @@ class Project extends Model } /** - * Get the value of DefaultBranchOnly / default_branch_only. - * * @return int */ public function getDefaultBranchOnly() @@ -340,15 +224,12 @@ class Project extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -360,15 +241,12 @@ class Project extends Model } /** - * Set the value of Title / title. - * - * Must not be null. * @param $value string */ public function setTitle($value) { - $this->validateNotNull('Title', $value); - $this->validateString('Title', $value); + $this->validateNotNull('title', $value); + $this->validateString('title', $value); if ($this->data['title'] === $value) { return; @@ -380,15 +258,12 @@ class Project extends Model } /** - * Set the value of Reference / reference. - * - * Must not be null. * @param $value string */ public function setReference($value) { - $this->validateNotNull('Reference', $value); - $this->validateString('Reference', $value); + $this->validateNotNull('reference', $value); + $this->validateString('reference', $value); if ($this->data['reference'] === $value) { return; @@ -400,15 +275,12 @@ class Project extends Model } /** - * Set the value of Branch / branch. - * - * Must not be null. * @param $value string */ public function setBranch($value) { - $this->validateNotNull('Branch', $value); - $this->validateString('Branch', $value); + $this->validateNotNull('branch', $value); + $this->validateString('branch', $value); if ($this->data['branch'] === $value) { return; @@ -420,15 +292,12 @@ class Project extends Model } /** - * Set the value of DefaultBranchOnly / default_branch_only. - * - * Must not be null. * @param $value int */ public function setDefaultBranchOnly($value) { - $this->validateNotNull('DefaultBranchOnly', $value); - $this->validateInt('DefaultBranchOnly', $value); + $this->validateNotNull('default_branch_only', $value); + $this->validateInt('default_branch_only', $value); if ($this->data['default_branch_only'] === $value) { return; @@ -440,13 +309,11 @@ class Project extends Model } /** - * Set the value of SshPrivateKey / ssh_private_key. - * * @param $value string */ public function setSshPrivateKey($value) { - $this->validateString('SshPrivateKey', $value); + $this->validateString('ssh_private_key', $value); if ($this->data['ssh_private_key'] === $value) { return; @@ -458,15 +325,12 @@ class Project extends Model } /** - * Set the value of Type / type. - * - * Must not be null. * @param $value string */ public function setType($value) { - $this->validateNotNull('Type', $value); - $this->validateString('Type', $value); + $this->validateNotNull('type', $value); + $this->validateString('type', $value); if ($this->data['type'] === $value) { return; @@ -478,13 +342,11 @@ class Project extends Model } /** - * Set the value of LastCommit / last_commit. - * * @param $value string */ public function setLastCommit($value) { - $this->validateString('LastCommit', $value); + $this->validateString('last_commit', $value); if ($this->data['last_commit'] === $value) { return; @@ -496,13 +358,11 @@ class Project extends Model } /** - * Set the value of BuildConfig / build_config. - * * @param $value string */ public function setBuildConfig($value) { - $this->validateString('BuildConfig', $value); + $this->validateString('build_config', $value); if ($this->data['build_config'] === $value) { return; @@ -514,13 +374,11 @@ class Project extends Model } /** - * Set the value of SshPublicKey / ssh_public_key. - * * @param $value string */ public function setSshPublicKey($value) { - $this->validateString('SshPublicKey', $value); + $this->validateString('ssh_public_key', $value); if ($this->data['ssh_public_key'] === $value) { return; @@ -532,15 +390,12 @@ class Project extends Model } /** - * Set the value of AllowPublicStatus / allow_public_status. - * - * Must not be null. * @param $value int */ public function setAllowPublicStatus($value) { - $this->validateNotNull('AllowPublicStatus', $value); - $this->validateInt('AllowPublicStatus', $value); + $this->validateNotNull('allow_public_status', $value); + $this->validateInt('allow_public_status', $value); if ($this->data['allow_public_status'] === $value) { return; @@ -552,15 +407,12 @@ class Project extends Model } /** - * Set the value of Archived / archived. - * - * Must not be null. * @param $value int */ public function setArchived($value) { - $this->validateNotNull('Archived', $value); - $this->validateInt('Archived', $value); + $this->validateNotNull('archived', $value); + $this->validateInt('archived', $value); if ($this->data['archived'] === $value) { return; @@ -572,15 +424,12 @@ class Project extends Model } /** - * Set the value of GroupId / group_id. - * - * Must not be null. * @param $value int */ public function setGroupId($value) { - $this->validateNotNull('GroupId', $value); - $this->validateInt('GroupId', $value); + $this->validateNotNull('group_id', $value); + $this->validateInt('group_id', $value); if ($this->data['group_id'] === $value) { return; @@ -594,8 +443,6 @@ class Project extends Model /** * Get the ProjectGroup model for this Project by Id. * - * @uses \PHPCensor\Store\ProjectGroupStore::getById() - * @uses \PHPCensor\Model\ProjectGroup * @return \PHPCensor\Model\ProjectGroup */ public function getGroup() @@ -606,11 +453,11 @@ class Project extends Model return null; } - $cacheKey = 'Cache.ProjectGroup.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'Cache.ProjectGroup.' . $key; + $rtn = $this->cache->get($cacheKey, null); if (empty($rtn)) { - $rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key); + $rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key); $this->cache->set($cacheKey, $rtn); } @@ -651,8 +498,6 @@ class Project extends Model /** * Get Build models by ProjectId for this Project. * - * @uses \PHPCensor\Store\BuildStore::getByProjectId() - * @uses \PHPCensor\Model\Build * @return \PHPCensor\Model\Build[] */ public function getProjectBuilds() @@ -660,22 +505,12 @@ class Project extends Model return Factory::getStore('Build', 'PHPCensor')->getByProjectId($this->getId()); } - /** - * Get BuildMeta models by ProjectId for this Project. - * - * @uses \PHPCensor\Store\BuildMetaStore::getByProjectId() - * @uses \PHPCensor\Model\BuildMeta - * @return \PHPCensor\Model\BuildMeta[] - */ - public function getProjectBuildMetas() - { - return Factory::getStore('BuildMeta', 'PHPCensor')->getByProjectId($this->getId()); - } - /** * Return the latest build from a specific branch, of a specific status, for this project. + * * @param string $branch - * @param null $status + * @param null $status + * * @return mixed|null */ public function getLatestBuild($branch = 'master', $status = null) @@ -702,7 +537,9 @@ class Project extends Model /** * Return the previous build from a specific branch, for this project. + * * @param string $branch + * * @return mixed|null */ public function getPreviousBuild($branch = 'master') @@ -723,7 +560,6 @@ class Project extends Model } /** - * Store this project's access_information data * @param string|array $value */ public function setAccessInformation($value) @@ -732,7 +568,7 @@ class Project extends Model $value = json_encode($value); } - $this->validateString('AccessInformation', $value); + $this->validateString('access_information', $value); if ($this->data['access_information'] === $value) { return; @@ -745,7 +581,9 @@ class Project extends Model /** * Get this project's access_information data. Pass a specific key or null for all data. + * * @param string|null $key + * * @return mixed|null|string */ public function getAccessInformation($key = null) @@ -771,7 +609,64 @@ class Project extends Model } /** - * Get the value of Branch / branch. + * @return \DateTime + */ + public function getCreateDate() + { + $rtn = $this->data['create_date']; + + if (!empty($rtn)) { + $rtn = new \DateTime($rtn); + } + + return $rtn; + } + + /** + * @param $value \DateTime + */ + public function setCreateDate($value) + { + $this->validateDate('create_date', $value); + + if ($this->data['create_date'] === $value) { + return; + } + + $this->data['create_date'] = $value; + + $this->setModified('create_date'); + } + + /** + * @return string + */ + public function getUserId() + { + $rtn = $this->data['user_id']; + + return (integer)$rtn; + } + + /** + * @param $value integer + */ + public function setUserId($value) + { + $this->validateNotNull('user_id', $value); + $this->validateInt('user_id', $value); + + if ($this->data['user_id'] === $value) { + return; + } + + $this->data['user_id'] = $value; + + $this->setModified('user_id'); + } + + /** + * Get the value of branch. * * @return string */ @@ -798,6 +693,7 @@ class Project extends Model /** * Return the name of a FontAwesome icon to represent this project, depending on its type. + * * @return string */ public function getIcon() @@ -850,7 +746,7 @@ class Project extends Model if (empty($rtn)) { $store = $this->getEnvironmentStore(); - $rtn = $store->getByProjectId($key); + $rtn = $store->getByProjectId($key); $this->cache->set($cacheKey, $rtn); } diff --git a/src/PHPCensor/Model/ProjectGroup.php b/src/PHPCensor/Model/ProjectGroup.php index 3d5adf16..68824381 100644 --- a/src/PHPCensor/Model/ProjectGroup.php +++ b/src/PHPCensor/Model/ProjectGroup.php @@ -26,94 +26,49 @@ class ProjectGroup extends Model * @var array */ protected $data = [ - 'id' => null, - 'title' => null, + 'id' => null, + 'title' => null, + 'create_date' => null, + 'user_id' => 0, ]; /** * @var array */ protected $getters = [ - // Direct property getters: - 'id' => 'getId', - 'title' => 'getTitle', - // Foreign key getters: + 'id' => 'getId', + 'title' => 'getTitle', + 'create_date' => 'getCreateDate', + 'user_id' => 'getUserId', ]; /** * @var array */ protected $setters = [ - // Direct property setters: - 'id' => 'setId', - 'title' => 'setTitle', - // Foreign key setters: + 'id' => 'setId', + 'title' => 'setTitle', + 'create_date' => 'setCreateDate', + 'user_id' => 'setUserId', ]; /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'title' => [ - 'type' => 'varchar', - 'length' => 100, - 'default' => null, - ], - ]; - - /** - * @var array - */ - public $indexes = [ - 'PRIMARY' => ['unique' => true, 'columns' => 'id'], - ]; - - /** - * @var array - */ - public $foreignKeys = []; - - /** - * Get the value of Id / id. - * * @return int */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } /** - * Get the value of Title / title. - * - * @return string - */ - public function getTitle() - { - $rtn = $this->data['title']; - - return $rtn; - } - - /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -125,15 +80,22 @@ class ProjectGroup extends Model } /** - * Set the value of Title / title. - * - * Must not be null. + * @return string + */ + public function getTitle() + { + $rtn = $this->data['title']; + + return $rtn; + } + + /** * @param $value string */ public function setTitle($value) { - $this->validateNotNull('Title', $value); - $this->validateString('Title', $value); + $this->validateNotNull('title', $value); + $this->validateString('title', $value); if ($this->data['title'] === $value) { return; @@ -144,11 +106,66 @@ class ProjectGroup extends Model $this->setModified('title'); } + /** + * @return \DateTime + */ + public function getCreateDate() + { + $rtn = $this->data['create_date']; + + if (!empty($rtn)) { + $rtn = new \DateTime($rtn); + } + + return $rtn; + } + + /** + * @param $value \DateTime + */ + public function setCreateDate($value) + { + $this->validateDate('create_date', $value); + + if ($this->data['create_date'] === $value) { + return; + } + + $this->data['create_date'] = $value; + + $this->setModified('create_date'); + } + + /** + * @return string + */ + public function getUserId() + { + $rtn = $this->data['user_id']; + + return (integer)$rtn; + } + + /** + * @param $value integer + */ + public function setUserId($value) + { + $this->validateNotNull('user_id', $value); + $this->validateInt('user_id', $value); + + if ($this->data['user_id'] === $value) { + return; + } + + $this->data['user_id'] = $value; + + $this->setModified('user_id'); + } + /** * Get Project models by GroupId for this ProjectGroup. * - * @uses \PHPCensor\Store\ProjectStore::getByGroupId() - * @uses \PHPCensor\Model\Project * @return \PHPCensor\Model\Project[] */ public function getGroupProjects() diff --git a/src/PHPCensor/Model/User.php b/src/PHPCensor/Model/User.php index 204d81fd..d49c7472 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,86 +71,9 @@ class User extends Model 'provider_key' => 'setProviderKey', 'provider_data' => 'setProviderData', 'remember_key' => 'setRememberKey', - // Foreign key setters: ]; /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'email' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'hash' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'is_admin' => [ - 'type' => 'int', - 'length' => 11, - ], - 'name' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'language' => [ - 'type' => 'varchar', - 'length' => 5, - 'default' => null, - ], - 'per_page' => [ - 'type' => 'int', - 'length' => 11, - 'default' => null, - ], - 'provider_key' => [ - 'type' => 'varchar', - 'length' => 255, - 'default' => 'internal', - ], - 'provider_data' => [ - 'type' => 'varchar', - 'length' => 255, - 'nullable' => true, - 'default' => null, - ], - 'remember_key' => [ - 'type' => 'varchar', - 'length' => 32, - 'nullable' => true, - 'default' => null, - ], - ]; - - /** - * @var array - */ - public $indexes = [ - 'PRIMARY' => ['unique' => true, 'columns' => 'id'], - 'idx_email' => ['unique' => true, 'columns' => 'email'], - 'email' => ['unique' => true, 'columns' => 'email'], - 'name' => ['columns' => 'name'], - ]; - - /** - * @var array - */ - public $foreignKeys = []; - - /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -164,8 +84,6 @@ class User extends Model } /** - * Get the value of Email / email. - * * @return string */ public function getEmail() @@ -176,8 +94,6 @@ class User extends Model } /** - * Get the value of Hash / hash. - * * @return string */ public function getHash() @@ -188,8 +104,6 @@ class User extends Model } /** - * Get the value of Name / name. - * * @return string */ public function getName() @@ -200,8 +114,6 @@ class User extends Model } /** - * Get the value of IsAdmin / is_admin. - * * @return int */ public function getIsAdmin() @@ -212,8 +124,6 @@ class User extends Model } /** - * Get the value of ProviderKey / provider_key. - * * @return string */ public function getProviderKey() @@ -224,8 +134,6 @@ class User extends Model } /** - * Get the value of ProviderData / provider_data. - * * @return string */ public function getProviderData() @@ -236,8 +144,6 @@ class User extends Model } /** - * Get the value of RememberKey / remember_key. - * * @return string */ public function getRememberKey() @@ -248,8 +154,6 @@ class User extends Model } /** - * Get the value of Language / language. - * * @return string */ public function getLanguage() @@ -260,8 +164,6 @@ class User extends Model } /** - * Get the value of PerPage / per_page. - * * @return string */ public function getPerPage() @@ -272,15 +174,12 @@ class User extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -292,15 +191,12 @@ class User extends Model } /** - * Set the value of Email / email. - * - * Must not be null. * @param $value string */ public function setEmail($value) { - $this->validateNotNull('Email', $value); - $this->validateString('Email', $value); + $this->validateNotNull('email', $value); + $this->validateString('email', $value); if ($this->data['email'] === $value) { return; @@ -312,15 +208,12 @@ class User extends Model } /** - * Set the value of Hash / hash. - * - * Must not be null. * @param $value string */ public function setHash($value) { - $this->validateNotNull('Hash', $value); - $this->validateString('Hash', $value); + $this->validateNotNull('hash', $value); + $this->validateString('hash', $value); if ($this->data['hash'] === $value) { return; @@ -332,15 +225,12 @@ class User extends Model } /** - * Set the value of Name / name. - * - * Must not be null. * @param $value string */ public function setName($value) { - $this->validateNotNull('Name', $value); - $this->validateString('Name', $value); + $this->validateNotNull('name', $value); + $this->validateString('name', $value); if ($this->data['name'] === $value) { return; @@ -352,15 +242,12 @@ class User extends Model } /** - * Set the value of IsAdmin / is_admin. - * - * Must not be null. * @param $value int */ public function setIsAdmin($value) { - $this->validateNotNull('IsAdmin', $value); - $this->validateInt('IsAdmin', $value); + $this->validateNotNull('is_admin', $value); + $this->validateInt('is_admin', $value); if ($this->data['is_admin'] === $value) { return; @@ -372,15 +259,12 @@ class User extends Model } /** - * Set the value of ProviderKey / provider_key. - * - * Must not be null. * @param $value string */ public function setProviderKey($value) { - $this->validateNotNull('ProviderKey', $value); - $this->validateString('ProviderKey', $value); + $this->validateNotNull('provider_key', $value); + $this->validateString('provider_key', $value); if ($this->data['provider_key'] === $value) { return; @@ -392,13 +276,11 @@ class User extends Model } /** - * Set the value of ProviderData / provider_data. - * * @param $value string */ public function setProviderData($value) { - $this->validateString('ProviderData', $value); + $this->validateString('provider_data', $value); if ($this->data['provider_data'] === $value) { return; @@ -410,13 +292,11 @@ class User extends Model } /** - * Set the value of RememberKey / remember_key. - * * @param $value string */ public function setRememberKey($value) { - $this->validateString('RememberKey', $value); + $this->validateString('remember_key', $value); if ($this->data['remember_key'] === $value) { return; @@ -428,9 +308,6 @@ class User extends Model } /** - * Set the value of Language / language. - * - * Must not be null. * @param $value string */ public function setLanguage($value) @@ -445,9 +322,6 @@ class User extends Model } /** - * Set the value of PerPage / per_page. - * - * Must not be null. * @param $value string */ public function setPerPage($value) 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/Service/BuildService.php b/src/PHPCensor/Service/BuildService.php index e4e0a67c..169b834d 100644 --- a/src/PHPCensor/Service/BuildService.php +++ b/src/PHPCensor/Service/BuildService.php @@ -36,11 +36,13 @@ class BuildService /** * @param Project $project * @param string $environment - * @param string|null $commitId + * @param string $commitId * @param string|null $branch * @param string|null $tag * @param string|null $committerEmail * @param string|null $commitMessage + * @param integer $source + * @param integer $userId * @param string|null $extra * * @return \PHPCensor\Model\Build @@ -48,15 +50,17 @@ class BuildService public function createBuild( Project $project, $environment, - $commitId = null, + $commitId = '', $branch = null, $tag = null, $committerEmail = null, $commitMessage = null, + $source = Build::SOURCE_UNKNOWN, + $userId = 0, $extra = null ) { $build = new Build(); - $build->setCreated(new \DateTime()); + $build->setCreateDate(new \DateTime()); $build->setProject($project); $build->setStatus(Build::STATUS_PENDING); $build->setEnvironment($environment); @@ -64,12 +68,9 @@ class BuildService $branches = $project->getBranchesByEnvironment($environment); $build->setExtraValue('branches', $branches); - if (!empty($commitId)) { - $build->setCommitId($commitId); - } else { - $build->setCommitId('Manual'); - $build->setCommitMessage('Manual'); - } + $build->setSource($source); + $build->setUserId($userId); + $build->setCommitId((string)$commitId); if (!empty($branch)) { $build->setBranch($branch); @@ -94,8 +95,7 @@ class BuildService } /** @var Build $build */ - $build = $this->buildStore->save($build); - + $build = $this->buildStore->save($build); $buildId = $build->getId(); if (!empty($buildId)) { @@ -119,12 +119,12 @@ class BuildService unset($data['id']); unset($data['status']); unset($data['log']); - unset($data['started']); - unset($data['finished']); + unset($data['start_date']); + unset($data['finish_date']); $build = new Build(); $build->setValues($data); - $build->setCreated(new \DateTime()); + $build->setCreateDate(new \DateTime()); $build->setStatus(Build::STATUS_PENDING); /** @var Build $build */ 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/Service/ProjectService.php b/src/PHPCensor/Service/ProjectService.php index f8887b4a..9d8628a7 100644 --- a/src/PHPCensor/Service/ProjectService.php +++ b/src/PHPCensor/Service/ProjectService.php @@ -25,16 +25,22 @@ class ProjectService /** * Create a new project model and use the project store to save it. - * @param string $title - * @param string $type - * @param string $reference - * @param array $options + * + * @param string $title + * @param string $type + * @param string $reference + * @param integer $userId + * @param array $options + * * @return \PHPCensor\Model\Project */ - public function createProject($title, $type, $reference, $options = []) + public function createProject($title, $type, $reference, $userId, $options = []) { // Create base project and use updateProject() to set its properties: $project = new Project(); + $project->setCreateDate(new \DateTime()); + $project->setUserId((integer)$userId); + return $this->updateProject($project, $title, $type, $reference, $options); } 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 4c6e11ad..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)) { @@ -44,52 +55,27 @@ class BuildMetaStore extends Store return null; } - /** - * Get multiple BuildMeta by ProjectId. - * @return array - */ - public function getByProjectId($value, $limit = 1000, $useConnection = 'read') - { - if (is_null($value)) { - throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); - } - - - $query = 'SELECT * FROM {{build_meta}} WHERE {{project_id}} = :project_id LIMIT :limit'; - $stmt = Database::getConnection($useConnection)->prepareCommon($query); - $stmt->bindValue(':project_id', $value); - $stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT); - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new BuildMeta($item); - }; - $rtn = array_map($map, $res); - - $count = count($rtn); - - return ['items' => $rtn, 'count' => $count]; - } else { - return ['items' => [], 'count' => 0]; - } - } - /** * Get multiple BuildMeta by BuildId. + * + * @param integer $buildId + * @param integer $limit + * @param string $useConnection + * * @return array + * + * @throws HttpException */ - public function getByBuildId($value, $limit = 1000, $useConnection = 'read') + public function getByBuildId($buildId, $limit = 1000, $useConnection = 'read') { - if (is_null($value)) { + if (is_null($buildId)) { throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } $query = 'SELECT * FROM {{build_meta}} WHERE {{build_id}} = :build_id LIMIT :limit'; $stmt = Database::getConnection($useConnection)->prepareCommon($query); - $stmt->bindValue(':build_id', $value); + $stmt->bindValue(':build_id', $buildId); $stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT); if ($stmt->execute()) { @@ -118,7 +104,7 @@ class BuildMetaStore extends Store public function getErrorsForUpgrade($limit) { $query = 'SELECT * FROM {{build_meta}} - WHERE {{meta_key}} IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\', \'technical_debt - data\') + WHERE {{meta_key}} IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\', \'technical_debt-data\') ORDER BY {{id}} ASC LIMIT :limit'; $stmt = Database::getConnection('read')->prepareCommon($query); diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 15c0a82d..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()) { @@ -117,10 +134,40 @@ class BuildStore extends Store } } + /** + * @param integer $limit + * @param integer $offset + * + * @return array + */ + public function getBuilds($limit = 5, $offset = 0) + { + $query = 'SELECT * FROM {{build}} ORDER BY {{id}} DESC LIMIT :limit OFFSET :offset'; + $stmt = Database::getConnection('read')->prepareCommon($query); + + $stmt->bindValue(':limit', $limit, \PDO::PARAM_INT); + $stmt->bindValue(':offset', $offset, \PDO::PARAM_INT); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return new Build($item); + }; + $rtn = array_map($map, $res); + + return $rtn; + } else { + return []; + } + } + /** * Return an array of the latest builds for a given project. - * @param null $projectId - * @param int $limit + * + * @param integer|null $projectId + * @param integer $limit + * * @return array */ public function getLatestBuilds($projectId = null, $limit = 5) @@ -155,8 +202,10 @@ class BuildStore extends Store /** * Return the latest build for a specific project, of a specific build status. - * @param null $projectId - * @param int $status + * + * @param integer|null $projectId + * @param integer $status + * * @return array|Build */ public function getLastBuildByStatus($projectId = null, $status = Build::STATUS_SUCCESS) @@ -209,8 +258,10 @@ class BuildStore extends Store /** * Returns all registered branches for project * - * @param $projectId + * @param integer $projectId + * * @return array + * * @throws \Exception */ public function getBuildBranches($projectId) @@ -229,11 +280,13 @@ class BuildStore extends Store /** * Return build metadata by key, project and optionally build id. - * @param $key - * @param $projectId - * @param null $buildId - * @param null $branch - * @param int $numResults + * + * @param string $key + * @param integer $projectId + * @param integer|null $buildId + * @param string|null $branch + * @param integer $numResults + * * @return array|null */ public function getMeta($key, $projectId, $buildId = null, $branch = null, $numResults = 1) @@ -241,8 +294,7 @@ class BuildStore extends Store $query = 'SELECT bm.build_id, bm.meta_key, bm.meta_value FROM {{build_meta}} AS {{bm}} LEFT JOIN {{build}} AS {{b}} ON b.id = bm.build_id - WHERE bm.meta_key = :key - AND bm.project_id = :projectId'; + WHERE bm.meta_key = :key AND b.project_id = :projectId'; // If we're getting comparative meta data, include previous builds // otherwise just include the specified build ID: @@ -290,20 +342,20 @@ class BuildStore extends Store /** * Set a metadata value for a given project and build ID. - * @param $projectId - * @param $buildId - * @param $key - * @param $value - * @return bool + * + * @param integer $buildId + * @param string $key + * @param string $value + * + * @return boolean */ - public function setMeta($projectId, $buildId, $key, $value) + public function setMeta($buildId, $key, $value) { - $cols = '{{project_id}}, {{build_id}}, {{meta_key}}, {{meta_value}}'; - $query = 'INSERT INTO {{build_meta}} ('.$cols.') VALUES (:projectId, :buildId, :key, :value)'; + $cols = '{{build_id}}, {{meta_key}}, {{meta_value}}'; + $query = 'INSERT INTO {{build_meta}} ('.$cols.') VALUES (:buildId, :key, :value)'; $stmt = Database::getConnection('read')->prepareCommon($query); $stmt->bindValue(':key', $key, \PDO::PARAM_STR); - $stmt->bindValue(':projectId', (int)$projectId, \PDO::PARAM_INT); $stmt->bindValue(':buildId', (int)$buildId, \PDO::PARAM_INT); $stmt->bindValue(':value', $value, \PDO::PARAM_STR); @@ -316,9 +368,11 @@ class BuildStore extends Store /** * Update status only if it synced with db - * @param Build $build - * @param int $status - * @return bool + * + * @param Build $build + * @param integer $status + * + * @return boolean */ public function updateStatusSync($build, $status) { 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()) { 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 60ba7d30..8288fd5a 100644 --- a/src/PHPCensor/View/Build/view.phtml +++ b/src/PHPCensor/View/Build/view.phtml @@ -1,4 +1,13 @@ - +
    @@ -78,10 +87,16 @@
    + + + + @@ -118,28 +133,28 @@
    + getSourceHumanize()); ?> +
    - + getCommitId(), 0, 7); ?>
    - 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 c7c80576..856f7dad 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(); ?>

    @@ -142,18 +142,18 @@ - getCreated()->format('Y-m-d H:i:s'); ?> + getCreateDate()->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 '—'; } ?> 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 ed9d1cf2..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; @@ -74,7 +78,7 @@ use PHPCensor\Model\Build; Build #getId(); ?> — - + getSourceHumanize()); ?>
      @@ -85,21 +89,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/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 cc5b9abc..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 + */ + ?>