Index: branches/5.2.x/core/kernel/utility/unit_config_reader.php
===================================================================
diff -u -N -r13840 -r14092
--- branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 13840)
+++ branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 14092)
@@ -1,6 +1,6 @@
configFiles = unserialize($data);
- shuffle($this->configFiles);
+
+ if ( !defined('DBG_VALIDATE_CONFIGS') && !DBG_VALIDATE_CONFIGS ) {
+ shuffle($this->configFiles);
+ }
}
else {
$this->findConfigFiles(FULL_PATH . DIRECTORY_SEPARATOR . 'core'); // search from core directory
@@ -369,6 +372,10 @@
if ($store_cache) {
$this->_sortRewriteListeners();
+
+ $after_event = new kEvent('adm:OnAfterCacheRebuild');
+ $this->Application->HandleEvent($after_event);
+
$this->CacheParsedData();
if (defined('DEBUG_MODE') && DEBUG_MODE && defined('DBG_VALIDATE_CONFIGS') && DBG_VALIDATE_CONFIGS) {
@@ -377,10 +384,7 @@
if (!isset($config['TableName'])) continue;
$this->ValidateConfig($prefix);
}
- }
-
- $after_event = new kEvent('adm:OnAfterCacheRebuild');
- $this->Application->HandleEvent($after_event);
+ }
}
}
@@ -438,7 +442,9 @@
$this->ParseConfigs();
$this->AfterConfigRead(false);
$this->processDynamicClones();
- $this->retrieveCollections();
+
+ // don't call kUnitConfigReader::retrieveCollections since it
+ // will overwrite what we already have in kApplication class instance
}
/**
@@ -620,8 +626,10 @@
$table_found = $conn->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 ;
}
@@ -635,12 +643,19 @@
'not_null_error2' => 'Field %s is described as NOT NULL in config, but does not have DEFAULT value',
'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)',
+ 'date_column_not_null_error' => 'Field %s must be NULL in config and database, since it contains date',
+ 'user_column_default_error' => 'Field %s must be have NULL as default value, since it holds user id',
'type_missing' => 'Type definition for field %s missing in config',
+ 'virtual_type_missing' => 'Type definition for virtual field %s missing in config',
+ 'virtual_default_missing' => 'Default value for virtual field %s not set in config',
+ 'virtual_not_null_error' => 'Virtual field %s cannot be not null, since it doesn\'t exist in database',
+ '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 +669,17 @@
$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'];
+ $formatter = array_key_exists('formatter', $options) ? $options['formatter'] : false;
+
if (!array_key_exists('default', $options)) {
$config_errors[] = sprintf($error_messages['default_missing'], $f_name);
$default_missing = true;
@@ -670,38 +690,84 @@
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 (($formatter == 'kDateFormatter') && $not_null) {
+ $config_errors[] = sprintf($error_messages['date_column_not_null_error'], $f_name);
+ }
+
+ // columns, holding userid should have NULL as default value
+ if (array_key_exists('type', $options) && !$default_missing) {
+ // both type and default value set
+
+ if (preg_match('/ById$/', $f_name) && $options['default'] !== null) {
+ $config_errors[] = sprintf($error_messages['user_column_default_error'], $f_name);
}
}
if (!array_key_exists('type', $options)) {
$config_errors[] = sprintf($error_messages['type_missing'], $f_name);
}
- if (!$default_missing) {
+ if (!$default_missing && ($field['Type'] != 'text')) {
+ 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 virtual fields
+ if ( array_key_exists('VirtualFields', $config) ) {
+ foreach ($config['VirtualFields'] as $f_name => $options) {
+ if (!array_key_exists('type', $options)) {
+ $config_errors[] = sprintf($error_messages['virtual_type_missing'], $f_name);
+ }
+
+ if (array_key_exists('not_null', $options)) {
+ $config_errors[] = sprintf($error_messages['virtual_not_null_error'], $f_name);
+ }
+
+ if (!array_key_exists('default', $options)) {
+ $config_errors[] = sprintf($error_messages['virtual_default_missing'], $f_name);
+ }
+ }
+ }
+
+ // 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);
+ }
+ }
+ }
+
+ $config_errors = array_unique($config_errors);
+ }
+
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++;
}
}