grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026query('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) {
if (isset($beanList[$the_module])) {
$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();
}
$result = $db->query("DESCRIBE $mod->table_name" . "_cstm");
while ($row = $db->fetchByAssoc($result)) {
$col = $row['Field'];
$type = $row['Type'];
$fieldDef = $mod->getFieldDefinition($col);
$the_field = get_widget($fieldDef['type']);
$the_field->set($fieldDef);
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') {
if (trim($the_field->get_db_type()) != trim($type)) {
echo "Fixing Column Type for $col changing $type to ". $the_field->get_db_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) {
$the_field = $mod->getFieldDefinition($field);
$field = get_widget($the_field['type']);
$field->set($the_field);
$query = $field->get_db_add_alter_table($mod->table_name . '_cstm');
echo $query;
if (!empty($query)) {
$mod->db->query($query);
}
}
}
}
}
DynamicField::deleteCache();
echo '
Done
';
if ($simulate) {
echo 'Execute non-simulation mode';
}