php-censor/src/PHPCensor/Model/Base/BuildBase.php

649 lines
14 KiB
PHP
Raw Normal View History

2013-05-03 17:02:53 +02:00
<?php
/**
* Build base model for table: build
*/
2016-07-19 20:28:11 +02:00
namespace PHPCensor\Model\Base;
2016-07-19 20:28:11 +02:00
use PHPCensor\Model;
2013-10-10 02:01:06 +02:00
use b8\Store\Factory;
2016-07-19 20:28:11 +02:00
use PHPCensor\Model\Project;
2013-05-03 17:02:53 +02:00
/**
* Build Base Model
*/
class BuildBase extends Model
{
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
public static $sleepable = [];
/**
* @var string
*/
protected $tableName = 'build';
/**
* @var string
*/
protected $modelName = 'Build';
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
protected $data = [
'id' => null,
'project_id' => null,
'commit_id' => null,
'status' => null,
'log' => null,
'branch' => null,
'created' => null,
'started' => null,
'finished' => null,
2013-07-30 03:55:29 +02:00
'committer_email' => null,
2016-04-21 06:58:09 +02:00
'commit_message' => null,
'extra' => null,
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
protected $getters = [
2013-10-10 02:01:06 +02:00
// Direct property getters:
2016-04-21 06:58:09 +02:00
'id' => 'getId',
'project_id' => 'getProjectId',
'commit_id' => 'getCommitId',
'status' => 'getStatus',
'log' => 'getLog',
'branch' => 'getBranch',
'created' => 'getCreated',
'started' => 'getStarted',
'finished' => 'getFinished',
2013-07-30 03:55:29 +02:00
'committer_email' => 'getCommitterEmail',
2016-04-21 06:58:09 +02:00
'commit_message' => 'getCommitMessage',
'extra' => 'getExtra',
2013-10-10 02:01:06 +02:00
// Foreign key getters:
'Project' => 'getProject',
2016-04-21 06:58:09 +02:00
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
protected $setters = [
2013-10-10 02:01:06 +02:00
// Direct property setters:
2016-04-21 06:58:09 +02:00
'id' => 'setId',
'project_id' => 'setProjectId',
'commit_id' => 'setCommitId',
'status' => 'setStatus',
'log' => 'setLog',
'branch' => 'setBranch',
'created' => 'setCreated',
'started' => 'setStarted',
'finished' => 'setFinished',
2013-07-30 03:55:29 +02:00
'committer_email' => 'setCommitterEmail',
2016-04-21 06:58:09 +02:00
'commit_message' => 'setCommitMessage',
'extra' => 'setExtra',
2013-10-10 02:01:06 +02:00
// Foreign key setters:
'Project' => 'setProject',
2016-04-21 06:58:09 +02:00
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
public $columns = [
'id' => [
'type' => 'int',
'length' => 11,
'primary_key' => true,
'auto_increment' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
'project_id' => [
'type' => 'int',
'length' => 11,
'default' => null,
2016-04-21 06:58:09 +02:00
],
'commit_id' => [
'type' => 'varchar',
'length' => 50,
2013-10-08 08:45:20 +02:00
'default' => null,
2016-04-21 06:58:09 +02:00
],
'status' => [
'type' => 'int',
'length' => 11,
'default' => null,
2016-04-21 06:58:09 +02:00
],
'log' => [
'type' => 'mediumtext',
'nullable' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
'branch' => [
'type' => 'varchar',
2016-04-25 19:30:23 +02:00
'length' => 250,
2013-10-08 08:45:20 +02:00
'default' => 'master',
2016-04-21 06:58:09 +02:00
],
'created' => [
'type' => 'datetime',
'nullable' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
'started' => [
'type' => 'datetime',
'nullable' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
'finished' => [
'type' => 'datetime',
'nullable' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
'committer_email' => [
'type' => 'varchar',
'length' => 512,
2013-07-30 03:55:29 +02:00
'nullable' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
'commit_message' => [
'type' => 'text',
2014-02-25 17:43:06 +01:00
'nullable' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
'extra' => [
'type' => 'text',
'nullable' => true,
2016-04-21 06:58:09 +02:00
'default' => null,
],
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
public $indexes = [
'PRIMARY' => ['unique' => true, 'columns' => 'id'],
'project_id' => ['columns' => 'project_id'],
'idx_status' => ['columns' => 'status'],
];
/**
* @var array
*/
2016-04-21 06:58:09 +02:00
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;
}
2013-07-30 03:55:29 +02:00
/**
* Get the value of CommitMessage / commit_message.
*
* @return string
*/
public function getCommitMessage()
2013-07-30 03:55:29 +02:00
{
$rtn = $this->data['commit_message'];
2013-07-30 03:55:29 +02:00
return $rtn;
}
2014-02-25 17:43:06 +01:00
/**
* Get the value of Extra / extra.
*
* @return string
*/
public function getExtra()
2014-02-25 17:43:06 +01:00
{
$rtn = $this->data['extra'];
2014-02-25 17:43:06 +01:00
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);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['id'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$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);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['project_id'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$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);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['commit_id'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$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);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['status'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$this->data['status'] = $value;
$this->_setModified('status');
}
/**
* Set the value of Log / log.
*
* @param $value string
*/
public function setLog($value)
{
$this->_validateString('Log', $value);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['log'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$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);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['branch'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$this->data['branch'] = $value;
$this->_setModified('branch');
}
/**
* Set the value of Created / created.
*
* @param $value \DateTime
*/
public function setCreated($value)
{
$this->_validateDate('Created', $value);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['created'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$this->data['created'] = $value;
$this->_setModified('created');
}
/**
* Set the value of Started / started.
*
* @param $value \DateTime
*/
public function setStarted($value)
{
$this->_validateDate('Started', $value);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['started'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$this->data['started'] = $value;
$this->_setModified('started');
}
/**
* Set the value of Finished / finished.
*
* @param $value \DateTime
*/
public function setFinished($value)
{
$this->_validateDate('Finished', $value);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['finished'] === $value) {
return;
}
2013-05-16 16:53:00 +02:00
$this->data['finished'] = $value;
$this->_setModified('finished');
}
2013-07-30 03:55:29 +02:00
/**
* Set the value of CommitterEmail / committer_email.
*
* @param $value string
*/
2013-07-30 03:55:29 +02:00
public function setCommitterEmail($value)
{
$this->_validateString('CommitterEmail', $value);
2013-10-10 02:01:06 +02:00
2013-10-08 08:45:20 +02:00
if ($this->data['committer_email'] === $value) {
2013-07-30 03:55:29 +02:00
return;
}
2013-07-30 03:55:29 +02:00
$this->data['committer_email'] = $value;
2013-07-30 03:55:29 +02:00
$this->_setModified('committer_email');
}
2014-02-25 17:43:06 +01:00
/**
* Set the value of CommitMessage / commit_message.
*
* @param $value string
*/
2014-02-25 17:43:06 +01:00
public function setCommitMessage($value)
{
$this->_validateString('CommitMessage', $value);
if ($this->data['commit_message'] === $value) {
return;
}
2014-02-25 17:43:06 +01:00
$this->data['commit_message'] = $value;
2014-02-25 17:43:06 +01:00
$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.
*
* @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)) {
2016-07-19 20:28:11 +02:00
$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?
2016-05-09 08:20:26 +02:00
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.
*
2016-05-09 08:20:26 +02:00
* @param $value Project
*/
2016-05-09 08:20:26 +02:00
public function setProjectObject(Project $value)
{
return $this->setProjectId($value->getId());
}
/**
* Get BuildError models by BuildId for this Build.
*
2016-07-19 20:28:11 +02:00
* @uses \PHPCensor\Store\BuildErrorStore::getByBuildId()
* @uses \PHPCensor\Model\BuildError
* @return \PHPCensor\Model\BuildError[]
*/
public function getBuildBuildErrors()
{
2016-07-19 20:28:11 +02:00
return Factory::getStore('BuildError', 'PHPCensor')->getByBuildId($this->getId());
}
/**
* Get BuildMeta models by BuildId for this Build.
*
2016-07-19 20:28:11 +02:00
* @uses \PHPCensor\Store\BuildMetaStore::getByBuildId()
* @uses \PHPCensor\Model\BuildMeta
* @return \PHPCensor\Model\BuildMeta[]
*/
public function getBuildBuildMetas()
{
2016-07-19 20:28:11 +02:00
return Factory::getStore('BuildMeta', 'PHPCensor')->getByBuildId($this->getId());
2014-02-25 17:43:06 +01:00
}
2013-05-03 17:02:53 +02:00
}