From 26abe50b8c18d9419001f5385a98ac3807166c54 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 30 Jan 2015 12:48:41 +0000 Subject: [PATCH] * Backup: backing up bool columns now for all databases as 1 or 0, but understanding PostgreSQL "t" or "f" too --- phpgwapi/inc/class.db_backup.inc.php | 29 +++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/phpgwapi/inc/class.db_backup.inc.php b/phpgwapi/inc/class.db_backup.inc.php index 1747a8acf6..d27ca30ca3 100644 --- a/phpgwapi/inc/class.db_backup.inc.php +++ b/phpgwapi/inc/class.db_backup.inc.php @@ -7,12 +7,14 @@ * @package api * @subpackage db * @author Ralf Becker - * @copyright (c) 2003-14 by Ralf Becker + * @copyright (c) 2003-15 by Ralf Becker * @version $Id$ */ /** * DB independent backup and restore of EGroupware database + * + * Backing up bool columns now for all databases as 1 or 0, but understanding PostgreSQL 't' or 'f' too. */ class db_backup { @@ -589,6 +591,14 @@ class db_backup { if ($data['type'] == 'blob') $blobs[] = $col; } + // check if we have an old PostgreSQL backup useing 't'/'f' for bool values + // --> convert them to MySQL and our new PostgreSQL format of 1/0 + $bools = array(); + foreach($this->schemas[$table]['fd'] as $col => $def) + { + if ($def['type'] === 'bool') $bools[] = $col; + } + if ($table == 'egw_cal_dates') error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd'])); if (feof($f)) break; continue; @@ -606,7 +616,7 @@ class db_backup if ($table) // do we already reached the data part { $import = true; - $data = self::csv_split($line, $cols, $blobs); + $data = self::csv_split($line, $cols, $blobs, $bools); if ($table == 'egw_async' && in_array('##last-check-run##',$data)) { @@ -742,9 +752,10 @@ class db_backup * @param string $line line to split * @param array $keys =null keys to use or null to use numeric ones * @param array $blobs =array() blob columns + * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups * @return array */ - public static function csv_split($line, $keys=null, $blobs=array()) + public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) { if (function_exists('str_getcsv')) // php5.3+ { @@ -783,6 +794,11 @@ class db_backup $fields[$key] = $tmp; } } + // decode bool columns, they might be 't'/'f' for old PostgreSQL backups + foreach($bools as $key) + { + $fields[$key] = egw_db::from_bool($fields[$key]); + } } return $fields; } @@ -813,6 +829,10 @@ class db_backup { $arr[$key] = base64_decode($field); } + elseif (in_array($key, $bools)) + { + $arr[$key] = egw_db::from_bool($field); + } else { $arr[$key] = $field == 'NULL' ? NULL : $field; @@ -844,6 +864,9 @@ class db_backup case 'blob': $data = base64_encode($data); break; + case 'bool': // we use MySQL 0, 1 in csv, not PostgreSQL 't', 'f' + $data = (int)egw_db::from_bool($data); + break; default: $data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"'; break;