query('SELECT * FROM fields_meta_data WHERE deleted = 0 ORDER BY custom_module'); $modules = array (); /* * get the real field_meta_data */ while ($row = $db->fetchByAssoc($result)) { $the_modules = $row['custom_module']; if (!isset ($modules[$the_modules])) { $modules[$the_modules] = array (); } $modules[$the_modules][$row['name']] = $row['name']; } $simulate = false; if (!isset ($_REQUEST['run'])) { $simulate = true; echo "SIMULATION MODE - NO CHANGES WILL BE MADE EXCEPT CLEARING CACHE"; } foreach ($modules as $the_module => $fields) { $class_name = $beanList[$the_module]; echo "

Scanning $the_module
"; require_once ($beanFiles[$class_name]); $mod = new $class_name (); if (!$db->tableExists($mod->table_name."_cstm")) { $mod->custom_fields = new DynamicField(); $mod->custom_fields->setup($mod); $mod->custom_fields->createCustomTable(); } $table = $db->getTableDescription($mod->table_name."_cstm"); foreach($table as $row) { $col = strtolower(empty ($row['Field']) ? $row['field'] : $row['Field']); $the_field = $mod->custom_fields->getField($col); $type = strtolower(empty ($row['Type']) ? $row['type'] : $row['Type']); if (!empty($row['data_precision']) && !empty($row['data_scale'])) { $type.='(' . $row['data_precision']; if (!empty($row['data_scale'])) { $type.=',' . $row['data_scale']; } $type.=')'; } elseif(!empty($row['data_length']) && (strtolower($row['type'])=='varchar' or strtolower($row['type'])=='varchar2')) { $type.='(' . $row['data_length'] . ')'; } if (!isset ($fields[$col]) && $col != 'id_c') { if (!$simulate) { $db->query("ALTER TABLE $mod->table_name"."_cstm DROP COLUMN $col"); } unset ($fields[$col]); echo "Dropping Column $col from $mod->table_name"."_cstm for module $the_module
"; } else { if ($col != 'id_c') { $db_data_type = strtolower(str_replace(' ' , '', $the_field->get_db_type())); $type = strtolower(str_replace(' ' , '', $type)); if (strcmp($db_data_type,$type) != 0) { echo "Fixing Column Type for $col changing $type to ".$db_data_type."
"; if (!$simulate) { $db->query($the_field->get_db_modify_alter_table($mod->table_name.'_cstm')); } } } unset ($fields[$col]); } } echo sizeof($fields)." field(s) missing from $mod->table_name"."_cstm
"; foreach ($fields as $field) { echo "Adding Column $field to $mod->table_name"."_cstm
"; if (!$simulate) $mod->custom_fields->add_existing_custom_field($field); } } DynamicField :: deleteCache(); echo '
Done
'; if ($simulate) { echo 'Execute non-simulation mode'; } ?>