Index: branches/5.1.x/core/kernel/utility/unit_config_reader.php
===================================================================
diff -u -N -r13750 -r13935
--- branches/5.1.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 13750)
+++ branches/5.1.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 13935)
@@ -1,6 +1,6 @@
Query('SHOW TABLES LIKE "'.$tablename.'"');
if (!$table_found) {
// config present, but table missing, strange
- $debugger->appendHTML("Config Warning: Table $tablename missing, but prefix ".$config['Prefix']." requires it!");
safeDefine('DBG_RAISE_ON_WARNINGS', 1);
+ $debugger->appendHTML("Config Warning: Table $tablename missing, but prefix ".$config['Prefix']." requires it!");
+ $debugger->WarningCount++;
+
return ;
}
@@ -636,11 +638,13 @@
'not_null_error3' => 'Field %s is described as NOT NULL in config, but is NULL in db',
'invalid_default' => 'Default value for field %s%s not sync. to db (in config = %s, in db = %s)',
'type_missing' => 'Type definition for field %s missing in config',
+ 'invalid_calculated_field' => 'Calculated field %s is missing corresponding virtual field',
);
$config_errors = Array ();
$tablename = preg_replace('/^'.preg_quote(TABLE_PREFIX, '/').'(.*)/', '\\1', $tablename); // remove table prefix
+ // validate unit config field declaration in relation to database table structure
foreach ($res as $field) {
$f_name = $field['Field'];
@@ -654,12 +658,16 @@
$config_errors[] = sprintf($error_messages['field_not_found'], $f_name);
}
else {
- if (is_numeric($field['Default'])) {
- $field['Default'] = preg_match('/[\.,]/', $field['Default']) ? (float)$field['Default'] : (int)$field['Default'];
+ $db_default = $field['Default'];
+
+ if (is_numeric($db_default)) {
+ $db_default = preg_match('/[\.,]/', $db_default) ? (float)$db_default : (int)$db_default;
}
- $options = $config['Fields'][$f_name];
$default_missing = false;
+ $options = $config['Fields'][$f_name];
+ $not_null = isset($options['not_null']) && $options['not_null'];
+
if (!array_key_exists('default', $options)) {
$config_errors[] = sprintf($error_messages['default_missing'], $f_name);
$default_missing = true;
@@ -670,38 +678,52 @@
if ( $f_name != $config['IDField'] && !isset($options['not_null']) /*&& !isset($options['required'])*/ ) {
$config_errors[] = sprintf($error_messages['not_null_error1'], $f_name);
}
- if (isset($options['not_null']) && $options['not_null'] && !isset($options['default']) ) {
+ if ($not_null && !isset($options['default']) ) {
$config_errors[] = sprintf($error_messages['not_null_error2'], $f_name);
}
}
- else {
- if (isset($options['not_null']) && $options['not_null']) {
- $config_errors[] = sprintf($error_messages['not_null_error3'], $f_name);
- }
+ elseif ($not_null) {
+ $config_errors[] = sprintf($error_messages['not_null_error3'], $f_name);
}
if (!array_key_exists('type', $options)) {
$config_errors[] = sprintf($error_messages['type_missing'], $f_name);
}
if (!$default_missing) {
+ if ( is_null($db_default) && $not_null ) {
+ $db_default = $options['type'] == 'string' ? '' : 0;
+ }
+
if ($f_name == $config['IDField'] && $options['type'] != 'string' && $options['default'] !== 0) {
$config_errors[] = sprintf($error_messages['invalid_default'], 'IDField ', $f_name, $this->varDump($options['default']), $this->varDump($field['Default']));
}
- else if ($options['default'] != '#NOW#' && $field['Default'] !== $options['default'] && !in_array($options['type'], $float_types)) {
- $config_errors[] = sprintf($error_messages['invalid_default'], '', $f_name, $this->varDump($options['default']), $this->varDump($field['Default']));
+ else if (((string)$options['default'] != '#NOW#') && ($db_default !== $options['default']) && !in_array($options['type'], $float_types)) {
+ $config_errors[] = sprintf($error_messages['invalid_default'], '', $f_name, $this->varDump($options['default']), $this->varDump($db_default));
}
}
}
}
}
+ // validate calculated fields
+ if ( array_key_exists('CalculatedFields', $config) ) {
+ foreach ($config['CalculatedFields'] as $special => $calculated_fields) {
+ foreach ($calculated_fields as $calculated_field => $calculated_field_expr) {
+ if ( !isset($config['VirtualFields'][$calculated_field]) ) {
+ $config_errors[] = sprintf($error_messages['invalid_calculated_field'], $calculated_field);
+ }
+ }
+ }
+ }
+
if ($config_errors) {
$error_prefix = 'Config Error'.(count($config_errors) > 1 ? 's' : '').': for prefix '.$config_link.' ('.$tablename.') in unit config:
';
$config_errors = $error_prefix.' '.implode('
', $config_errors);
- $debugger->appendHTML($config_errors);
safeDefine('DBG_RAISE_ON_WARNINGS', 1);
+ $debugger->appendHTML($config_errors);
+ $debugger->WarningCount++;
}
}
Index: branches/5.1.x/core/units/admin/admin_events_handler.php
===================================================================
diff -u -N -r13664 -r13935
--- branches/5.1.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 13664)
+++ branches/5.1.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 13935)
@@ -1,6 +1,6 @@
add formatter
$field_options['formatter'] = 'kFormatter';
$field_options['format'] = '%01.'.$regs[1].'f';
- if ($field_info['Null'] != 'YES') {
+
+ if ($not_null) {
// null fields, will most likely have NULL as default value
$default_value = 0;
}
}
- else {
+ elseif ($not_null) {
// no size information, just convert to float
- if ($field_info['Null'] != 'YES') {
- // null fields, will most likely have NULL as default value
- $default_value = (float)$default_value;
- }
+ // null fields, will most likely have NULL as default value
+ $default_value = (float)$default_value;
+
}
}
@@ -302,7 +313,7 @@
$grid_col_options['filter_block'] = 'grid_options_filter';
}
- if ($field_info['Null'] != 'YES') {
+ if ($not_null) {
$field_options['not_null'] = 1;
}
@@ -311,15 +322,15 @@
$id_field = $field_info['Field'];
}
- if ($php_type == 'int' && !array_key_exists('not_null', $field_options)) {
+ if ($php_type == 'int' && !$not_null) {
// numeric null field
if (preg_match('/(On|Date)$/', $field_info['Field']) || $field_info['Field'] == 'Modified') {
$field_options['formatter'] = 'kDateFormatter';
$grid_col_options['filter_block'] = 'grid_date_rage_filter';
}
}
- if ($php_type == 'int' && ($field_info['Null'] != 'YES' || is_numeric($default_value))) {
+ if ($php_type == 'int' && ($not_null || is_numeric($default_value))) {
// is integer field AND not null
$field_options['default'] = (int)$default_value;
}
Index: branches/5.1.x/core/units/helpers/multilanguage_helper.php
===================================================================
diff -u -N -r13750 -r13935
--- branches/5.1.x/core/units/helpers/multilanguage_helper.php (.../multilanguage_helper.php) (revision 13750)
+++ branches/5.1.x/core/units/helpers/multilanguage_helper.php (.../multilanguage_helper.php) (revision 13935)
@@ -1,6 +1,6 @@
Conn->qstr($field_options['default']);
$field_mask['type'] = $field_options['db_type'];
}
- $field_mask['default'] = 'DEFAULT '.$default_value;
+ $field_mask['default'] = ($field_mask['null'] == 'NOT NULL' && $default_value == 'NULL') ? '' : 'DEFAULT '.$default_value;
if (strtoupper($field_mask['type']) == 'TEXT') {
// text fields in mysql doesn't have default value