diff --git a/src/PHPCensor/Model/Base/BuildBase.php b/src/PHPCensor/Model/Base/BuildBase.php deleted file mode 100644 index 83f8b9ce..00000000 --- a/src/PHPCensor/Model/Base/BuildBase.php +++ /dev/null @@ -1,629 +0,0 @@ - null, - 'project_id' => null, - 'commit_id' => null, - 'status' => null, - 'log' => null, - 'branch' => null, - 'created' => null, - 'started' => null, - 'finished' => null, - 'committer_email' => null, - 'commit_message' => null, - 'extra' => null, - ]; - - /** - * @var array - */ - protected $getters = [ - // Direct property getters: - 'id' => 'getId', - 'project_id' => 'getProjectId', - 'commit_id' => 'getCommitId', - 'status' => 'getStatus', - 'log' => 'getLog', - 'branch' => 'getBranch', - 'created' => 'getCreated', - 'started' => 'getStarted', - 'finished' => 'getFinished', - 'committer_email' => 'getCommitterEmail', - 'commit_message' => 'getCommitMessage', - 'extra' => 'getExtra', - - // Foreign key getters: - 'Project' => 'getProject', - ]; - - /** - * @var array - */ - protected $setters = [ - // Direct property setters: - 'id' => 'setId', - 'project_id' => 'setProjectId', - 'commit_id' => 'setCommitId', - 'status' => 'setStatus', - 'log' => 'setLog', - 'branch' => 'setBranch', - 'created' => 'setCreated', - 'started' => 'setStarted', - 'finished' => 'setFinished', - 'committer_email' => 'setCommitterEmail', - 'commit_message' => 'setCommitMessage', - 'extra' => 'setExtra', - - // 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', - ], - '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, - ], - ]; - - /** - * @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 - */ - public function getId() - { - $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 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; - } - - /** - * Get the value of CommitMessage / commit_message. - * - * @return string - */ - public function getCommitMessage() - { - $rtn = $this->data['commit_message']; - - return $rtn; - } - - /** - * Get the value of Extra / extra. - * - * @return string - */ - public function getExtra() - { - $rtn = $this->data['extra']; - - 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); - - if ($this->data['id'] === $value) { - return; - } - - $this->data['id'] = $value; - - $this->setModified('id'); - } - - /** - * Set the value of ProjectId / project_id. Must not be null. - * - * @param $value int - */ - public function setProjectId($value) - { - $this->validateNotNull('ProjectId', $value); - $this->validateInt('ProjectId', $value); - - if ($this->data['project_id'] === $value) { - return; - } - - $this->data['project_id'] = $value; - - $this->setModified('project_id'); - } - - /** - * Set the value of CommitId / commit_id. Must not be null. - * - * @param $value string - */ - public function setCommitId($value) - { - $this->validateNotNull('CommitId', $value); - $this->validateString('CommitId', $value); - - if ($this->data['commit_id'] === $value) { - return; - } - - $this->data['commit_id'] = $value; - - $this->setModified('commit_id'); - } - - /** - * Set the value of Status / status. Must not be null. - * - * @param $value int - */ - public function setStatus($value) - { - $this->validateNotNull('Status', $value); - $this->validateInt('Status', $value); - - if ($this->data['status'] === $value) { - return; - } - - $this->data['status'] = $value; - - $this->setModified('status'); - } - - /** - * 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'); - } - - /** - * Get the Project model for this Build by Id. - * - * @return \PHPCensor\Model\Project - */ - public function getProject() - { - $key = $this->getProjectId(); - - if (empty($key)) { - return null; - } - - return Factory::getStore('Project', 'PHPCensor')->getById($key); - } - - /** - * 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 BuildError models by BuildId for this Build. - * - * @return \PHPCensor\Model\BuildError[] - */ - public function getBuildBuildErrors() - { - return Factory::getStore('BuildError', 'PHPCensor')->getByBuildId($this->getId()); - } - - /** - * Get BuildMeta models by BuildId for this Build. - * - * @return \PHPCensor\Model\BuildMeta[] - */ - public function getBuildBuildMetas() - { - return Factory::getStore('BuildMeta', 'PHPCensor')->getByBuildId($this->getId()); - } -} diff --git a/src/PHPCensor/Model/Base/BuildErrorBase.php b/src/PHPCensor/Model/Base/BuildErrorBase.php deleted file mode 100644 index 543d1b99..00000000 --- a/src/PHPCensor/Model/Base/BuildErrorBase.php +++ /dev/null @@ -1,504 +0,0 @@ - null, - 'build_id' => null, - 'plugin' => null, - 'file' => null, - 'line_start' => null, - 'line_end' => null, - 'severity' => null, - 'message' => null, - 'created_date' => null, - ]; - - /** - * @var array - */ - protected $getters = [ - // Direct property getters: - 'id' => 'getId', - 'build_id' => 'getBuildId', - 'plugin' => 'getPlugin', - 'file' => 'getFile', - 'line_start' => 'getLineStart', - 'line_end' => 'getLineEnd', - 'severity' => 'getSeverity', - 'message' => 'getMessage', - 'created_date' => 'getCreatedDate', - - // Foreign key getters: - 'Build' => 'getBuild', - ]; - - /** - * @var array - */ - protected $setters = [ - // Direct property setters: - 'id' => 'setId', - 'build_id' => 'setBuildId', - 'plugin' => 'setPlugin', - 'file' => 'setFile', - 'line_start' => 'setLineStart', - 'line_end' => 'setLineEnd', - 'severity' => 'setSeverity', - 'message' => 'setMessage', - 'created_date' => 'setCreatedDate', - - // 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() - { - $rtn = $this->data['id']; - - return $rtn; - } - - /** - * Get the value of BuildId / build_id. - * - * @return int - */ - public function getBuildId() - { - $rtn = $this->data['build_id']; - - return $rtn; - } - - /** - * Get the value of Plugin / plugin. - * - * @return string - */ - public function getPlugin() - { - $rtn = $this->data['plugin']; - - return $rtn; - } - - /** - * Get the value of File / file. - * - * @return string - */ - public function getFile() - { - $rtn = $this->data['file']; - - return $rtn; - } - - /** - * Get the value of LineStart / line_start. - * - * @return int - */ - public function getLineStart() - { - $rtn = $this->data['line_start']; - - return $rtn; - } - - /** - * Get the value of LineEnd / line_end. - * - * @return int - */ - public function getLineEnd() - { - $rtn = $this->data['line_end']; - - return $rtn; - } - - /** - * Get the value of Severity / severity. - * - * @return int - */ - public function getSeverity() - { - $rtn = $this->data['severity']; - - return $rtn; - } - - /** - * Get the value of Message / message. - * - * @return string - */ - public function getMessage() - { - $rtn = $this->data['message']; - - return $rtn; - } - - /** - * Get the value of CreatedDate / created_date. - * - * @return \DateTime - */ - public function getCreatedDate() - { - $rtn = $this->data['created_date']; - - if (!empty($rtn)) { - $rtn = new \DateTime($rtn); - } - - 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); - - if ($this->data['id'] === $value) { - return; - } - - $this->data['id'] = $value; - - $this->setModified('id'); - } - - /** - * 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); - - if ($this->data['build_id'] === $value) { - return; - } - - $this->data['build_id'] = $value; - - $this->setModified('build_id'); - } - - /** - * 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); - - if ($this->data['plugin'] === $value) { - return; - } - - $this->data['plugin'] = $value; - - $this->setModified('plugin'); - } - - /** - * Set the value of File / file. - * - * @param $value string - */ - public function setFile($value) - { - $this->validateString('File', $value); - - if ($this->data['file'] === $value) { - return; - } - - $this->data['file'] = $value; - - $this->setModified('file'); - } - - /** - * Set the value of LineStart / line_start. - * - * @param $value int - */ - public function setLineStart($value) - { - $this->validateInt('LineStart', $value); - - if ($this->data['line_start'] === $value) { - return; - } - - $this->data['line_start'] = $value; - - $this->setModified('line_start'); - } - - /** - * Set the value of LineEnd / line_end. - * - * @param $value int - */ - public function setLineEnd($value) - { - $this->validateInt('LineEnd', $value); - - if ($this->data['line_end'] === $value) { - return; - } - - $this->data['line_end'] = $value; - - $this->setModified('line_end'); - } - - /** - * 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); - - if ($this->data['severity'] === $value) { - return; - } - - $this->data['severity'] = $value; - - $this->setModified('severity'); - } - - /** - * 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); - - if ($this->data['message'] === $value) { - return; - } - - $this->data['message'] = $value; - - $this->setModified('message'); - } - - /** - * 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); - - if ($this->data['created_date'] === $value) { - return; - } - - $this->data['created_date'] = $value; - - $this->setModified('created_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() - { - $key = $this->getBuildId(); - - if (empty($key)) { - return null; - } - - $cacheKey = 'Cache.Build.' . $key; - $rtn = $this->cache->get($cacheKey, null); - - if (empty($rtn)) { - $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; - } - - /** - * Set Build - Accepts an ID, an array representing a Build or a Build model. - * - * @param $value mixed - */ - public function setBuild($value) - { - // Is this an instance of Build? - if ($value instanceof Build) { - return $this->setBuildObject($value); - } - - // Is this an array representing a Build item? - if (is_array($value) && !empty($value['id'])) { - return $this->setBuildId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setBuildId($value); - } - - /** - * Set Build - Accepts a Build model. - * - * @param $value Build - */ - public function setBuildObject(Build $value) - { - return $this->setBuildId($value->getId()); - } -} diff --git a/src/PHPCensor/Model/Base/BuildMetaBase.php b/src/PHPCensor/Model/Base/BuildMetaBase.php deleted file mode 100644 index a56be7e8..00000000 --- a/src/PHPCensor/Model/Base/BuildMetaBase.php +++ /dev/null @@ -1,409 +0,0 @@ - null, - 'project_id' => null, - 'build_id' => null, - 'meta_key' => null, - 'meta_value' => null, - ]; - - /** - * @var array - */ - 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', - ]; - - /** - * @var array - */ - 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', - ]; - - /** - * @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']; - - 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']; - - return $rtn; - } - - /** - * Get the value of MetaKey / meta_key. - * - * @return string - */ - public function getMetaKey() - { - $rtn = $this->data['meta_key']; - - return $rtn; - } - - /** - * Get the value of MetaValue / meta_value. - * - * @return string - */ - public function getMetaValue() - { - $rtn = $this->data['meta_value']; - - 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); - - if ($this->data['id'] === $value) { - return; - } - - $this->data['id'] = $value; - - $this->setModified('id'); - } - - /** - * Set the value of ProjectId / project_id. - * - * Must not be null. - * @param $value int - */ - public function setProjectId($value) - { - $this->validateNotNull('ProjectId', $value); - $this->validateInt('ProjectId', $value); - - if ($this->data['project_id'] === $value) { - return; - } - - $this->data['project_id'] = $value; - - $this->setModified('project_id'); - } - - /** - * Set the value of BuildId / build_id. - * - * Must not be null. - * @param $value int - */ - public function setBuildId($value) - { - $this->validateNotNull('BuildId', $value); - $this->validateInt('BuildId', $value); - - if ($this->data['build_id'] === $value) { - return; - } - - $this->data['build_id'] = $value; - - $this->setModified('build_id'); - } - - /** - * 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); - - if ($this->data['meta_key'] === $value) { - return; - } - - $this->data['meta_key'] = $value; - - $this->setModified('meta_key'); - } - - /** - * 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); - - if ($this->data['meta_value'] === $value) { - return; - } - - $this->data['meta_value'] = $value; - - $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() - { - $key = $this->getBuildId(); - - if (empty($key)) { - return null; - } - - $cacheKey = 'Cache.Build.' . $key; - $rtn = $this->cache->get($cacheKey, null); - - if (empty($rtn)) { - $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; - } - - /** - * Set Build - Accepts an ID, an array representing a Build or a Build model. - * - * @param $value mixed - */ - public function setBuild($value) - { - // Is this an instance of Build? - if ($value instanceof Build) { - return $this->setBuildObject($value); - } - - // Is this an array representing a Build item? - if (is_array($value) && !empty($value['id'])) { - return $this->setBuildId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setBuildId($value); - } - - /** - * Set Build - Accepts a Build model. - * - * @param $value Build - */ - public function setBuildObject(Build $value) - { - return $this->setBuildId($value->getId()); - } -} diff --git a/src/PHPCensor/Model/Base/ProjectBase.php b/src/PHPCensor/Model/Base/ProjectBase.php deleted file mode 100644 index f123272e..00000000 --- a/src/PHPCensor/Model/Base/ProjectBase.php +++ /dev/null @@ -1,678 +0,0 @@ - null, - 'title' => null, - 'reference' => null, - 'branch' => null, - 'ssh_private_key' => null, - 'type' => null, - 'access_information' => null, - 'last_commit' => null, - 'build_config' => null, - 'ssh_public_key' => null, - 'allow_public_status' => null, - 'archived' => null, - 'group_id' => null, - ]; - - /** - * @var array - */ - protected $getters = [ - // Direct property getters: - 'id' => 'getId', - 'title' => 'getTitle', - 'reference' => 'getReference', - 'branch' => 'getBranch', - 'ssh_private_key' => 'getSshPrivateKey', - 'type' => 'getType', - 'access_information' => 'getAccessInformation', - 'last_commit' => 'getLastCommit', - 'build_config' => 'getBuildConfig', - 'ssh_public_key' => 'getSshPublicKey', - 'allow_public_status' => 'getAllowPublicStatus', - 'archived' => 'getArchived', - 'group_id' => 'getGroupId', - // Foreign key getters: - 'Group' => 'getGroup', - ]; - - /** - * @var array - */ - protected $setters = [ - // Direct property setters: - 'id' => 'setId', - 'title' => 'setTitle', - 'reference' => 'setReference', - 'branch' => 'setBranch', - 'ssh_private_key' => 'setSshPrivateKey', - 'type' => 'setType', - 'access_information' => 'setAccessInformation', - 'last_commit' => 'setLastCommit', - 'build_config' => 'setBuildConfig', - 'ssh_public_key' => 'setSshPublicKey', - 'allow_public_status' => 'setAllowPublicStatus', - 'archived' => 'setArchived', - 'group_id' => 'setGroupId', - // Foreign key setters: - 'Group' => 'setGroup', - ]; - - /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'title' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'reference' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => null, - ], - 'branch' => [ - 'type' => 'varchar', - 'length' => 250, - 'default' => 'master', - ], - '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']; - - return $rtn; - } - - /** - * Get the value of Title / title. - * - * @return string - */ - public function getTitle() - { - $rtn = $this->data['title']; - - return $rtn; - } - - /** - * Get the value of Reference / reference. - * - * @return string - */ - public function getReference() - { - $rtn = $this->data['reference']; - - return $rtn; - } - - /** - * Get the value of Branch / branch. - * - * @return string - */ - public function getBranch() - { - $rtn = $this->data['branch']; - - return $rtn; - } - - /** - * Get the value of SshPrivateKey / ssh_private_key. - * - * @return string - */ - public function getSshPrivateKey() - { - $rtn = $this->data['ssh_private_key']; - - return $rtn; - } - - /** - * Get the value of Type / type. - * - * @return string - */ - public function getType() - { - $rtn = $this->data['type']; - - return $rtn; - } - - /** - * Get the value of AccessInformation / access_information. - * - * @return string - */ - public function getAccessInformation() - { - $rtn = $this->data['access_information']; - - return $rtn; - } - - /** - * Get the value of LastCommit / last_commit. - * - * @return string - */ - public function getLastCommit() - { - $rtn = $this->data['last_commit']; - - return $rtn; - } - - /** - * Get the value of BuildConfig / build_config. - * - * @return string - */ - public function getBuildConfig() - { - $rtn = $this->data['build_config']; - - return $rtn; - } - - /** - * Get the value of SshPublicKey / ssh_public_key. - * - * @return string - */ - public function getSshPublicKey() - { - $rtn = $this->data['ssh_public_key']; - - return $rtn; - } - - /** - * Get the value of AllowPublicStatus / allow_public_status. - * - * @return int - */ - public function getAllowPublicStatus() - { - $rtn = $this->data['allow_public_status']; - - return $rtn; - } - - /** - * Get the value of Archived / archived. - * - * @return int - */ - public function getArchived() - { - $rtn = $this->data['archived']; - - return $rtn; - } - - /** - * Get the value of GroupId / group_id. - * - * @return int - */ - public function getGroupId() - { - $rtn = $this->data['group_id']; - - 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); - - if ($this->data['id'] === $value) { - return; - } - - $this->data['id'] = $value; - - $this->setModified('id'); - } - - /** - * 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); - - if ($this->data['title'] === $value) { - return; - } - - $this->data['title'] = $value; - - $this->setModified('title'); - } - - /** - * 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); - - if ($this->data['reference'] === $value) { - return; - } - - $this->data['reference'] = $value; - - $this->setModified('reference'); - } - - /** - * 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 SshPrivateKey / ssh_private_key. - * - * @param $value string - */ - public function setSshPrivateKey($value) - { - $this->validateString('SshPrivateKey', $value); - - if ($this->data['ssh_private_key'] === $value) { - return; - } - - $this->data['ssh_private_key'] = $value; - - $this->setModified('ssh_private_key'); - } - - /** - * 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); - - if ($this->data['type'] === $value) { - return; - } - - $this->data['type'] = $value; - - $this->setModified('type'); - } - - /** - * Set the value of AccessInformation / access_information. - * - * @param $value string - */ - public function setAccessInformation($value) - { - $this->validateString('AccessInformation', $value); - - if ($this->data['access_information'] === $value) { - return; - } - - $this->data['access_information'] = $value; - - $this->setModified('access_information'); - } - - /** - * Set the value of LastCommit / last_commit. - * - * @param $value string - */ - public function setLastCommit($value) - { - $this->validateString('LastCommit', $value); - - if ($this->data['last_commit'] === $value) { - return; - } - - $this->data['last_commit'] = $value; - - $this->setModified('last_commit'); - } - - /** - * Set the value of BuildConfig / build_config. - * - * @param $value string - */ - public function setBuildConfig($value) - { - $this->validateString('BuildConfig', $value); - - if ($this->data['build_config'] === $value) { - return; - } - - $this->data['build_config'] = $value; - - $this->setModified('build_config'); - } - - /** - * Set the value of SshPublicKey / ssh_public_key. - * - * @param $value string - */ - public function setSshPublicKey($value) - { - $this->validateString('SshPublicKey', $value); - - if ($this->data['ssh_public_key'] === $value) { - return; - } - - $this->data['ssh_public_key'] = $value; - - $this->setModified('ssh_public_key'); - } - - /** - * 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); - - if ($this->data['allow_public_status'] === $value) { - return; - } - - $this->data['allow_public_status'] = $value; - - $this->setModified('allow_public_status'); - } - - /** - * 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); - - if ($this->data['archived'] === $value) { - return; - } - - $this->data['archived'] = $value; - - $this->setModified('archived'); - } - - /** - * 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); - - if ($this->data['group_id'] === $value) { - return; - } - - $this->data['group_id'] = $value; - - $this->setModified('group_id'); - } - - /** - * 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() - { - $key = $this->getGroupId(); - - if (empty($key)) { - return null; - } - - $cacheKey = 'Cache.ProjectGroup.' . $key; - $rtn = $this->cache->get($cacheKey, null); - - if (empty($rtn)) { - $rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; - } - - /** - * Set Group - Accepts an ID, an array representing a ProjectGroup or a ProjectGroup model. - * - * @param $value mixed - */ - public function setGroup($value) - { - // Is this an instance of ProjectGroup? - if ($value instanceof ProjectGroup) { - return $this->setGroupObject($value); - } - - // Is this an array representing a ProjectGroup item? - if (is_array($value) && !empty($value['id'])) { - return $this->setGroupId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setGroupId($value); - } - - /** - * Set Group - Accepts a ProjectGroup model. - * - * @param $value ProjectGroup - */ - public function setGroupObject(ProjectGroup $value) - { - return $this->setGroupId($value->getId()); - } - - /** - * Get Build models by ProjectId for this Project. - * - * @uses \PHPCensor\Store\BuildStore::getByProjectId() - * @uses \PHPCensor\Model\Build - * @return \PHPCensor\Model\Build[] - */ - public function getProjectBuilds() - { - 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()); - } -} diff --git a/src/PHPCensor/Model/Base/ProjectGroupBase.php b/src/PHPCensor/Model/Base/ProjectGroupBase.php deleted file mode 100644 index 1ed0d39c..00000000 --- a/src/PHPCensor/Model/Base/ProjectGroupBase.php +++ /dev/null @@ -1,165 +0,0 @@ - null, - 'title' => null, - ]; - - /** - * @var array - */ - protected $getters = [ - // Direct property getters: - 'id' => 'getId', - 'title' => 'getTitle', - // Foreign key getters: - ]; - - /** - * @var array - */ - protected $setters = [ - // Direct property setters: - 'id' => 'setId', - 'title' => 'setTitle', - // Foreign key setters: - ]; - - /** - * @var array - */ - public $columns = [ - 'id' => [ - 'type' => 'int', - 'length' => 11, - 'primary_key' => true, - 'auto_increment' => true, - 'default' => null, - ], - 'title' => [ - 'type' => 'varchar', - 'length' => 100, - 'default' => null, - ], - ]; - - /** - * @var array - */ - public $indexes = [ - 'PRIMARY' => ['unique' => true, 'columns' => 'id'], - ]; - - /** - * @var array - */ - public $foreignKeys = []; - - /** - * Get the value of Id / id. - * - * @return int - */ - public function getId() - { - $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); - - if ($this->data['id'] === $value) { - return; - } - - $this->data['id'] = $value; - - $this->setModified('id'); - } - - /** - * 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); - - if ($this->data['title'] === $value) { - return; - } - - $this->data['title'] = $value; - - $this->setModified('title'); - } - - /** - * Get Project models by GroupId for this ProjectGroup. - * - * @uses \PHPCensor\Store\ProjectStore::getByGroupId() - * @uses \PHPCensor\Model\Project - * @return \PHPCensor\Model\Project[] - */ - public function getGroupProjects() - { - return Factory::getStore('Project', 'PHPCensor')->getByGroupId($this->getId(), false); - } -} diff --git a/src/PHPCensor/Model/Base/UserBase.php b/src/PHPCensor/Model/Base/UserBase.php deleted file mode 100644 index 27006706..00000000 --- a/src/PHPCensor/Model/Base/UserBase.php +++ /dev/null @@ -1,441 +0,0 @@ - null, - 'email' => null, - 'hash' => null, - 'is_admin' => null, - 'name' => null, - 'language' => null, - 'per_page' => null, - 'provider_key' => null, - 'provider_data' => null, - ]; - - /** - * @var array - */ - protected $getters = [ - // Direct property getters: - 'id' => 'getId', - 'email' => 'getEmail', - 'hash' => 'getHash', - 'is_admin' => 'getIsAdmin', - 'name' => 'getName', - 'language' => 'getLanguage', - 'per_page' => 'getPerPage', - 'provider_key' => 'getProviderKey', - 'provider_data' => 'getProviderData', - // Foreign key getters: - ]; - - /** - * @var array - */ - protected $setters = [ - // Direct property setters: - 'id' => 'setId', - 'email' => 'setEmail', - 'hash' => 'setHash', - 'is_admin' => 'setIsAdmin', - 'name' => 'setName', - 'language' => 'setLanguage', - 'per_page' => 'setPerPage', - 'provider_key' => 'setProviderKey', - 'provider_data' => 'setProviderData', - // 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, - ], - ]; - - /** - * @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() - { - $rtn = $this->data['id']; - - return $rtn; - } - - /** - * Get the value of Email / email. - * - * @return string - */ - public function getEmail() - { - $rtn = $this->data['email']; - - return $rtn; - } - - /** - * Get the value of Hash / hash. - * - * @return string - */ - public function getHash() - { - $rtn = $this->data['hash']; - - return $rtn; - } - - /** - * Get the value of Name / name. - * - * @return string - */ - public function getName() - { - $rtn = $this->data['name']; - - return $rtn; - } - - /** - * Get the value of IsAdmin / is_admin. - * - * @return int - */ - public function getIsAdmin() - { - $rtn = $this->data['is_admin']; - - return $rtn; - } - - /** - * Get the value of ProviderKey / provider_key. - * - * @return string - */ - public function getProviderKey() - { - $rtn = $this->data['provider_key']; - - return $rtn; - } - - /** - * Get the value of ProviderData / provider_data. - * - * @return string - */ - public function getProviderData() - { - $rtn = $this->data['provider_data']; - - return $rtn; - } - - /** - * Get the value of Language / language. - * - * @return string - */ - public function getLanguage() - { - $rtn = $this->data['language']; - - return $rtn; - } - - /** - * Get the value of PerPage / per_page. - * - * @return string - */ - public function getPerPage() - { - $rtn = $this->data['per_page']; - - 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); - - if ($this->data['id'] === $value) { - return; - } - - $this->data['id'] = $value; - - $this->setModified('id'); - } - - /** - * 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); - - if ($this->data['email'] === $value) { - return; - } - - $this->data['email'] = $value; - - $this->setModified('email'); - } - - /** - * 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); - - if ($this->data['hash'] === $value) { - return; - } - - $this->data['hash'] = $value; - - $this->setModified('hash'); - } - - /** - * 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); - - if ($this->data['name'] === $value) { - return; - } - - $this->data['name'] = $value; - - $this->setModified('name'); - } - - /** - * 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); - - if ($this->data['is_admin'] === $value) { - return; - } - - $this->data['is_admin'] = $value; - - $this->setModified('is_admin'); - } - - /** - * 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); - - if ($this->data['provider_key'] === $value) { - return; - } - - $this->data['provider_key'] = $value; - - $this->setModified('provider_key'); - } - - /** - * Set the value of ProviderData / provider_data. - * - * @param $value string - */ - public function setProviderData($value) - { - $this->validateString('ProviderData', $value); - - if ($this->data['provider_data'] === $value) { - return; - } - - $this->data['provider_data'] = $value; - - $this->setModified('provider_data'); - } - - /** - * Set the value of Language / language. - * - * Must not be null. - * @param $value string - */ - public function setLanguage($value) - { - if ($this->data['language'] === $value) { - return; - } - - $this->data['language'] = $value; - - $this->setModified('language'); - } - - /** - * Set the value of PerPage / per_page. - * - * Must not be null. - * @param $value string - */ - public function setPerPage($value) - { - if ($this->data['per_page'] === $value) { - return; - } - - $this->data['per_page'] = $value; - - $this->setModified('per_page'); - } - - /** - * @return integer - */ - public function getFinalPerPage() - { - $perPage = $this->getPerPage(); - if ($perPage) { - return (integer)$perPage; - } - - return (integer)Config::getInstance()->get('php-censor.per_page', 10); - } -} diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index d7cf512f..d4f25945 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -1,26 +1,605 @@ */ -class Build extends BuildBase +class Build extends Model { + /** + * @var array + */ + public static $sleepable = []; + + /** + * @var string + */ + protected $tableName = 'build'; + + /** + * @var string + */ + protected $modelName = 'Build'; + + /** + * @var array + */ + protected $data = [ + 'id' => null, + 'project_id' => null, + 'commit_id' => null, + 'status' => null, + 'log' => null, + 'branch' => null, + 'created' => null, + 'started' => null, + 'finished' => null, + 'committer_email' => null, + 'commit_message' => null, + 'extra' => null, + ]; + + /** + * @var array + */ + protected $getters = [ + // Direct property getters: + 'id' => 'getId', + 'project_id' => 'getProjectId', + 'commit_id' => 'getCommitId', + 'status' => 'getStatus', + 'log' => 'getLog', + 'branch' => 'getBranch', + 'created' => 'getCreated', + 'started' => 'getStarted', + 'finished' => 'getFinished', + 'committer_email' => 'getCommitterEmail', + 'commit_message' => 'getCommitMessage', + 'extra' => 'getExtra', + + // Foreign key getters: + 'Project' => 'getProject', + ]; + + /** + * @var array + */ + protected $setters = [ + // Direct property setters: + 'id' => 'setId', + 'project_id' => 'setProjectId', + 'commit_id' => 'setCommitId', + 'status' => 'setStatus', + 'log' => 'setLog', + 'branch' => 'setBranch', + 'created' => 'setCreated', + 'started' => 'setStarted', + 'finished' => 'setFinished', + 'committer_email' => 'setCommitterEmail', + 'commit_message' => 'setCommitMessage', + 'extra' => 'setExtra', + + // 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', + ], + '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, + ], + ]; + + /** + * @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 + */ + public function getId() + { + $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 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); + + if ($this->data['id'] === $value) { + return; + } + + $this->data['id'] = $value; + + $this->setModified('id'); + } + + /** + * Set the value of ProjectId / project_id. Must not be null. + * + * @param $value int + */ + public function setProjectId($value) + { + $this->validateNotNull('ProjectId', $value); + $this->validateInt('ProjectId', $value); + + if ($this->data['project_id'] === $value) { + return; + } + + $this->data['project_id'] = $value; + + $this->setModified('project_id'); + } + + /** + * Set the value of CommitId / commit_id. Must not be null. + * + * @param $value string + */ + public function setCommitId($value) + { + $this->validateNotNull('CommitId', $value); + $this->validateString('CommitId', $value); + + if ($this->data['commit_id'] === $value) { + return; + } + + $this->data['commit_id'] = $value; + + $this->setModified('commit_id'); + } + + /** + * Set the value of Status / status. Must not be null. + * + * @param $value int + */ + public function setStatus($value) + { + $this->validateNotNull('Status', $value); + $this->validateInt('Status', $value); + + if ($this->data['status'] === $value) { + return; + } + + $this->data['status'] = $value; + + $this->setModified('status'); + } + + /** + * 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'); + } + + /** + * Get the Project model for this Build by Id. + * + * @return \PHPCensor\Model\Project + */ + public function getProject() + { + $key = $this->getProjectId(); + + if (empty($key)) { + return null; + } + + return Factory::getStore('Project', 'PHPCensor')->getById($key); + } + + /** + * 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 BuildError models by BuildId for this Build. + * + * @return \PHPCensor\Model\BuildError[] + */ + public function getBuildBuildErrors() + { + return Factory::getStore('BuildError', 'PHPCensor')->getByBuildId($this->getId()); + } + + /** + * Get BuildMeta models by BuildId for this Build. + * + * @return \PHPCensor\Model\BuildMeta[] + */ + public function getBuildBuildMetas() + { + return Factory::getStore('BuildMeta', 'PHPCensor')->getByBuildId($this->getId()); + } + const STATUS_PENDING = 0; const STATUS_RUNNING = 1; const STATUS_SUCCESS = 2; diff --git a/src/PHPCensor/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index 4819f854..7a1f70a6 100644 --- a/src/PHPCensor/Model/BuildError.php +++ b/src/PHPCensor/Model/BuildError.php @@ -1,18 +1,499 @@ null, + 'build_id' => null, + 'plugin' => null, + 'file' => null, + 'line_start' => null, + 'line_end' => null, + 'severity' => null, + 'message' => null, + 'created_date' => null, + ]; + + /** + * @var array + */ + protected $getters = [ + // Direct property getters: + 'id' => 'getId', + 'build_id' => 'getBuildId', + 'plugin' => 'getPlugin', + 'file' => 'getFile', + 'line_start' => 'getLineStart', + 'line_end' => 'getLineEnd', + 'severity' => 'getSeverity', + 'message' => 'getMessage', + 'created_date' => 'getCreatedDate', + + // Foreign key getters: + 'Build' => 'getBuild', + ]; + + /** + * @var array + */ + protected $setters = [ + // Direct property setters: + 'id' => 'setId', + 'build_id' => 'setBuildId', + 'plugin' => 'setPlugin', + 'file' => 'setFile', + 'line_start' => 'setLineStart', + 'line_end' => 'setLineEnd', + 'severity' => 'setSeverity', + 'message' => 'setMessage', + 'created_date' => 'setCreatedDate', + + // 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() + { + $rtn = $this->data['id']; + + return $rtn; + } + + /** + * Get the value of BuildId / build_id. + * + * @return int + */ + public function getBuildId() + { + $rtn = $this->data['build_id']; + + return $rtn; + } + + /** + * Get the value of Plugin / plugin. + * + * @return string + */ + public function getPlugin() + { + $rtn = $this->data['plugin']; + + return $rtn; + } + + /** + * Get the value of File / file. + * + * @return string + */ + public function getFile() + { + $rtn = $this->data['file']; + + return $rtn; + } + + /** + * Get the value of LineStart / line_start. + * + * @return int + */ + public function getLineStart() + { + $rtn = $this->data['line_start']; + + return $rtn; + } + + /** + * Get the value of LineEnd / line_end. + * + * @return int + */ + public function getLineEnd() + { + $rtn = $this->data['line_end']; + + return $rtn; + } + + /** + * Get the value of Severity / severity. + * + * @return int + */ + public function getSeverity() + { + $rtn = $this->data['severity']; + + return $rtn; + } + + /** + * Get the value of Message / message. + * + * @return string + */ + public function getMessage() + { + $rtn = $this->data['message']; + + return $rtn; + } + + /** + * Get the value of CreatedDate / created_date. + * + * @return \DateTime + */ + public function getCreatedDate() + { + $rtn = $this->data['created_date']; + + if (!empty($rtn)) { + $rtn = new \DateTime($rtn); + } + + 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); + + if ($this->data['id'] === $value) { + return; + } + + $this->data['id'] = $value; + + $this->setModified('id'); + } + + /** + * 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); + + if ($this->data['build_id'] === $value) { + return; + } + + $this->data['build_id'] = $value; + + $this->setModified('build_id'); + } + + /** + * 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); + + if ($this->data['plugin'] === $value) { + return; + } + + $this->data['plugin'] = $value; + + $this->setModified('plugin'); + } + + /** + * Set the value of File / file. + * + * @param $value string + */ + public function setFile($value) + { + $this->validateString('File', $value); + + if ($this->data['file'] === $value) { + return; + } + + $this->data['file'] = $value; + + $this->setModified('file'); + } + + /** + * Set the value of LineStart / line_start. + * + * @param $value int + */ + public function setLineStart($value) + { + $this->validateInt('LineStart', $value); + + if ($this->data['line_start'] === $value) { + return; + } + + $this->data['line_start'] = $value; + + $this->setModified('line_start'); + } + + /** + * Set the value of LineEnd / line_end. + * + * @param $value int + */ + public function setLineEnd($value) + { + $this->validateInt('LineEnd', $value); + + if ($this->data['line_end'] === $value) { + return; + } + + $this->data['line_end'] = $value; + + $this->setModified('line_end'); + } + + /** + * 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); + + if ($this->data['severity'] === $value) { + return; + } + + $this->data['severity'] = $value; + + $this->setModified('severity'); + } + + /** + * 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); + + if ($this->data['message'] === $value) { + return; + } + + $this->data['message'] = $value; + + $this->setModified('message'); + } + + /** + * 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); + + if ($this->data['created_date'] === $value) { + return; + } + + $this->data['created_date'] = $value; + + $this->setModified('created_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() + { + $key = $this->getBuildId(); + + if (empty($key)) { + return null; + } + + $cacheKey = 'Cache.Build.' . $key; + $rtn = $this->cache->get($cacheKey, null); + + if (empty($rtn)) { + $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); + $this->cache->set($cacheKey, $rtn); + } + + return $rtn; + } + + /** + * Set Build - Accepts an ID, an array representing a Build or a Build model. + * + * @param $value mixed + */ + public function setBuild($value) + { + // Is this an instance of Build? + if ($value instanceof Build) { + return $this->setBuildObject($value); + } + + // Is this an array representing a Build item? + if (is_array($value) && !empty($value['id'])) { + return $this->setBuildId($value['id']); + } + + // Is this a scalar value representing the ID of this foreign key? + return $this->setBuildId($value); + } + + /** + * Set Build - Accepts a Build model. + * + * @param $value Build + */ + public function setBuildObject(Build $value) + { + return $this->setBuildId($value->getId()); + } + const SEVERITY_CRITICAL = 0; const SEVERITY_HIGH = 1; const SEVERITY_NORMAL = 2; diff --git a/src/PHPCensor/Model/BuildMeta.php b/src/PHPCensor/Model/BuildMeta.php index 68c3dc51..656f81b5 100644 --- a/src/PHPCensor/Model/BuildMeta.php +++ b/src/PHPCensor/Model/BuildMeta.php @@ -1,22 +1,400 @@ null, + 'project_id' => null, + 'build_id' => null, + 'meta_key' => null, + 'meta_value' => null, + ]; + + /** + * @var array + */ + 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', + ]; + + /** + * @var array + */ + 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', + ]; + + /** + * @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']; + + 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']; + + return $rtn; + } + + /** + * Get the value of MetaKey / meta_key. + * + * @return string + */ + public function getMetaKey() + { + $rtn = $this->data['meta_key']; + + return $rtn; + } + + /** + * Get the value of MetaValue / meta_value. + * + * @return string + */ + public function getMetaValue() + { + $rtn = $this->data['meta_value']; + + 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); + + if ($this->data['id'] === $value) { + return; + } + + $this->data['id'] = $value; + + $this->setModified('id'); + } + + /** + * Set the value of ProjectId / project_id. + * + * Must not be null. + * @param $value int + */ + public function setProjectId($value) + { + $this->validateNotNull('ProjectId', $value); + $this->validateInt('ProjectId', $value); + + if ($this->data['project_id'] === $value) { + return; + } + + $this->data['project_id'] = $value; + + $this->setModified('project_id'); + } + + /** + * Set the value of BuildId / build_id. + * + * Must not be null. + * @param $value int + */ + public function setBuildId($value) + { + $this->validateNotNull('BuildId', $value); + $this->validateInt('BuildId', $value); + + if ($this->data['build_id'] === $value) { + return; + } + + $this->data['build_id'] = $value; + + $this->setModified('build_id'); + } + + /** + * 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); + + if ($this->data['meta_key'] === $value) { + return; + } + + $this->data['meta_key'] = $value; + + $this->setModified('meta_key'); + } + + /** + * 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); + + if ($this->data['meta_value'] === $value) { + return; + } + + $this->data['meta_value'] = $value; + + $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() + { + $key = $this->getBuildId(); + + if (empty($key)) { + return null; + } + + $cacheKey = 'Cache.Build.' . $key; + $rtn = $this->cache->get($cacheKey, null); + + if (empty($rtn)) { + $rtn = Factory::getStore('Build', 'PHPCensor')->getById($key); + $this->cache->set($cacheKey, $rtn); + } + + return $rtn; + } + + /** + * Set Build - Accepts an ID, an array representing a Build or a Build model. + * + * @param $value mixed + */ + public function setBuild($value) + { + // Is this an instance of Build? + if ($value instanceof Build) { + return $this->setBuildObject($value); + } + + // Is this an array representing a Build item? + if (is_array($value) && !empty($value['id'])) { + return $this->setBuildId($value['id']); + } + + // Is this a scalar value representing the ID of this foreign key? + return $this->setBuildId($value); + } + + /** + * Set Build - Accepts a Build model. + * + * @param $value Build + */ + public function setBuildObject(Build $value) + { + return $this->setBuildId($value->getId()); + } } diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index ee83a88d..4ce32e54 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -1,27 +1,635 @@ -* @package PHPCI -* @subpackage Core -*/ -class Project extends ProjectBase + * @author Dan Cryer + */ +class Project extends Model { + /** + * @var array + */ + public static $sleepable = []; + + /** + * @var string + */ + protected $tableName = 'project'; + + /** + * @var string + */ + protected $modelName = 'Project'; + + /** + * @var array + */ + protected $data = [ + 'id' => null, + 'title' => null, + 'reference' => null, + 'branch' => null, + 'ssh_private_key' => null, + 'type' => null, + 'access_information' => null, + 'last_commit' => null, + 'build_config' => null, + 'ssh_public_key' => null, + 'allow_public_status' => null, + 'archived' => null, + 'group_id' => null, + ]; + + /** + * @var array + */ + protected $getters = [ + // Direct property getters: + 'id' => 'getId', + 'title' => 'getTitle', + 'reference' => 'getReference', + 'branch' => 'getBranch', + 'ssh_private_key' => 'getSshPrivateKey', + 'type' => 'getType', + 'access_information' => 'getAccessInformation', + 'last_commit' => 'getLastCommit', + 'build_config' => 'getBuildConfig', + 'ssh_public_key' => 'getSshPublicKey', + 'allow_public_status' => 'getAllowPublicStatus', + 'archived' => 'getArchived', + 'group_id' => 'getGroupId', + // Foreign key getters: + 'Group' => 'getGroup', + ]; + + /** + * @var array + */ + protected $setters = [ + // Direct property setters: + 'id' => 'setId', + 'title' => 'setTitle', + 'reference' => 'setReference', + 'branch' => 'setBranch', + 'ssh_private_key' => 'setSshPrivateKey', + 'type' => 'setType', + 'access_information' => 'setAccessInformation', + 'last_commit' => 'setLastCommit', + 'build_config' => 'setBuildConfig', + 'ssh_public_key' => 'setSshPublicKey', + 'allow_public_status' => 'setAllowPublicStatus', + 'archived' => 'setArchived', + 'group_id' => 'setGroupId', + // Foreign key setters: + 'Group' => 'setGroup', + ]; + + /** + * @var array + */ + public $columns = [ + 'id' => [ + 'type' => 'int', + 'length' => 11, + 'primary_key' => true, + 'auto_increment' => true, + 'default' => null, + ], + 'title' => [ + 'type' => 'varchar', + 'length' => 250, + 'default' => null, + ], + 'reference' => [ + 'type' => 'varchar', + 'length' => 250, + 'default' => null, + ], + 'branch' => [ + 'type' => 'varchar', + 'length' => 250, + 'default' => 'master', + ], + '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']; + + return $rtn; + } + + /** + * Get the value of Title / title. + * + * @return string + */ + public function getTitle() + { + $rtn = $this->data['title']; + + return $rtn; + } + + /** + * Get the value of Reference / reference. + * + * @return string + */ + public function getReference() + { + $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']; + + return $rtn; + } + + /** + * Get the value of Type / type. + * + * @return string + */ + public function getType() + { + $rtn = $this->data['type']; + + return $rtn; + } + + /** + * Get the value of LastCommit / last_commit. + * + * @return string + */ + public function getLastCommit() + { + $rtn = $this->data['last_commit']; + + return $rtn; + } + + /** + * Get the value of BuildConfig / build_config. + * + * @return string + */ + public function getBuildConfig() + { + $rtn = $this->data['build_config']; + + return $rtn; + } + + /** + * Get the value of SshPublicKey / ssh_public_key. + * + * @return string + */ + public function getSshPublicKey() + { + $rtn = $this->data['ssh_public_key']; + + return $rtn; + } + + /** + * Get the value of AllowPublicStatus / allow_public_status. + * + * @return int + */ + public function getAllowPublicStatus() + { + $rtn = $this->data['allow_public_status']; + + return $rtn; + } + + /** + * Get the value of Archived / archived. + * + * @return int + */ + public function getArchived() + { + $rtn = $this->data['archived']; + + return $rtn; + } + + /** + * Get the value of GroupId / group_id. + * + * @return int + */ + public function getGroupId() + { + $rtn = $this->data['group_id']; + + 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); + + if ($this->data['id'] === $value) { + return; + } + + $this->data['id'] = $value; + + $this->setModified('id'); + } + + /** + * 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); + + if ($this->data['title'] === $value) { + return; + } + + $this->data['title'] = $value; + + $this->setModified('title'); + } + + /** + * 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); + + if ($this->data['reference'] === $value) { + return; + } + + $this->data['reference'] = $value; + + $this->setModified('reference'); + } + + /** + * 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 SshPrivateKey / ssh_private_key. + * + * @param $value string + */ + public function setSshPrivateKey($value) + { + $this->validateString('SshPrivateKey', $value); + + if ($this->data['ssh_private_key'] === $value) { + return; + } + + $this->data['ssh_private_key'] = $value; + + $this->setModified('ssh_private_key'); + } + + /** + * 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); + + if ($this->data['type'] === $value) { + return; + } + + $this->data['type'] = $value; + + $this->setModified('type'); + } + + /** + * Set the value of LastCommit / last_commit. + * + * @param $value string + */ + public function setLastCommit($value) + { + $this->validateString('LastCommit', $value); + + if ($this->data['last_commit'] === $value) { + return; + } + + $this->data['last_commit'] = $value; + + $this->setModified('last_commit'); + } + + /** + * Set the value of BuildConfig / build_config. + * + * @param $value string + */ + public function setBuildConfig($value) + { + $this->validateString('BuildConfig', $value); + + if ($this->data['build_config'] === $value) { + return; + } + + $this->data['build_config'] = $value; + + $this->setModified('build_config'); + } + + /** + * Set the value of SshPublicKey / ssh_public_key. + * + * @param $value string + */ + public function setSshPublicKey($value) + { + $this->validateString('SshPublicKey', $value); + + if ($this->data['ssh_public_key'] === $value) { + return; + } + + $this->data['ssh_public_key'] = $value; + + $this->setModified('ssh_public_key'); + } + + /** + * 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); + + if ($this->data['allow_public_status'] === $value) { + return; + } + + $this->data['allow_public_status'] = $value; + + $this->setModified('allow_public_status'); + } + + /** + * 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); + + if ($this->data['archived'] === $value) { + return; + } + + $this->data['archived'] = $value; + + $this->setModified('archived'); + } + + /** + * 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); + + if ($this->data['group_id'] === $value) { + return; + } + + $this->data['group_id'] = $value; + + $this->setModified('group_id'); + } + + /** + * 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() + { + $key = $this->getGroupId(); + + if (empty($key)) { + return null; + } + + $cacheKey = 'Cache.ProjectGroup.' . $key; + $rtn = $this->cache->get($cacheKey, null); + + if (empty($rtn)) { + $rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key); + $this->cache->set($cacheKey, $rtn); + } + + return $rtn; + } + + /** + * Set Group - Accepts an ID, an array representing a ProjectGroup or a ProjectGroup model. + * + * @param $value mixed + */ + public function setGroup($value) + { + // Is this an instance of ProjectGroup? + if ($value instanceof ProjectGroup) { + return $this->setGroupObject($value); + } + + // Is this an array representing a ProjectGroup item? + if (is_array($value) && !empty($value['id'])) { + return $this->setGroupId($value['id']); + } + + // Is this a scalar value representing the ID of this foreign key? + return $this->setGroupId($value); + } + + /** + * Set Group - Accepts a ProjectGroup model. + * + * @param $value ProjectGroup + */ + public function setGroupObject(ProjectGroup $value) + { + return $this->setGroupId($value->getId()); + } + + /** + * Get Build models by ProjectId for this Project. + * + * @uses \PHPCensor\Store\BuildStore::getByProjectId() + * @uses \PHPCensor\Model\Build + * @return \PHPCensor\Model\Build[] + */ + public function getProjectBuilds() + { + 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 @@ -82,7 +690,15 @@ class Project extends ProjectBase $value = json_encode($value); } - parent::setAccessInformation($value); + $this->validateString('AccessInformation', $value); + + if ($this->data['access_information'] === $value) { + return; + } + + $this->data['access_information'] = $value; + + $this->setModified('access_information'); } /** diff --git a/src/PHPCensor/Model/ProjectGroup.php b/src/PHPCensor/Model/ProjectGroup.php index 9c764971..3d5adf16 100644 --- a/src/PHPCensor/Model/ProjectGroup.php +++ b/src/PHPCensor/Model/ProjectGroup.php @@ -1,18 +1,158 @@ null, + 'title' => null, + ]; + + /** + * @var array + */ + protected $getters = [ + // Direct property getters: + 'id' => 'getId', + 'title' => 'getTitle', + // Foreign key getters: + ]; + + /** + * @var array + */ + protected $setters = [ + // Direct property setters: + 'id' => 'setId', + 'title' => 'setTitle', + // Foreign key setters: + ]; + + /** + * @var array + */ + public $columns = [ + 'id' => [ + 'type' => 'int', + 'length' => 11, + 'primary_key' => true, + 'auto_increment' => true, + 'default' => null, + ], + 'title' => [ + 'type' => 'varchar', + 'length' => 100, + 'default' => null, + ], + ]; + + /** + * @var array + */ + public $indexes = [ + 'PRIMARY' => ['unique' => true, 'columns' => 'id'], + ]; + + /** + * @var array + */ + public $foreignKeys = []; + + /** + * Get the value of Id / id. + * + * @return int + */ + public function getId() + { + $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); + + if ($this->data['id'] === $value) { + return; + } + + $this->data['id'] = $value; + + $this->setModified('id'); + } + + /** + * 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); + + if ($this->data['title'] === $value) { + return; + } + + $this->data['title'] = $value; + + $this->setModified('title'); + } + + /** + * Get Project models by GroupId for this ProjectGroup. + * + * @uses \PHPCensor\Store\ProjectStore::getByGroupId() + * @uses \PHPCensor\Model\Project + * @return \PHPCensor\Model\Project[] + */ + public function getGroupProjects() + { + return Factory::getStore('Project', 'PHPCensor')->getByGroupId($this->getId(), false); + } } diff --git a/src/PHPCensor/Model/User.php b/src/PHPCensor/Model/User.php index e3afe0f1..e80582c4 100644 --- a/src/PHPCensor/Model/User.php +++ b/src/PHPCensor/Model/User.php @@ -1,25 +1,437 @@ -* @package PHPCI -* @subpackage Core -*/ -class User extends UserBase + * @author Dan Cryer + */ +class User extends Model { - // This class has been left blank so that you can modify it - changes in this file will not be overwritten. + /** + * @var array + */ + public static $sleepable = []; + + /** + * @var string + */ + protected $tableName = 'user'; + + /** + * @var string + */ + protected $modelName = 'User'; + + /** + * @var array + */ + protected $data = [ + 'id' => null, + 'email' => null, + 'hash' => null, + 'is_admin' => null, + 'name' => null, + 'language' => null, + 'per_page' => null, + 'provider_key' => null, + 'provider_data' => null, + ]; + + /** + * @var array + */ + protected $getters = [ + // Direct property getters: + 'id' => 'getId', + 'email' => 'getEmail', + 'hash' => 'getHash', + 'is_admin' => 'getIsAdmin', + 'name' => 'getName', + 'language' => 'getLanguage', + 'per_page' => 'getPerPage', + 'provider_key' => 'getProviderKey', + 'provider_data' => 'getProviderData', + // Foreign key getters: + ]; + + /** + * @var array + */ + protected $setters = [ + // Direct property setters: + 'id' => 'setId', + 'email' => 'setEmail', + 'hash' => 'setHash', + 'is_admin' => 'setIsAdmin', + 'name' => 'setName', + 'language' => 'setLanguage', + 'per_page' => 'setPerPage', + 'provider_key' => 'setProviderKey', + 'provider_data' => 'setProviderData', + // 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, + ], + ]; + + /** + * @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() + { + $rtn = $this->data['id']; + + return $rtn; + } + + /** + * Get the value of Email / email. + * + * @return string + */ + public function getEmail() + { + $rtn = $this->data['email']; + + return $rtn; + } + + /** + * Get the value of Hash / hash. + * + * @return string + */ + public function getHash() + { + $rtn = $this->data['hash']; + + return $rtn; + } + + /** + * Get the value of Name / name. + * + * @return string + */ + public function getName() + { + $rtn = $this->data['name']; + + return $rtn; + } + + /** + * Get the value of IsAdmin / is_admin. + * + * @return int + */ + public function getIsAdmin() + { + $rtn = $this->data['is_admin']; + + return $rtn; + } + + /** + * Get the value of ProviderKey / provider_key. + * + * @return string + */ + public function getProviderKey() + { + $rtn = $this->data['provider_key']; + + return $rtn; + } + + /** + * Get the value of ProviderData / provider_data. + * + * @return string + */ + public function getProviderData() + { + $rtn = $this->data['provider_data']; + + return $rtn; + } + + /** + * Get the value of Language / language. + * + * @return string + */ + public function getLanguage() + { + $rtn = $this->data['language']; + + return $rtn; + } + + /** + * Get the value of PerPage / per_page. + * + * @return string + */ + public function getPerPage() + { + $rtn = $this->data['per_page']; + + 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); + + if ($this->data['id'] === $value) { + return; + } + + $this->data['id'] = $value; + + $this->setModified('id'); + } + + /** + * 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); + + if ($this->data['email'] === $value) { + return; + } + + $this->data['email'] = $value; + + $this->setModified('email'); + } + + /** + * 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); + + if ($this->data['hash'] === $value) { + return; + } + + $this->data['hash'] = $value; + + $this->setModified('hash'); + } + + /** + * 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); + + if ($this->data['name'] === $value) { + return; + } + + $this->data['name'] = $value; + + $this->setModified('name'); + } + + /** + * 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); + + if ($this->data['is_admin'] === $value) { + return; + } + + $this->data['is_admin'] = $value; + + $this->setModified('is_admin'); + } + + /** + * 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); + + if ($this->data['provider_key'] === $value) { + return; + } + + $this->data['provider_key'] = $value; + + $this->setModified('provider_key'); + } + + /** + * Set the value of ProviderData / provider_data. + * + * @param $value string + */ + public function setProviderData($value) + { + $this->validateString('ProviderData', $value); + + if ($this->data['provider_data'] === $value) { + return; + } + + $this->data['provider_data'] = $value; + + $this->setModified('provider_data'); + } + + /** + * Set the value of Language / language. + * + * Must not be null. + * @param $value string + */ + public function setLanguage($value) + { + if ($this->data['language'] === $value) { + return; + } + + $this->data['language'] = $value; + + $this->setModified('language'); + } + + /** + * Set the value of PerPage / per_page. + * + * Must not be null. + * @param $value string + */ + public function setPerPage($value) + { + if ($this->data['per_page'] === $value) { + return; + } + + $this->data['per_page'] = $value; + + $this->setModified('per_page'); + } + + /** + * @return integer + */ + public function getFinalPerPage() + { + $perPage = $this->getPerPage(); + if ($perPage) { + return (integer)$perPage; + } + + return (integer)Config::getInstance()->get('php-censor.per_page', 10); + } } diff --git a/src/PHPCensor/Store/Base/BuildErrorStoreBase.php b/src/PHPCensor/Store/Base/BuildErrorStoreBase.php deleted file mode 100644 index 2bc31f9b..00000000 --- a/src/PHPCensor/Store/Base/BuildErrorStoreBase.php +++ /dev/null @@ -1,85 +0,0 @@ -getById($value, $useConnection); - } - - /** - * Get a single BuildError by Id. - * @return null|BuildError - */ - public function getById($value, $useConnection = 'read') - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new BuildError($data); - } - } - - return null; - } - - /** - * Get multiple BuildError by BuildId. - * @return array - */ - public function getByBuildId($value, $limit = 1000, $useConnection = 'read') - { - if (is_null($value)) { - 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(':limit', (int)$limit, \PDO::PARAM_INT); - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new BuildError($item); - }; - $rtn = array_map($map, $res); - - $count = count($rtn); - - return ['items' => $rtn, 'count' => $count]; - } else { - return ['items' => [], 'count' => 0]; - } - } -} diff --git a/src/PHPCensor/Store/Base/BuildMetaStoreBase.php b/src/PHPCensor/Store/Base/BuildMetaStoreBase.php deleted file mode 100644 index 6410732b..00000000 --- a/src/PHPCensor/Store/Base/BuildMetaStoreBase.php +++ /dev/null @@ -1,117 +0,0 @@ -getById($value, $useConnection); - } - - /** - * Get a single BuildMeta by Id. - * @return null|BuildMeta - */ - public function getById($value, $useConnection = 'read') - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new BuildMeta($data); - } - } - - return null; - } - - /** - * Get multiple BuildMeta by ProjectId. - * @return array - */ - public function getByProjectId($value, $limit = 1000, $useConnection = 'read') - { - if (is_null($value)) { - throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); - } - - - $query = 'SELECT * FROM {{build_meta}} WHERE {{project_id}} = :project_id LIMIT :limit'; - $stmt = Database::getConnection($useConnection)->prepareCommon($query); - $stmt->bindValue(':project_id', $value); - $stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT); - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new BuildMeta($item); - }; - $rtn = array_map($map, $res); - - $count = count($rtn); - - return ['items' => $rtn, 'count' => $count]; - } else { - return ['items' => [], 'count' => 0]; - } - } - - /** - * Get multiple BuildMeta by BuildId. - * @return array - */ - public function getByBuildId($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 {{build_id}} = :build_id LIMIT :limit'; - $stmt = Database::getConnection($useConnection)->prepareCommon($query); - $stmt->bindValue(':build_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]; - } - } -} diff --git a/src/PHPCensor/Store/Base/BuildStoreBase.php b/src/PHPCensor/Store/Base/BuildStoreBase.php deleted file mode 100644 index 849c1a65..00000000 --- a/src/PHPCensor/Store/Base/BuildStoreBase.php +++ /dev/null @@ -1,123 +0,0 @@ -getById($value, $useConnection); - } - - /** - * Get a single Build by Id. - * @return null|Build - */ - public function getById($value, $useConnection = 'read') - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new Build($data); - } - } - - return null; - } - - /** - * Get multiple Build 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}} 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 Build($item); - }; - $rtn = array_map($map, $res); - - $count = count($rtn); - - return ['items' => $rtn, 'count' => $count]; - } else { - return ['items' => [], 'count' => 0]; - } - } - - /** - * Get multiple Build by Status. - * - * @param $value - * @param int $limit - * @param string $useConnection - * - * @return array - * - * @throws HttpException - */ - public function getByStatus($value, $limit = 1000, $useConnection = 'read') - { - if (is_null($value)) { - 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(':limit', (int)$limit, \PDO::PARAM_INT); - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new Build($item); - }; - $rtn = array_map($map, $res); - - $count = count($rtn); - - return ['items' => $rtn, 'count' => $count]; - } else { - return ['items' => [], 'count' => 0]; - } - } -} diff --git a/src/PHPCensor/Store/Base/ProjectGroupStoreBase.php b/src/PHPCensor/Store/Base/ProjectGroupStoreBase.php deleted file mode 100644 index a8aed1a8..00000000 --- a/src/PHPCensor/Store/Base/ProjectGroupStoreBase.php +++ /dev/null @@ -1,90 +0,0 @@ -getById($value, $useConnection); - } - - /** - * Get a single ProjectGroup by Id. - * - * @param integer $value - * @param string $useConnection - * - * @return ProjectGroup|null - * - * @throws HttpException - */ - public function getById($value, $useConnection = 'read') - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new ProjectGroup($data); - } - } - - return null; - } - - /** - * Get a single ProjectGroup by title. - * - * @param integer $value - * @param string $useConnection - * - * @return ProjectGroup|null - * - * @throws HttpException - */ - public function getByTitle($value, $useConnection = 'read') - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new ProjectGroup($data); - } - } - - return null; - } -} diff --git a/src/PHPCensor/Store/Base/ProjectStoreBase.php b/src/PHPCensor/Store/Base/ProjectStoreBase.php deleted file mode 100644 index 50992bfb..00000000 --- a/src/PHPCensor/Store/Base/ProjectStoreBase.php +++ /dev/null @@ -1,117 +0,0 @@ -getById($value, $useConnection); - } - - /** - * Get a single Project by Id. - * @return null|Project - */ - public function getById($value, $useConnection = 'read') - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new Project($data); - } - } - - return null; - } - - /** - * Get multiple Project by Title. - * @return array - */ - public function getByTitle($value, $limit = 1000, $useConnection = 'read') - { - if (is_null($value)) { - 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(':limit', (int)$limit, \PDO::PARAM_INT); - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new Project($item); - }; - $rtn = array_map($map, $res); - - $count = count($rtn); - - return ['items' => $rtn, 'count' => $count]; - } else { - return ['items' => [], 'count' => 0]; - } - } - - /** - * Get multiple Project by GroupId. - * @return array - */ - public function getByGroupId($value, $limit = 1000, $useConnection = 'read') - { - if (is_null($value)) { - throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); - } - - - $query = 'SELECT * FROM {{project}} WHERE {{group_id}} = :group_id LIMIT :limit'; - $stmt = Database::getConnection($useConnection)->prepareCommon($query); - $stmt->bindValue(':group_id', $value); - $stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT); - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new Project($item); - }; - $rtn = array_map($map, $res); - - $count = count($rtn); - - return ['items' => $rtn, 'count' => $count]; - } else { - return ['items' => [], 'count' => 0]; - } - } -} diff --git a/src/PHPCensor/Store/Base/UserStoreBase.php b/src/PHPCensor/Store/Base/UserStoreBase.php deleted file mode 100644 index e8ab3f35..00000000 --- a/src/PHPCensor/Store/Base/UserStoreBase.php +++ /dev/null @@ -1,143 +0,0 @@ -getById($value, $useConnection); - } - - /** - * Get a single User by Id. - * @return null|User - */ - public function getById($value, $useConnection = 'read') - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new User($data); - } - } - - return null; - } - - /** - * - * Get a single User by Email. - * - * @param string $value - * - * @throws HttpException - * - * @return User - */ - public function getByEmail($value) - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new User($data); - } - } - - return null; - } - - /** - * - * Get a single User by Email or Name. - * - * @param string $value - * - * @throws HttpException - * - * @return User - */ - public function getByEmailOrName($value) - { - if (is_null($value)) { - 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); - - if ($stmt->execute()) { - if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { - return new User($data); - } - } - - return null; - } - - /** - * Get multiple User by Name. - * @return array - */ - public function getByName($value, $limit = 1000, $useConnection = 'read') - { - if (is_null($value)) { - 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(':limit', (int)$limit, \PDO::PARAM_INT); - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new User($item); - }; - $rtn = array_map($map, $res); - - $count = count($rtn); - - return ['items' => $rtn, 'count' => $count]; - } else { - return ['items' => [], 'count' => 0]; - } - } -} diff --git a/src/PHPCensor/Store/BuildErrorStore.php b/src/PHPCensor/Store/BuildErrorStore.php index 5e937382..1dbc7fea 100644 --- a/src/PHPCensor/Store/BuildErrorStore.php +++ b/src/PHPCensor/Store/BuildErrorStore.php @@ -1,21 +1,81 @@ getById($value, $useConnection); + } + + /** + * Get a single BuildError by Id. + * @return null|BuildError + */ + public function getById($value, $useConnection = 'read') + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new BuildError($data); + } + } + + return null; + } + + /** + * Get multiple BuildError by BuildId. + * @return array + */ + public function getByBuildId($value, $limit = 1000, $useConnection = 'read') + { + if (is_null($value)) { + 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(':limit', (int)$limit, \PDO::PARAM_INT); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return new BuildError($item); + }; + $rtn = array_map($map, $res); + + $count = count($rtn); + + return ['items' => $rtn, 'count' => $count]; + } else { + return ['items' => [], 'count' => 0]; + } + } + /** * Get a list of errors for a given build, since a given time. * @param $buildId diff --git a/src/PHPCensor/Store/BuildMetaStore.php b/src/PHPCensor/Store/BuildMetaStore.php index 269f726d..4c6e11ad 100644 --- a/src/PHPCensor/Store/BuildMetaStore.php +++ b/src/PHPCensor/Store/BuildMetaStore.php @@ -1,24 +1,113 @@ getById($value, $useConnection); + } + + /** + * Get a single BuildMeta by Id. + * @return null|BuildMeta + */ + public function getById($value, $useConnection = 'read') + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new BuildMeta($data); + } + } + + return null; + } + + /** + * Get multiple BuildMeta by ProjectId. + * @return array + */ + public function getByProjectId($value, $limit = 1000, $useConnection = 'read') + { + if (is_null($value)) { + throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); + } + + + $query = 'SELECT * FROM {{build_meta}} WHERE {{project_id}} = :project_id LIMIT :limit'; + $stmt = Database::getConnection($useConnection)->prepareCommon($query); + $stmt->bindValue(':project_id', $value); + $stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return new BuildMeta($item); + }; + $rtn = array_map($map, $res); + + $count = count($rtn); + + return ['items' => $rtn, 'count' => $count]; + } else { + return ['items' => [], 'count' => 0]; + } + } + + /** + * Get multiple BuildMeta by BuildId. + * @return array + */ + public function getByBuildId($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 {{build_id}} = :build_id LIMIT :limit'; + $stmt = Database::getConnection($useConnection)->prepareCommon($query); + $stmt->bindValue(':build_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]; + } + } + /** * Only used by an upgrade migration to move errors from build_meta to build_error * diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 246ab902..ed593eac 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -1,26 +1,122 @@ -* @package PHPCI -* @subpackage Core -*/ -class BuildStore extends BuildStoreBase + * @author Dan Cryer + */ +class BuildStore extends Store { + protected $tableName = 'build'; + protected $modelName = '\PHPCensor\Model\Build'; + protected $primaryKey = 'id'; + + /** + * Get a Build by primary key (Id) + */ + public function getByPrimaryKey($value, $useConnection = 'read') + { + return $this->getById($value, $useConnection); + } + + /** + * Get a single Build by Id. + * @return null|Build + */ + public function getById($value, $useConnection = 'read') + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new Build($data); + } + } + + return null; + } + + /** + * Get multiple Build 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}} 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 Build($item); + }; + $rtn = array_map($map, $res); + + $count = count($rtn); + + return ['items' => $rtn, 'count' => $count]; + } else { + return ['items' => [], 'count' => 0]; + } + } + + /** + * Get multiple Build by Status. + * + * @param $value + * @param int $limit + * @param string $useConnection + * + * @return array + * + * @throws HttpException + */ + public function getByStatus($value, $limit = 1000, $useConnection = 'read') + { + if (is_null($value)) { + 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(':limit', (int)$limit, \PDO::PARAM_INT); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return new Build($item); + }; + $rtn = array_map($map, $res); + + $count = count($rtn); + + return ['items' => $rtn, 'count' => $count]; + } else { + return ['items' => [], 'count' => 0]; + } + } + /** * Return an array of the latest builds for a given project. * @param null $projectId diff --git a/src/PHPCensor/Store/ProjectGroupStore.php b/src/PHPCensor/Store/ProjectGroupStore.php index 54a6580e..790a9134 100644 --- a/src/PHPCensor/Store/ProjectGroupStore.php +++ b/src/PHPCensor/Store/ProjectGroupStore.php @@ -1,18 +1,83 @@ getById($value, $useConnection); + } + + /** + * Get a single ProjectGroup by Id. + * + * @param integer $value + * @param string $useConnection + * + * @return ProjectGroup|null + * + * @throws HttpException + */ + public function getById($value, $useConnection = 'read') + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new ProjectGroup($data); + } + } + + return null; + } + + /** + * Get a single ProjectGroup by title. + * + * @param integer $value + * @param string $useConnection + * + * @return ProjectGroup|null + * + * @throws HttpException + */ + public function getByTitle($value, $useConnection = 'read') + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new ProjectGroup($data); + } + } + + return null; + } } diff --git a/src/PHPCensor/Store/ProjectStore.php b/src/PHPCensor/Store/ProjectStore.php index fe22bbe2..bc58d7f0 100644 --- a/src/PHPCensor/Store/ProjectStore.php +++ b/src/PHPCensor/Store/ProjectStore.php @@ -1,26 +1,84 @@ -* @package PHPCI -* @subpackage Core -*/ -class ProjectStore extends ProjectStoreBase + * @author Dan Cryer + */ +class ProjectStore extends Store { + protected $tableName = 'project'; + protected $modelName = '\PHPCensor\Model\Project'; + protected $primaryKey = 'id'; + + /** + * Get a Project by primary key (Id) + */ + public function getByPrimaryKey($value, $useConnection = 'read') + { + return $this->getById($value, $useConnection); + } + + /** + * Get a single Project by Id. + * @return null|Project + */ + public function getById($value, $useConnection = 'read') + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new Project($data); + } + } + + return null; + } + + /** + * Get multiple Project by Title. + * @return array + */ + public function getByTitle($value, $limit = 1000, $useConnection = 'read') + { + if (is_null($value)) { + 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(':limit', (int)$limit, \PDO::PARAM_INT); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return new Project($item); + }; + $rtn = array_map($map, $res); + + $count = count($rtn); + + return ['items' => $rtn, 'count' => $count]; + } else { + return ['items' => [], 'count' => 0]; + } + } + /** * Returns a list of all branch names PHPCI has run builds against. * @param $projectId diff --git a/src/PHPCensor/Store/UserStore.php b/src/PHPCensor/Store/UserStore.php index 38699da3..dbb356fe 100644 --- a/src/PHPCensor/Store/UserStore.php +++ b/src/PHPCensor/Store/UserStore.php @@ -1,23 +1,139 @@ -* @package PHPCI -* @subpackage Core -*/ -class UserStore extends UserStoreBase + * @author Dan Cryer + */ +class UserStore extends Store { - // This class has been left blank so that you can modify it - changes in this file will not be overwritten. + protected $tableName = 'user'; + protected $modelName = '\PHPCensor\Model\User'; + protected $primaryKey = 'id'; + + /** + * Get a User by primary key (Id) + */ + public function getByPrimaryKey($value, $useConnection = 'read') + { + return $this->getById($value, $useConnection); + } + + /** + * Get a single User by Id. + * @return null|User + */ + public function getById($value, $useConnection = 'read') + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new User($data); + } + } + + return null; + } + + /** + * + * Get a single User by Email. + * + * @param string $value + * + * @throws HttpException + * + * @return User + */ + public function getByEmail($value) + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new User($data); + } + } + + return null; + } + + /** + * + * Get a single User by Email or Name. + * + * @param string $value + * + * @throws HttpException + * + * @return User + */ + public function getByEmailOrName($value) + { + if (is_null($value)) { + 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); + + if ($stmt->execute()) { + if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { + return new User($data); + } + } + + return null; + } + + /** + * Get multiple User by Name. + * @return array + */ + public function getByName($value, $limit = 1000, $useConnection = 'read') + { + if (is_null($value)) { + 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(':limit', (int)$limit, \PDO::PARAM_INT); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return new User($item); + }; + $rtn = array_map($map, $res); + + $count = count($rtn); + + return ['items' => $rtn, 'count' => $count]; + } else { + return ['items' => [], 'count' => 0]; + } + } } diff --git a/tests/PHPCensor/Model/BuildTest.php b/tests/PHPCensor/Model/BuildTest.php index f7858e02..096fda34 100644 --- a/tests/PHPCensor/Model/BuildTest.php +++ b/tests/PHPCensor/Model/BuildTest.php @@ -29,7 +29,6 @@ class BuildTest extends \PHPUnit_Framework_TestCase $build = new Build(); $this->assertTrue($build instanceof \b8\Model); $this->assertTrue($build instanceof Model); - $this->assertTrue($build instanceof Model\Base\BuildBase); } public function testExecute_TestBaseBuildDefaults() diff --git a/tests/PHPCensor/Model/ProjectTest.php b/tests/PHPCensor/Model/ProjectTest.php index d753526f..4eed900f 100644 --- a/tests/PHPCensor/Model/ProjectTest.php +++ b/tests/PHPCensor/Model/ProjectTest.php @@ -20,16 +20,11 @@ use PHPCensor\Model; */ class ProjectTest extends \PHPUnit_Framework_TestCase { - public function setUp() - { - } - public function testExecute_TestIsAValidModel() { $project = new Project(); $this->assertTrue($project instanceof \b8\Model); $this->assertTrue($project instanceof Model); - $this->assertTrue($project instanceof Model\Base\ProjectBase); } public function testExecute_TestGitDefaultBranch()