From cc09d95a3dc80df79d2ae80e4de61620553aeb87 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Tue, 8 Oct 2013 07:45:20 +0100 Subject: [PATCH] SQL strict mode fixes. Closes #127 --- PHPCI/Command/UpdateCommand.php | 42 +++++++++++++++++++ PHPCI/Model/Base/BuildBase.php | 37 +++++++++++------ PHPCI/Model/Base/BuildMetaBase.php | 56 +++++++++++++++++++++++--- PHPCI/Model/Base/ProjectBase.php | 21 ++++++---- PHPCI/Model/Base/UserBase.php | 15 ++++--- console | 2 + public/assets/js/build-plugins/time.js | 4 +- 7 files changed, 145 insertions(+), 32 deletions(-) create mode 100644 PHPCI/Command/UpdateCommand.php diff --git a/PHPCI/Command/UpdateCommand.php b/PHPCI/Command/UpdateCommand.php new file mode 100644 index 00000000..e5806025 --- /dev/null +++ b/PHPCI/Command/UpdateCommand.php @@ -0,0 +1,42 @@ + + * @package PHPCI + * @subpackage Console + */ +class UpdateCommand extends Command +{ + protected function configure() + { + $this + ->setName('phpci:update') + ->setDescription('Update the database to reflect modified models.'); + } + + /** + * Generates Model and Store classes by reading database meta data. + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + // Update the database: + $gen = new \b8\Database\Generator(\b8\Database::getConnection(), 'PHPCI', './PHPCI/Model/Base/'); + $gen->generate(); + } +} diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index 33f3d406..e620452f 100644 --- a/PHPCI/Model/Base/BuildBase.php +++ b/PHPCI/Model/Base/BuildBase.php @@ -90,52 +90,64 @@ class BuildBase extends Model 'length' => '11', 'primary_key' => true, 'auto_increment' => true, + 'default' => null, ), 'project_id' => array( 'type' => 'int', 'length' => '11', + 'default' => null, ), 'commit_id' => array( 'type' => 'varchar', 'length' => '50', + 'nullable' => true, + 'default' => null, ), 'status' => array( 'type' => 'tinyint', 'length' => '4', + 'default' => '0', ), 'log' => array( 'type' => 'longtext', 'length' => '', 'nullable' => true, + 'default' => null, ), 'branch' => array( 'type' => 'varchar', 'length' => '50', + 'default' => 'master', ), 'created' => array( 'type' => 'datetime', 'length' => '', 'nullable' => true, + 'default' => null, ), 'started' => array( 'type' => 'datetime', 'length' => '', 'nullable' => true, + 'default' => null, ), 'finished' => array( 'type' => 'datetime', 'length' => '', 'nullable' => true, + 'default' => null, ), 'plugins' => array( 'type' => 'text', 'length' => '', 'nullable' => true, + 'default' => null, ), 'committer_email' => array( 'type' => 'varchar', 'length' => '512', 'nullable' => true, + 'default' => null, ), ); @@ -330,7 +342,7 @@ class BuildBase extends Model { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if ($this->data['id'] == $value) { + if ($this->data['id'] === $value) { return; } @@ -349,7 +361,7 @@ class BuildBase extends Model { $this->_validateNotNull('ProjectId', $value); $this->_validateInt('ProjectId', $value); - if ($this->data['project_id'] == $value) { + if ($this->data['project_id'] === $value) { return; } @@ -361,14 +373,13 @@ class BuildBase extends Model /** * Set the value of CommitId / commit_id. * - * Must not be null. * @param $value string */ public function setCommitId($value) { - $this->_validateNotNull('CommitId', $value); + $this->_validateString('CommitId', $value); - if ($this->data['commit_id'] == $value) { + if ($this->data['commit_id'] === $value) { return; } @@ -387,7 +398,7 @@ class BuildBase extends Model { $this->_validateNotNull('Status', $value); $this->_validateInt('Status', $value); - if ($this->data['status'] == $value) { + if ($this->data['status'] === $value) { return; } @@ -405,7 +416,7 @@ class BuildBase extends Model { $this->_validateString('Log', $value); - if ($this->data['log'] == $value) { + if ($this->data['log'] === $value) { return; } @@ -424,7 +435,7 @@ class BuildBase extends Model { $this->_validateNotNull('Branch', $value); $this->_validateString('Branch', $value); - if ($this->data['branch'] == $value) { + if ($this->data['branch'] === $value) { return; } @@ -442,7 +453,7 @@ class BuildBase extends Model { $this->_validateDate('Created', $value); - if ($this->data['created'] == $value) { + if ($this->data['created'] === $value) { return; } @@ -460,7 +471,7 @@ class BuildBase extends Model { $this->_validateDate('Started', $value); - if ($this->data['started'] == $value) { + if ($this->data['started'] === $value) { return; } @@ -478,7 +489,7 @@ class BuildBase extends Model { $this->_validateDate('Finished', $value); - if ($this->data['finished'] == $value) { + if ($this->data['finished'] === $value) { return; } @@ -496,7 +507,7 @@ class BuildBase extends Model { $this->_validateString('Plugins', $value); - if ($this->data['plugins'] == $value) { + if ($this->data['plugins'] === $value) { return; } @@ -514,7 +525,7 @@ class BuildBase extends Model { $this->_validateString('CommitterEmail', $value); - if ($this->data['committer_email'] == $value) { + if ($this->data['committer_email'] === $value) { return; } diff --git a/PHPCI/Model/Base/BuildMetaBase.php b/PHPCI/Model/Base/BuildMetaBase.php index f9aa94e5..8fb62832 100644 --- a/PHPCI/Model/Base/BuildMetaBase.php +++ b/PHPCI/Model/Base/BuildMetaBase.php @@ -33,6 +33,7 @@ class BuildMetaBase extends Model */ protected $data = array( 'id' => null, + 'project_id' => null, 'build_id' => null, 'key' => null, 'value' => null, @@ -43,6 +44,7 @@ class BuildMetaBase extends Model */ protected $getters = array( 'id' => 'getId', + 'project_id' => 'getProjectId', 'build_id' => 'getBuildId', 'key' => 'getKey', 'value' => 'getValue', @@ -54,6 +56,7 @@ class BuildMetaBase extends Model */ protected $setters = array( 'id' => 'setId', + 'project_id' => 'setProjectId', 'build_id' => 'setBuildId', 'key' => 'setKey', 'value' => 'setValue', @@ -69,19 +72,29 @@ class BuildMetaBase extends Model 'length' => '10', 'primary_key' => true, 'auto_increment' => true, + 'default' => null, + ), + 'project_id' => array( + 'type' => 'int', + 'length' => '11', + 'default' => null, ), 'build_id' => array( 'type' => 'int', 'length' => '11', + 'nullable' => true, + 'default' => null, ), 'key' => array( 'type' => 'varchar', 'length' => '255', + 'default' => '', ), 'value' => array( 'type' => 'text', 'length' => '', 'nullable' => true, + 'default' => null, ), ); @@ -120,6 +133,19 @@ class BuildMetaBase extends Model return $rtn; } + /** + * Get the value of ProjectId / project_id. + * + * @return int + */ + public function getProjectId() + { + $rtn = $this->data['project_id']; + + + return $rtn; + } + /** * Get the value of BuildId / build_id. * @@ -169,7 +195,7 @@ class BuildMetaBase extends Model { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if ($this->data['id'] == $value) { + if ($this->data['id'] === $value) { return; } @@ -179,16 +205,34 @@ class BuildMetaBase extends Model } /** - * Set the value of BuildId / build_id. + * Set the value of ProjectId / project_id. * * Must not be null. * @param $value int */ + public function setProjectId($value) + { + $this->_validateNotNull('ProjectId', $value); + $this->_validateInt('ProjectId', $value); + if ($this->data['project_id'] === $value) { + return; + } + + $this->data['project_id'] = $value; + + $this->_setModified('project_id'); + } + + /** + * Set the value of BuildId / build_id. + * + * @param $value int + */ public function setBuildId($value) { - $this->_validateNotNull('BuildId', $value); + $this->_validateInt('BuildId', $value); - if ($this->data['build_id'] == $value) { + if ($this->data['build_id'] === $value) { return; } @@ -207,7 +251,7 @@ class BuildMetaBase extends Model { $this->_validateNotNull('Key', $value); $this->_validateString('Key', $value); - if ($this->data['key'] == $value) { + if ($this->data['key'] === $value) { return; } @@ -225,7 +269,7 @@ class BuildMetaBase extends Model { $this->_validateString('Value', $value); - if ($this->data['value'] == $value) { + if ($this->data['value'] === $value) { return; } diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index d00916bb..6a128b42 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -76,31 +76,38 @@ class ProjectBase extends Model 'length' => '11', 'primary_key' => true, 'auto_increment' => true, + 'default' => null, ), 'title' => array( 'type' => 'varchar', 'length' => '250', + 'default' => '', ), 'reference' => array( 'type' => 'varchar', 'length' => '250', + 'default' => '', ), 'git_key' => array( 'type' => 'text', 'length' => '', + 'default' => null, ), 'type' => array( 'type' => 'varchar', 'length' => '50', + 'default' => '', ), 'token' => array( 'type' => 'varchar', 'length' => '50', 'nullable' => true, + 'default' => null, ), 'access_information' => array( 'type' => 'varchar', 'length' => '250', + 'default' => null, ), ); @@ -219,7 +226,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if ($this->data['id'] == $value) { + if ($this->data['id'] === $value) { return; } @@ -238,7 +245,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Title', $value); $this->_validateString('Title', $value); - if ($this->data['title'] == $value) { + if ($this->data['title'] === $value) { return; } @@ -257,7 +264,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Reference', $value); $this->_validateString('Reference', $value); - if ($this->data['reference'] == $value) { + if ($this->data['reference'] === $value) { return; } @@ -276,7 +283,7 @@ class ProjectBase extends Model { $this->_validateNotNull('GitKey', $value); $this->_validateString('GitKey', $value); - if ($this->data['git_key'] == $value) { + if ($this->data['git_key'] === $value) { return; } @@ -295,7 +302,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Type', $value); $this->_validateString('Type', $value); - if ($this->data['type'] == $value) { + if ($this->data['type'] === $value) { return; } @@ -313,7 +320,7 @@ class ProjectBase extends Model { $this->_validateString('Token', $value); - if ($this->data['token'] == $value) { + if ($this->data['token'] === $value) { return; } @@ -332,7 +339,7 @@ class ProjectBase extends Model { $this->_validateNotNull('AccessInformation', $value); $this->_validateString('AccessInformation', $value); - if ($this->data['access_information'] == $value) { + if ($this->data['access_information'] === $value) { return; } diff --git a/PHPCI/Model/Base/UserBase.php b/PHPCI/Model/Base/UserBase.php index aab1e21b..0f95e93b 100644 --- a/PHPCI/Model/Base/UserBase.php +++ b/PHPCI/Model/Base/UserBase.php @@ -70,22 +70,27 @@ class UserBase extends Model 'length' => '11', 'primary_key' => true, 'auto_increment' => true, + 'default' => null, ), 'email' => array( 'type' => 'varchar', 'length' => '250', + 'default' => '', ), 'hash' => array( 'type' => 'varchar', 'length' => '250', + 'default' => '', ), 'is_admin' => array( 'type' => 'tinyint', 'length' => '1', + 'default' => '0', ), 'name' => array( 'type' => 'varchar', 'length' => '250', + 'default' => '', ), ); @@ -179,7 +184,7 @@ class UserBase extends Model { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if ($this->data['id'] == $value) { + if ($this->data['id'] === $value) { return; } @@ -198,7 +203,7 @@ class UserBase extends Model { $this->_validateNotNull('Email', $value); $this->_validateString('Email', $value); - if ($this->data['email'] == $value) { + if ($this->data['email'] === $value) { return; } @@ -217,7 +222,7 @@ class UserBase extends Model { $this->_validateNotNull('Hash', $value); $this->_validateString('Hash', $value); - if ($this->data['hash'] == $value) { + if ($this->data['hash'] === $value) { return; } @@ -236,7 +241,7 @@ class UserBase extends Model { $this->_validateNotNull('IsAdmin', $value); $this->_validateInt('IsAdmin', $value); - if ($this->data['is_admin'] == $value) { + if ($this->data['is_admin'] === $value) { return; } @@ -255,7 +260,7 @@ class UserBase extends Model { $this->_validateNotNull('Name', $value); $this->_validateString('Name', $value); - if ($this->data['name'] == $value) { + if ($this->data['name'] === $value) { return; } diff --git a/console b/console index dd71d058..dd44b13b 100755 --- a/console +++ b/console @@ -23,6 +23,7 @@ require('bootstrap.php'); use PHPCI\Command\RunCommand; use PHPCI\Command\GenerateCommand; +use PHPCI\Command\UpdateCommand; use PHPCI\Command\InstallCommand; use PHPCI\Command\DaemonCommand; use Symfony\Component\Console\Application; @@ -30,6 +31,7 @@ use Symfony\Component\Console\Application; $application = new Application(); $application->add(new RunCommand); $application->add(new InstallCommand); +$application->add(new UpdateCommand); $application->add(new GenerateCommand); $application->add(new DaemonCommand); $application->run(); diff --git a/public/assets/js/build-plugins/time.js b/public/assets/js/build-plugins/time.js index 5705ed9a..4e697bf6 100644 --- a/public/assets/js/build-plugins/time.js +++ b/public/assets/js/build-plugins/time.js @@ -27,7 +27,9 @@ var timePlugin = PHPCI.UiPlugin.extend({ ''; }, - onUpdate: function(build) { + onUpdate: function(e) { + var build = e.queryData; + $('#created').text(build.created); $('#started').text(build.started); $('#finished').text(build.finished);