diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index 648bb18c..97b427b5 100644 --- a/PHPCI/Model/Base/BuildBase.php +++ b/PHPCI/Model/Base/BuildBase.php @@ -45,8 +45,6 @@ class BuildBase extends Model 'committer_email' => null, 'commit_message' => null, 'extra' => null, - 'parent_id' => null, - 'engine' => null, ); /** @@ -66,12 +64,9 @@ class BuildBase extends Model 'committer_email' => 'getCommitterEmail', 'commit_message' => 'getCommitMessage', 'extra' => 'getExtra', - 'parent_id' => 'getParentId', - 'engine' => 'getEngine', // Foreign key getters: 'Project' => 'getProject', - 'Parent' => 'getParent', ); /** @@ -91,12 +86,9 @@ class BuildBase extends Model 'committer_email' => 'setCommitterEmail', 'commit_message' => 'setCommitMessage', 'extra' => 'setExtra', - 'parent_id' => 'setParentId', - 'engine' => 'setEngine', // Foreign key setters: 'Project' => 'setProject', - 'Parent' => 'setParent', ); /** @@ -167,18 +159,6 @@ class BuildBase extends Model 'nullable' => true, 'default' => null, ), - 'parent_id' => array( - 'type' => 'int', - 'length' => 11, - 'nullable' => true, - 'default' => null, - ), - 'engine' => array( - 'type' => 'varchar', - 'length' => 50, - 'nullable' => true, - 'default' => null, - ), ); /** @@ -188,7 +168,6 @@ class BuildBase extends Model 'PRIMARY' => array('unique' => true, 'columns' => 'id'), 'project_id' => array('columns' => 'project_id'), 'idx_status' => array('columns' => 'status'), - 'parent_id' => array('columns' => 'parent_id'), ); /** @@ -202,13 +181,6 @@ class BuildBase extends Model 'table' => 'project', 'col' => 'id' ), - 'build_ibfk_2' => array( - 'local_col' => 'parent_id', - 'update' => 'CASCADE', - 'delete' => 'CASCADE', - 'table' => 'build', - 'col' => 'id' - ), ); /** @@ -367,30 +339,6 @@ class BuildBase extends Model return $rtn; } - /** - * Get the value of ParentId / parent_id. - * - * @return int - */ - public function getParentId() - { - $rtn = $this->data['parent_id']; - - return $rtn; - } - - /** - * Get the value of Engine / engine. - * - * @return string - */ - public function getEngine() - { - $rtn = $this->data['engine']; - - return $rtn; - } - /** * Set the value of Id / id. * @@ -615,42 +563,6 @@ class BuildBase extends Model $this->_setModified('extra'); } - /** - * Set the value of ParentId / parent_id. - * - * @param $value int - */ - public function setParentId($value) - { - $this->_validateInt('ParentId', $value); - - if ($this->data['parent_id'] === $value) { - return; - } - - $this->data['parent_id'] = $value; - - $this->_setModified('parent_id'); - } - - /** - * Set the value of Engine / engine. - * - * @param $value string - */ - public function setEngine($value) - { - $this->_validateString('Engine', $value); - - if ($this->data['engine'] === $value) { - return; - } - - $this->data['engine'] = $value; - - $this->_setModified('engine'); - } - /** * Get the Project model for this Build by Id. * @@ -708,75 +620,6 @@ class BuildBase extends Model return $this->setProjectId($value->getId()); } - /** - * Get the Build model for this Build by Id. - * - * @uses \PHPCI\Store\BuildStore::getById() - * @uses \PHPCI\Model\Build - * @return \PHPCI\Model\Build - */ - public function getParent() - { - $key = $this->getParentId(); - - if (empty($key)) { - return null; - } - - $cacheKey = 'Cache.Build.' . $key; - $rtn = $this->cache->get($cacheKey, null); - - if (empty($rtn)) { - $rtn = Factory::getStore('Build', 'PHPCI')->getById($key); - $this->cache->set($cacheKey, $rtn); - } - - return $rtn; - } - - /** - * Set Parent - Accepts an ID, an array representing a Build or a Build model. - * - * @param $value mixed - */ - public function setParent($value) - { - // Is this an instance of Build? - if ($value instanceof \PHPCI\Model\Build) { - return $this->setParentObject($value); - } - - // Is this an array representing a Build item? - if (is_array($value) && !empty($value['id'])) { - return $this->setParentId($value['id']); - } - - // Is this a scalar value representing the ID of this foreign key? - return $this->setParentId($value); - } - - /** - * Set Parent - Accepts a Build model. - * - * @param $value \PHPCI\Model\Build - */ - public function setParentObject(\PHPCI\Model\Build $value) - { - return $this->setParentId($value->getId()); - } - - /** - * Get Build models by ParentId for this Build. - * - * @uses \PHPCI\Store\BuildStore::getByParentId() - * @uses \PHPCI\Model\Build - * @return \PHPCI\Model\Build[] - */ - public function getParentBuilds() - { - return Factory::getStore('Build', 'PHPCI')->getByParentId($this->getId()); - } - /** * Get BuildMeta models by BuildId for this Build. * diff --git a/PHPCI/Store/Base/BuildStoreBase.php b/PHPCI/Store/Base/BuildStoreBase.php index ff21155a..b67d5f73 100644 --- a/PHPCI/Store/Base/BuildStoreBase.php +++ b/PHPCI/Store/Base/BuildStoreBase.php @@ -107,36 +107,4 @@ class BuildStoreBase extends Store return array('items' => array(), 'count' => 0); } } - - public function getByParentId($value, $limit = null, $useConnection = 'read') - { - if (is_null($value)) { - throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); - } - - $add = ''; - - if ($limit) { - $add .= ' LIMIT ' . $limit; - } - - $count = null; - - $query = 'SELECT * FROM `build` WHERE `parent_id` = :parent_id' . $add; - $stmt = Database::getConnection($useConnection)->prepare($query); - $stmt->bindValue(':parent_id', $value); - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new Build($item); - }; - $rtn = array_map($map, $res); - - return array('items' => $rtn, 'count' => $count); - } else { - return array('items' => array(), 'count' => 0); - } - } }