From 4ec6d854c2f71a908110918806029ea1384aa304 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 15 Oct 2017 21:58:36 +0700 Subject: [PATCH] Added 'user_id' column to 'build' table (created by) + Renamed columns 'created' -> 'create_date', 'started' -> 'start_date' and 'finished' -> 'finish_date' + Code style fixes. --- public/assets/js/build.js | 4 +- src/B8Framework/Model.php | 18 +- src/PHPCensor/Builder.php | 4 +- src/PHPCensor/Command/RunCommand.php | 6 +- .../Command/ScheduleBuildCommand.php | 2 +- src/PHPCensor/Controller/BuildController.php | 18 +- .../Controller/ProjectController.php | 6 +- .../Controller/WebhookController.php | 2 + ...0171015123827_added_additional_columns.php | 68 ++ src/PHPCensor/Model/Build.php | 847 +++++++++--------- src/PHPCensor/Model/BuildError.php | 86 +- src/PHPCensor/Model/BuildMeta.php | 46 +- src/PHPCensor/Model/Environment.php | 34 +- src/PHPCensor/Model/Project.php | 129 +-- src/PHPCensor/Model/ProjectGroup.php | 20 +- src/PHPCensor/Model/User.php | 76 +- src/PHPCensor/Service/BuildService.php | 7 +- src/PHPCensor/Service/BuildStatusService.php | 2 +- src/PHPCensor/View/Build/header-row.phtml | 15 +- src/PHPCensor/View/Build/view.phtml | 19 +- src/PHPCensor/View/BuildStatus/view.phtml | 2 +- .../View/Home/ajax-dashboard-project.phtml | 18 +- src/PHPCensor/View/Home/ajax-timeline.phtml | 14 +- .../View/Home/dashboard-projects.phtml | 18 +- src/PHPCensor/View/Home/index.phtml | 14 +- src/PHPCensor/View/Project/ajax-builds.phtml | 2 +- src/PHPCensor/Worker/BuildWorker.php | 2 +- tests/PHPCensor/Service/BuildServiceTest.php | 16 +- .../Service/BuiltStatusServiceTest.php | 4 +- 29 files changed, 694 insertions(+), 805 deletions(-) create mode 100644 src/PHPCensor/Migrations/20171015123827_added_additional_columns.php diff --git a/public/assets/js/build.js b/public/assets/js/build.js index bfe55494..9229a512 100644 --- a/public/assets/js/build.js +++ b/public/assets/js/build.js @@ -30,8 +30,8 @@ var Build = Class.extend({ if (self.buildData) { $('.build-duration').html(self.buildData.duration ? (self.buildData.duration + ' ' + Lang.get('seconds')) : ('0 ' + Lang.get('seconds'))); - $('.build-started').html(self.buildData.started ? self.buildData.started : ''); - $('.build-finished').html(self.buildData.finished ? self.buildData.finished : ''); + $('.build-started').html(self.buildData.start_date ? self.buildData.start_date : ''); + $('.build-finished').html(self.buildData.finish_date ? self.buildData.finish_date : ''); $('#log pre').html(self.buildData.log); $('.errors-table tbody').html(self.buildData.error_html); diff --git a/src/B8Framework/Model.php b/src/B8Framework/Model.php index d7eb3497..929a8ed3 100644 --- a/src/B8Framework/Model.php +++ b/src/B8Framework/Model.php @@ -76,8 +76,9 @@ class Model $rtn = $childArray; } else { - $rtn = (is_string($value) && !mb_check_encoding($value, 'UTF-8')) ? mb_convert_encoding($value, - 'UTF-8') : $value; + $rtn = (is_string($value) && !mb_check_encoding($value, 'UTF-8')) + ? mb_convert_encoding($value, 'UTF-8') + : $value; } } @@ -121,7 +122,7 @@ class Model protected function validateString($name, $value) { if (!is_string($value) && !is_null($value)) { - throw new HttpException\ValidationException($name . ' must be a string.'); + throw new HttpException\ValidationException('Column "', $name . '" must be a string.'); } } @@ -132,7 +133,7 @@ class Model } if (!is_numeric($value) && !is_null($value)) { - throw new HttpException\ValidationException($name . ' must be an integer.'); + throw new HttpException\ValidationException('Column "', $name . '" must be an integer.'); } if (!is_int($value) && !is_null($value)) { @@ -143,7 +144,7 @@ class Model protected function validateFloat($name, &$value) { if (!is_numeric($value) && !is_null($value)) { - throw new HttpException\ValidationException($name . ' must be a float.'); + throw new HttpException\ValidationException('Column "', $name . '" must be a float.'); } if (!is_float($value) && !is_null($value)) { @@ -158,17 +159,16 @@ class Model } if ((!is_object($value) || !($value instanceof \DateTime)) && !is_null($value)) { - throw new HttpException\ValidationException($name . ' must be a date object.'); + throw new HttpException\ValidationException('Column "', $name . '" must be a date object.'); } - $value = empty($value) ? null : $value->format('Y-m-d H:i:s'); } - protected function validateNotNull($name, &$value) + protected function validateNotNull($name, $value) { if (is_null($value)) { - throw new HttpException\ValidationException($name . ' must not be null.'); + throw new HttpException\ValidationException('Column "', $name . '" must not be null.'); } } diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index 37e8496e..09fe5233 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -185,7 +185,7 @@ class Builder implements LoggerAwareInterface } // Update the build in the database, ping any external services. - $this->build->setStarted(new \DateTime()); + $this->build->setStartDate(new \DateTime()); $this->store->save($this->build); $this->build->sendStatusPostback(); $success = true; @@ -256,7 +256,7 @@ class Builder implements LoggerAwareInterface // Update the build in the database, ping any external services, etc. $this->build->sendStatusPostback(); - $this->build->setFinished(new \DateTime()); + $this->build->setFinishDate(new \DateTime()); $removeBuilds = (bool)Config::getInstance()->get('php-censor.build.remove_builds', true); if ($removeBuilds) { diff --git a/src/PHPCensor/Command/RunCommand.php b/src/PHPCensor/Command/RunCommand.php index 1ae13d51..2ff7f563 100644 --- a/src/PHPCensor/Command/RunCommand.php +++ b/src/PHPCensor/Command/RunCommand.php @@ -114,7 +114,7 @@ class RunCommand extends Command $this->logger->addError($ex->getMessage()); $build->setStatus(Build::STATUS_FAILED); - $build->setFinished(new \DateTime()); + $build->setFinishDate(new \DateTime()); $build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage()); $buildStore->save($build); $build->sendStatusPostback(); @@ -154,12 +154,12 @@ class RunCommand extends Command $build = BuildFactory::getBuild($build); $now = time(); - $start = $build->getStarted()->getTimestamp(); + $start = $build->getStartDate()->getTimestamp(); if (($now - $start) > $timeout) { $this->logger->addInfo(sprintf('Build %d marked as failed due to timeout.', $build->getId())); $build->setStatus(Build::STATUS_FAILED); - $build->setFinished(new \DateTime()); + $build->setFinishDate(new \DateTime()); $store->save($build); $build->removeBuildDirectory(); continue; diff --git a/src/PHPCensor/Command/ScheduleBuildCommand.php b/src/PHPCensor/Command/ScheduleBuildCommand.php index 1f76df63..57c02f9f 100644 --- a/src/PHPCensor/Command/ScheduleBuildCommand.php +++ b/src/PHPCensor/Command/ScheduleBuildCommand.php @@ -83,7 +83,7 @@ class ScheduleBuildCommand extends Command // If it's running or just created, we don't want to reschedule already. continue; } - if ($date < $build->getFinished()) { + if ($date < $build->getFinishDate()) { // If finished date is newer then the specified since days, we don't want to reschedule continue; } diff --git a/src/PHPCensor/Controller/BuildController.php b/src/PHPCensor/Controller/BuildController.php index 297aa138..d8435d17 100644 --- a/src/PHPCensor/Controller/BuildController.php +++ b/src/PHPCensor/Controller/BuildController.php @@ -125,20 +125,20 @@ class BuildController extends Controller */ protected function getBuildData(Build $build) { - $data = []; - $data['status'] = (int)$build->getStatus(); - $data['log'] = $this->cleanLog($build->getLog()); - $data['created'] = !is_null($build->getCreated()) ? $build->getCreated()->format('Y-m-d H:i:s') : null; - $data['started'] = !is_null($build->getStarted()) ? $build->getStarted()->format('Y-m-d H:i:s') : null; - $data['finished'] = !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : null; - $data['duration'] = $build->getDuration(); + $data = []; + $data['status'] = (int)$build->getStatus(); + $data['log'] = $this->cleanLog($build->getLog()); + $data['create_date'] = !is_null($build->getCreateDate()) ? $build->getCreateDate()->format('Y-m-d H:i:s') : null; + $data['start_date'] = !is_null($build->getStartDate()) ? $build->getStartDate()->format('Y-m-d H:i:s') : null; + $data['finish_date'] = !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : null; + $data['duration'] = $build->getDuration(); /** @var \PHPCensor\Store\BuildErrorStore $errorStore */ $errorStore = b8\Store\Factory::getStore('BuildError'); $errors = $errorStore->getErrorsForBuild($build->getId()); - $errorView = new b8\View('Build/errors'); - $errorView->build = $build; + $errorView = new b8\View('Build/errors'); + $errorView->build = $build; $errorView->errors = $errors; $data['errors'] = $errorStore->getErrorTotalForBuild($build->getId()); diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index e78317b1..96299a42 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -173,16 +173,18 @@ class ProjectController extends PHPCensor\Controller ]; } - $email = $_SESSION['php-censor-user']->getEmail(); + /** @var PHPCensor\Model\User $user */ + $user = $_SESSION['php-censor-user']; $build = $this->buildService->createBuild( $project, $environment, '', $branch, null, - $email, + $user->getEmail(), null, Build::SOURCE_MANUAL_WEB, + $user->getId(), $extra ); diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index 4e040bbf..afa43337 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -666,6 +666,7 @@ class WebhookController extends Controller $committer, $commitMessage, Build::SOURCE_WEBHOOK, + 0, $extra ); @@ -704,6 +705,7 @@ class WebhookController extends Controller $committer, $commitMessage, Build::SOURCE_WEBHOOK, + 0, $extra ); diff --git a/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php b/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php new file mode 100644 index 00000000..8cf3454b --- /dev/null +++ b/src/PHPCensor/Migrations/20171015123827_added_additional_columns.php @@ -0,0 +1,68 @@ +table('build'); + + if (!$table->hasColumn('user_id')) { + $table + ->addColumn('user_id', 'integer', ['default' => 0]) + ->save(); + } + + $table = $this->table('build'); + + if ($table->hasColumn('created')) { + $table + ->renameColumn('created', 'create_date') + ->save(); + } + + if ($table->hasColumn('started')) { + $table + ->renameColumn('started', 'start_date') + ->save(); + } + + if ($table->hasColumn('finished')) { + $table + ->renameColumn('finished', 'finish_date') + ->save(); + } + } + + public function down() + { + $table = $this->table('build'); + + if ($table->hasColumn('user_id')) { + $table + ->removeColumn('user_id') + ->save(); + } + + $table = $this->table('build'); + + if ($table->hasColumn('create_date')) { + $table + ->renameColumn('create_date', 'created') + ->save(); + } + + if ($table->hasColumn('start_date')) { + $table + ->renameColumn('start_date', 'started') + ->save(); + } + + if ($table->hasColumn('finish_date')) { + $table + ->renameColumn('finish_date', 'finished') + ->save(); + } + } +} diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index 4c62d4c3..f2aadc90 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -21,10 +21,10 @@ class Build extends Model const STAGE_FIXED = 'fixed'; const STAGE_BROKEN = 'broken'; - const STATUS_PENDING = 0; - const STATUS_RUNNING = 1; - const STATUS_SUCCESS = 2; - const STATUS_FAILED = 3; + const STATUS_PENDING = 0; + const STATUS_RUNNING = 1; + const STATUS_SUCCESS = 2; + const STATUS_FAILED = 3; const SOURCE_UNKNOWN = 0; const SOURCE_MANUAL_WEB = 1; @@ -58,14 +58,15 @@ class Build extends Model 'log' => null, 'branch' => null, 'tag' => null, - 'created' => null, - 'started' => null, - 'finished' => null, + 'create_date' => null, + 'start_date' => null, + 'finish_date' => null, 'committer_email' => null, 'commit_message' => null, 'extra' => null, 'environment' => null, 'source' => Build::SOURCE_UNKNOWN, + 'user_id' => 0, ]; /** @@ -80,14 +81,15 @@ class Build extends Model 'log' => 'getLog', 'branch' => 'getBranch', 'tag' => 'getTag', - 'created' => 'getCreated', - 'started' => 'getStarted', - 'finished' => 'getFinished', + 'create_date' => 'getCreateDate', + 'start_date' => 'getStartDate', + 'finish_date' => 'getFinishDate', 'committer_email' => 'getCommitterEmail', 'commit_message' => 'getCommitMessage', 'extra' => 'getExtra', 'environment' => 'getEnvironment', 'source' => 'getSource', + 'user_id' => 'getUserId', // Foreign key getters: 'Project' => 'getProject', @@ -105,22 +107,21 @@ class Build extends Model 'log' => 'setLog', 'branch' => 'setBranch', 'setTag' => 'setTag', - 'created' => 'setCreated', - 'started' => 'setStarted', - 'finished' => 'setFinished', + 'create_date' => 'setCreateDate', + 'start_date' => 'setStartDate', + 'finish_date' => 'setFinishDate', 'committer_email' => 'setCommitterEmail', 'commit_message' => 'setCommitMessage', 'extra' => 'setExtra', 'environment' => 'setEnvironment', 'source' => 'setSource', + 'user_id' => 'setUserId', // Foreign key setters: 'Project' => 'setProject', ]; /** - * Get the value of Id / id. - * * @return integer */ public function getId() @@ -131,134 +132,12 @@ class Build extends Model } /** - * Get the value of ProjectId / project_id. - * - * @return integer - */ - public function getProjectId() - { - $rtn = $this->data['project_id']; - - return (integer)$rtn; - } - - /** - * Get the value of CommitId / commit_id. - * - * @return string - */ - public function getCommitId() - { - $rtn = $this->data['commit_id']; - - return $rtn; - } - - /** - * Get the value of Status / status. - * - * @return integer - */ - public function getStatus() - { - $rtn = $this->data['status']; - - return (integer)$rtn; - } - - /** - * Get the value of Log / log. - * - * @return string - */ - public function getLog() - { - $rtn = $this->data['log']; - - return $rtn; - } - - /** - * Get the value of Branch / branch. - * - * @return string - */ - public function getBranch() - { - $rtn = $this->data['branch']; - - return $rtn; - } - - /** - * Get the value of Created / created. - * - * @return \DateTime - */ - public function getCreated() - { - $rtn = $this->data['created']; - - if (!empty($rtn)) { - $rtn = new \DateTime($rtn); - } - - return $rtn; - } - - /** - * Get the value of Started / started. - * - * @return \DateTime - */ - public function getStarted() - { - $rtn = $this->data['started']; - - if (!empty($rtn)) { - $rtn = new \DateTime($rtn); - } - - return $rtn; - } - - /** - * Get the value of Finished / finished. - * - * @return \DateTime - */ - public function getFinished() - { - $rtn = $this->data['finished']; - - if (!empty($rtn)) { - $rtn = new \DateTime($rtn); - } - - return $rtn; - } - - /** - * Get the value of CommitterEmail / committer_email. - * - * @return string - */ - public function getCommitterEmail() - { - $rtn = $this->data['committer_email']; - - return $rtn; - } - - /** - * Set the value of Id / id. Must not be null. - * * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -270,14 +149,22 @@ class Build extends Model } /** - * Set the value of ProjectId / project_id. Must not be null. - * + * @return integer + */ + public function getProjectId() + { + $rtn = $this->data['project_id']; + + return (integer)$rtn; + } + + /** * @param $value int */ public function setProjectId($value) { - $this->validateNotNull('ProjectId', $value); - $this->validateInt('ProjectId', $value); + $this->validateNotNull('project_id', $value); + $this->validateInt('project_id', $value); if ($this->data['project_id'] === $value) { return; @@ -289,14 +176,22 @@ class Build extends Model } /** - * Set the value of CommitId / commit_id. Must not be null. - * + * @return string + */ + public function getCommitId() + { + $rtn = $this->data['commit_id']; + + return $rtn; + } + + /** * @param $value string */ public function setCommitId($value) { - $this->validateNotNull('CommitId', $value); - $this->validateString('CommitId', $value); + $this->validateNotNull('commit_id', $value); + $this->validateString('commit_id', $value); if ($this->data['commit_id'] === $value) { return; @@ -308,14 +203,22 @@ class Build extends Model } /** - * Set the value of Status / status. Must not be null. - * + * @return integer + */ + public function getStatus() + { + $rtn = $this->data['status']; + + return (integer)$rtn; + } + + /** * @param $value int */ public function setStatus($value) { - $this->validateNotNull('Status', $value); - $this->validateInt('Status', $value); + $this->validateNotNull('status', $value); + $this->validateInt('status', $value); if ($this->data['status'] === $value) { return; @@ -327,15 +230,315 @@ class Build extends Model } /** - * Set the value of Status / status only if it synced with db. Must not be null. + * @return string + */ + public function getLog() + { + $rtn = $this->data['log']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setLog($value) + { + $this->validateString('log', $value); + + if ($this->data['log'] === $value) { + return; + } + + $this->data['log'] = $value; + + $this->setModified('log'); + } + + /** + * @return string + */ + public function getBranch() + { + $rtn = $this->data['branch']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setBranch($value) + { + $this->validateNotNull('branch', $value); + $this->validateString('branch', $value); + + if ($this->data['branch'] === $value) { + return; + } + + $this->data['branch'] = $value; + + $this->setModified('branch'); + } + + /** + * @return \DateTime + */ + public function getCreateDate() + { + $rtn = $this->data['create_date']; + + if (!empty($rtn)) { + $rtn = new \DateTime($rtn); + } + + return $rtn; + } + + /** + * @param $value \DateTime + */ + public function setCreateDate($value) + { + $this->validateDate('create_date', $value); + + if ($this->data['create_date'] === $value) { + return; + } + + $this->data['create_date'] = $value; + + $this->setModified('create_date'); + } + + /** + * @return \DateTime + */ + public function getStartDate() + { + $rtn = $this->data['start_date']; + + if (!empty($rtn)) { + $rtn = new \DateTime($rtn); + } + + return $rtn; + } + + /** + * @param $value \DateTime + */ + public function setStartDate($value) + { + $this->validateDate('start_date', $value); + + if ($this->data['start_date'] === $value) { + return; + } + + $this->data['start_date'] = $value; + + $this->setModified('start_date'); + } + + /** + * @return \DateTime + */ + public function getFinishDate() + { + $rtn = $this->data['finish_date']; + + if (!empty($rtn)) { + $rtn = new \DateTime($rtn); + } + + return $rtn; + } + + /** + * @param $value \DateTime + */ + public function setFinishDate($value) + { + $this->validateDate('finish_date', $value); + + if ($this->data['finish_date'] === $value) { + return; + } + + $this->data['finish_date'] = $value; + + $this->setModified('finish_date'); + } + + /** + * @return string + */ + public function getCommitterEmail() + { + $rtn = $this->data['committer_email']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setCommitterEmail($value) + { + $this->validateString('committer_email', $value); + + if ($this->data['committer_email'] === $value) { + return; + } + + $this->data['committer_email'] = $value; + + $this->setModified('committer_email'); + } + + /** + * @return string + */ + public function getCommitMessage() + { + $rtn = htmlspecialchars($this->data['commit_message']); + + return $rtn; + } + + /** + * @param $value string + */ + public function setCommitMessage($value) + { + $this->validateString('commit_message', $value); + + if ($this->data['commit_message'] === $value) { + return; + } + + $this->data['commit_message'] = $value; + + $this->setModified('commit_message'); + } + + /** + * @return string + */ + public function getTag() + { + $rtn = $this->data['tag']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setTag($value) + { + $this->validateString('tag', $value); + + if ($this->data['tag'] === $value) { + return; + } + + $this->data['tag'] = $value; + + $this->setModified('tag'); + } + + /** + * @return string + */ + public function getSource() + { + $rtn = $this->data['source']; + + return (integer)$rtn; + } + + /** + * @param $value integer + */ + public function setSource($value) + { + $this->validateInt('source', $value); + + if ($this->data['source'] === $value) { + return; + } + + $this->data['source'] = $value; + + $this->setModified('source'); + } + + /** + * @return string + */ + public function getUserId() + { + $rtn = $this->data['user_id']; + + return (integer)$rtn; + } + + /** + * @param $value integer + */ + public function setUserId($value) + { + $this->validateNotNull('user_id', $value); + $this->validateInt('user_id', $value); + + if ($this->data['user_id'] === $value) { + return; + } + + $this->data['user_id'] = $value; + + $this->setModified('user_id'); + } + + /** + * @return string + */ + public function getEnvironment() + { + $rtn = $this->data['environment']; + + return $rtn; + } + + /** + * @param $value string + */ + public function setEnvironment($value) + { + $this->validateString('environment', $value); + + if ($this->data['environment'] === $value) { + return; + } + + $this->data['environment'] = $value; + + $this->setModified('environment'); + } + + /** + * Set the value of status only if it synced with db. Must not be null. * * @param $value int * @return bool */ public function setStatusSync($value) { - $this->validateNotNull('Status', $value); - $this->validateInt('Status', $value); + $this->validateNotNull('status', $value); + $this->validateInt('status', $value); if ($this->data['status'] !== $value) { $store = Factory::getStore('Build'); @@ -347,185 +550,11 @@ class Build extends Model return false; } - /** - * Set the value of Log / log. - * - * @param $value string - */ - public function setLog($value) - { - $this->validateString('Log', $value); - - if ($this->data['log'] === $value) { - return; - } - - $this->data['log'] = $value; - - $this->setModified('log'); - } - - /** - * Set the value of Branch / branch. Must not be null. - * - * @param $value string - */ - public function setBranch($value) - { - $this->validateNotNull('Branch', $value); - $this->validateString('Branch', $value); - - if ($this->data['branch'] === $value) { - return; - } - - $this->data['branch'] = $value; - - $this->setModified('branch'); - } - - /** - * Set the value of Created / created. - * - * @param $value \DateTime - */ - public function setCreated($value) - { - $this->validateDate('Created', $value); - - if ($this->data['created'] === $value) { - return; - } - - $this->data['created'] = $value; - - $this->setModified('created'); - } - - /** - * Set the value of Started / started. - * - * @param $value \DateTime - */ - public function setStarted($value) - { - $this->validateDate('Started', $value); - - if ($this->data['started'] === $value) { - return; - } - - $this->data['started'] = $value; - - $this->setModified('started'); - } - - /** - * Set the value of Finished / finished. - * - * @param $value \DateTime - */ - public function setFinished($value) - { - $this->validateDate('Finished', $value); - - if ($this->data['finished'] === $value) { - return; - } - - $this->data['finished'] = $value; - - $this->setModified('finished'); - } - - /** - * Set the value of CommitterEmail / committer_email. - * - * @param $value string - */ - public function setCommitterEmail($value) - { - $this->validateString('CommitterEmail', $value); - - if ($this->data['committer_email'] === $value) { - return; - } - - $this->data['committer_email'] = $value; - - $this->setModified('committer_email'); - } - - /** - * Set the value of CommitMessage / commit_message. - * - * @param $value string - */ - public function setCommitMessage($value) - { - $this->validateString('CommitMessage', $value); - - if ($this->data['commit_message'] === $value) { - return; - } - - $this->data['commit_message'] = $value; - - $this->setModified('commit_message'); - } - - /** - * Set the value of Extra / extra. - * - * @param $value string - */ - public function setExtra($value) - { - $this->validateString('Extra', $value); - - if ($this->data['extra'] === $value) { - return; - } - - $this->data['extra'] = $value; - - $this->setModified('extra'); - } - - /** - * Set the value of Extra / extra. - * - * @param $name string - * @param $value mixed - */ - public function setExtraValue($name, $value) - { - $extra = json_decode($this->data['extra'], true); - if ($extra === false) { - $extra = []; - } - $extra[$name] = $value; - $this->setExtra(json_encode($extra)); - } - - /** - * Set the values of Extra / extra. - * - * @param $values mixed - */ - public function setExtraValues($values) - { - $extra = json_decode($this->data['extra'], true); - if ($extra === false) { - $extra = []; - } - $extra = array_replace($extra, $values); - $this->setExtra(json_encode($extra)); - } - /** * Return a value from the build's "extra" JSON array. + * * @param null $key + * * @return mixed|null|string */ public function getExtra($key = null) @@ -543,6 +572,53 @@ class Build extends Model return $rtn; } + /** + * @param $value string + */ + public function setExtra($value) + { + $this->validateString('extra', $value); + + if ($this->data['extra'] === $value) { + return; + } + + $this->data['extra'] = $value; + + $this->setModified('extra'); + } + + /** + * Set the value of extra. + * + * @param $name string + * @param $value mixed + */ + public function setExtraValue($name, $value) + { + $extra = json_decode($this->data['extra'], true); + if ($extra === false) { + $extra = []; + } + $extra[$name] = $value; + $this->setExtra(json_encode($extra)); + } + + /** + * Set the values of extra. + * + * @param $values mixed + */ + public function setExtraValues($values) + { + $extra = json_decode($this->data['extra'], true); + if ($extra === false) { + $extra = []; + } + $extra = array_replace($extra, $values); + $this->setExtra(json_encode($extra)); + } + /** * Get the Project model for this Build by Id. * @@ -764,17 +840,6 @@ class Build extends Model return $config; } - /** - * Returns the commit message for this build. - * @return string - */ - public function getCommitMessage() - { - $rtn = htmlspecialchars($this->data['commit_message']); - - return $rtn; - } - /** * Allows specific build types (e.g. Github) to report violations back to their respective services. * @param Builder $builder @@ -852,17 +917,18 @@ class Build extends Model /** * Get the number of seconds a build has been running for. + * * @return int */ public function getDuration() { - $start = $this->getStarted(); + $start = $this->getStartDate(); if (empty($start)) { return 0; } - $end = $this->getFinished(); + $end = $this->getFinishDate(); if (empty($end)) { $end = new \DateTime(); @@ -873,15 +939,16 @@ class Build extends Model /** * get time a build has been running for in hour/minute/seconds format (e.g. 1h 21m 45s) + * * @return string */ public function getPrettyDuration() { - $start = $this->getStarted(); + $start = $this->getStartDate(); if (!$start) { $start = new \DateTime(); } - $end = $this->getFinished(); + $end = $this->getFinishDate(); if (!$end) { $end = new \DateTime(); } @@ -910,96 +977,6 @@ class Build extends Model return false; } - /** - * Get the value of Tag / tag. - * - * @return string - */ - public function getTag() - { - $rtn = $this->data['tag']; - - return $rtn; - } - - /** - * Set the value of Tag / tag. - * - * @param $value string - */ - public function setTag($value) - { - $this->validateString('Tag', $value); - - if ($this->data['tag'] === $value) { - return; - } - - $this->data['tag'] = $value; - - $this->setModified('tag'); - } - - /** - * Get the value of source. - * - * @return string - */ - public function getSource() - { - $rtn = $this->data['source']; - - return (integer)$rtn; - } - - /** - * Set the value of source. - * - * @param $value integer - */ - public function setSource($value) - { - $this->validateInt('Source', $value); - - if ($this->data['source'] === $value) { - return; - } - - $this->data['source'] = $value; - - $this->setModified('source'); - } - - /** - * Get the value of Environment / environment. - * - * @return string - */ - public function getEnvironment() - { - $rtn = $this->data['environment']; - - return $rtn; - } - - /** - * Set the value of Environment / environment. - * - * @param $value string - */ - public function setEnvironment($value) - { - $this->validateString('Environment', $value); - - if ($this->data['environment'] === $value) { - return; - } - - $this->data['environment'] = $value; - - $this->setModified('environment'); - } - /** * Create an SSH key file on disk for this build. * diff --git a/src/PHPCensor/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index 135aeecc..a24ca754 100644 --- a/src/PHPCensor/Model/BuildError.php +++ b/src/PHPCensor/Model/BuildError.php @@ -7,6 +7,11 @@ use b8\Store\Factory; class BuildError extends Model { + const SEVERITY_CRITICAL = 0; + const SEVERITY_HIGH = 1; + const SEVERITY_NORMAL = 2; + const SEVERITY_LOW = 3; + /** * @var array */ @@ -76,8 +81,6 @@ class BuildError extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -88,8 +91,6 @@ class BuildError extends Model } /** - * Get the value of BuildId / build_id. - * * @return int */ public function getBuildId() @@ -100,8 +101,6 @@ class BuildError extends Model } /** - * Get the value of Plugin / plugin. - * * @return string */ public function getPlugin() @@ -112,8 +111,6 @@ class BuildError extends Model } /** - * Get the value of File / file. - * * @return string */ public function getFile() @@ -124,8 +121,6 @@ class BuildError extends Model } /** - * Get the value of LineStart / line_start. - * * @return int */ public function getLineStart() @@ -136,8 +131,6 @@ class BuildError extends Model } /** - * Get the value of LineEnd / line_end. - * * @return int */ public function getLineEnd() @@ -148,8 +141,6 @@ class BuildError extends Model } /** - * Get the value of Severity / severity. - * * @return int */ public function getSeverity() @@ -160,8 +151,6 @@ class BuildError extends Model } /** - * Get the value of Message / message. - * * @return string */ public function getMessage() @@ -172,8 +161,6 @@ class BuildError extends Model } /** - * Get the value of CreatedDate / created_date. - * * @return \DateTime */ public function getCreatedDate() @@ -188,15 +175,12 @@ class BuildError extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -208,15 +192,12 @@ class BuildError extends Model } /** - * Set the value of BuildId / build_id. - * - * Must not be null. * @param $value int */ public function setBuildId($value) { - $this->validateNotNull('BuildId', $value); - $this->validateInt('BuildId', $value); + $this->validateNotNull('build_id', $value); + $this->validateInt('build_id', $value); if ($this->data['build_id'] === $value) { return; @@ -228,15 +209,12 @@ class BuildError extends Model } /** - * Set the value of Plugin / plugin. - * - * Must not be null. * @param $value string */ public function setPlugin($value) { - $this->validateNotNull('Plugin', $value); - $this->validateString('Plugin', $value); + $this->validateNotNull('plugin', $value); + $this->validateString('plugin', $value); if ($this->data['plugin'] === $value) { return; @@ -248,13 +226,11 @@ class BuildError extends Model } /** - * Set the value of File / file. - * * @param $value string */ public function setFile($value) { - $this->validateString('File', $value); + $this->validateString('file', $value); if ($this->data['file'] === $value) { return; @@ -266,13 +242,11 @@ class BuildError extends Model } /** - * Set the value of LineStart / line_start. - * * @param $value int */ public function setLineStart($value) { - $this->validateInt('LineStart', $value); + $this->validateInt('line_start', $value); if ($this->data['line_start'] === $value) { return; @@ -284,13 +258,11 @@ class BuildError extends Model } /** - * Set the value of LineEnd / line_end. - * * @param $value int */ public function setLineEnd($value) { - $this->validateInt('LineEnd', $value); + $this->validateInt('line_end', $value); if ($this->data['line_end'] === $value) { return; @@ -302,15 +274,12 @@ class BuildError extends Model } /** - * Set the value of Severity / severity. - * - * Must not be null. * @param $value int */ public function setSeverity($value) { - $this->validateNotNull('Severity', $value); - $this->validateInt('Severity', $value); + $this->validateNotNull('severity', $value); + $this->validateInt('severity', $value); if ($this->data['severity'] === $value) { return; @@ -322,15 +291,12 @@ class BuildError extends Model } /** - * Set the value of Message / message. - * - * Must not be null. * @param $value string */ public function setMessage($value) { - $this->validateNotNull('Message', $value); - $this->validateString('Message', $value); + $this->validateNotNull('message', $value); + $this->validateString('message', $value); if ($this->data['message'] === $value) { return; @@ -342,15 +308,12 @@ class BuildError extends Model } /** - * Set the value of CreatedDate / created_date. - * - * Must not be null. * @param $value \DateTime */ public function setCreatedDate($value) { - $this->validateNotNull('CreatedDate', $value); - $this->validateDate('CreatedDate', $value); + $this->validateNotNull('created_date', $value); + $this->validateDate('created_date', $value); if ($this->data['created_date'] === $value) { return; @@ -364,8 +327,6 @@ class BuildError extends Model /** * Get the Build model for this BuildError by Id. * - * @uses \PHPCensor\Store\BuildStore::getById() - * @uses \PHPCensor\Model\Build * @return \PHPCensor\Model\Build */ public function getBuild() @@ -418,13 +379,9 @@ class BuildError extends Model return $this->setBuildId($value->getId()); } - const SEVERITY_CRITICAL = 0; - const SEVERITY_HIGH = 1; - const SEVERITY_NORMAL = 2; - const SEVERITY_LOW = 3; - /** * Get the language string key for this error's severity level. + * * @return string */ public function getSeverityString() @@ -446,6 +403,7 @@ class BuildError extends Model /** * Get the class to apply to HTML elements representing this error. + * * @return string */ public function getSeverityClass() diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index 7ef1475e..0efa761c 100644 --- a/src/PHPCensor/Model/BuildMeta.php +++ b/src/PHPCensor/Model/BuildMeta.php @@ -61,8 +61,6 @@ class BuildMeta extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -73,8 +71,6 @@ class BuildMeta extends Model } /** - * Get the value of BuildId / build_id. - * * @return int */ public function getBuildId() @@ -85,8 +81,6 @@ class BuildMeta extends Model } /** - * Get the value of MetaKey / meta_key. - * * @return string */ public function getMetaKey() @@ -97,8 +91,6 @@ class BuildMeta extends Model } /** - * Get the value of MetaValue / meta_value. - * * @return string */ public function getMetaValue() @@ -109,15 +101,12 @@ class BuildMeta extends Model } /** - * Set the value of Id / id. - * - * Must not be null. - * @param $value int + * @param int $value */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -129,15 +118,12 @@ class BuildMeta extends Model } /** - * Set the value of BuildId / build_id. - * - * Must not be null. - * @param $value int + * @param int $value */ public function setBuildId($value) { - $this->validateNotNull('BuildId', $value); - $this->validateInt('BuildId', $value); + $this->validateNotNull('build_id', $value); + $this->validateInt('build_id', $value); if ($this->data['build_id'] === $value) { return; @@ -149,15 +135,12 @@ class BuildMeta extends Model } /** - * Set the value of MetaKey / meta_key. - * - * Must not be null. * @param $value string */ public function setMetaKey($value) { - $this->validateNotNull('MetaKey', $value); - $this->validateString('MetaKey', $value); + $this->validateNotNull('meta_key', $value); + $this->validateString('meta_key', $value); if ($this->data['meta_key'] === $value) { return; @@ -169,15 +152,12 @@ class BuildMeta extends Model } /** - * Set the value of MetaValue / meta_value. - * - * Must not be null. * @param $value string */ public function setMetaValue($value) { - $this->validateNotNull('MetaValue', $value); - $this->validateString('MetaValue', $value); + $this->validateNotNull('meta_value', $value); + $this->validateString('meta_value', $value); if ($this->data['meta_value'] === $value) { return; @@ -191,8 +171,6 @@ class BuildMeta extends Model /** * Get the Build model for this BuildMeta by Id. * - * @uses \PHPCensor\Store\BuildStore::getById() - * @uses \PHPCensor\Model\Build * @return \PHPCensor\Model\Build */ public function getBuild() @@ -203,8 +181,8 @@ class BuildMeta extends Model return null; } - $cacheKey = 'Cache.Build.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'Cache.Build.' . $key; + $rtn = $this->cache->get($cacheKey, null); if (empty($rtn)) { $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); diff --git a/src/PHPCensor/Model/Environment.php b/src/PHPCensor/Model/Environment.php index ece87a98..e70da4ee 100644 --- a/src/PHPCensor/Model/Environment.php +++ b/src/PHPCensor/Model/Environment.php @@ -52,8 +52,6 @@ class Environment extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -64,8 +62,6 @@ class Environment extends Model } /** - * Get the value of Id / id. - * * @return int */ public function getProjectId() @@ -76,8 +72,6 @@ class Environment extends Model } /** - * Get the value of Title / title. - * * @return string */ public function getName() @@ -88,8 +82,6 @@ class Environment extends Model } /** - * Get the value of Title / title. - * * @return array */ public function getBranches() @@ -100,15 +92,12 @@ class Environment extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -120,15 +109,12 @@ class Environment extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setProjectId($value) { - $this->validateNotNull('ProjectId', $value); - $this->validateInt('ProjectId', $value); + $this->validateNotNull('project_id', $value); + $this->validateInt('project_id', $value); if ($this->data['project_id'] === $value) { return; @@ -140,15 +126,12 @@ class Environment extends Model } /** - * Set the value of Name / name - * - * Must not be null. * @param $value string */ public function setName($value) { - $this->validateNotNull('Name', $value); - $this->validateString('Name', $value); + $this->validateNotNull('name', $value); + $this->validateString('name', $value); if ($this->data['name'] === $value) { return; @@ -160,14 +143,11 @@ class Environment extends Model } /** - * Set the value of Branches / branches - * - * Must not be null. * @param $value array */ public function setBranches($value) { - $this->validateNotNull('Branches', $value); + $this->validateNotNull('branches', $value); $value = implode("\n", $value); if ($this->data['branches'] === $value) { diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 9276d0ee..9696e61f 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -98,8 +98,6 @@ class Project extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -110,8 +108,6 @@ class Project extends Model } /** - * Get the value of Title / title. - * * @return string */ public function getTitle() @@ -122,8 +118,6 @@ class Project extends Model } /** - * Get the value of Reference / reference. - * * @return string */ public function getReference() @@ -134,8 +128,6 @@ class Project extends Model } /** - * Get the value of SshPrivateKey / ssh_private_key. - * * @return string */ public function getSshPrivateKey() @@ -146,8 +138,6 @@ class Project extends Model } /** - * Get the value of Type / type. - * * @return string */ public function getType() @@ -158,8 +148,6 @@ class Project extends Model } /** - * Get the value of LastCommit / last_commit. - * * @return string */ public function getLastCommit() @@ -170,8 +158,6 @@ class Project extends Model } /** - * Get the value of BuildConfig / build_config. - * * @return string */ public function getBuildConfig() @@ -182,8 +168,6 @@ class Project extends Model } /** - * Get the value of SshPublicKey / ssh_public_key. - * * @return string */ public function getSshPublicKey() @@ -194,8 +178,6 @@ class Project extends Model } /** - * Get the value of AllowPublicStatus / allow_public_status. - * * @return int */ public function getAllowPublicStatus() @@ -206,8 +188,6 @@ class Project extends Model } /** - * Get the value of Archived / archived. - * * @return int */ public function getArchived() @@ -218,8 +198,6 @@ class Project extends Model } /** - * Get the value of GroupId / group_id. - * * @return int */ public function getGroupId() @@ -230,8 +208,6 @@ class Project extends Model } /** - * Get the value of DefaultBranchOnly / default_branch_only. - * * @return int */ public function getDefaultBranchOnly() @@ -242,15 +218,12 @@ class Project extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -262,15 +235,12 @@ class Project extends Model } /** - * Set the value of Title / title. - * - * Must not be null. * @param $value string */ public function setTitle($value) { - $this->validateNotNull('Title', $value); - $this->validateString('Title', $value); + $this->validateNotNull('title', $value); + $this->validateString('title', $value); if ($this->data['title'] === $value) { return; @@ -282,15 +252,12 @@ class Project extends Model } /** - * Set the value of Reference / reference. - * - * Must not be null. * @param $value string */ public function setReference($value) { - $this->validateNotNull('Reference', $value); - $this->validateString('Reference', $value); + $this->validateNotNull('reference', $value); + $this->validateString('reference', $value); if ($this->data['reference'] === $value) { return; @@ -302,15 +269,12 @@ class Project extends Model } /** - * Set the value of Branch / branch. - * - * Must not be null. * @param $value string */ public function setBranch($value) { - $this->validateNotNull('Branch', $value); - $this->validateString('Branch', $value); + $this->validateNotNull('branch', $value); + $this->validateString('branch', $value); if ($this->data['branch'] === $value) { return; @@ -322,15 +286,12 @@ class Project extends Model } /** - * Set the value of DefaultBranchOnly / default_branch_only. - * - * Must not be null. * @param $value int */ public function setDefaultBranchOnly($value) { - $this->validateNotNull('DefaultBranchOnly', $value); - $this->validateInt('DefaultBranchOnly', $value); + $this->validateNotNull('default_branch_only', $value); + $this->validateInt('default_branch_only', $value); if ($this->data['default_branch_only'] === $value) { return; @@ -342,13 +303,11 @@ class Project extends Model } /** - * Set the value of SshPrivateKey / ssh_private_key. - * * @param $value string */ public function setSshPrivateKey($value) { - $this->validateString('SshPrivateKey', $value); + $this->validateString('ssh_private_key', $value); if ($this->data['ssh_private_key'] === $value) { return; @@ -360,15 +319,12 @@ class Project extends Model } /** - * Set the value of Type / type. - * - * Must not be null. * @param $value string */ public function setType($value) { - $this->validateNotNull('Type', $value); - $this->validateString('Type', $value); + $this->validateNotNull('type', $value); + $this->validateString('type', $value); if ($this->data['type'] === $value) { return; @@ -380,13 +336,11 @@ class Project extends Model } /** - * Set the value of LastCommit / last_commit. - * * @param $value string */ public function setLastCommit($value) { - $this->validateString('LastCommit', $value); + $this->validateString('last_commit', $value); if ($this->data['last_commit'] === $value) { return; @@ -398,13 +352,11 @@ class Project extends Model } /** - * Set the value of BuildConfig / build_config. - * * @param $value string */ public function setBuildConfig($value) { - $this->validateString('BuildConfig', $value); + $this->validateString('build_config', $value); if ($this->data['build_config'] === $value) { return; @@ -416,13 +368,11 @@ class Project extends Model } /** - * Set the value of SshPublicKey / ssh_public_key. - * * @param $value string */ public function setSshPublicKey($value) { - $this->validateString('SshPublicKey', $value); + $this->validateString('ssh_public_key', $value); if ($this->data['ssh_public_key'] === $value) { return; @@ -434,15 +384,12 @@ class Project extends Model } /** - * Set the value of AllowPublicStatus / allow_public_status. - * - * Must not be null. * @param $value int */ public function setAllowPublicStatus($value) { - $this->validateNotNull('AllowPublicStatus', $value); - $this->validateInt('AllowPublicStatus', $value); + $this->validateNotNull('allow_public_status', $value); + $this->validateInt('allow_public_status', $value); if ($this->data['allow_public_status'] === $value) { return; @@ -454,15 +401,12 @@ class Project extends Model } /** - * Set the value of Archived / archived. - * - * Must not be null. * @param $value int */ public function setArchived($value) { - $this->validateNotNull('Archived', $value); - $this->validateInt('Archived', $value); + $this->validateNotNull('archived', $value); + $this->validateInt('archived', $value); if ($this->data['archived'] === $value) { return; @@ -474,15 +418,12 @@ class Project extends Model } /** - * Set the value of GroupId / group_id. - * - * Must not be null. * @param $value int */ public function setGroupId($value) { - $this->validateNotNull('GroupId', $value); - $this->validateInt('GroupId', $value); + $this->validateNotNull('group_id', $value); + $this->validateInt('group_id', $value); if ($this->data['group_id'] === $value) { return; @@ -496,8 +437,6 @@ class Project extends Model /** * Get the ProjectGroup model for this Project by Id. * - * @uses \PHPCensor\Store\ProjectGroupStore::getById() - * @uses \PHPCensor\Model\ProjectGroup * @return \PHPCensor\Model\ProjectGroup */ public function getGroup() @@ -508,11 +447,11 @@ class Project extends Model return null; } - $cacheKey = 'Cache.ProjectGroup.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'Cache.ProjectGroup.' . $key; + $rtn = $this->cache->get($cacheKey, null); if (empty($rtn)) { - $rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key); + $rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key); $this->cache->set($cacheKey, $rtn); } @@ -553,8 +492,6 @@ class Project extends Model /** * Get Build models by ProjectId for this Project. * - * @uses \PHPCensor\Store\BuildStore::getByProjectId() - * @uses \PHPCensor\Model\Build * @return \PHPCensor\Model\Build[] */ public function getProjectBuilds() @@ -564,8 +501,10 @@ class Project extends Model /** * Return the latest build from a specific branch, of a specific status, for this project. + * * @param string $branch - * @param null $status + * @param null $status + * * @return mixed|null */ public function getLatestBuild($branch = 'master', $status = null) @@ -592,7 +531,9 @@ class Project extends Model /** * Return the previous build from a specific branch, for this project. + * * @param string $branch + * * @return mixed|null */ public function getPreviousBuild($branch = 'master') @@ -613,7 +554,6 @@ class Project extends Model } /** - * Store this project's access_information data * @param string|array $value */ public function setAccessInformation($value) @@ -622,7 +562,7 @@ class Project extends Model $value = json_encode($value); } - $this->validateString('AccessInformation', $value); + $this->validateString('access_information', $value); if ($this->data['access_information'] === $value) { return; @@ -635,7 +575,9 @@ class Project extends Model /** * Get this project's access_information data. Pass a specific key or null for all data. + * * @param string|null $key + * * @return mixed|null|string */ public function getAccessInformation($key = null) @@ -661,7 +603,7 @@ class Project extends Model } /** - * Get the value of Branch / branch. + * Get the value of branch. * * @return string */ @@ -688,6 +630,7 @@ class Project extends Model /** * Return the name of a FontAwesome icon to represent this project, depending on its type. + * * @return string */ public function getIcon() @@ -740,7 +683,7 @@ class Project extends Model if (empty($rtn)) { $store = $this->getEnvironmentStore(); - $rtn = $store->getByProjectId($key); + $rtn = $store->getByProjectId($key); $this->cache->set($cacheKey, $rtn); } diff --git a/src/PHPCensor/Model/ProjectGroup.php b/src/PHPCensor/Model/ProjectGroup.php index 904f1e81..2457b8b5 100644 --- a/src/PHPCensor/Model/ProjectGroup.php +++ b/src/PHPCensor/Model/ProjectGroup.php @@ -47,8 +47,6 @@ class ProjectGroup extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -59,8 +57,6 @@ class ProjectGroup extends Model } /** - * Get the value of Title / title. - * * @return string */ public function getTitle() @@ -71,15 +67,12 @@ class ProjectGroup extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -91,15 +84,12 @@ class ProjectGroup extends Model } /** - * Set the value of Title / title. - * - * Must not be null. * @param $value string */ public function setTitle($value) { - $this->validateNotNull('Title', $value); - $this->validateString('Title', $value); + $this->validateNotNull('title', $value); + $this->validateString('title', $value); if ($this->data['title'] === $value) { return; @@ -113,8 +103,6 @@ class ProjectGroup extends Model /** * Get Project models by GroupId for this ProjectGroup. * - * @uses \PHPCensor\Store\ProjectStore::getByGroupId() - * @uses \PHPCensor\Model\Project * @return \PHPCensor\Model\Project[] */ public function getGroupProjects() diff --git a/src/PHPCensor/Model/User.php b/src/PHPCensor/Model/User.php index fc466743..d49c7472 100644 --- a/src/PHPCensor/Model/User.php +++ b/src/PHPCensor/Model/User.php @@ -74,8 +74,6 @@ class User extends Model ]; /** - * Get the value of Id / id. - * * @return int */ public function getId() @@ -86,8 +84,6 @@ class User extends Model } /** - * Get the value of Email / email. - * * @return string */ public function getEmail() @@ -98,8 +94,6 @@ class User extends Model } /** - * Get the value of Hash / hash. - * * @return string */ public function getHash() @@ -110,8 +104,6 @@ class User extends Model } /** - * Get the value of Name / name. - * * @return string */ public function getName() @@ -122,8 +114,6 @@ class User extends Model } /** - * Get the value of IsAdmin / is_admin. - * * @return int */ public function getIsAdmin() @@ -134,8 +124,6 @@ class User extends Model } /** - * Get the value of ProviderKey / provider_key. - * * @return string */ public function getProviderKey() @@ -146,8 +134,6 @@ class User extends Model } /** - * Get the value of ProviderData / provider_data. - * * @return string */ public function getProviderData() @@ -158,8 +144,6 @@ class User extends Model } /** - * Get the value of RememberKey / remember_key. - * * @return string */ public function getRememberKey() @@ -170,8 +154,6 @@ class User extends Model } /** - * Get the value of Language / language. - * * @return string */ public function getLanguage() @@ -182,8 +164,6 @@ class User extends Model } /** - * Get the value of PerPage / per_page. - * * @return string */ public function getPerPage() @@ -194,15 +174,12 @@ class User extends Model } /** - * Set the value of Id / id. - * - * Must not be null. * @param $value int */ public function setId($value) { - $this->validateNotNull('Id', $value); - $this->validateInt('Id', $value); + $this->validateNotNull('id', $value); + $this->validateInt('id', $value); if ($this->data['id'] === $value) { return; @@ -214,15 +191,12 @@ class User extends Model } /** - * Set the value of Email / email. - * - * Must not be null. * @param $value string */ public function setEmail($value) { - $this->validateNotNull('Email', $value); - $this->validateString('Email', $value); + $this->validateNotNull('email', $value); + $this->validateString('email', $value); if ($this->data['email'] === $value) { return; @@ -234,15 +208,12 @@ class User extends Model } /** - * Set the value of Hash / hash. - * - * Must not be null. * @param $value string */ public function setHash($value) { - $this->validateNotNull('Hash', $value); - $this->validateString('Hash', $value); + $this->validateNotNull('hash', $value); + $this->validateString('hash', $value); if ($this->data['hash'] === $value) { return; @@ -254,15 +225,12 @@ class User extends Model } /** - * Set the value of Name / name. - * - * Must not be null. * @param $value string */ public function setName($value) { - $this->validateNotNull('Name', $value); - $this->validateString('Name', $value); + $this->validateNotNull('name', $value); + $this->validateString('name', $value); if ($this->data['name'] === $value) { return; @@ -274,15 +242,12 @@ class User extends Model } /** - * Set the value of IsAdmin / is_admin. - * - * Must not be null. * @param $value int */ public function setIsAdmin($value) { - $this->validateNotNull('IsAdmin', $value); - $this->validateInt('IsAdmin', $value); + $this->validateNotNull('is_admin', $value); + $this->validateInt('is_admin', $value); if ($this->data['is_admin'] === $value) { return; @@ -294,15 +259,12 @@ class User extends Model } /** - * Set the value of ProviderKey / provider_key. - * - * Must not be null. * @param $value string */ public function setProviderKey($value) { - $this->validateNotNull('ProviderKey', $value); - $this->validateString('ProviderKey', $value); + $this->validateNotNull('provider_key', $value); + $this->validateString('provider_key', $value); if ($this->data['provider_key'] === $value) { return; @@ -314,13 +276,11 @@ class User extends Model } /** - * Set the value of ProviderData / provider_data. - * * @param $value string */ public function setProviderData($value) { - $this->validateString('ProviderData', $value); + $this->validateString('provider_data', $value); if ($this->data['provider_data'] === $value) { return; @@ -332,13 +292,11 @@ class User extends Model } /** - * Set the value of RememberKey / remember_key. - * * @param $value string */ public function setRememberKey($value) { - $this->validateString('RememberKey', $value); + $this->validateString('remember_key', $value); if ($this->data['remember_key'] === $value) { return; @@ -350,9 +308,6 @@ class User extends Model } /** - * Set the value of Language / language. - * - * Must not be null. * @param $value string */ public function setLanguage($value) @@ -367,9 +322,6 @@ class User extends Model } /** - * Set the value of PerPage / per_page. - * - * Must not be null. * @param $value string */ public function setPerPage($value) diff --git a/src/PHPCensor/Service/BuildService.php b/src/PHPCensor/Service/BuildService.php index af2e3284..1922540f 100644 --- a/src/PHPCensor/Service/BuildService.php +++ b/src/PHPCensor/Service/BuildService.php @@ -42,6 +42,7 @@ class BuildService * @param string|null $committerEmail * @param string|null $commitMessage * @param integer $source + * @param integer $userId * @param string|null $extra * * @return \PHPCensor\Model\Build @@ -55,10 +56,11 @@ class BuildService $committerEmail = null, $commitMessage = null, $source = Build::SOURCE_UNKNOWN, + $userId = 0, $extra = null ) { $build = new Build(); - $build->setCreated(new \DateTime()); + $build->setCreateDate(new \DateTime()); $build->setProject($project); $build->setStatus(Build::STATUS_PENDING); $build->setEnvironment($environment); @@ -67,6 +69,7 @@ class BuildService $build->setExtraValue('branches', $branches); $build->setSource($source); + $build->setUserId($userId); $build->setCommitId((string)$commitId); if (!empty($branch)) { @@ -121,7 +124,7 @@ class BuildService $build = new Build(); $build->setValues($data); - $build->setCreated(new \DateTime()); + $build->setCreateDate(new \DateTime()); $build->setStatus(Build::STATUS_PENDING); /** @var Build $build */ diff --git a/src/PHPCensor/Service/BuildStatusService.php b/src/PHPCensor/Service/BuildStatusService.php index 8a323d18..d3a53d6e 100644 --- a/src/PHPCensor/Service/BuildStatusService.php +++ b/src/PHPCensor/Service/BuildStatusService.php @@ -155,7 +155,7 @@ class BuildStatusService { $dateFormat = 'Y-m-d\\TH:i:sO'; if ($buildInfo = $this->getFinishedBuildInfo()) { - return ($buildInfo->getFinished()) ? $buildInfo->getFinished()->format($dateFormat) : ''; + return ($buildInfo->getFinishDate()) ? $buildInfo->getFinishDate()->format($dateFormat) : ''; } return ''; } diff --git a/src/PHPCensor/View/Build/header-row.phtml b/src/PHPCensor/View/Build/header-row.phtml index 7bb8f4d0..b2038c4d 100644 --- a/src/PHPCensor/View/Build/header-row.phtml +++ b/src/PHPCensor/View/Build/header-row.phtml @@ -1,4 +1,13 @@ - +
  • getCommitterEmail()): ?> @@ -11,9 +20,9 @@ getProject()->getTitle(); ?> getStatus() == \PHPCensor\Model\Build::STATUS_PENDING): ?> - getCreated()->format('H:i')); ?> + getCreateDate()->format('H:i')); ?> getStatus() == \PHPCensor\Model\Build::STATUS_RUNNING): ?> - getStarted()->format('H:i')); ?> + getStartDate()->format('H:i')); ?>

    getBranch()); ?>

    diff --git a/src/PHPCensor/View/Build/view.phtml b/src/PHPCensor/View/Build/view.phtml index 7bba273b..8288fd5a 100644 --- a/src/PHPCensor/View/Build/view.phtml +++ b/src/PHPCensor/View/Build/view.phtml @@ -1,4 +1,13 @@ - +
    @@ -124,28 +133,28 @@ - getCreated() ? $build->getCreated()->format('Y-m-d H:i:s') : ''; ?> + getCreateDate() ? $build->getCreateDate()->format('Y-m-d H:i:s') : ''); ?> - getStarted() ? $build->getStarted()->format('Y-m-d H:i:s') : ''; ?> + getStartDate() ? $build->getStartDate()->format('Y-m-d H:i:s') : ''); ?> - getFinished() ? $build->getFinished()->format('Y-m-d H:i:s') : ''; ?> + getFinishDate() ? $build->getFinishDate()->format('Y-m-d H:i:s') : ''); ?> - getDuration(); ?> + getDuration(); ?> diff --git a/src/PHPCensor/View/BuildStatus/view.phtml b/src/PHPCensor/View/BuildStatus/view.phtml index 7a30b624..856f7dad 100644 --- a/src/PHPCensor/View/BuildStatus/view.phtml +++ b/src/PHPCensor/View/BuildStatus/view.phtml @@ -142,7 +142,7 @@ - getCreated()->format('Y-m-d H:i:s'); ?> + getCreateDate()->format('Y-m-d H:i:s'); ?> getCommitId())) { diff --git a/src/PHPCensor/View/Home/ajax-dashboard-project.phtml b/src/PHPCensor/View/Home/ajax-dashboard-project.phtml index 3daec637..1f00e379 100644 --- a/src/PHPCensor/View/Home/ajax-dashboard-project.phtml +++ b/src/PHPCensor/View/Home/ajax-dashboard-project.phtml @@ -1,5 +1,11 @@ getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $success; + $success = is_null($success) && !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : $success; break; case 3: $failures++; $statuses[] = 'failed'; - $failure = is_null($failure) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $failure; + $failure = is_null($failure) && !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : $failure; break; } } @@ -61,8 +67,8 @@ if ($buildCount > 0) { $shortMessage = Lang::get('x_of_x_failed_short', $failures, $buildCount); $message = Lang::get('x_of_x_failed', $failures, $buildCount); - if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) { - $message .= Lang::get('last_successful_build', $lastSuccess->getFinished()->format('Y-m-d H:i:s')); + if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinishDate())) { + $message .= Lang::get('last_successful_build', $lastSuccess->getFinishDate()->format('Y-m-d H:i:s')); } else { $message .= Lang::get('never_built_successfully'); } @@ -70,8 +76,8 @@ if ($buildCount > 0) { $message = Lang::get('all_builds_passed', $buildCount); $shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount); - if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) { - $message .= Lang::get('last_failed_build', $lastFailure->getFinished()->format('Y-m-d H:i:s')); + if (!is_null($lastFailure) && !is_null($lastFailure->getFinishDate())) { + $message .= Lang::get('last_failed_build', $lastFailure->getFinishDate()->format('Y-m-d H:i:s')); } else { $message .= Lang::get('never_failed_build'); } diff --git a/src/PHPCensor/View/Home/ajax-timeline.phtml b/src/PHPCensor/View/Home/ajax-timeline.phtml index 4071721a..b9037810 100644 --- a/src/PHPCensor/View/Home/ajax-timeline.phtml +++ b/src/PHPCensor/View/Home/ajax-timeline.phtml @@ -3,6 +3,10 @@ use PHPCensor\Helper\Lang; use PHPCensor\Model\Build; +/** + * @var Build[] $builds + */ + ?>
      @@ -14,32 +18,32 @@ use PHPCensor\Model\Build; switch ($build->getStatus()) { case Build::STATUS_PENDING: - $updated = $build->getCreated(); + $updated = $build->getCreateDate(); $label = Lang::get('pending'); $color = 'blue'; break; case Build::STATUS_RUNNING: - $updated = $build->getStarted(); + $updated = $build->getStartDate(); $label = Lang::get('running'); $color = 'yellow'; break; case Build::STATUS_SUCCESS: - $updated = $build->getFinished(); + $updated = $build->getFinishDate(); $label = Lang::get('success'); $color = 'green'; break; case Build::STATUS_FAILED: - $updated = $build->getFinished(); + $updated = $build->getFinishDate(); $label = Lang::get('failed'); $color = 'red'; break; } if (!$updated) { - $updated = $build->getCreated(); + $updated = $build->getCreateDate(); } if ($updated->format('Y-m-d') != $last->format('Y-m-d')): $last = $updated; diff --git a/src/PHPCensor/View/Home/dashboard-projects.phtml b/src/PHPCensor/View/Home/dashboard-projects.phtml index b884c679..1b046bac 100644 --- a/src/PHPCensor/View/Home/dashboard-projects.phtml +++ b/src/PHPCensor/View/Home/dashboard-projects.phtml @@ -1,5 +1,11 @@ getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $success; + $success = is_null($success) && !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : $success; break; case 3: $failures++; $statuses[] = 'failed'; - $failure = is_null($failure) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $failure; + $failure = is_null($failure) && !is_null($build->getFinishDate()) ? $build->getFinishDate()->format('Y-m-d H:i:s') : $failure; break; } } @@ -62,8 +68,8 @@ foreach($projects as $project): $shortMessage = Lang::get('x_of_x_failed_short', $failures, $buildCount); $message = Lang::get('x_of_x_failed', $failures, $buildCount); - if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) { - $message .= Lang::get('last_successful_build', $lastSuccess->getFinished()->format('Y-m-d H:i:s')); + if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinishDate())) { + $message .= Lang::get('last_successful_build', $lastSuccess->getFinishDate()->format('Y-m-d H:i:s')); } else { $message .= Lang::get('never_built_successfully'); } @@ -71,8 +77,8 @@ foreach($projects as $project): $message = Lang::get('all_builds_passed', $buildCount); $shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount); - if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) { - $message .= Lang::get('last_failed_build', $lastFailure->getFinished()->format('Y-m-d H:i:s')); + if (!is_null($lastFailure) && !is_null($lastFailure->getFinishDate())) { + $message .= Lang::get('last_failed_build', $lastFailure->getFinishDate()->format('Y-m-d H:i:s')); } else { $message .= Lang::get('never_failed_build'); } diff --git a/src/PHPCensor/View/Home/index.phtml b/src/PHPCensor/View/Home/index.phtml index d55301c3..873bc86b 100644 --- a/src/PHPCensor/View/Home/index.phtml +++ b/src/PHPCensor/View/Home/index.phtml @@ -3,6 +3,10 @@ use PHPCensor\Helper\Lang; use PHPCensor\Model\Build; +/** + * @var Build[] $builds + */ + ?>