From: Andrey Kutejko Date: Sat, 27 Jul 2013 16:01:20 +0000 (+0300) Subject: refactor index definition X-Git-Tag: 0.6~58 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=b6926277cb24a7e67513e794f29a711f24088ad7;p=ipf-legacy-orm.git refactor index definition --- diff --git a/ipf/orm/import/builder.php b/ipf/orm/import/builder.php index 1fd3c97..bdb1728 100644 --- a/ipf/orm/import/builder.php +++ b/ipf/orm/import/builder.php @@ -37,7 +37,7 @@ class IPF_ORM_Import_Builder if (isset($definition['indexes']) && is_array($definition['indexes']) && !empty($definition['indexes'])) foreach ($definition['indexes'] as $indexName => $definitions) - $ret[] = " \$this->index('" . $indexName . "', " . self::varExport($definitions) . ');'; + $ret[] = " \$table->addIndex('" . $indexName . "', " . self::varExport($definitions) . ');'; if (isset($definition['attributes']) && is_array($definition['attributes']) && !empty($definition['attributes'])) $ret[] = $this->buildAttributes($definition['attributes']); diff --git a/ipf/orm/record/abstract.php b/ipf/orm/record/abstract.php index e03cf83..29058f2 100644 --- a/ipf/orm/record/abstract.php +++ b/ipf/orm/record/abstract.php @@ -17,14 +17,6 @@ abstract class IPF_ORM_Record_Abstract extends IPF_ORM_Access return $this->_table; } - public function index($name, array $definition = array()) - { - if ( ! $definition) { - return $this->_table->getIndex($name); - } else { - return $this->_table->addIndex($name, $definition); - } - } public function setAttribute($attr, $value) { $this->_table->setAttribute($attr, $value); diff --git a/ipf/orm/template/orderable.php b/ipf/orm/template/orderable.php index 34a4d74..9e7ea2c 100644 --- a/ipf/orm/template/orderable.php +++ b/ipf/orm/template/orderable.php @@ -25,9 +25,10 @@ class IPF_ORM_Template_Orderable extends IPF_ORM_Template public function setTableDefinition() { - $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); + $table = $this->getTable(); + $table->setColumn($this->columnName, 'integer', null, array('exclude' => $this->exclude)); + $table->addIndex($table->getOption('tableName') . '_orderable_' . $this->columnName, array('fields' => array($this->columnName))); + $table->listeners['Orderable_'.$this->columnName] = new IPF_ORM_Template_Listener_Orderable($this->columnName, $this->prepend); } } diff --git a/ipf/orm/template/sluggable.php b/ipf/orm/template/sluggable.php index a73d120..c9e0003 100644 --- a/ipf/orm/template/sluggable.php +++ b/ipf/orm/template/sluggable.php @@ -22,15 +22,16 @@ class IPF_ORM_Template_Sluggable extends IPF_ORM_Template public function setTableDefinition() { - $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'])) { + $table = $this->getTable(); + + $table->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']); $indexFields = array_merge($indexFields, $this->_options['uniqueBy']); - $this->index($this->_options['indexName'], array('fields' => $indexFields, - 'type' => 'unique')); + $table->addIndex($this->_options['indexName'], array('fields' => $indexFields, 'type' => 'unique')); } - $this->getTable()->listeners['Sluggable_'.print_r($this->_options, true)] = new IPF_ORM_Template_Listener_Sluggable($this->_options); + $table->listeners['Sluggable_'.print_r($this->_options, true)] = new IPF_ORM_Template_Listener_Sluggable($this->_options); } }