From 79ff7e77938d5e2bd3c598f3b5525cca232df3a3 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 27 Jul 2013 18:47:52 +0300 Subject: [PATCH] refactor adding columns --- ipf/admin/models/_generated/BaseAdminLog.php | 14 +++++++------- ipf/auth/models/_generated/BasePermission.php | 2 +- ipf/auth/models/_generated/BaseRole.php | 2 +- .../models/_generated/BaseRolePermission.php | 4 ++-- ipf/auth/models/_generated/BaseUser.php | 18 +++++++++--------- .../models/_generated/BaseUserPermission.php | 4 ++-- ipf/auth/models/_generated/BaseUserRole.php | 4 ++-- ipf/orm/import/builder.php | 2 +- ipf/orm/record/abstract.php | 12 ------------ ipf/orm/template/orderable.php | 2 +- ipf/orm/template/owned.php | 2 +- ipf/orm/template/sluggable.php | 2 +- ipf/orm/template/timestampable.php | 4 ++-- ipf/session/models/_generated/BaseSession.php | 6 +++--- 14 files changed, 33 insertions(+), 45 deletions(-) diff --git a/ipf/admin/models/_generated/BaseAdminLog.php b/ipf/admin/models/_generated/BaseAdminLog.php index 1c6aa57..a76d24c 100644 --- a/ipf/admin/models/_generated/BaseAdminLog.php +++ b/ipf/admin/models/_generated/BaseAdminLog.php @@ -11,13 +11,13 @@ abstract class BaseAdminLog extends IPF_ORM_Record public function setTableDefinition() { $this->setTableName('admin_log'); - $this->hasColumn('username', 'string', 32, array('type' => 'string', 'length' => '32')); - $this->hasColumn('user_id', 'integer', null, array('type' => 'integer')); - $this->hasColumn('object_id', 'integer', null, array('type' => 'integer')); - $this->hasColumn('object_class', 'string', 200, array('type' => 'string', 'length' => '200')); - $this->hasColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200')); - $this->hasColumn('action_flag', 'integer', null, array('type' => 'integer')); - $this->hasColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200')); + $this->getTable()->setColumn('username', 'string', 32, array('type' => 'string', 'length' => '32')); + $this->getTable()->setColumn('user_id', 'integer', null, array('type' => 'integer')); + $this->getTable()->setColumn('object_id', 'integer', null, array('type' => 'integer')); + $this->getTable()->setColumn('object_class', 'string', 200, array('type' => 'string', 'length' => '200')); + $this->getTable()->setColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200')); + $this->getTable()->setColumn('action_flag', 'integer', null, array('type' => 'integer')); + $this->getTable()->setColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200')); $this->index('idx_object_id', array('fields' => 'object_id')); $this->index('idx_object_class', array('fields' => 'object_class')); $this->index('idx_created_at', array('fields' => 'created_at')); diff --git a/ipf/auth/models/_generated/BasePermission.php b/ipf/auth/models/_generated/BasePermission.php index 351ce32..69c7648 100644 --- a/ipf/auth/models/_generated/BasePermission.php +++ b/ipf/auth/models/_generated/BasePermission.php @@ -11,7 +11,7 @@ abstract class BasePermission extends IPF_ORM_Record public function setTableDefinition() { $this->setTableName('auth_permission'); - $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255')); + $this->getTable()->setColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255')); $this->option('type', 'INNODB'); $this->option('collate', 'utf8_unicode_ci'); $this->option('charset', 'utf8'); diff --git a/ipf/auth/models/_generated/BaseRole.php b/ipf/auth/models/_generated/BaseRole.php index 8eef347..e9bdf4c 100644 --- a/ipf/auth/models/_generated/BaseRole.php +++ b/ipf/auth/models/_generated/BaseRole.php @@ -11,7 +11,7 @@ abstract class BaseRole extends IPF_ORM_Record public function setTableDefinition() { $this->setTableName('auth_role'); - $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'notblank' => true, 'length' => '255')); + $this->getTable()->setColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'notblank' => true, 'length' => '255')); $this->option('type', 'INNODB'); $this->option('collate', 'utf8_unicode_ci'); $this->option('charset', 'utf8'); diff --git a/ipf/auth/models/_generated/BaseRolePermission.php b/ipf/auth/models/_generated/BaseRolePermission.php index 084fed0..bdf64c5 100644 --- a/ipf/auth/models/_generated/BaseRolePermission.php +++ b/ipf/auth/models/_generated/BaseRolePermission.php @@ -11,8 +11,8 @@ abstract class BaseRolePermission extends IPF_ORM_Record public function setTableDefinition() { $this->setTableName('auth_role_permission'); - $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->getTable()->setColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->getTable()->setColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true)); $this->option('type', 'INNODB'); $this->option('collate', 'utf8_unicode_ci'); $this->option('charset', 'utf8'); diff --git a/ipf/auth/models/_generated/BaseUser.php b/ipf/auth/models/_generated/BaseUser.php index 7213eeb..ba17448 100644 --- a/ipf/auth/models/_generated/BaseUser.php +++ b/ipf/auth/models/_generated/BaseUser.php @@ -11,15 +11,15 @@ abstract class BaseUser extends IPF_ORM_Record public function setTableDefinition() { $this->setTableName('auth_user'); - $this->hasColumn('username', 'string', 32, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'unique' => true, 'length' => '32')); - $this->hasColumn('password', 'string', 128, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'length' => '128')); - $this->hasColumn('first_name', 'string', 32, array('type' => 'string', 'length' => '32')); - $this->hasColumn('last_name', 'string', 32, array('type' => 'string', 'length' => '32')); - $this->hasColumn('email', 'string', 200, array('type' => 'string', 'email' => true, 'notnull' => true, 'notblank' => true, 'unique' => true, 'length' => '200')); - $this->hasColumn('is_staff', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); - $this->hasColumn('is_active', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); - $this->hasColumn('is_superuser', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); - $this->hasColumn('last_login', 'timestamp', null, array('type' => 'timestamp')); + $this->getTable()->setColumn('username', 'string', 32, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'unique' => true, 'length' => '32')); + $this->getTable()->setColumn('password', 'string', 128, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'length' => '128')); + $this->getTable()->setColumn('first_name', 'string', 32, array('type' => 'string', 'length' => '32')); + $this->getTable()->setColumn('last_name', 'string', 32, array('type' => 'string', 'length' => '32')); + $this->getTable()->setColumn('email', 'string', 200, array('type' => 'string', 'email' => true, 'notnull' => true, 'notblank' => true, 'unique' => true, 'length' => '200')); + $this->getTable()->setColumn('is_staff', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); + $this->getTable()->setColumn('is_active', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); + $this->getTable()->setColumn('is_superuser', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); + $this->getTable()->setColumn('last_login', 'timestamp', null, array('type' => 'timestamp')); $this->option('type', 'INNODB'); $this->option('collate', 'utf8_unicode_ci'); $this->option('charset', 'utf8'); diff --git a/ipf/auth/models/_generated/BaseUserPermission.php b/ipf/auth/models/_generated/BaseUserPermission.php index 9cfd2e3..227ed05 100644 --- a/ipf/auth/models/_generated/BaseUserPermission.php +++ b/ipf/auth/models/_generated/BaseUserPermission.php @@ -11,8 +11,8 @@ abstract class BaseUserPermission extends IPF_ORM_Record public function setTableDefinition() { $this->setTableName('auth_user_permission'); - $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->getTable()->setColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->getTable()->setColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true)); $this->option('type', 'INNODB'); $this->option('collate', 'utf8_unicode_ci'); $this->option('charset', 'utf8'); diff --git a/ipf/auth/models/_generated/BaseUserRole.php b/ipf/auth/models/_generated/BaseUserRole.php index 24d4732..ab9b2dd 100644 --- a/ipf/auth/models/_generated/BaseUserRole.php +++ b/ipf/auth/models/_generated/BaseUserRole.php @@ -11,8 +11,8 @@ abstract class BaseUserRole extends IPF_ORM_Record public function setTableDefinition() { $this->setTableName('auth_user_role'); - $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->getTable()->setColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->getTable()->setColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true)); $this->option('type', 'INNODB'); $this->option('collate', 'utf8_unicode_ci'); $this->option('charset', 'utf8'); diff --git a/ipf/orm/import/builder.php b/ipf/orm/import/builder.php index b0633a9..8258b5d 100644 --- a/ipf/orm/import/builder.php +++ b/ipf/orm/import/builder.php @@ -163,7 +163,7 @@ class IPF_ORM_Import_Builder $result = array(); foreach ($columns as $name => $column) { $columnName = isset($column['name']) ? $column['name']:$name; - $build = " ".'$this->hasColumn(\'' . $columnName . '\', \'' . $column['type'] . '\''; + $build = " ".'$this->getTable()->setColumn(\'' . $columnName . '\', \'' . $column['type'] . '\''; if ($column['length']) { if (is_numeric($column['length'])) diff --git a/ipf/orm/record/abstract.php b/ipf/orm/record/abstract.php index f34c98c..41fd7f7 100644 --- a/ipf/orm/record/abstract.php +++ b/ipf/orm/record/abstract.php @@ -102,18 +102,6 @@ abstract class IPF_ORM_Record_Abstract extends IPF_ORM_Access return $this; } - public function hasColumn($name, $type, $length = 2147483647, $options = "") - { - $this->_table->setColumn($name, $type, $length, $options); - } - - public function hasColumns(array $definitions) - { - foreach ($definitions as $name => $options) { - $this->hasColumn($name, $options['type'], $options['length'], $options); - } - } - public function bindQueryParts(array $queryParts) { $this->_table->bindQueryParts($queryParts); diff --git a/ipf/orm/template/orderable.php b/ipf/orm/template/orderable.php index 3d82df9..34a4d74 100644 --- a/ipf/orm/template/orderable.php +++ b/ipf/orm/template/orderable.php @@ -25,7 +25,7 @@ class IPF_ORM_Template_Orderable extends IPF_ORM_Template public function setTableDefinition() { - $this->hasColumn($this->columnName, 'integer', null, array('exclude' => $this->exclude)); + $this->getTable()->setColumn($this->columnName, 'integer', null, array('exclude' => $this->exclude)); $this->index($this->getTable()->getOption('tableName') . '_orderable_' . $this->columnName, array('fields' => array($this->columnName))); $this->getTable()->listeners['Orderable_'.$this->columnName] = new IPF_ORM_Template_Listener_Orderable($this->columnName, $this->prepend); } diff --git a/ipf/orm/template/owned.php b/ipf/orm/template/owned.php index dbe2a96..db204c0 100644 --- a/ipf/orm/template/owned.php +++ b/ipf/orm/template/owned.php @@ -28,7 +28,7 @@ class IPF_ORM_Template_Owned extends IPF_ORM_Template public function setTableDefinition() { - $this->hasColumn($this->columnName, 'integer', null, array( + $this->getTable()->setColumn($this->columnName, 'integer', null, array( 'exclude' => $this->exclude, 'verbose' => $this->verbose, )); diff --git a/ipf/orm/template/sluggable.php b/ipf/orm/template/sluggable.php index 35e5700..a73d120 100644 --- a/ipf/orm/template/sluggable.php +++ b/ipf/orm/template/sluggable.php @@ -22,7 +22,7 @@ class IPF_ORM_Template_Sluggable extends IPF_ORM_Template public function setTableDefinition() { - $this->hasColumn($this->_options['name'], $this->_options['type'], $this->_options['length'], $this->_options['options']); + $this->getTable()->setColumn($this->_options['name'], $this->_options['type'], $this->_options['length'], $this->_options['options']); if ($this->_options['unique'] == true && $this->_options['uniqueIndex'] == true && ! empty($this->_options['fields'])) { $indexFields = array($this->_options['name']); diff --git a/ipf/orm/template/timestampable.php b/ipf/orm/template/timestampable.php index 7c0c1fb..5c7c813 100644 --- a/ipf/orm/template/timestampable.php +++ b/ipf/orm/template/timestampable.php @@ -31,10 +31,10 @@ class IPF_ORM_Template_Timestampable extends IPF_ORM_Template public function setTableDefinition() { if (!$this->_options['created']['disabled']) { - $this->hasColumn($this->_options['created']['name'], $this->_options['created']['type'], null, $this->_options['created']['options']); + $this->getTable()->setColumn($this->_options['created']['name'], $this->_options['created']['type'], null, $this->_options['created']['options']); } if (!$this->_options['updated']['disabled']) { - $this->hasColumn($this->_options['updated']['name'], $this->_options['updated']['type'], null, $this->_options['updated']['options']); + $this->getTable()->setColumn($this->_options['updated']['name'], $this->_options['updated']['type'], null, $this->_options['updated']['options']); } $this->getTable()->listeners['Timestampable_'.print_r($this->_options, true)] = new IPF_ORM_Template_Listener_Timestampable($this->_options); } diff --git a/ipf/session/models/_generated/BaseSession.php b/ipf/session/models/_generated/BaseSession.php index 760b01a..242e682 100644 --- a/ipf/session/models/_generated/BaseSession.php +++ b/ipf/session/models/_generated/BaseSession.php @@ -11,9 +11,9 @@ abstract class BaseSession extends IPF_ORM_Record public function setTableDefinition() { $this->setTableName('session'); - $this->hasColumn('session_key', 'string', 40, array('primary' => true, 'type' => 'string', 'length' => '40')); - $this->hasColumn('session_data', 'string', null, array('type' => 'string')); - $this->hasColumn('expire_data', 'timestamp', null, array('type' => 'timestamp')); + $this->getTable()->setColumn('session_key', 'string', 40, array('primary' => true, 'type' => 'string', 'length' => '40')); + $this->getTable()->setColumn('session_data', 'string', null, array('type' => 'string')); + $this->getTable()->setColumn('expire_data', 'timestamp', null, array('type' => 'timestamp')); } -- 2.49.0