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

View file

@ -20,24 +20,11 @@ class BuildMetaStoreBase extends Store
protected $modelName = '\PHPCI\Model\BuildMeta'; protected $modelName = '\PHPCI\Model\BuildMeta';
protected $primaryKey = 'id'; 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') public function getByPrimaryKey($value, $useConnection = 'read')
{ {
return $this->getById($value, $useConnection); 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') public function getById($value, $useConnection = 'read')
{ {
if (is_null($value)) { if (is_null($value)) {
@ -57,31 +44,17 @@ class BuildMetaStoreBase extends Store
return null; return null;
} }
/** public function getByProjectId($value, $limit = 1000, $useConnection = 'read')
* 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')
{ {
if (is_null($value)) { if (is_null($value)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
} }
$add = '';
if ($limit) { $query = 'SELECT * FROM `build_meta` WHERE `project_id` = :project_id LIMIT :limit';
$add .= ' LIMIT ' . $limit;
}
$count = null;
$query = 'SELECT * FROM `build_meta` WHERE `project_id` = :project_id' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query); $stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':project_id', $value); $stmt->bindValue(':project_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) { if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -91,37 +64,25 @@ class BuildMetaStoreBase extends Store
}; };
$rtn = array_map($map, $res); $rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count); return array('items' => $rtn, 'count' => $count);
} else { } else {
return array('items' => array(), 'count' => 0); return array('items' => array(), 'count' => 0);
} }
} }
/** public function getByBuildId($value, $limit = 1000, $useConnection = 'read')
* 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')
{ {
if (is_null($value)) { if (is_null($value)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
} }
$add = '';
if ($limit) { $query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id LIMIT :limit';
$add .= ' LIMIT ' . $limit;
}
$count = null;
$query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query); $stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':build_id', $value); $stmt->bindValue(':build_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) { if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -131,6 +92,8 @@ class BuildMetaStoreBase extends Store
}; };
$rtn = array_map($map, $res); $rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count); return array('items' => $rtn, 'count' => $count);
} else { } else {
return array('items' => array(), 'count' => 0); return array('items' => array(), 'count' => 0);

View file

@ -20,24 +20,11 @@ class BuildStoreBase extends Store
protected $modelName = '\PHPCI\Model\Build'; protected $modelName = '\PHPCI\Model\Build';
protected $primaryKey = 'id'; 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') public function getByPrimaryKey($value, $useConnection = 'read')
{ {
return $this->getById($value, $useConnection); 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') public function getById($value, $useConnection = 'read')
{ {
if (is_null($value)) { if (is_null($value)) {
@ -57,31 +44,17 @@ class BuildStoreBase extends Store
return null; return null;
} }
/** public function getByProjectId($value, $limit = 1000, $useConnection = 'read')
* 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')
{ {
if (is_null($value)) { if (is_null($value)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
} }
$add = '';
if ($limit) { $query = 'SELECT * FROM `build` WHERE `project_id` = :project_id LIMIT :limit';
$add .= ' LIMIT ' . $limit;
}
$count = null;
$query = 'SELECT * FROM `build` WHERE `project_id` = :project_id' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query); $stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':project_id', $value); $stmt->bindValue(':project_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) { if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -91,37 +64,25 @@ class BuildStoreBase extends Store
}; };
$rtn = array_map($map, $res); $rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count); return array('items' => $rtn, 'count' => $count);
} else { } else {
return array('items' => array(), 'count' => 0); return array('items' => array(), 'count' => 0);
} }
} }
/** public function getByStatus($value, $limit = 1000, $useConnection = 'read')
* 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')
{ {
if (is_null($value)) { if (is_null($value)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
} }
$add = '';
if ($limit) { $query = 'SELECT * FROM `build` WHERE `status` = :status LIMIT :limit';
$add .= ' LIMIT ' . $limit;
}
$count = null;
$query = 'SELECT * FROM `build` WHERE `status` = :status' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query); $stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':status', $value); $stmt->bindValue(':status', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) { if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -131,6 +92,8 @@ class BuildStoreBase extends Store
}; };
$rtn = array_map($map, $res); $rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count); return array('items' => $rtn, 'count' => $count);
} else { } else {
return array('items' => array(), 'count' => 0); return array('items' => array(), 'count' => 0);

View file

@ -20,24 +20,11 @@ class ProjectStoreBase extends Store
protected $modelName = '\PHPCI\Model\Project'; protected $modelName = '\PHPCI\Model\Project';
protected $primaryKey = 'id'; 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') public function getByPrimaryKey($value, $useConnection = 'read')
{ {
return $this->getById($value, $useConnection); 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') public function getById($value, $useConnection = 'read')
{ {
if (is_null($value)) { if (is_null($value)) {
@ -57,31 +44,17 @@ class ProjectStoreBase extends Store
return null; return null;
} }
/** public function getByTitle($value, $limit = 1000, $useConnection = 'read')
* 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')
{ {
if (is_null($value)) { if (is_null($value)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
} }
$add = '';
if ($limit) { $query = 'SELECT * FROM `project` WHERE `title` = :title LIMIT :limit';
$add .= ' LIMIT ' . $limit;
}
$count = null;
$query = 'SELECT * FROM `project` WHERE `title` = :title' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query); $stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':title', $value); $stmt->bindValue(':title', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) { if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -91,6 +64,8 @@ class ProjectStoreBase extends Store
}; };
$rtn = array_map($map, $res); $rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count); return array('items' => $rtn, 'count' => $count);
} else { } else {
return array('items' => array(), 'count' => 0); return array('items' => array(), 'count' => 0);

View file

@ -20,24 +20,11 @@ class UserStoreBase extends Store
protected $modelName = '\PHPCI\Model\User'; protected $modelName = '\PHPCI\Model\User';
protected $primaryKey = 'id'; 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') public function getByPrimaryKey($value, $useConnection = 'read')
{ {
return $this->getById($value, $useConnection); 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') public function getById($value, $useConnection = 'read')
{ {
if (is_null($value)) { if (is_null($value)) {
@ -57,13 +44,6 @@ class UserStoreBase extends Store
return null; 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') public function getByEmail($value, $useConnection = 'read')
{ {
if (is_null($value)) { if (is_null($value)) {