Changeset 4556

Show
Ignore:
Timestamp:
06/24/08 05:24:44 (7 months ago)
Author:
jwage
Message:

Enhanced code to clean column definitions properly when importing records from another source.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/lib/Doctrine/Import/Builder.php

    r4507 r4556  
    530530            } 
    531531 
    532             // The column definition is one array, everthing but name, type and length are an array of 
    533             // possible options. This removes the name, type and length and creates the options array for 
    534             // the column definition 
    535532            $options = $column; 
    536             $unset = array('name', 'type', 'length', 'alltypes', 'ntype'); 
     533 
     534            // Remove name, alltypes, ntype. They are not needed in options array 
     535            unset($options['name']); 
     536            unset($options['alltypes']); 
     537            unset($options['ntype']); 
     538 
     539            // Remove notnull => true if the column is primary 
     540            // Primary columns are implied to be notnull in Doctrine 
     541            if (isset($options['primary']) && $options['primary'] == true && (isset($options['notnull']) && $options['notnull'] == true)) { 
     542                unset($options['notnull']); 
     543            } 
     544 
     545            // Remove default if the value is 0 and the column is a primary key 
     546            // Doctrine defaults to 0 if it is a primary key 
     547            if (isset($options['primary']) && $options['primary'] == true && (isset($options['default']) && $options['default'] == 0)) { 
     548                unset($options['default']); 
     549            } 
     550 
     551            // These can be removed if they are empty. They all default to a false/0/null value anyways 
     552            $remove = array('fixed', 'primary', 'notnull', 'autoincrement', 'unsigned'); 
     553            foreach ($remove as $key) { 
     554                if (isset($options[$key]) && empty($options[$key])) { 
     555                    unset($options[$key]); 
     556                } 
     557            } 
     558 
     559            // Remove null and empty array values 
    537560            foreach ($options as $key => $value) { 
    538                 // Remove column elements which are specified above or are null 
    539                 if (in_array($key, $unset) || is_null($value) || (is_array($value) && empty($value))) { 
     561                if (is_null($value) || (is_array($value) && empty($value))) { 
    540562                    unset($options[$key]); 
    541563                }