From 08a43cac5ea83f98535d504e52de3466b30bf059 Mon Sep 17 00:00:00 2001 From: gbateson Date: Fri, 25 Sep 2009 06:22:00 +0000 Subject: [PATCH] stricter checking of null fields when restoring HotPots in order to avoid unwanted chars being inserted into empty char fields on PostgreSQL sites --- mod/hotpot/restorelib.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/mod/hotpot/restorelib.php b/mod/hotpot/restorelib.php index 684e2b3ba92..27934070f41 100644 --- a/mod/hotpot/restorelib.php +++ b/mod/hotpot/restorelib.php @@ -362,17 +362,14 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys, foreach ($table_columns[$table] as $column) { if ($column->not_null) { $name = $column->name; - if ($name<>'id' && empty($record->$name)) { - if (isset($column->default_value)) { - $default = $column->default_value; - } else { - if (preg_match('/int|decimal|double|float|time|year/i', $column->type)) { - $default = 0; - } else { - $default = ''; - } - } - $record->$name = $default; + if ($name=='id' || (isset($record->$name) && ! is_null($record->$name))) { + // do nothing + } else if (isset($column->default_value)) { + $record->$name = $column->default_value; + } else if (preg_match('/int|decimal|double|float|time|year/i', $column->type)) { + $record->$name = 0; + } else { + $record->$name = ''; } } }