Code style fixes + phpdocs.
This commit is contained in:
parent
9e57de043e
commit
508465fc74
|
@ -15,25 +15,36 @@ class BuildErrorStore extends Store
|
|||
|
||||
/**
|
||||
* Get a BuildError by primary key (Id)
|
||||
*
|
||||
* @param integer $key
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|BuildError
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
public function getByPrimaryKey($key, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
return $this->getById($key, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single BuildError by Id.
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|BuildError
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
public function getById($id, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($id)) {
|
||||
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);
|
||||
$stmt->bindValue(':id', $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -46,18 +57,25 @@ class BuildErrorStore extends Store
|
|||
|
||||
/**
|
||||
* Get multiple BuildError by BuildId.
|
||||
*
|
||||
* @param integer $buildId
|
||||
* @param integer $limit
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getByBuildId($value, $limit = 1000, $useConnection = 'read')
|
||||
public function getByBuildId($buildId, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($buildId)) {
|
||||
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(':build_id', $buildId);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
|
@ -78,8 +96,10 @@ class BuildErrorStore extends Store
|
|||
|
||||
/**
|
||||
* Get a list of errors for a given build, since a given time.
|
||||
* @param $buildId
|
||||
* @param string $since date string
|
||||
*
|
||||
* @param integer $buildId
|
||||
* @param string $since date string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorsForBuild($buildId, $since = null)
|
||||
|
@ -116,8 +136,9 @@ class BuildErrorStore extends Store
|
|||
|
||||
/**
|
||||
* Gets the total number of errors for a given build.
|
||||
* @param $buildId
|
||||
* @param string $since date string
|
||||
*
|
||||
* @param integer $buildId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorTotalForBuild($buildId)
|
||||
|
|
|
@ -11,7 +11,7 @@ use b8\Database;
|
|||
class BuildErrorWriter
|
||||
{
|
||||
/** @var int */
|
||||
protected $build_id;
|
||||
protected $buildId;
|
||||
|
||||
/** @var array */
|
||||
protected $errors = [];
|
||||
|
@ -20,17 +20,17 @@ class BuildErrorWriter
|
|||
* @var int
|
||||
* @see https://stackoverflow.com/questions/40361164/pdoexception-sqlstatehy000-general-error-7-number-of-parameters-must-be-bet
|
||||
*/
|
||||
protected $buffer_size;
|
||||
protected $bufferSize;
|
||||
|
||||
/**
|
||||
* BuildErrorWriter constructor.
|
||||
*
|
||||
* @param int $build_id
|
||||
* @param int $buildId
|
||||
*/
|
||||
public function __construct($build_id)
|
||||
public function __construct($buildId)
|
||||
{
|
||||
$this->buffer_size = (integer)Config::getInstance()->get('php-censor.build.writer_buffer_size', 500);
|
||||
$this->build_id = $build_id;
|
||||
$this->bufferSize = (integer)Config::getInstance()->get('php-censor.build.writer_buffer_size', 500);
|
||||
$this->buildId = $buildId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,33 +48,33 @@ class BuildErrorWriter
|
|||
* @param string $message
|
||||
* @param int $severity
|
||||
* @param string $file
|
||||
* @param int $line_start
|
||||
* @param int $line_end
|
||||
* @param \DateTime $created_date
|
||||
* @param int $lineStart
|
||||
* @param int $lineEnd
|
||||
* @param \DateTime $createdDate
|
||||
*/
|
||||
public function write(
|
||||
$plugin,
|
||||
$message,
|
||||
$severity,
|
||||
$file = null,
|
||||
$line_start = null,
|
||||
$line_end = null,
|
||||
$created_date = null
|
||||
$lineStart = null,
|
||||
$lineEnd = null,
|
||||
$createdDate = null
|
||||
) {
|
||||
if (is_null($created_date)) {
|
||||
$created_date = new \DateTime();
|
||||
if (is_null($createdDate)) {
|
||||
$createdDate = new \DateTime();
|
||||
}
|
||||
$this->errors[] = [
|
||||
'plugin' => (string)$plugin,
|
||||
'message' => (string)$message,
|
||||
'severity' => (int)$severity,
|
||||
'file' => !is_null($file) ? (string)$file : null,
|
||||
'line_start' => !is_null($line_start) ? (int)$line_start : null,
|
||||
'line_end' => !is_null($line_end) ? (int)$line_end : null,
|
||||
'created_date' => $created_date->format('Y-m-d H:i:s'),
|
||||
'line_start' => !is_null($lineStart) ? (int)$lineStart : null,
|
||||
'line_end' => !is_null($lineEnd) ? (int)$lineEnd : null,
|
||||
'created_date' => $createdDate->format('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
if (count($this->errors) >= $this->buffer_size) {
|
||||
if (count($this->errors) >= $this->bufferSize) {
|
||||
$this->flush();
|
||||
}
|
||||
}
|
||||
|
@ -88,10 +88,10 @@ class BuildErrorWriter
|
|||
return;
|
||||
}
|
||||
|
||||
$insert_values_placeholders = [];
|
||||
$insert_values_data = [];
|
||||
$insertValuesPlaceholders = [];
|
||||
$insertValuesData = [];
|
||||
foreach ($this->errors as $i => $error) {
|
||||
$insert_values_placeholders[] = '(
|
||||
$insertValuesPlaceholders[] = '(
|
||||
:build_id' . $i . ',
|
||||
:plugin' . $i . ',
|
||||
:file' . $i . ',
|
||||
|
@ -101,14 +101,14 @@ class BuildErrorWriter
|
|||
:message' . $i . ',
|
||||
:created_date' . $i . '
|
||||
)';
|
||||
$insert_values_data['build_id' . $i] = $this->build_id;
|
||||
$insert_values_data['plugin' . $i] = $error['plugin'];
|
||||
$insert_values_data['file' . $i] = $error['file'];
|
||||
$insert_values_data['line_start' . $i] = $error['line_start'];
|
||||
$insert_values_data['line_end' . $i] = $error['line_end'];
|
||||
$insert_values_data['severity' . $i] = $error['severity'];
|
||||
$insert_values_data['message' . $i] = $error['message'];
|
||||
$insert_values_data['created_date' . $i] = $error['created_date'];
|
||||
$insertValuesData['build_id' . $i] = $this->buildId;
|
||||
$insertValuesData['plugin' . $i] = $error['plugin'];
|
||||
$insertValuesData['file' . $i] = $error['file'];
|
||||
$insertValuesData['line_start' . $i] = $error['line_start'];
|
||||
$insertValuesData['line_end' . $i] = $error['line_end'];
|
||||
$insertValuesData['severity' . $i] = $error['severity'];
|
||||
$insertValuesData['message' . $i] = $error['message'];
|
||||
$insertValuesData['created_date' . $i] = $error['created_date'];
|
||||
}
|
||||
$query = '
|
||||
INSERT INTO {{build_error}} (
|
||||
|
@ -121,10 +121,10 @@ class BuildErrorWriter
|
|||
{{message}},
|
||||
{{created_date}}
|
||||
)
|
||||
VALUES ' . join(', ', $insert_values_placeholders) . '
|
||||
VALUES ' . join(', ', $insertValuesPlaceholders) . '
|
||||
';
|
||||
$stmt = Database::getConnection('write')->prepareCommon($query);
|
||||
$stmt->execute($insert_values_data);
|
||||
$stmt->execute($insertValuesData);
|
||||
$this->errors = [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,31 +9,42 @@ use b8\Exception\HttpException;
|
|||
|
||||
class BuildMetaStore extends Store
|
||||
{
|
||||
protected $tableName = 'build_meta';
|
||||
protected $modelName = '\PHPCensor\Model\BuildMeta';
|
||||
protected $primaryKey = 'id';
|
||||
protected $tableName = 'build_meta';
|
||||
protected $modelName = '\PHPCensor\Model\BuildMeta';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a BuildMeta by primary key (Id)
|
||||
*
|
||||
* @param integer $key
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|BuildMeta
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
public function getByPrimaryKey($key, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
return $this->getById($key, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single BuildMeta by Id.
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|BuildMeta
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
public function getById($id, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($id)) {
|
||||
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);
|
||||
$stmt->bindValue(':id', $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -46,18 +57,25 @@ class BuildMetaStore extends Store
|
|||
|
||||
/**
|
||||
* Get multiple BuildMeta by BuildId.
|
||||
*
|
||||
* @param integer $buildId
|
||||
* @param integer $limit
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getByBuildId($value, $limit = 1000, $useConnection = 'read')
|
||||
public function getByBuildId($buildId, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($buildId)) {
|
||||
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(':build_id', $buildId);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
|
|
|
@ -18,25 +18,36 @@ class BuildStore extends Store
|
|||
|
||||
/**
|
||||
* Get a Build by primary key (Id)
|
||||
*
|
||||
* @param integer $key
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|Build
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
public function getByPrimaryKey($key, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
return $this->getById($key, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single Build by Id.
|
||||
* @return null|Build
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return Build|null
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
public function getById($id, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($id)) {
|
||||
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);
|
||||
$stmt->bindValue(':id', $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -49,18 +60,24 @@ class BuildStore extends Store
|
|||
|
||||
/**
|
||||
* Get multiple Build by ProjectId.
|
||||
*
|
||||
* @param integer $projectId
|
||||
* @param integer $limit
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getByProjectId($value, $limit = 1000, $useConnection = 'read')
|
||||
public function getByProjectId($projectId, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($projectId)) {
|
||||
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(':project_id', $projectId);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
|
@ -82,23 +99,23 @@ class BuildStore extends Store
|
|||
/**
|
||||
* Get multiple Build by Status.
|
||||
*
|
||||
* @param $value
|
||||
* @param int $limit
|
||||
* @param string $useConnection
|
||||
* @param integer $status
|
||||
* @param integer $limit
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getByStatus($value, $limit = 1000, $useConnection = 'read')
|
||||
public function getByStatus($status, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($status)) {
|
||||
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(':status', $status);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
|
@ -147,8 +164,10 @@ class BuildStore extends Store
|
|||
|
||||
/**
|
||||
* Return an array of the latest builds for a given project.
|
||||
* @param null $projectId
|
||||
* @param int $limit
|
||||
*
|
||||
* @param integer|null $projectId
|
||||
* @param integer $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLatestBuilds($projectId = null, $limit = 5)
|
||||
|
@ -183,8 +202,10 @@ class BuildStore extends Store
|
|||
|
||||
/**
|
||||
* Return the latest build for a specific project, of a specific build status.
|
||||
* @param null $projectId
|
||||
* @param int $status
|
||||
*
|
||||
* @param integer|null $projectId
|
||||
* @param integer $status
|
||||
*
|
||||
* @return array|Build
|
||||
*/
|
||||
public function getLastBuildByStatus($projectId = null, $status = Build::STATUS_SUCCESS)
|
||||
|
@ -237,8 +258,10 @@ class BuildStore extends Store
|
|||
/**
|
||||
* Returns all registered branches for project
|
||||
*
|
||||
* @param $projectId
|
||||
* @param integer $projectId
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getBuildBranches($projectId)
|
||||
|
@ -257,11 +280,13 @@ class BuildStore extends Store
|
|||
|
||||
/**
|
||||
* Return build metadata by key, project and optionally build id.
|
||||
* @param $key
|
||||
* @param $projectId
|
||||
* @param null $buildId
|
||||
* @param null $branch
|
||||
* @param int $numResults
|
||||
*
|
||||
* @param string $key
|
||||
* @param integer $projectId
|
||||
* @param integer|null $buildId
|
||||
* @param string|null $branch
|
||||
* @param integer $numResults
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getMeta($key, $projectId, $buildId = null, $branch = null, $numResults = 1)
|
||||
|
@ -318,11 +343,11 @@ class BuildStore extends Store
|
|||
/**
|
||||
* Set a metadata value for a given project and build ID.
|
||||
*
|
||||
* @param $buildId
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @param integer $buildId
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
* @return boolean
|
||||
*/
|
||||
public function setMeta($buildId, $key, $value)
|
||||
{
|
||||
|
@ -343,9 +368,11 @@ class BuildStore extends Store
|
|||
|
||||
/**
|
||||
* Update status only if it synced with db
|
||||
* @param Build $build
|
||||
* @param int $status
|
||||
* @return bool
|
||||
*
|
||||
* @param Build $build
|
||||
* @param integer $status
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function updateStatusSync($build, $status)
|
||||
{
|
||||
|
|
|
@ -15,31 +15,36 @@ class EnvironmentStore extends Store
|
|||
|
||||
/**
|
||||
* Get a Environment by primary key (Id)
|
||||
* @param int $value
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @param integer $key
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|Environment
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
public function getByPrimaryKey($key, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
return $this->getById($key, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single Environment by Id.
|
||||
* @param $value
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|Environment
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
public function getById($id, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($id)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM {{environment}} WHERE {{id}} = :id LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
|
||||
$stmt->bindValue(':id', $value);
|
||||
$stmt->bindValue(':id', $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -52,24 +57,24 @@ class EnvironmentStore extends Store
|
|||
|
||||
/**
|
||||
* Get multiple Environment by Project id.
|
||||
*
|
||||
* @param integer $value
|
||||
*
|
||||
* @param integer $projectId
|
||||
* @param string $useConnection
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getByProjectId($value, $useConnection = 'read')
|
||||
public function getByProjectId($projectId, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($projectId)) {
|
||||
throw new \Exception('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM {{environment}} WHERE {{project_id}} = :project_id';
|
||||
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
|
||||
|
||||
$stmt->bindValue(':project_id', $value);
|
||||
$stmt->bindValue(':project_id', $projectId);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
|
|
@ -9,38 +9,43 @@ use PHPCensor\Model\ProjectGroup;
|
|||
|
||||
class ProjectGroupStore extends Store
|
||||
{
|
||||
protected $tableName = 'project_group';
|
||||
protected $modelName = '\PHPCensor\Model\ProjectGroup';
|
||||
protected $primaryKey = 'id';
|
||||
protected $tableName = 'project_group';
|
||||
protected $modelName = '\PHPCensor\Model\ProjectGroup';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a ProjectGroup by primary key (Id)
|
||||
*
|
||||
* @param integer $key
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|ProjectGroup
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
public function getByPrimaryKey($key, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
return $this->getById($key, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single ProjectGroup by Id.
|
||||
*
|
||||
* @param integer $value
|
||||
* @param integer $id
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return ProjectGroup|null
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
public function getById($id, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($id)) {
|
||||
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);
|
||||
$stmt->bindValue(':id', $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -54,23 +59,23 @@ class ProjectGroupStore extends Store
|
|||
/**
|
||||
* Get a single ProjectGroup by title.
|
||||
*
|
||||
* @param integer $value
|
||||
* @param integer $title
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return ProjectGroup|null
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getByTitle($value, $useConnection = 'read')
|
||||
public function getByTitle($title, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($title)) {
|
||||
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);
|
||||
$stmt->bindValue(':title', $title);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
|
|
@ -12,31 +12,42 @@ use b8\Exception\HttpException;
|
|||
*/
|
||||
class ProjectStore extends Store
|
||||
{
|
||||
protected $tableName = 'project';
|
||||
protected $modelName = '\PHPCensor\Model\Project';
|
||||
protected $primaryKey = 'id';
|
||||
protected $tableName = 'project';
|
||||
protected $modelName = '\PHPCensor\Model\Project';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a Project by primary key (Id)
|
||||
*
|
||||
* @param integer $key
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|Project
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
public function getByPrimaryKey($key, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
return $this->getById($key, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single Project by Id.
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|Project
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
public function getById($id, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($id)) {
|
||||
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);
|
||||
$stmt->bindValue(':id', $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -49,18 +60,25 @@ class ProjectStore extends Store
|
|||
|
||||
/**
|
||||
* Get multiple Project by Title.
|
||||
*
|
||||
* @param string $title
|
||||
* @param integer $limit
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getByTitle($value, $limit = 1000, $useConnection = 'read')
|
||||
public function getByTitle($title, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($title)) {
|
||||
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(':title', $title);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
|
@ -81,7 +99,9 @@ class ProjectStore extends Store
|
|||
|
||||
/**
|
||||
* Returns a list of all branch names PHPCI has run builds against.
|
||||
*
|
||||
* @param $projectId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getKnownBranches($projectId)
|
||||
|
@ -106,9 +126,9 @@ class ProjectStore extends Store
|
|||
|
||||
/**
|
||||
* Get a list of all projects, ordered by their title.
|
||||
*
|
||||
*
|
||||
* @param boolean $archived
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll($archived = false)
|
||||
|
@ -139,19 +159,19 @@ class ProjectStore extends Store
|
|||
|
||||
/**
|
||||
* Get multiple Project by GroupId.
|
||||
*
|
||||
* @param integer $value
|
||||
*
|
||||
* @param integer $groupId
|
||||
* @param boolean $archived
|
||||
* @param integer $limit
|
||||
* @param string $useConnection
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getByGroupId($value, $archived = false, $limit = 1000, $useConnection = 'read')
|
||||
public function getByGroupId($groupId, $archived = false, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($groupId)) {
|
||||
throw new \Exception('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
$archived = (integer)$archived;
|
||||
|
@ -159,7 +179,7 @@ class ProjectStore extends Store
|
|||
$query = 'SELECT * FROM {{project}} WHERE {{group_id}} = :group_id AND {{archived}} = :archived ORDER BY {{title}} LIMIT :limit';
|
||||
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
|
||||
|
||||
$stmt->bindValue(':group_id', $value);
|
||||
$stmt->bindValue(':group_id', $groupId);
|
||||
$stmt->bindValue(':archived', $archived);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
|
|
|
@ -12,31 +12,42 @@ use PHPCensor\Model\User;
|
|||
*/
|
||||
class UserStore extends Store
|
||||
{
|
||||
protected $tableName = 'user';
|
||||
protected $modelName = '\PHPCensor\Model\User';
|
||||
protected $primaryKey = 'id';
|
||||
protected $tableName = 'user';
|
||||
protected $modelName = '\PHPCensor\Model\User';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a User by primary key (Id)
|
||||
*
|
||||
* @param integer $key
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|User
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
public function getByPrimaryKey($key, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
return $this->getById($key, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single User by Id.
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return null|User
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
public function getById($id, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($id)) {
|
||||
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);
|
||||
$stmt->bindValue(':id', $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -48,25 +59,24 @@ class UserStore extends Store
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get a single User by Email.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $email
|
||||
*
|
||||
* @throws HttpException
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getByEmail($value)
|
||||
public function getByEmail($email)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($email)) {
|
||||
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);
|
||||
$stmt->bindValue(':email', $email);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -78,24 +88,23 @@ class UserStore extends Store
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get a single User by Email or Name.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $emailOrName
|
||||
*
|
||||
* @throws HttpException
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getByEmailOrName($value)
|
||||
public function getByEmailOrName($emailOrName)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($emailOrName)) {
|
||||
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);
|
||||
$stmt->bindValue(':value', $emailOrName);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -107,24 +116,23 @@ class UserStore extends Store
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get a single User by RememberKey.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $rememberKey
|
||||
*
|
||||
* @throws HttpException
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getByRememberKey($value)
|
||||
public function getByRememberKey($rememberKey)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($rememberKey)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM {{user}} WHERE {{remember_key}} = :value LIMIT 1';
|
||||
$query = 'SELECT * FROM {{user}} WHERE {{remember_key}} = :remember_key LIMIT 1';
|
||||
$stmt = Database::getConnection()->prepareCommon($query);
|
||||
$stmt->bindValue(':value', $value);
|
||||
$stmt->bindValue(':remember_key', $rememberKey);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
@ -137,20 +145,24 @@ class UserStore extends Store
|
|||
|
||||
/**
|
||||
* Get multiple User by Name.
|
||||
*
|
||||
* @throws HttpException
|
||||
*
|
||||
*
|
||||
* @param string $name
|
||||
* @param integer $limit
|
||||
* @param string $useConnection
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getByName($value, $limit = 1000, $useConnection = 'read')
|
||||
public function getByName($name, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_null($name)) {
|
||||
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(':name', $name);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
|
|
Loading…
Reference in a new issue