Fixed namespaces (PHPCI -> PHPCensor)
This commit is contained in:
parent
60d74b0b44
commit
60a2b7282a
238 changed files with 1014 additions and 863 deletions
85
src/PHPCensor/Store/Base/BuildErrorStoreBase.php
Normal file
85
src/PHPCensor/Store/Base/BuildErrorStoreBase.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* BuildError base store for table: build_error
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store\Base;
|
||||
|
||||
use b8\Database;
|
||||
use b8\Exception\HttpException;
|
||||
use PHPCensor\Store;
|
||||
use PHPCensor\Model\BuildError;
|
||||
|
||||
/**
|
||||
* BuildError Base Store
|
||||
*/
|
||||
class BuildErrorStoreBase extends Store
|
||||
{
|
||||
protected $tableName = 'build_error';
|
||||
protected $modelName = '\PHPCensor\Model\BuildError';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a BuildError by primary key (Id)
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single BuildError by Id.
|
||||
* @return null|BuildError
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `build_error` WHERE `id` = :id LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':id', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new BuildError($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple BuildError by BuildId.
|
||||
* @return array
|
||||
*/
|
||||
public function getByBuildId($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
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)->prepare($query);
|
||||
$stmt->bindValue(':build_id', $value);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new BuildError($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
117
src/PHPCensor/Store/Base/BuildMetaStoreBase.php
Normal file
117
src/PHPCensor/Store/Base/BuildMetaStoreBase.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* BuildMeta base store for table: build_meta
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store\Base;
|
||||
|
||||
use b8\Database;
|
||||
use b8\Exception\HttpException;
|
||||
use PHPCensor\Store;
|
||||
use PHPCensor\Model\BuildMeta;
|
||||
|
||||
/**
|
||||
* BuildMeta Base Store
|
||||
*/
|
||||
class BuildMetaStoreBase extends Store
|
||||
{
|
||||
protected $tableName = 'build_meta';
|
||||
protected $modelName = '\PHPCensor\Model\BuildMeta';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a BuildMeta by primary key (Id)
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single BuildMeta by Id.
|
||||
* @return null|BuildMeta
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `build_meta` WHERE `id` = :id LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':id', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new BuildMeta($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple BuildMeta by ProjectId.
|
||||
* @return array
|
||||
*/
|
||||
public function getByProjectId($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
|
||||
$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);
|
||||
|
||||
$map = function ($item) {
|
||||
return new BuildMeta($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple BuildMeta by BuildId.
|
||||
* @return array
|
||||
*/
|
||||
public function getByBuildId($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
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)->prepare($query);
|
||||
$stmt->bindValue(':build_id', $value);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new BuildMeta($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
117
src/PHPCensor/Store/Base/BuildStoreBase.php
Normal file
117
src/PHPCensor/Store/Base/BuildStoreBase.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Build base store for table: build
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store\Base;
|
||||
|
||||
use b8\Database;
|
||||
use b8\Exception\HttpException;
|
||||
use PHPCensor\Store;
|
||||
use PHPCensor\Model\Build;
|
||||
|
||||
/**
|
||||
* Build Base Store
|
||||
*/
|
||||
class BuildStoreBase extends Store
|
||||
{
|
||||
protected $tableName = 'build';
|
||||
protected $modelName = '\PHPCensor\Model\Build';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a Build by primary key (Id)
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single Build by Id.
|
||||
* @return null|Build
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `build` WHERE `id` = :id LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':id', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new Build($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple Build by ProjectId.
|
||||
* @return array
|
||||
*/
|
||||
public function getByProjectId($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
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)->prepare($query);
|
||||
$stmt->bindValue(':project_id', $value);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new Build($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple Build by Status.
|
||||
* @return array
|
||||
*/
|
||||
public function getByStatus($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
|
||||
$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);
|
||||
|
||||
$map = function ($item) {
|
||||
return new Build($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/PHPCensor/Store/Base/ProjectGroupStoreBase.php
Normal file
53
src/PHPCensor/Store/Base/ProjectGroupStoreBase.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ProjectGroup base store for table: project_group
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store\Base;
|
||||
|
||||
use b8\Database;
|
||||
use b8\Exception\HttpException;
|
||||
use PHPCensor\Store;
|
||||
use PHPCensor\Model\ProjectGroup;
|
||||
|
||||
/**
|
||||
* ProjectGroup Base Store
|
||||
*/
|
||||
class ProjectGroupStoreBase extends Store
|
||||
{
|
||||
protected $tableName = 'project_group';
|
||||
protected $modelName = '\PHPCensor\Model\ProjectGroup';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a ProjectGroup by primary key (Id)
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single ProjectGroup by Id.
|
||||
* @return null|ProjectGroup
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `project_group` WHERE `id` = :id LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':id', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new ProjectGroup($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
117
src/PHPCensor/Store/Base/ProjectStoreBase.php
Normal file
117
src/PHPCensor/Store/Base/ProjectStoreBase.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Project base store for table: project
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store\Base;
|
||||
|
||||
use b8\Database;
|
||||
use b8\Exception\HttpException;
|
||||
use PHPCensor\Store;
|
||||
use PHPCensor\Model\Project;
|
||||
|
||||
/**
|
||||
* Project Base Store
|
||||
*/
|
||||
class ProjectStoreBase extends Store
|
||||
{
|
||||
protected $tableName = 'project';
|
||||
protected $modelName = '\PHPCensor\Model\Project';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a Project by primary key (Id)
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single Project by Id.
|
||||
* @return null|Project
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `project` WHERE `id` = :id LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':id', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new Project($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple Project by Title.
|
||||
* @return array
|
||||
*/
|
||||
public function getByTitle($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
|
||||
$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);
|
||||
|
||||
$map = function ($item) {
|
||||
return new Project($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple Project by GroupId.
|
||||
* @return array
|
||||
*/
|
||||
public function getByGroupId($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
|
||||
$query = 'SELECT * FROM `project` WHERE `group_id` = :group_id LIMIT :limit';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':group_id', $value);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new Project($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
108
src/PHPCensor/Store/Base/UserStoreBase.php
Normal file
108
src/PHPCensor/Store/Base/UserStoreBase.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* User base store for table: user
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store\Base;
|
||||
|
||||
use b8\Database;
|
||||
use b8\Exception\HttpException;
|
||||
use PHPCensor\Store;
|
||||
use PHPCensor\Model\User;
|
||||
|
||||
/**
|
||||
* User Base Store
|
||||
*/
|
||||
class UserStoreBase extends Store
|
||||
{
|
||||
protected $tableName = 'user';
|
||||
protected $modelName = '\PHPCensor\Model\User';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Get a User by primary key (Id)
|
||||
*/
|
||||
public function getByPrimaryKey($value, $useConnection = 'read')
|
||||
{
|
||||
return $this->getById($value, $useConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single User by Id.
|
||||
* @return null|User
|
||||
*/
|
||||
public function getById($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `user` WHERE `id` = :id LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':id', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new User($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single User by Email.
|
||||
* @return null|User
|
||||
*/
|
||||
public function getByEmail($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `user` WHERE `email` = :email LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':email', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new User($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple User by Name.
|
||||
* @return array
|
||||
*/
|
||||
public function getByName($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
|
||||
$query = 'SELECT * FROM `user` WHERE `name` = :name LIMIT :limit';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':name', $value);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new User($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
80
src/PHPCensor/Store/BuildErrorStore.php
Normal file
80
src/PHPCensor/Store/BuildErrorStore.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* BuildError store for table: build_error
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store;
|
||||
|
||||
use b8\Database;
|
||||
use PHPCensor\Model\BuildError;
|
||||
use PHPCensor\Store\Base\BuildErrorStoreBase;
|
||||
|
||||
/**
|
||||
* BuildError Store
|
||||
* @uses PHPCI\Store\Base\BuildErrorStoreBase
|
||||
*/
|
||||
class BuildErrorStore extends BuildErrorStoreBase
|
||||
{
|
||||
/**
|
||||
* Get a list of errors for a given build, since a given time.
|
||||
* @param $buildId
|
||||
* @param string $since date string
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorsForBuild($buildId, $since = null)
|
||||
{
|
||||
$query = 'SELECT * FROM build_error
|
||||
WHERE build_id = :build';
|
||||
|
||||
if (!is_null($since)) {
|
||||
$query .= ' AND created_date > :since';
|
||||
}
|
||||
|
||||
$query .= ' LIMIT 15000';
|
||||
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
|
||||
$stmt->bindValue(':build', $buildId, \PDO::PARAM_INT);
|
||||
|
||||
if (!is_null($since)) {
|
||||
$stmt->bindValue(':since', $since);
|
||||
}
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new BuildError($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
return $rtn;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total number of errors for a given build.
|
||||
* @param $buildId
|
||||
* @param string $since date string
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorTotalForBuild($buildId)
|
||||
{
|
||||
$query = 'SELECT COUNT(*) AS total FROM build_error
|
||||
WHERE build_id = :build';
|
||||
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
|
||||
$stmt->bindValue(':build', $buildId, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
return $res['total'];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
52
src/PHPCensor/Store/BuildMetaStore.php
Normal file
52
src/PHPCensor/Store/BuildMetaStore.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store;
|
||||
|
||||
use PHPCensor\Store\Base\BuildMetaStoreBase;
|
||||
use b8\Database;
|
||||
use PHPCensor\Model\BuildMeta;
|
||||
|
||||
/**
|
||||
* BuildMeta Store
|
||||
* @uses PHPCI\Store\Base\BuildMetaStoreBase
|
||||
*/
|
||||
class BuildMetaStore extends BuildMetaStoreBase
|
||||
{
|
||||
/**
|
||||
* Only used by an upgrade migration to move errors from build_meta to build_error
|
||||
*
|
||||
* @param $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorsForUpgrade($limit)
|
||||
{
|
||||
$query = 'SELECT * FROM build_meta
|
||||
WHERE meta_key IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\', \'technical_debt - data\')
|
||||
ORDER BY id ASC LIMIT :limit';
|
||||
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
|
||||
$stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new BuildMeta($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
return $rtn;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
217
src/PHPCensor/Store/BuildStore.php
Normal file
217
src/PHPCensor/Store/BuildStore.php
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store;
|
||||
|
||||
use b8\Database;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Store\Base\BuildStoreBase;
|
||||
|
||||
/**
|
||||
* Build Store
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
class BuildStore extends BuildStoreBase
|
||||
{
|
||||
/**
|
||||
* Return an array of the latest builds for a given project.
|
||||
* @param null $projectId
|
||||
* @param int $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getLatestBuilds($projectId = null, $limit = 5)
|
||||
{
|
||||
if (!is_null($projectId)) {
|
||||
$query = 'SELECT * FROM build WHERE `project_id` = :pid ORDER BY id DESC LIMIT :limit';
|
||||
} else {
|
||||
$query = 'SELECT * FROM build ORDER BY id DESC LIMIT :limit';
|
||||
}
|
||||
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
|
||||
if (!is_null($projectId)) {
|
||||
$stmt->bindValue(':pid', $projectId);
|
||||
}
|
||||
|
||||
$stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new Build($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
return $rtn;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the latest build for a specific project, of a specific build status.
|
||||
* @param null $projectId
|
||||
* @param int $status
|
||||
* @return array|Build
|
||||
*/
|
||||
public function getLastBuildByStatus($projectId = null, $status = Build::STATUS_SUCCESS)
|
||||
{
|
||||
$query = 'SELECT * FROM build WHERE project_id = :pid AND status = :status ORDER BY id DESC LIMIT 1';
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
$stmt->bindValue(':pid', $projectId);
|
||||
$stmt->bindValue(':status', $status);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new Build($data);
|
||||
}
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of builds for a given project and commit ID.
|
||||
* @param $projectId
|
||||
* @param $commitId
|
||||
* @return array
|
||||
*/
|
||||
public function getByProjectAndCommit($projectId, $commitId)
|
||||
{
|
||||
$query = 'SELECT * FROM `build` WHERE `project_id` = :project_id AND `commit_id` = :commit_id';
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
$stmt->bindValue(':project_id', $projectId);
|
||||
$stmt->bindValue(':commit_id', $commitId);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new Build($item);
|
||||
};
|
||||
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
return ['items' => $rtn, 'count' => count($rtn)];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered branches for project
|
||||
*
|
||||
* @param $projectId
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getBuildBranches($projectId)
|
||||
{
|
||||
$query = 'SELECT DISTINCT `branch` FROM `build` WHERE `project_id` = :project_id';
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
$stmt->bindValue(':project_id', $projectId);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
return $res;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return build metadata by key, project and optionally build id.
|
||||
* @param $key
|
||||
* @param $projectId
|
||||
* @param null $buildId
|
||||
* @param null $branch
|
||||
* @param int $numResults
|
||||
* @return array|null
|
||||
*/
|
||||
public function getMeta($key, $projectId, $buildId = null, $branch = null, $numResults = 1)
|
||||
{
|
||||
$query = 'SELECT bm.build_id, bm.meta_key, bm.meta_value
|
||||
FROM build_meta AS bm
|
||||
LEFT JOIN build b ON b.id = bm.build_id
|
||||
WHERE bm.meta_key = :key
|
||||
AND bm.project_id = :projectId';
|
||||
|
||||
// If we're getting comparative meta data, include previous builds
|
||||
// otherwise just include the specified build ID:
|
||||
if ($numResults > 1) {
|
||||
$query .= ' AND bm.build_id <= :buildId ';
|
||||
} else {
|
||||
$query .= ' AND bm.build_id = :buildId ';
|
||||
}
|
||||
|
||||
// Include specific branch information if required:
|
||||
if (!is_null($branch)) {
|
||||
$query .= ' AND b.branch = :branch ';
|
||||
}
|
||||
|
||||
$query .= ' ORDER BY bm.id DESC LIMIT :numResults';
|
||||
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);
|
||||
$stmt->bindValue(':projectId', (int)$projectId, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(':buildId', (int)$buildId, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(':numResults', (int)$numResults, \PDO::PARAM_INT);
|
||||
|
||||
if (!is_null($branch)) {
|
||||
$stmt->bindValue(':branch', $branch, \PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$rtn = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$rtn = array_reverse($rtn);
|
||||
$rtn = array_map(function ($item) {
|
||||
$item['meta_value'] = json_decode($item['meta_value'], true);
|
||||
return $item;
|
||||
}, $rtn);
|
||||
|
||||
if (!count($rtn)) {
|
||||
return null;
|
||||
} else {
|
||||
return $rtn;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a metadata value for a given project and build ID.
|
||||
* @param $projectId
|
||||
* @param $buildId
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function setMeta($projectId, $buildId, $key, $value)
|
||||
{
|
||||
$cols = '`project_id`, `build_id`, `meta_key`, `meta_value`';
|
||||
$query = 'REPLACE INTO build_meta ('.$cols.') VALUES (:projectId, :buildId, :key, :value)';
|
||||
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);
|
||||
$stmt->bindValue(':projectId', (int)$projectId, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(':buildId', (int)$buildId, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(':value', $value, \PDO::PARAM_STR);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/PHPCensor/Store/ProjectGroupStore.php
Normal file
18
src/PHPCensor/Store/ProjectGroupStore.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ProjectGroup store for table: project_group
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store;
|
||||
|
||||
use PHPCensor\Store\Base\ProjectGroupStoreBase;
|
||||
|
||||
/**
|
||||
* ProjectGroup Store
|
||||
* @uses PHPCI\Store\Base\ProjectGroupStoreBase
|
||||
*/
|
||||
class ProjectGroupStore extends ProjectGroupStoreBase
|
||||
{
|
||||
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
|
||||
}
|
||||
109
src/PHPCensor/Store/ProjectStore.php
Normal file
109
src/PHPCensor/Store/ProjectStore.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store;
|
||||
|
||||
use b8\Database;
|
||||
use PHPCensor\Model\Project;
|
||||
use PHPCensor\Store\Base\ProjectStoreBase;
|
||||
|
||||
/**
|
||||
* Project Store
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
class ProjectStore extends ProjectStoreBase
|
||||
{
|
||||
/**
|
||||
* Returns a list of all branch names PHPCI has run builds against.
|
||||
* @param $projectId
|
||||
* @return array
|
||||
*/
|
||||
public function getKnownBranches($projectId)
|
||||
{
|
||||
$query = 'SELECT DISTINCT branch from build WHERE project_id = :pid';
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
$stmt->bindValue(':pid', $projectId);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return $item['branch'];
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
return $rtn;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all projects, ordered by their title.
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
$query = 'SELECT * FROM `project` ORDER BY `title` ASC';
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new Project($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple Project by GroupId.
|
||||
* @param int $value
|
||||
* @param int $limit
|
||||
* @param string $useConnection
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getByGroupId($value, $limit = 1000, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new \Exception('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `project` WHERE `group_id` = :group_id ORDER BY title LIMIT :limit';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':group_id', $value);
|
||||
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new Project($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
$count = count($rtn);
|
||||
|
||||
return ['items' => $rtn, 'count' => $count];
|
||||
} else {
|
||||
return ['items' => [], 'count' => 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/PHPCensor/Store/UserStore.php
Normal file
23
src/PHPCensor/Store/UserStore.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Store;
|
||||
|
||||
use PHPCensor\Store\Base\UserStoreBase;
|
||||
|
||||
/**
|
||||
* User Store
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
class UserStore extends UserStoreBase
|
||||
{
|
||||
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue