]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
refactor index definition
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 16:01:20 +0000 (19:01 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 16:01:20 +0000 (19:01 +0300)
ipf/orm/import/builder.php
ipf/orm/record/abstract.php
ipf/orm/template/orderable.php
ipf/orm/template/sluggable.php

index 1fd3c971ac272b628c71e31229df767df299ba9e..bdb172831e33b8d0a98da8dd019933fec3681bcc 100644 (file)
@@ -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']);
index e03cf839fa6b75fb0483b917b9d8b35e018dcbea..29058f284c3d4733474750bfbdaa8bdcd12c5026 100644 (file)
@@ -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);
index 34a4d7429b97a2f8fd1015e9c53d0e80fe904307..9e7ea2cf9e33cbd3889cefb6a9a35dc2a7235ace 100644 (file)
@@ -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);
     }
 }
 
index a73d12002fac7247fa423ceabeee64d15f29ec88..c9e0003bb51a41bf9dc7efbcc2d41b7e9dd961c0 100644 (file)
@@ -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);
     }
 }