diff --git a/PHPCI/Command/GenerateCommand.php b/PHPCI/Command/GenerateCommand.php index 3a97f70c..44a499de 100644 --- a/PHPCI/Command/GenerateCommand.php +++ b/PHPCI/Command/GenerateCommand.php @@ -37,7 +37,7 @@ class GenerateCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $gen = new CodeGenerator(Database::getConnection(), 'PHPCI', PHPCI_DIR . '/PHPCI/', false); + $gen = new CodeGenerator(Database::getConnection(), ['default' => 'PHPCI'], ['default' => PHPCI_DIR], false); $gen->generateModels(); $gen->generateStores(); } diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index c8761e87..1b118440 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -54,6 +54,7 @@ class WebhookController extends \PHPCI\Controller $build->setLog(''); $build->setCreated(new \DateTime()); $build->setBranch($commit['branch']); + $build->setCommitMessage($commit['message']); $this->buildStore->save($build); } catch (\Exception $ex) { } @@ -137,6 +138,7 @@ class WebhookController extends \PHPCI\Controller $build->setCreated(new \DateTime()); $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); $build->setCommitterEmail($commit['committer']['email']); + $build->setCommitMessage($commit['message']); $build = $this->buildStore->save($build); $build->sendStatusPostback(); } @@ -150,6 +152,8 @@ class WebhookController extends \PHPCI\Controller $build->setCreated(new \DateTime()); $build->setBranch(str_replace('refs/tags/', 'Tag: ', $payload['ref'])); $build->setCommitterEmail($payload['pusher']['email']); + $build->setCommitMessage($payload['head_commit']['message']); + $build = $this->buildStore->save($build); $build->sendStatusPostback(); } @@ -185,6 +189,7 @@ class WebhookController extends \PHPCI\Controller $build->setCreated(new \DateTime()); $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); $build->setCommitterEmail($commit['author']['email']); + $build->setCommitMessage($commit['message']); $build = $this->buildStore->save($build); $build->sendStatusPostback(); } diff --git a/PHPCI/Model.php b/PHPCI/Model.php new file mode 100644 index 00000000..392df656 --- /dev/null +++ b/PHPCI/Model.php @@ -0,0 +1,7 @@ + null, 'plugins' => null, 'committer_email' => null, + 'commit_message' => null, ); /** @@ -62,6 +63,7 @@ class BuildBase extends Model 'finished' => 'getFinished', 'plugins' => 'getPlugins', 'committer_email' => 'getCommitterEmail', + 'commit_message' => 'getCommitMessage', // Foreign key getters: 'Project' => 'getProject', @@ -83,6 +85,7 @@ class BuildBase extends Model 'finished' => 'setFinished', 'plugins' => 'setPlugins', 'committer_email' => 'setCommitterEmail', + 'commit_message' => 'setCommitMessage', // Foreign key setters: 'Project' => 'setProject', @@ -113,6 +116,7 @@ class BuildBase extends Model 'status' => array( 'type' => 'tinyint', 'length' => 4, + 'default' => null, ), 'log' => array( 'type' => 'longtext', @@ -150,6 +154,11 @@ class BuildBase extends Model 'nullable' => true, 'default' => null, ), + 'commit_message' => array( + 'type' => 'text', + 'nullable' => true, + 'default' => null, + ), ); /** @@ -318,6 +327,18 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of CommitMessage / commit_message. + * + * @return string + */ + public function getCommitMessage() + { + $rtn = $this->data['commit_message']; + + return $rtn; + } + /** * Set the value of Id / id. * @@ -524,6 +545,24 @@ class BuildBase extends Model $this->_setModified('committer_email'); } + /** + * Set the value of CommitMessage / commit_message. + * + * @param $value string + */ + public function setCommitMessage($value) + { + $this->_validateString('CommitMessage', $value); + + if ($this->data['commit_message'] === $value) { + return; + } + + $this->data['commit_message'] = $value; + + $this->_setModified('commit_message'); + } + /** * Get the Project model for this Build by Id. * @@ -543,24 +582,13 @@ class BuildBase extends Model $rtn = $this->cache->get($cacheKey, null); if (empty($rtn)) { - $rtn = Factory::getStore('Project')->getById($key); + $rtn = Factory::getStore('Project', 'PHPCI')->getById($key); $this->cache->set($cacheKey, $rtn); } return $rtn; } - /** - * Get the value of the project's Title / title. - * - * @return string - */ - public function getProjectTitle() - { - return $this->getProject()->getTitle(); - } - - /** * Set Project - Accepts an ID, an array representing a Project or a Project model. * @@ -601,6 +629,33 @@ class BuildBase extends Model */ public function getBuildBuildMetas() { - return Factory::getStore('BuildMeta')->getByBuildId($this->getId()); + return Factory::getStore('BuildMeta', 'PHPCI')->getByBuildId($this->getId()); } + + + + + public static function getByPrimaryKey($value, $useConnection = 'read') + { + return Factory::getStore('Build', 'PHPCI')->getByPrimaryKey($value, $useConnection); + } + + + public static function getById($value, $useConnection = 'read') + { + return Factory::getStore('Build', 'PHPCI')->getById($value, $useConnection); + } + + public static function getByProjectId($value, $limit = null, $useConnection = 'read') + { + return Factory::getStore('Build', 'PHPCI')->getByProjectId($value, $limit, $useConnection); + } + + public static function getByStatus($value, $limit = null, $useConnection = 'read') + { + return Factory::getStore('Build', 'PHPCI')->getByStatus($value, $limit, $useConnection); + } + + + } diff --git a/PHPCI/Model/Base/BuildMetaBase.php b/PHPCI/Model/Base/BuildMetaBase.php index 9ef0f457..83333102 100644 --- a/PHPCI/Model/Base/BuildMetaBase.php +++ b/PHPCI/Model/Base/BuildMetaBase.php @@ -6,7 +6,7 @@ namespace PHPCI\Model\Base; -use b8\Model; +use PHPCI\Model; use b8\Store\Factory; /** @@ -95,6 +95,7 @@ class BuildMetaBase extends Model 'meta_key' => array( 'type' => 'varchar', 'length' => 255, + 'default' => null, ), 'meta_value' => array( 'type' => 'text', @@ -299,7 +300,7 @@ class BuildMetaBase extends Model $rtn = $this->cache->get($cacheKey, null); if (empty($rtn)) { - $rtn = Factory::getStore('Build')->getById($key); + $rtn = Factory::getStore('Build', 'PHPCI')->getById($key); $this->cache->set($cacheKey, $rtn); } @@ -336,4 +337,26 @@ class BuildMetaBase extends Model { return $this->setBuildId($value->getId()); } + + + + + public static function getByPrimaryKey($value, $useConnection = 'read') + { + return Factory::getStore('BuildMeta', 'PHPCI')->getByPrimaryKey($value, $useConnection); + } + + + public static function getById($value, $useConnection = 'read') + { + return Factory::getStore('BuildMeta', 'PHPCI')->getById($value, $useConnection); + } + + public static function getByBuildId($value, $limit = null, $useConnection = 'read') + { + return Factory::getStore('BuildMeta', 'PHPCI')->getByBuildId($value, $limit, $useConnection); + } + + + } diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index 0ef016f7..df1c0a34 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -6,7 +6,7 @@ namespace PHPCI\Model\Base; -use b8\Model; +use PHPCI\Model; use b8\Store\Factory; /** @@ -91,10 +91,12 @@ class ProjectBase extends Model 'title' => array( 'type' => 'varchar', 'length' => 250, + 'default' => null, ), 'reference' => array( 'type' => 'varchar', 'length' => 250, + 'default' => null, ), 'git_key' => array( 'type' => 'text', @@ -215,21 +217,11 @@ class ProjectBase extends Model /** * Get the value of AccessInformation / access_information. * - * @param string|null $key Key of desired information - * * @return string */ - public function getAccessInformation($key = null) + public function getAccessInformation() { - $data = unserialize($this->data['access_information']); - - if (is_null($key)) { - $rtn = $data; - } else if (isset($data[$key])) { - $rtn = $data[$key]; - } else { - $rtn = null; - } + $rtn = $this->data['access_information']; return $rtn; } @@ -407,6 +399,28 @@ class ProjectBase extends Model */ public function getProjectBuilds() { - return Factory::getStore('Build')->getByProjectId($this->getId()); + return Factory::getStore('Build', 'PHPCI')->getByProjectId($this->getId()); } + + + + + public static function getByPrimaryKey($value, $useConnection = 'read') + { + return Factory::getStore('Project', 'PHPCI')->getByPrimaryKey($value, $useConnection); + } + + + public static function getById($value, $useConnection = 'read') + { + return Factory::getStore('Project', 'PHPCI')->getById($value, $useConnection); + } + + public static function getByTitle($value, $limit = null, $useConnection = 'read') + { + return Factory::getStore('Project', 'PHPCI')->getByTitle($value, $limit, $useConnection); + } + + + } diff --git a/PHPCI/Model/Base/UserBase.php b/PHPCI/Model/Base/UserBase.php index e8035660..f0b0e393 100644 --- a/PHPCI/Model/Base/UserBase.php +++ b/PHPCI/Model/Base/UserBase.php @@ -6,7 +6,7 @@ namespace PHPCI\Model\Base; -use b8\Model; +use PHPCI\Model; use b8\Store\Factory; /** @@ -82,14 +82,17 @@ class UserBase extends Model 'email' => array( 'type' => 'varchar', 'length' => 250, + 'default' => null, ), 'hash' => array( 'type' => 'varchar', 'length' => 250, + 'default' => null, ), 'is_admin' => array( 'type' => 'tinyint', 'length' => 1, + 'default' => null, ), 'name' => array( 'type' => 'varchar', @@ -270,4 +273,26 @@ class UserBase extends Model $this->_setModified('name'); } + + + + + public static function getByPrimaryKey($value, $useConnection = 'read') + { + return Factory::getStore('User', 'PHPCI')->getByPrimaryKey($value, $useConnection); + } + + + public static function getById($value, $useConnection = 'read') + { + return Factory::getStore('User', 'PHPCI')->getById($value, $useConnection); + } + + public static function getByEmail($value, $useConnection = 'read') + { + return Factory::getStore('User', 'PHPCI')->getByEmail($value, $useConnection); + } + + + } diff --git a/PHPCI/Store.php b/PHPCI/Store.php new file mode 100644 index 00000000..f0352680 --- /dev/null +++ b/PHPCI/Store.php @@ -0,0 +1,7 @@ +prepare($query); $stmt->bindValue(':id', $value); @@ -58,7 +58,7 @@ class BuildMetaStoreBase extends Store $count = null; - $query = 'SELECT * FROM build_meta WHERE build_id = :build_id' . $add; + $query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id' . $add; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':build_id', $value); diff --git a/PHPCI/Store/Base/BuildStoreBase.php b/PHPCI/Store/Base/BuildStoreBase.php index f0e66085..b67d5f73 100644 --- a/PHPCI/Store/Base/BuildStoreBase.php +++ b/PHPCI/Store/Base/BuildStoreBase.php @@ -8,7 +8,7 @@ namespace PHPCI\Store\Base; use b8\Database; use b8\Exception\HttpException; -use b8\Store; +use PHPCI\Store; use PHPCI\Model\Build; /** @@ -31,7 +31,7 @@ class BuildStoreBase extends Store throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM build WHERE id = :id LIMIT 1'; + $query = 'SELECT * FROM `build` WHERE `id` = :id LIMIT 1'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':id', $value); @@ -58,7 +58,7 @@ class BuildStoreBase extends Store $count = null; - $query = 'SELECT * FROM build WHERE project_id = :project_id' . $add; + $query = 'SELECT * FROM `build` WHERE `project_id` = :project_id' . $add; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':project_id', $value); @@ -90,7 +90,7 @@ class BuildStoreBase extends Store $count = null; - $query = 'SELECT * FROM build WHERE status = :status' . $add; + $query = 'SELECT * FROM `build` WHERE `status` = :status' . $add; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':status', $value); diff --git a/PHPCI/Store/Base/ProjectStoreBase.php b/PHPCI/Store/Base/ProjectStoreBase.php index 8b78c055..410a305e 100644 --- a/PHPCI/Store/Base/ProjectStoreBase.php +++ b/PHPCI/Store/Base/ProjectStoreBase.php @@ -8,7 +8,7 @@ namespace PHPCI\Store\Base; use b8\Database; use b8\Exception\HttpException; -use b8\Store; +use PHPCI\Store; use PHPCI\Model\Project; /** @@ -31,7 +31,7 @@ class ProjectStoreBase extends Store throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM project WHERE id = :id LIMIT 1'; + $query = 'SELECT * FROM `project` WHERE `id` = :id LIMIT 1'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':id', $value); @@ -58,7 +58,7 @@ class ProjectStoreBase extends Store $count = null; - $query = 'SELECT * FROM project WHERE title = :title' . $add; + $query = 'SELECT * FROM `project` WHERE `title` = :title' . $add; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':title', $value); diff --git a/PHPCI/Store/Base/UserStoreBase.php b/PHPCI/Store/Base/UserStoreBase.php index c4268804..fd903d8e 100644 --- a/PHPCI/Store/Base/UserStoreBase.php +++ b/PHPCI/Store/Base/UserStoreBase.php @@ -8,7 +8,7 @@ namespace PHPCI\Store\Base; use b8\Database; use b8\Exception\HttpException; -use b8\Store; +use PHPCI\Store; use PHPCI\Model\User; /** @@ -31,7 +31,7 @@ class UserStoreBase extends Store throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM user WHERE id = :id LIMIT 1'; + $query = 'SELECT * FROM `user` WHERE `id` = :id LIMIT 1'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':id', $value); @@ -50,7 +50,7 @@ class UserStoreBase extends Store throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM user WHERE email = :email LIMIT 1'; + $query = 'SELECT * FROM `user` WHERE `email` = :email LIMIT 1'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':email', $value); diff --git a/PHPCI/View/Build/view.phtml b/PHPCI/View/Build/view.phtml index 022979f3..26cc9618 100644 --- a/PHPCI/View/Build/view.phtml +++ b/PHPCI/View/Build/view.phtml @@ -1,6 +1,11 @@
Your commit = $build->getCommitId(); ?> caused a failed build in project = $project->getTitle(); ?>.
+= $build->getCommitMessage(); ?>
+Please review your commit and the build log.