Fixing issues related to LIMIT in Base Store files.

This commit is contained in:
Dan Cryer 2015-02-12 11:08:45 +00:00
parent 9379da1393
commit d481140ea2
5 changed files with 63 additions and 182 deletions

View file

@ -38,11 +38,11 @@ class ProjectBase extends Model
'reference' => null,
'branch' => null,
'ssh_private_key' => null,
'ssh_public_key' => null,
'type' => null,
'access_information' => null,
'last_commit' => null,
'build_config' => null,
'ssh_public_key' => null,
'allow_public_status' => null,
);
@ -56,11 +56,11 @@ class ProjectBase extends Model
'reference' => 'getReference',
'branch' => 'getBranch',
'ssh_private_key' => 'getSshPrivateKey',
'ssh_public_key' => 'getSshPublicKey',
'type' => 'getType',
'access_information' => 'getAccessInformation',
'last_commit' => 'getLastCommit',
'build_config' => 'getBuildConfig',
'ssh_public_key' => 'getSshPublicKey',
'allow_public_status' => 'getAllowPublicStatus',
// Foreign key getters:
@ -76,11 +76,11 @@ class ProjectBase extends Model
'reference' => 'setReference',
'branch' => 'setBranch',
'ssh_private_key' => 'setSshPrivateKey',
'ssh_public_key' => 'setSshPublicKey',
'type' => 'setType',
'access_information' => 'setAccessInformation',
'last_commit' => 'setLastCommit',
'build_config' => 'setBuildConfig',
'ssh_public_key' => 'setSshPublicKey',
'allow_public_status' => 'setAllowPublicStatus',
// Foreign key setters:
@ -117,11 +117,6 @@ class ProjectBase extends Model
'nullable' => true,
'default' => null,
),
'ssh_public_key' => array(
'type' => 'text',
'nullable' => true,
'default' => null,
),
'type' => array(
'type' => 'varchar',
'length' => 50,
@ -144,6 +139,11 @@ class ProjectBase extends Model
'nullable' => true,
'default' => null,
),
'ssh_public_key' => array(
'type' => 'text',
'nullable' => true,
'default' => null,
),
'allow_public_status' => array(
'type' => 'int',
'length' => 11,
@ -224,18 +224,6 @@ class ProjectBase extends Model
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 Type / type.
*
@ -284,6 +272,18 @@ class ProjectBase extends Model
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.
*
@ -394,24 +394,6 @@ class ProjectBase extends Model
$this->_setModified('ssh_private_key');
}
/**
* 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 Type / type.
*
@ -486,6 +468,24 @@ class ProjectBase extends Model
$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.
*

View file

@ -20,24 +20,11 @@ class BuildMetaStoreBase extends Store
protected $modelName = '\PHPCI\Model\BuildMeta';
protected $primaryKey = 'id';
/**
* Get a BuildMeta by primary key.
* @param mixed $value Primary key.
* @param string $useConnection Connection to use (read / write)
* @return \PHPCI\Model\BuildMeta|null
*/
public function getByPrimaryKey($value, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
}
/**
* Get a BuildMeta by Id.
* @param mixed $value.
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\BuildMeta|null;
*/
public function getById($value, $useConnection = 'read')
{
if (is_null($value)) {
@ -57,31 +44,17 @@ class BuildMetaStoreBase extends Store
return null;
}
/**
* Get an array of BuildMeta by ProjectId.
* @param mixed $value.
* @param int $limit
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\BuildMeta[]
*/
public function getByProjectId($value, $limit = null, $useConnection = 'read')
public function getByProjectId($value, $limit = 1000, $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_meta` WHERE `project_id` = :project_id' . $add;
$query = 'SELECT * FROM `build_meta` WHERE `project_id` = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':project_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -91,37 +64,25 @@ class BuildMetaStoreBase extends Store
};
$rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);
}
}
/**
* Get an array of BuildMeta by BuildId.
* @param mixed $value.
* @param int $limit
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\BuildMeta[]
*/
public function getByBuildId($value, $limit = null, $useConnection = 'read')
public function getByBuildId($value, $limit = 1000, $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_meta` WHERE `build_id` = :build_id' . $add;
$query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':build_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -131,6 +92,8 @@ class BuildMetaStoreBase extends Store
};
$rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);

View file

@ -20,24 +20,11 @@ class BuildStoreBase extends Store
protected $modelName = '\PHPCI\Model\Build';
protected $primaryKey = 'id';
/**
* Get a Build by primary key.
* @param mixed $value Primary key.
* @param string $useConnection Connection to use (read / write)
* @return \PHPCI\Model\Build|null
*/
public function getByPrimaryKey($value, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
}
/**
* Get a Build by Id.
* @param mixed $value.
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\Build|null;
*/
public function getById($value, $useConnection = 'read')
{
if (is_null($value)) {
@ -57,31 +44,17 @@ class BuildStoreBase extends Store
return null;
}
/**
* Get an array of Build by ProjectId.
* @param mixed $value.
* @param int $limit
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\Build[]
*/
public function getByProjectId($value, $limit = null, $useConnection = 'read')
public function getByProjectId($value, $limit = 1000, $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 `project_id` = :project_id' . $add;
$query = 'SELECT * FROM `build` WHERE `project_id` = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':project_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -91,37 +64,25 @@ class BuildStoreBase extends Store
};
$rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);
}
}
/**
* Get an array of Build by Status.
* @param mixed $value.
* @param int $limit
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\Build[]
*/
public function getByStatus($value, $limit = null, $useConnection = 'read')
public function getByStatus($value, $limit = 1000, $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 `status` = :status' . $add;
$query = 'SELECT * FROM `build` WHERE `status` = :status LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':status', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -131,6 +92,8 @@ class BuildStoreBase extends Store
};
$rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);

View file

@ -20,24 +20,11 @@ class ProjectStoreBase extends Store
protected $modelName = '\PHPCI\Model\Project';
protected $primaryKey = 'id';
/**
* Get a Project by primary key.
* @param mixed $value Primary key.
* @param string $useConnection Connection to use (read / write)
* @return \PHPCI\Model\Project|null
*/
public function getByPrimaryKey($value, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
}
/**
* Get a Project by Id.
* @param mixed $value.
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\Project|null;
*/
public function getById($value, $useConnection = 'read')
{
if (is_null($value)) {
@ -57,31 +44,17 @@ class ProjectStoreBase extends Store
return null;
}
/**
* Get an array of Project by Title.
* @param mixed $value.
* @param int $limit
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\Project[]
*/
public function getByTitle($value, $limit = null, $useConnection = 'read')
public function getByTitle($value, $limit = 1000, $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 `project` WHERE `title` = :title' . $add;
$query = 'SELECT * FROM `project` WHERE `title` = :title LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':title', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -91,6 +64,8 @@ class ProjectStoreBase extends Store
};
$rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);

View file

@ -20,24 +20,11 @@ class UserStoreBase extends Store
protected $modelName = '\PHPCI\Model\User';
protected $primaryKey = 'id';
/**
* Get a User by primary key.
* @param mixed $value Primary key.
* @param string $useConnection Connection to use (read / write)
* @return \PHPCI\Model\User|null
*/
public function getByPrimaryKey($value, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
}
/**
* Get a User by Id.
* @param mixed $value.
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\User|null;
*/
public function getById($value, $useConnection = 'read')
{
if (is_null($value)) {
@ -57,13 +44,6 @@ class UserStoreBase extends Store
return null;
}
/**
* Get a User by Email.
* @param mixed $value.
* @param string $useConnection Connection to use (read / write)
* @throws \b8\Exception\HttpException
* @return \PHPCI\Model\User|null;
*/
public function getByEmail($value, $useConnection = 'read')
{
if (is_null($value)) {