Test Setup Failed
Push — master ( 12c298...4a14e0 )
by Ralf
22:03
created
api/src/Storage/Base2.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return so_sql2
55 55
 	 */
56
-	function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false)
56
+	function __construct($app = '', $table = '', Api\Db $db = null, $column_prefix = '', $no_clone = false)
57 57
 	{
58
-		parent::__construct($app,$table,$db,$column_prefix,$no_clone);
58
+		parent::__construct($app, $table, $db, $column_prefix, $no_clone);
59 59
 	}
60 60
 
61 61
 	/**
@@ -68,13 +68,13 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	function __get($property)
70 70
 	{
71
-		switch($property)
71
+		switch ($property)
72 72
 		{
73 73
 			case 'id':
74 74
 				$property = $this->autoinc_id;
75 75
 				break;
76 76
 		}
77
-		if (in_array($property,$this->db_cols) || in_array($property,$this->non_db_cols))
77
+		if (in_array($property, $this->db_cols) || in_array($property, $this->non_db_cols))
78 78
 		{
79 79
 			return $this->data[$property];
80 80
 		}
@@ -88,15 +88,15 @@  discard block
 block discarded – undo
88 88
 	 * @param string $property
89 89
 	 * @param mixed $value
90 90
 	 */
91
-	function __set($property,$value)
91
+	function __set($property, $value)
92 92
 	{
93
-		switch($property)
93
+		switch ($property)
94 94
 		{
95 95
 			case 'id':
96 96
 				$property = $this->autoinc_id;
97 97
 				break;
98 98
 		}
99
-		if (in_array($property,$this->db_cols) || in_array($property,$this->non_db_cols))
99
+		if (in_array($property, $this->db_cols) || in_array($property, $this->non_db_cols))
100 100
 		{
101 101
 			$this->data[$property] = $value;
102 102
 		}
Please login to merge, or discard this patch.
api/src/Exception/NoPermission/App.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class App extends Exception\NoPermission
23 23
 {
24
-	function __construct($msg=null,$code=101)
24
+	function __construct($msg = null, $code = 101)
25 25
 	{
26 26
 		if (isset($GLOBALS['egw_info']['apps'][$msg]))
27 27
 		{
@@ -39,6 +39,6 @@  discard block
 block discarded – undo
39 39
 						'"'.$app.'"');
40 40
 			}
41 41
 		}
42
-		parent::__construct($msg,$code);
42
+		parent::__construct($msg, $code);
43 43
 	}
44 44
 }
Please login to merge, or discard this patch.
api/src/Exception/NoPermission/Admin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,10 +19,10 @@
 block discarded – undo
19 19
  */
20 20
 class Admin extends App
21 21
 {
22
-	function __construct($msg=null,$code=102)
22
+	function __construct($msg = null, $code = 102)
23 23
 	{
24 24
 		if (is_null($msg)) $msg = 'admin';
25 25
 
26
-		parent::__construct($msg,$code);
26
+		parent::__construct($msg, $code);
27 27
 	}
28 28
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,10 @@
 block discarded – undo
21 21
 {
22 22
 	function __construct($msg=null,$code=102)
23 23
 	{
24
-		if (is_null($msg)) $msg = 'admin';
24
+		if (is_null($msg))
25
+		{
26
+			$msg = 'admin';
27
+		}
25 28
 
26 29
 		parent::__construct($msg,$code);
27 30
 	}
Please login to merge, or discard this patch.
api/src/Exception/NotFound.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,10 +26,10 @@
 block discarded – undo
26 26
 	 * @param string $msg =null message, default "Entry not found!"
27 27
 	 * @param int $code =99 numerical code, default 2
28 28
 	 */
29
-	function __construct($msg=null,$code=2)
29
+	function __construct($msg = null, $code = 2)
30 30
 	{
31 31
 		if (is_null($msg)) $msg = lang('Entry not found!');
32 32
 
33
-		parent::__construct($msg,$code);
33
+		parent::__construct($msg, $code);
34 34
 	}
35 35
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,10 @@
 block discarded – undo
28 28
 	 */
29 29
 	function __construct($msg=null,$code=2)
30 30
 	{
31
-		if (is_null($msg)) $msg = lang('Entry not found!');
31
+		if (is_null($msg))
32
+		{
33
+			$msg = lang('Entry not found!');
34
+		}
32 35
 
33 36
 		parent::__construct($msg,$code);
34 37
 	}
Please login to merge, or discard this patch.
api/src/Exception/Redirect.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	 * @param string $msg
34 34
 	 * @param int $code
35 35
 	 */
36
-	function __construct($url,$app=null,$msg=null,$code=301)
36
+	function __construct($url, $app = null, $msg = null, $code = 301)
37 37
 	{
38 38
 		$this->url = $url;
39 39
 		$this->app = $app;
Please login to merge, or discard this patch.
api/src/Exception/NoPermission.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@
 block discarded – undo
27 27
 	 * @param string $msg =null message, default "Permission denied!"
28 28
 	 * @param int $code =100 numerical code, default 100
29 29
 	 */
30
-	function __construct($msg=null,$code=100)
30
+	function __construct($msg = null, $code = 100)
31 31
 	{
32 32
 		if (is_null($msg)) $msg = lang('Permisson denied!');
33 33
 
34
-		parent::__construct($msg,$code);
34
+		parent::__construct($msg, $code);
35 35
 	}
36 36
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,10 @@
 block discarded – undo
29 29
 	 */
30 30
 	function __construct($msg=null,$code=100)
31 31
 	{
32
-		if (is_null($msg)) $msg = lang('Permisson denied!');
32
+		if (is_null($msg))
33
+		{
34
+			$msg = lang('Permisson denied!');
35
+		}
33 36
 
34 37
 		parent::__construct($msg,$code);
35 38
 	}
Please login to merge, or discard this patch.
api/src/Db/CallbackIterator.php 1 patch
Spacing   +9 added lines, -10 removed lines patch added patch discarded remove patch
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 	 * @param array $params =array() additional parameters, row is always first parameter
100 100
 	 * @param $key_callback =null optional callback, if you want different keys
101 101
 	 */
102
-	public function __construct(\Traversable $rs, $callback, $params=array(), $key_callback=null)
102
+	public function __construct(\Traversable $rs, $callback, $params = array(), $key_callback = null)
103 103
 	{
104 104
 		$this->callback = $callback;
105 105
 		$this->params = $params;
106 106
 		$this->key_callback = $key_callback;
107 107
 
108
-		if (is_a($rs,'IteratorAggregate'))
108
+		if (is_a($rs, 'IteratorAggregate'))
109 109
 		{
110 110
 			$this->rs = $rs->getIterator();
111 111
 		}
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function current()
124 124
 	{
125
-		if (is_a($this->rs,'iterator'))
125
+		if (is_a($this->rs, 'iterator'))
126 126
 		{
127 127
 			$params = $this->params;
128 128
 			array_unshift($params, $this->rs->current());
@@ -138,11 +138,10 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function key()
140 140
 	{
141
-		if (is_a($this->rs,'iterator'))
141
+		if (is_a($this->rs, 'iterator'))
142 142
 		{
143 143
 			return $this->key_callback ?
144
-				call_user_func($this->key_callback, $this->rs->current()) :
145
-				$this->rs->key();
144
+				call_user_func($this->key_callback, $this->rs->current()) : $this->rs->key();
146 145
 		}
147 146
 		return 0;
148 147
 	}
@@ -152,7 +151,7 @@  discard block
 block discarded – undo
152 151
 	 */
153 152
 	public function next()
154 153
 	{
155
-		if (is_a($this->rs,'iterator'))
154
+		if (is_a($this->rs, 'iterator'))
156 155
 		{
157 156
 			return $this->rs->next();
158 157
 		}
@@ -163,7 +162,7 @@  discard block
 block discarded – undo
163 162
 	 */
164 163
 	public function rewind()
165 164
 	{
166
-		if (is_a($this->rs,'iterator'))
165
+		if (is_a($this->rs, 'iterator'))
167 166
 		{
168 167
 			return $this->rs->rewind();
169 168
 		}
@@ -174,9 +173,9 @@  discard block
 block discarded – undo
174 173
 	 *
175 174
 	 * @return boolean
176 175
 	 */
177
-	public function valid ()
176
+	public function valid()
178 177
 	{
179
-		if (is_a($this->rs,'iterator'))
178
+		if (is_a($this->rs, 'iterator'))
180 179
 		{
181 180
 			return $this->rs->valid();
182 181
 		}
Please login to merge, or discard this patch.
api/src/Db/Backup.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 		$zip = NULL;
382 382
 		$_f = NULL;
383 383
 		if($type == 'zip')
384
-	    {
384
+		{
385 385
 			// has already been verified to be available in fopen_backup
386 386
 			$zip = new ZipArchive;
387 387
 			if(($zip->open($filename)) !== TRUE)
@@ -719,9 +719,9 @@  discard block
 block discarded – undo
719 719
 		while($file = $list[0])
720 720
 		{
721 721
 			if(is_dir($file) && $file != '.' && $file != '..')
722
-			    self::remove_dir_content($dir.'/'.$file);
722
+				self::remove_dir_content($dir.'/'.$file);
723 723
 			if(is_file($file) && $file != '.' && $file != '..')
724
-			    unlink($dir.'/'.$file);
724
+				unlink($dir.'/'.$file);
725 725
 			array_shift($list);
726 726
 		}
727 727
 		//rmdir($dir);  // dont remove own dir
@@ -967,8 +967,8 @@  discard block
 block discarded – undo
967 967
 				echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>';
968 968
 			}
969 969
 
970
-		    fclose($f);
971
-		    if (file_exists($name)) unlink($name);
970
+			fclose($f);
971
+			if (file_exists($name)) unlink($name);
972 972
 			return TRUE;
973 973
 		}
974 974
 		// save files ....
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	 * @var array
51 51
 	 */
52 52
 	var $exclude_tables = array(
53
-		'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions',	// eGW's session-tables
54
-		'phpgw_anglemail',	// email's cache
55
-		'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus',	// felamimail's cache
53
+		'egw_sessions', 'egw_app_sessions', 'phpgw_sessions', 'phpgw_app_sessions', // eGW's session-tables
54
+		'phpgw_anglemail', // email's cache
55
+		'egw_felamimail_cache', 'egw_felamimail_folderstatus', 'phpgw_felamimail_cache', 'phpgw_felamimail_folderstatus', // felamimail's cache
56 56
 		'egw_phpfreechat', // as of the fieldnames of the table a restore would fail within egroupware, and chatcontent is of no particular intrest
57 57
 	);
58 58
 	/**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @var boolean
86 86
 	 */
87
-	var $backup_files = false ;
87
+	var $backup_files = false;
88 88
 	/**
89 89
 	 * Reference to schema_proc's Api\Db object
90 90
 	 *
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	{
100 100
 		if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']) && !isset($GLOBALS['egw_setup']->db))
101 101
 		{
102
-			$GLOBALS['egw_setup']->loaddb();	// we run inside setup, but db object is not loaded
102
+			$GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded
103 103
 		}
104 104
 		if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc))	// schema_proc already instanciated, use it
105 105
 		{
@@ -117,21 +117,21 @@  discard block
 block discarded – undo
117 117
 		{
118 118
 			if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table)))
119 119
 			{
120
-				if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__)->fetchColumn()))
120
+				if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'", __LINE__, __FILE__)->fetchColumn()))
121 121
 				{
122 122
 					error_log(__METHOD__."->"."No files Directory set/found");
123 123
 				}
124
-				if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__)->fetchColumn()))
124
+				if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'", __LINE__, __FILE__)->fetchColumn()))
125 125
 				{
126 126
 					$this->backup_dir = $this->files_dir.'/db_backup';
127 127
 				}
128
-				$this->charset = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'",__LINE__,__FILE__)->fetchColumn();
129
-				$this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table,'app_version',array('app_name'=>array('api','phpgwapi')),
130
-					__LINE__,__FILE__,0,'ORDER BY app_name ASC')->fetchColumn();
128
+				$this->charset = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'", __LINE__, __FILE__)->fetchColumn();
129
+				$this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table, 'app_version', array('app_name'=>array('api', 'phpgwapi')),
130
+					__LINE__, __FILE__, 0, 'ORDER BY app_name ASC')->fetchColumn();
131 131
 				// Backup settings
132
-				$this->backup_mincount = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'",__LINE__,__FILE__)->fetchColumn();
132
+				$this->backup_mincount = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'", __LINE__, __FILE__)->fetchColumn();
133 133
 				// backup files too
134
-				$this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'",__LINE__,__FILE__)->fetchColumn();
134
+				$this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'", __LINE__, __FILE__)->fetchColumn();
135 135
 			}
136 136
 			if (!$this->charset) $this->charset = 'utf-8';
137 137
 		}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 			$this->backup_files = $GLOBALS['egw_info']['server']['backup_files'];
147 147
 			$this->charset = Api\Translation::charset();
148 148
 
149
-			$this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api'])?'api':'phpgwapi']['version'];
149
+			$this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api']) ? 'api' : 'phpgwapi']['version'];
150 150
 		}
151 151
 		// Set a default value if not set.
152 152
 		if (!isset($this->backup_mincount))
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		{
163 163
 			mkdir($this->backup_dir);
164 164
 		}
165
-		switch($this->db->Type)
165
+		switch ($this->db->Type)
166 166
 		{
167 167
 			case 'sapdb':
168 168
 			case 'maxdb':
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @param $reading =false opening for reading ('rb') or writing ('wb')
180 180
 	 * @return string/resource/zip error-msg of file-handle
181 181
 	 */
182
-	function fopen_backup($name=false,$reading=false)
182
+	function fopen_backup($name = false, $reading = false)
183 183
 	{
184 184
 		//echo "function fopen_backup($name,$reading)<br>";	// !
185 185
 		if (!$name)
@@ -188,27 +188,27 @@  discard block
 block discarded – undo
188 188
 			if (!$this->backup_dir || !is_writable($this->backup_dir))
189 189
 			{
190 190
 				//echo '   -> !$this->backup_dir || !is_writable($this->backup_dir)<br>';	// !
191
-				return lang("backupdir '%1' is not writeable by the webserver",$this->backup_dir);
191
+				return lang("backupdir '%1' is not writeable by the webserver", $this->backup_dir);
192 192
 			}
193 193
 			$name = $this->backup_dir.'/db_backup-'.date('YmdHi');
194 194
 		}
195 195
 		else	// remove the extension, to use the correct wrapper based on the extension
196 196
 		{
197 197
 			//echo '-> else<br>';	// !
198
-			$name = preg_replace('/\.(bz2|gz)$/i','',$name);
198
+			$name = preg_replace('/\.(bz2|gz)$/i', '', $name);
199 199
 		}
200 200
 		$mode = $reading ? 'rb' : 'wb';
201
-		list( , $type) = explode('.', basename($name));
202
-		if($type == 'zip' && $reading && $this->backup_files)
201
+		list(, $type) = explode('.', basename($name));
202
+		if ($type == 'zip' && $reading && $this->backup_files)
203 203
 		{
204 204
 			//echo '-> $type == "zip" && $reading<br>';	// !
205
-			if(!class_exists('ZipArchive', false))
205
+			if (!class_exists('ZipArchive', false))
206 206
 			{
207 207
 				$this->backup_files = false;
208 208
 				//echo '   -> (new ZipArchive) == NULL<br>';	// !
209 209
 				return lang("Cant open %1, needs ZipArchive", $name)."<br>\n";
210 210
 			}
211
-			if(!($f = fopen($name, $mode)))
211
+			if (!($f = fopen($name, $mode)))
212 212
 			{
213 213
 				//echo '   -> !($f = fopen($name, $mode))<br>';	// !
214 214
 				$lang_mode = $reading ? lang("reading") : lang("writing");
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
 			}
217 217
 			return $f;
218 218
 		}
219
-		if(class_exists('ZipArchive', false) && !$reading && $this->backup_files)
219
+		if (class_exists('ZipArchive', false) && !$reading && $this->backup_files)
220 220
 		{
221 221
 			//echo '-> (new ZipArchive) != NULL && !$reading; '.$name.'<br>';	// !
222
-			if(!($f = fopen($name, $mode)))
222
+			if (!($f = fopen($name, $mode)))
223 223
 			{
224 224
 				//echo '   -> !($f = fopen($name, $mode))<br>';	// !
225 225
 				$lang_mode = $reading ? lang("reading") : lang("writing");
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 			}
228 228
 			return $f;
229 229
 		}
230
-		if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) &&
231
-	 		!($f = fopen("compress.zlib://$name.gz",$mode)) &&
232
- 		 	!($f = fopen($name,$mode))
230
+		if (!($f = fopen("compress.bzip2://$name.bz2", $mode)) &&
231
+	 		!($f = fopen("compress.zlib://$name.gz", $mode)) &&
232
+ 		 	!($f = fopen($name, $mode))
233 233
 		)
234 234
 		{
235 235
 			//echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>';	// !
@@ -256,13 +256,13 @@  discard block
 block discarded – undo
256 256
 		/* Search the backup directory for matching files. */
257 257
 		$handle = @opendir($this->backup_dir);
258 258
 		$files = array();
259
-		while($handle && ($file = readdir($handle)))
259
+		while ($handle && ($file = readdir($handle)))
260 260
 		{
261 261
 			/* Filter for only the files with the regular name (un-renamed).
262 262
 			 * Leave special backup files (renamed) in place.
263 263
 			 * Note that this also excludes "." and "..".
264 264
 			 */
265
-			if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/",$file))
265
+			if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/", $file))
266 266
 			{
267 267
 				$files[filectime($this->backup_dir.'/'.$file)] = $file;
268 268
 			}
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 		/* Sort the files by ctime. */
273 273
 		krsort($files);
274 274
 		$count = 0;
275
-		foreach($files as $file)
275
+		foreach ($files as $file)
276 276
 		{
277 277
 			if ($count >= $this->backup_mincount)//
278 278
 			{
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 					array_push($files_return, $file);
283 283
 				}
284 284
 			}
285
-			$count ++;
285
+			$count++;
286 286
 		}
287 287
 	}
288 288
 
@@ -292,13 +292,13 @@  discard block
 block discarded – undo
292 292
 	 * @param int $minCount Minimum number of backups to keep.
293 293
 	 * @param boolean $backupFiles include files in backup or not, default dont change!
294 294
 	 */
295
-	function saveConfig($minCount,$backupFiles=null)
295
+	function saveConfig($minCount, $backupFiles = null)
296 296
 	{
297
-		Api\Config::save_value('backup_mincount',$this->backup_mincount=(int)$minCount,'phpgwapi');
297
+		Api\Config::save_value('backup_mincount', $this->backup_mincount = (int)$minCount, 'phpgwapi');
298 298
 
299 299
 		if (!is_null($backupFiles))
300 300
 		{
301
-			Api\Config::save_value('backup_files',$this->backup_files=(boolean)$backupFiles,'phpgwapi');
301
+			Api\Config::save_value('backup_files', $this->backup_files = (boolean)$backupFiles, 'phpgwapi');
302 302
 		}
303 303
 	}
304 304
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 		'httpproxy_server_password',
322 322
 		'system_charset',
323 323
 		'usecookies',
324
-		'install_id',	// do not restore install_id, as that would give two systems with identical install_id
324
+		'install_id', // do not restore install_id, as that would give two systems with identical install_id
325 325
 	);
326 326
 
327 327
 	/**
@@ -335,20 +335,20 @@  discard block
 block discarded – undo
335 335
 	 *
336 336
 	 * @returns An empty string or an error message in case of failure.
337 337
 	 */
338
-	function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=500)
338
+	function restore($f, $convert_to_system_charset = true, $filename = '', $protect_system_config = true, $insert_n_rows = 500)
339 339
 	{
340 340
 		@set_time_limit(0);
341
-		ini_set('auto_detect_line_endings',true);
341
+		ini_set('auto_detect_line_endings', true);
342 342
 
343
-		if (true) $convert_to_system_charset = true;	// enforce now utf-8 as system charset restores of old backups
343
+		if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups
344 344
 
345 345
 		if ($protect_system_config)
346 346
 		{
347 347
 			$system_config = array();
348
-			foreach($this->db->select(self::TABLE,'*',array(
348
+			foreach ($this->db->select(self::TABLE, '*', array(
349 349
 				'config_app' => 'phpgwapi',
350 350
 				'config_name' => self::$system_config,
351
-			),__LINE__,__FILE__) as $row)
351
+			), __LINE__, __FILE__) as $row)
352 352
 			{
353 353
 				$system_config[] = $row;
354 354
 			}
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 		// as MySQL 5.7+ has sql_mode STRICT_(ALL|TRANS)_TABLES enabled by default,
358 358
 		// it will no longer restore '0000-00-00 00:00:00' in timestamps it created before,
359 359
 		// so switching strict-mode off temporary for the restore (we dont create these!)
360
-		if (substr($this->db->Type,0,5) == 'mysql')
360
+		if (substr($this->db->Type, 0, 5) == 'mysql')
361 361
 		{
362 362
 			$this->db->query("SET SESSION sql_mode=(SELECT REPLACE(REPLACE(@@sql_mode,'STRICT_ALL_TABLES',''),'STRICT_TRANS_TABLES',''))", __LINE__, __FILE__);
363 363
 		}
@@ -368,17 +368,17 @@  discard block
 block discarded – undo
368 368
 
369 369
 
370 370
 		// drop all existing tables
371
-		foreach($this->adodb->MetaTables('TABLES') as $table)
371
+		foreach ($this->adodb->MetaTables('TABLES') as $table)
372 372
 		{
373
-			if ($this->system_tables && preg_match($this->system_tables,$table) ||
374
-				$this->egw_tables && !preg_match($this->egw_tables,$table))
373
+			if ($this->system_tables && preg_match($this->system_tables, $table) ||
374
+				$this->egw_tables && !preg_match($this->egw_tables, $table))
375 375
 			{
376 376
 				 continue;
377 377
 			}
378 378
 			$this->schema_proc->DropTable($table);
379 379
 		}
380 380
 		// it could be an old backup
381
-		list( , $type) = explode('.', basename($filename));
381
+		list(, $type) = explode('.', basename($filename));
382 382
 		$dir = $this->files_dir; // $GLOBALS['egw_info']['server']['files_dir'];
383 383
 		// we may have to clean up old backup - left overs
384 384
 		if (is_dir($dir.'/database_backup'))
@@ -391,20 +391,20 @@  discard block
 block discarded – undo
391 391
 		$name = "";
392 392
 		$zip = NULL;
393 393
 		$_f = NULL;
394
-		if($type == 'zip')
394
+		if ($type == 'zip')
395 395
 	    {
396 396
 			// has already been verified to be available in fopen_backup
397 397
 			$zip = new ZipArchive;
398
-			if(($zip->open($filename)) !== TRUE)
398
+			if (($zip->open($filename)) !== TRUE)
399 399
 			{
400 400
 				return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n";
401 401
 			}
402
-			self::remove_dir_content($dir);  // removes the files-dir
402
+			self::remove_dir_content($dir); // removes the files-dir
403 403
 			$zip->extractTo($dir);
404 404
 			$_f = $f;
405 405
 			$list = $this->get_file_list($dir.'/database_backup/');
406 406
 			$name = $dir.'/database_backup/'.basename($list[0]);
407
-			if(!($f = fopen($name, 'rb')))
407
+			if (!($f = fopen($name, 'rb')))
408 408
 			{
409 409
 				return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n";
410 410
 			}
@@ -415,56 +415,56 @@  discard block
 block discarded – undo
415 415
 		{
416 416
 			$this->db->insert(Api\Config::TABLE, array(
417 417
 				'config_value' => $this->schema_proc->system_charset,
418
-			),array(
418
+			), array(
419 419
 				'config_app' => 'phpgwapi',
420 420
 				'config_name' => 'system_charset',
421
-			),__LINE__,__FILE__);
421
+			), __LINE__, __FILE__);
422 422
 		}
423 423
 		// restore protected system config
424 424
 		if ($protect_system_config)
425 425
 		{
426
-			foreach($system_config as $row)
426
+			foreach ($system_config as $row)
427 427
 			{
428
-				$this->db->insert(self::TABLE,array('config_value'=>$row['config_value']),array(
428
+				$this->db->insert(self::TABLE, array('config_value'=>$row['config_value']), array(
429 429
 					'config_name' => $row['config_name'],
430 430
 					'config_app'  => $row['config_app'],
431
-				),__LINE__,__FILE__);
431
+				), __LINE__, __FILE__);
432 432
 			}
433 433
 			// check and reset cookie configuration, if it does not match current enviroment
434 434
 			// if $_SERVER[HTTP_HOST] does not end with cookiedomain --> delete cookiedomain
435
-			if (($cookiedomain = $this->db->select(self::TABLE,'config_value',array(
435
+			if (($cookiedomain = $this->db->select(self::TABLE, 'config_value', array(
436 436
 					'config_app' => 'phpgwapi',
437 437
 					'config_name' => 'cookiedomain',
438
-				),__LINE__,__FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) &&
439
-				(list($hostname) = explode(':',$_SERVER['HTTP_HOST'])) &&
440
-				substr($hostname,-strlen($cookiedomain) !== $cookiedomain))
438
+				), __LINE__, __FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) &&
439
+				(list($hostname) = explode(':', $_SERVER['HTTP_HOST'])) &&
440
+				substr($hostname, -strlen($cookiedomain) !== $cookiedomain))
441 441
 			{
442
-				$this->db->delete(self::TABLE,array(
442
+				$this->db->delete(self::TABLE, array(
443 443
 					'config_app' => 'phpgwapi',
444 444
 					'config_name' => 'cookiedomain',
445
-				),__LINE__,__FILE__);
445
+				), __LINE__, __FILE__);
446 446
 			}
447 447
 			// if configured webserver_url does NOT start with cookiepath --> delete cookiepath
448
-			if (($cookiepath = $this->db->select(self::TABLE,'config_value',array(
448
+			if (($cookiepath = $this->db->select(self::TABLE, 'config_value', array(
449 449
 					'config_app' => 'phpgwapi',
450 450
 					'config_name' => 'cookiepath',
451
-				),__LINE__,__FILE__)->fetchColumn()) &&
452
-				substr(parse_url($system_config['webserver_url'], PHP_URL_PATH),0,strlen($cookiepath) !== $cookiepath))
451
+				), __LINE__, __FILE__)->fetchColumn()) &&
452
+				substr(parse_url($system_config['webserver_url'], PHP_URL_PATH), 0, strlen($cookiepath) !== $cookiepath))
453 453
 			{
454
-				$this->db->delete(self::TABLE,array(
454
+				$this->db->delete(self::TABLE, array(
455 455
 					'config_app' => 'phpgwapi',
456 456
 					'config_name' => 'cookiepath',
457
-				),__LINE__,__FILE__);
457
+				), __LINE__, __FILE__);
458 458
 			}
459 459
 		}
460 460
 		// zip?
461
-		if($type == 'zip')
461
+		if ($type == 'zip')
462 462
 		{
463 463
 			fclose($f);
464 464
 			unlink($name);
465 465
 			rmdir($dir.'/database_backup');
466 466
 		}
467
-		if (substr($this->db->Type,0,5) != 'mysql')
467
+		if (substr($this->db->Type, 0, 5) != 'mysql')
468 468
 		{
469 469
 			if (!$this->db->transaction_commit())
470 470
 			{
@@ -499,26 +499,26 @@  discard block
 block discarded – undo
499 499
 	 * @param int|string $insert_n_rows =500 how many rows to insert in one sql statement, or string with column-name used as unique key for insert
500 500
 	 * @returns int number of rows read from csv file
501 501
 	 */
502
-	function db_restore($f, $insert_n_rows=500)
502
+	function db_restore($f, $insert_n_rows = 500)
503 503
 	{
504 504
 		$convert_to_system_charset = true;
505 505
 		$table = null;
506 506
 		$n = 0;
507 507
 		$rows = array();
508
-		while(!feof($f))
508
+		while (!feof($f))
509 509
 		{
510 510
 			$line = trim(fgets($f)); ++$n;
511 511
 
512 512
 			if (empty($line)) continue;
513 513
 
514
-			if (substr($line,0,9) == 'version: ')
514
+			if (substr($line, 0, 9) == 'version: ')
515 515
 			{
516 516
 				// currenty not used: $api_version = trim(substr($line,9));
517 517
 				continue;
518 518
 			}
519
-			if (substr($line,0,9) == 'charset: ')
519
+			if (substr($line, 0, 9) == 'charset: ')
520 520
 			{
521
-				$charset = trim(substr($line,9));
521
+				$charset = trim(substr($line, 9));
522 522
 				// needed if mbstring.func_overload > 0, else eg. substr does not work with non ascii chars
523 523
 				$ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset';
524 524
 				@ini_set($ini_default_charset, $charset);
@@ -526,18 +526,18 @@  discard block
 block discarded – undo
526 526
 				// check if we really need to convert the charset, as it's not perfect and can do some damage
527 527
 				if ($convert_to_system_charset && !strcasecmp($this->schema_proc->system_charset, $charset))
528 528
 				{
529
-					$convert_to_system_charset = false;	// no conversation necessary
529
+					$convert_to_system_charset = false; // no conversation necessary
530 530
 				}
531 531
 				continue;
532 532
 			}
533
-			if (substr($line,0,8) == 'schema: ')
533
+			if (substr($line, 0, 8) == 'schema: ')
534 534
 			{
535 535
 				// create the tables in the backup set
536
-				$this->schemas = json_php_unserialize(trim(substr($line,8)));
537
-				foreach($this->schemas as $table_name => $schema)
536
+				$this->schemas = json_php_unserialize(trim(substr($line, 8)));
537
+				foreach ($this->schemas as $table_name => $schema)
538 538
 				{
539 539
 					// if column is longtext in current schema, convert text to longtext, in case user already updated column
540
-					foreach($schema['fd'] as $col => &$def)
540
+					foreach ($schema['fd'] as $col => &$def)
541 541
 					{
542 542
 						if ($def['type'] == 'text' && $this->db->get_column_attribute($col, $table_name, true, 'type') == 'longtext')
543 543
 						{
@@ -549,27 +549,27 @@  discard block
 block discarded – undo
549 549
 				}
550 550
 				continue;
551 551
 			}
552
-			if (substr($line,0,7) == 'table: ')
552
+			if (substr($line, 0, 7) == 'table: ')
553 553
 			{
554 554
 				if ($rows)	// flush pending rows of last table
555 555
 				{
556 556
 					$this->insert_multiple($table, $rows, $this->schemas[$table]);
557 557
 				}
558 558
 				$rows = array();
559
-				$table = substr($line,7);
559
+				$table = substr($line, 7);
560 560
 				if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table);
561 561
 				$auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null;
562 562
 
563
-				$cols = self::csv_split($line=fgets($f)); ++$n;
563
+				$cols = self::csv_split($line = fgets($f)); ++$n;
564 564
 				$blobs = array();
565
-				foreach($this->schemas[$table]['fd'] as $col => $data)
565
+				foreach ($this->schemas[$table]['fd'] as $col => $data)
566 566
 				{
567 567
 					if ($data['type'] == 'blob') $blobs[] = $col;
568 568
 				}
569 569
 				// check if we have an old PostgreSQL backup useing 't'/'f' for bool values
570 570
 				// --> convert them to MySQL and our new PostgreSQL format of 1/0
571 571
 				$bools = array();
572
-				foreach($this->schemas[$table]['fd'] as $col => $def)
572
+				foreach ($this->schemas[$table]['fd'] as $col => $def)
573 573
 				{
574 574
 					if ($def['type'] === 'bool') $bools[] = $col;
575 575
 				}
@@ -582,15 +582,15 @@  discard block
 block discarded – undo
582 582
 				$import = true;
583 583
 				$data = self::csv_split($line, $cols, $blobs, $bools);
584 584
 
585
-				if ($table == 'egw_async' && in_array('##last-check-run##',$data))
585
+				if ($table == 'egw_async' && in_array('##last-check-run##', $data))
586 586
 				{
587 587
 					//echo '<p>'.lang("Line %1: '%2'<br><b>csv data does contain ##last-check-run## of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n";
588 588
 					//echo 'data=<pre>'.print_r($data,true)."</pre>\n";
589 589
 					$import = false;
590 590
 				}
591
-				if (in_array($table,$this->exclude_tables))
591
+				if (in_array($table, $this->exclude_tables))
592 592
 				{
593
-					echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n";
593
+					echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.", $table)."</b></p>\n";
594 594
 					$import = false; // dont restore data of excluded tables
595 595
 				}
596 596
 				if ($import)
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 					{
600 600
 						if ($convert_to_system_charset)
601 601
 						{
602
-							$data = Api\Translation::convert($data,$charset);
602
+							$data = Api\Translation::convert($data, $charset);
603 603
 						}
604 604
 						if ($insert_n_rows > 1)
605 605
 						{
@@ -613,27 +613,27 @@  discard block
 block discarded – undo
613 613
 							}
614 614
 						}
615 615
 						// update existing table using given unique key in $insert_n_rows (also removing auto-id/sequence)
616
-						elseif(!is_numeric($insert_n_rows))
616
+						elseif (!is_numeric($insert_n_rows))
617 617
 						{
618 618
 							$where = array($insert_n_rows => $data[$insert_n_rows]);
619 619
 							unset($data[$insert_n_rows]);
620 620
 							if ($auto_id) unset($data[$auto_id]);
621
-							$this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]);
621
+							$this->db->insert($table, $data, $where, __LINE__, __FILE__, false, false, $this->schemas[$table]);
622 622
 						}
623 623
 						else
624 624
 						{
625 625
 							try {
626
-								$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
626
+								$this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $this->schemas[$table]);
627 627
 							}
628
-							catch(Exception\InvalidSql $e) {
628
+							catch (Exception\InvalidSql $e) {
629 629
 								echo "<p>".$e->getMessage()."</p>\n";
630 630
 							}
631 631
 						}
632 632
 					}
633 633
 					else
634 634
 					{
635
-						echo '<p>'.lang("Line %1: '%2'<br><b>csv data does not match column-count of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n";
636
-						echo 'data=<pre>'.print_r($data,true)."</pre>\n";
635
+						echo '<p>'.lang("Line %1: '%2'<br><b>csv data does not match column-count of table %3 ==> ignored</b>", $n, $line, $table)."</p>\n";
636
+						echo 'data=<pre>'.print_r($data, true)."</pre>\n";
637 637
 					}
638 638
 				}
639 639
 			}
@@ -643,14 +643,14 @@  discard block
 block discarded – undo
643 643
 			$this->insert_multiple($table, $rows, $this->schemas[$table]);
644 644
 		}
645 645
 		// updated the sequences, if the DB uses them
646
-		foreach($this->schemas as $table => $schema)
646
+		foreach ($this->schemas as $table => $schema)
647 647
 		{
648
-			foreach($schema['fd'] as $column => $definition)
648
+			foreach ($schema['fd'] as $column => $definition)
649 649
 			{
650 650
 				if ($definition['type'] == 'auto')
651 651
 				{
652
-					$this->schema_proc->UpdateSequence($table,$column);
653
-					break;	// max. one per table
652
+					$this->schema_proc->UpdateSequence($table, $column);
653
+					break; // max. one per table
654 654
 				}
655 655
 			}
656 656
 		}
@@ -673,15 +673,15 @@  discard block
 block discarded – undo
673 673
 		try {
674 674
 			$this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema);
675 675
 		}
676
-		catch(Exception\InvalidSql $e)
676
+		catch (Exception\InvalidSql $e)
677 677
 		{
678 678
 			// try inserting them one by one, ignoring doublicates
679
-			foreach($rows as $data)
679
+			foreach ($rows as $data)
680 680
 			{
681 681
 				try {
682 682
 					$this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema);
683 683
 				}
684
-				catch(Exception\InvalidSql $e) {
684
+				catch (Exception\InvalidSql $e) {
685 685
 					echo "<p>".$e->getMessage()."</p>\n";
686 686
 				}
687 687
 			}
@@ -696,11 +696,11 @@  discard block
 block discarded – undo
696 696
 	private static function remove_dir_content($dir)
697 697
 	{
698 698
 		$list = scandir($dir);
699
-		while($file = $list[0])
699
+		while ($file = $list[0])
700 700
 		{
701
-			if(is_dir($file) && $file != '.' && $file != '..')
701
+			if (is_dir($file) && $file != '.' && $file != '..')
702 702
 			    self::remove_dir_content($dir.'/'.$file);
703
-			if(is_file($file) && $file != '.' && $file != '..')
703
+			if (is_file($file) && $file != '.' && $file != '..')
704 704
 			    unlink($dir.'/'.$file);
705 705
 			array_shift($list);
706 706
 		}
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	 * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups
726 726
 	 * @return array
727 727
 	 */
728
-	public static function csv_split($line, $keys=null, $blobs=array(), $bools=array())
728
+	public static function csv_split($line, $keys = null, $blobs = array(), $bools = array())
729 729
 	{
730 730
 		if (function_exists('str_getcsv'))	// php5.3+
731 731
 		{
@@ -738,9 +738,9 @@  discard block
 block discarded – undo
738 738
 				'\\n'    => "\n",
739 739
 				'\\r'    => "\r")), ',', '"', '\0');
740 740
 			// replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash
741
-			foreach($fields as &$field)
741
+			foreach ($fields as &$field)
742 742
 			{
743
-				switch($field)
743
+				switch ($field)
744 744
 				{
745 745
 					case self::NULL_TOKEN:
746 746
 						$field = 'NULL';
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 			{
758 758
 				$fields = array_combine($keys, $fields);
759 759
 				// base64-decode blob columns, if they are base64 encoded
760
-				foreach($blobs as $key)
760
+				foreach ($blobs as $key)
761 761
 				{
762 762
 					if (!is_null($fields[$key]) && ($tmp = base64_decode($fields[$key], true)) !== false)
763 763
 					{
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 					}
766 766
 				}
767 767
 				// decode bool columns, they might be 't'/'f' for old PostgreSQL backups
768
-				foreach($bools as $key)
768
+				foreach ($bools as $key)
769 769
 				{
770 770
 					if (isset($fields[$key]))	// do NOT replace NULL with false/0
771 771
 					{
@@ -776,11 +776,11 @@  discard block
 block discarded – undo
776 776
 			return $fields;
777 777
 		}
778 778
 		// pre 5.3 implementation
779
-		$fields = explode(',',trim($line));
779
+		$fields = explode(',', trim($line));
780 780
 
781 781
 		$str_pending = False;
782 782
 		$n = 0;
783
-		foreach($fields as $field)
783
+		foreach ($fields as $field)
784 784
 		{
785 785
 			if ($str_pending !== False)
786 786
 			{
@@ -791,12 +791,12 @@  discard block
 block discarded – undo
791 791
 
792 792
 			if ($field[0] == '"')
793 793
 			{
794
-				if (substr($field,-1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/',$field))
794
+				if (substr($field, -1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/', $field))
795 795
 				{
796 796
 					$str_pending = $field;
797 797
 					continue;
798 798
 				}
799
-				$arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1)));
799
+				$arr[$key] = str_replace(self::BACKSLASH_TOKEN, '\\', str_replace(array('\\\\', '\\n', '\\r', '\\"'), array(self::BACKSLASH_TOKEN, "\n", "\r", '"'), substr($field, 1, -1)));
800 800
 			}
801 801
 			elseif ($keys && strlen($field) > 26)
802 802
 			{
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 	/**
819 819
 	 * escape data for csv
820 820
 	 */
821
-	public static function escape_data(&$data,$col,$defs)
821
+	public static function escape_data(&$data, $col, $defs)
822 822
 	{
823 823
 		if (is_null($data))
824 824
 		{
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 		}
827 827
 		else
828 828
 		{
829
-			switch($defs[$col]['type'])
829
+			switch ($defs[$col]['type'])
830 830
 			{
831 831
 				case 'int':
832 832
 				case 'auto':
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 					$data = (int)Api\Db::from_bool($data);
842 842
 					break;
843 843
 				default:
844
-					$data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"';
844
+					$data = '"'.str_replace(array('\\', "\n", "\r", '"'), array('\\\\', '\\n', '\\r', '\\"'), $data).'"';
845 845
 					break;
846 846
 			}
847 847
 		}
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
 	 *	default of null limits memory usage if there is no primary key, by locking table and use ROW_CHUCK
861 861
 	 * @todo use https://github.com/maennchen/ZipStream-PHP to not assemble all files in memmory
862 862
 	 */
863
-	function backup($f, $lock_table=null)
863
+	function backup($f, $lock_table = null)
864 864
 	{
865 865
 		//echo "function backup($f)<br>";	// !
866 866
 		@set_time_limit(0);
@@ -876,15 +876,15 @@  discard block
 block discarded – undo
876 876
 		$name = $this->backup_dir.'/db_backup-'.date('YmdHi');
877 877
 		$filename = $name.'.zip';
878 878
 		$zippresent = false;
879
-		if(class_exists('ZipArchive') && $this->backup_files)
879
+		if (class_exists('ZipArchive') && $this->backup_files)
880 880
 		{
881 881
 			$zip = new ZipArchive;
882
-			if(is_object($zip))
882
+			if (is_object($zip))
883 883
 			{
884 884
 				$zippresent = true;
885 885
 				//echo '-> is_object($zip); '.$filename.'<br>';	// !
886 886
 				$res = $zip->open($filename, ZipArchive::CREATE);
887
-				if($res !== TRUE)
887
+				if ($res !== TRUE)
888 888
 				{
889 889
 					//echo '   -> !$res<br>';	// !
890 890
 					return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n";
@@ -892,22 +892,22 @@  discard block
 block discarded – undo
892 892
 				$file_list = $this->get_file_list($dir);
893 893
 			}
894 894
 		}
895
-		fwrite($f,"EGroupware backup from ".date('Y-m-d H:i:s')."\n\n");
895
+		fwrite($f, "EGroupware backup from ".date('Y-m-d H:i:s')."\n\n");
896 896
 
897
-		fwrite($f,"version: $this->api_version\n\n");
897
+		fwrite($f, "version: $this->api_version\n\n");
898 898
 
899
-		fwrite($f,"charset: $this->charset\n\n");
899
+		fwrite($f, "charset: $this->charset\n\n");
900 900
 
901
-		$this->schema_backup($f);	// add the schema in a human readable form too
901
+		$this->schema_backup($f); // add the schema in a human readable form too
902 902
 
903
-		fwrite($f,"\nschema: ".json_encode($this->schemas)."\n");
903
+		fwrite($f, "\nschema: ".json_encode($this->schemas)."\n");
904 904
 
905 905
 		// let apps know that backup is about to start
906 906
 		Api\Hooks::process('backup_starts', array(), true);
907 907
 
908
-		foreach($this->schemas as $table => $schema)
908
+		foreach ($this->schemas as $table => $schema)
909 909
 		{
910
-			if (in_array($table,$this->exclude_tables)) continue;	// dont backup
910
+			if (in_array($table, $this->exclude_tables)) continue; // dont backup
911 911
 
912 912
 			// do we have a primary key?
913 913
 			// --> use it to order and limit rows, to kope with rows being added during backup
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
 			do {
924 924
 				$num_rows = 0;
925 925
 				// querying only chunks for 10000 rows, to not run into memory limit on huge tables
926
-				foreach($this->db->select($table, '*',
926
+				foreach ($this->db->select($table, '*',
927 927
 					// limit by maximum primary key already received
928 928
 					empty($pk) || !$max ? false : $pk.' > '.$this->db->quote($max, $schema['fd'][$pk]['type']),
929 929
 					__LINE__, __FILE__,
@@ -934,15 +934,15 @@  discard block
 block discarded – undo
934 934
 					false, self::ROW_CHUNK) as $row)
935 935
 				{
936 936
 					if (!empty($pk)) $max = $row[$pk];
937
-					if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
937
+					if ($total === 0) fwrite($f, "\ntable: $table\n".implode(',', array_keys($row))."\n");
938 938
 
939 939
 					array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']);
940
-					fwrite($f,implode(',',$row)."\n");
940
+					fwrite($f, implode(',', $row)."\n");
941 941
 					++$total;
942 942
 					++$num_rows;
943 943
 				}
944 944
 			}
945
-			while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
945
+			while ((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
946 946
 
947 947
 			if (!$pk) $this->db->rollback_lock($table);
948 948
 		}
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
 		// let apps know that backup is finished
951 951
 		Api\Hooks::process('backup_finished', array(), true);
952 952
 
953
-		if(!$zippresent)  // save without files
953
+		if (!$zippresent)  // save without files
954 954
 		{
955 955
 			if ($this->backup_files)
956 956
 			{
@@ -965,16 +965,16 @@  discard block
 block discarded – undo
965 965
 		//echo $name.'<br>';
966 966
 		$zip->addFile($name, 'database_backup/'.basename($name));
967 967
 		$count = 1;
968
-		foreach($file_list as $file)
968
+		foreach ($file_list as $file)
969 969
 		{
970 970
 			//echo substr($file,strlen($dir)+1).'<br>';
971 971
 			//echo $file.'<br>';
972
-			$zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file);
973
-			if(($count++) == 100) { // the file descriptor limit
972
+			$zip->addFile($file, substr($file, strlen($dir) + 1)); //,substr($file);
973
+			if (($count++) == 100) { // the file descriptor limit
974 974
 				$zip->close();
975
-				if(($zip = new ZipArchive())) {
975
+				if (($zip = new ZipArchive())) {
976 976
 					$zip->open($filename);
977
-					$count =0;
977
+					$count = 0;
978 978
 				}
979 979
 			}
980 980
 		}
@@ -997,17 +997,17 @@  discard block
 block discarded – undo
997 997
 	{
998 998
 		//chdir($f);
999 999
 		//echo "Processing $f <br>";
1000
-		if ($path_name =='') $path_name = $f;
1000
+		if ($path_name == '') $path_name = $f;
1001 1001
 		$tlist = scandir($f);
1002 1002
 		$list = array();
1003 1003
 		$i = $cnt;
1004
-		while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1004
+		while ($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1005 1005
 		{
1006
-			if($file == '.' || $file == '..')
1006
+			if ($file == '.' || $file == '..')
1007 1007
 			{
1008 1008
 				array_shift($tlist);
1009 1009
 			}
1010
-			elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false)
1010
+			elseif ($file == 'debug.txt' && stripos($f, 'activesync') !== false)
1011 1011
 			{
1012 1012
 				// skip activesync debug.txt on backupFiles
1013 1013
 				//error_log(__METHOD__.__LINE__.'->'.$f.'/'.$file);
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 			}
1016 1016
 			else
1017 1017
 			{
1018
-				if(is_dir($f.'/'.$file))
1018
+				if (is_dir($f.'/'.$file))
1019 1019
 				{
1020 1020
 					$nlist = $this->get_file_list($f.'/'.$file, $i);
1021 1021
 					$list += $nlist;
@@ -1036,12 +1036,12 @@  discard block
 block discarded – undo
1036 1036
 	 *
1037 1037
 	 * @param resource|boolean $f
1038 1038
 	 */
1039
-	function schema_backup($f=False)
1039
+	function schema_backup($f = False)
1040 1040
 	{
1041
-		foreach($this->adodb->MetaTables('TABLES') as $table)
1041
+		foreach ($this->adodb->MetaTables('TABLES') as $table)
1042 1042
 		{
1043
-			if ($this->system_tables && preg_match($this->system_tables,$table) ||
1044
-				$this->egw_tables && !preg_match($this->egw_tables,$table))
1043
+			if ($this->system_tables && preg_match($this->system_tables, $table) ||
1044
+				$this->egw_tables && !preg_match($this->egw_tables, $table))
1045 1045
 			{
1046 1046
 				continue;
1047 1047
 			}
@@ -1060,17 +1060,17 @@  discard block
 block discarded – undo
1060 1060
 			}
1061 1061
 		}
1062 1062
 		$def = "\t\$phpgw_baseline = ";
1063
-		$def .= self::write_array($this->schemas,1);
1063
+		$def .= self::write_array($this->schemas, 1);
1064 1064
 		$def .= ";\n";
1065 1065
 
1066 1066
 		if ($f)
1067 1067
 		{
1068
-			fwrite($f,$def);
1068
+			fwrite($f, $def);
1069 1069
 		}
1070 1070
 		else
1071 1071
 		{
1072 1072
 			$def = "<?php\n\t/* EGroupware schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def;
1073
-			Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def));
1073
+			Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php', 'text/plain', bytes($def));
1074 1074
 			echo $def;
1075 1075
 		}
1076 1076
 	}
@@ -1080,9 +1080,9 @@  discard block
 block discarded – undo
1080 1080
 	 *
1081 1081
 	 * copied from etemplate/inc/class.db_tools.inc.php
1082 1082
 	 */
1083
-	private static function write_array($arr,$depth,$parent='')
1083
+	private static function write_array($arr, $depth, $parent = '')
1084 1084
 	{
1085
-		if (in_array($parent,array('pk','fk','ix','uc')))
1085
+		if (in_array($parent, array('pk', 'fk', 'ix', 'uc')))
1086 1086
 		{
1087 1087
 			$depth = 0;
1088 1088
 		}
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
 		$def = "array($tabs".($tabs ? "\t" : '');
1099 1099
 
1100 1100
 		$n = 0;
1101
-		foreach($arr as $key => $val)
1101
+		foreach ($arr as $key => $val)
1102 1102
 		{
1103 1103
 			if (!is_int($key))
1104 1104
 			{
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
 			}
1107 1107
 			if (is_array($val))
1108 1108
 			{
1109
-				$def .= self::write_array($val,$parent == 'fd' ? 0 : $depth,$key);
1109
+				$def .= self::write_array($val, $parent == 'fd' ? 0 : $depth, $key);
1110 1110
 			}
1111 1111
 			else
1112 1112
 			{
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
 					$def .= "'$val'";
1120 1120
 				}
1121 1121
 			}
1122
-			if ($n < count($arr)-1)
1122
+			if ($n < count($arr) - 1)
1123 1123
 			{
1124 1124
 				$def .= ",$tabs".($tabs ? "\t" : '');
1125 1125
 			}
Please login to merge, or discard this patch.
Braces   +127 added lines, -35 removed lines patch added patch discarded remove patch
@@ -101,25 +101,34 @@  discard block
 block discarded – undo
101 101
 		{
102 102
 			$GLOBALS['egw_setup']->loaddb();	// we run inside setup, but db object is not loaded
103 103
 		}
104
-		if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc))	// schema_proc already instanciated, use it
104
+		if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc))
105
+		{
106
+			// schema_proc already instanciated, use it
105 107
 		{
106 108
 			$this->schema_proc = $GLOBALS['egw_setup']->oProc;
107 109
 		}
110
+		}
108 111
 		else
109 112
 		{
110 113
 			$this->schema_proc = new Api\Db\Schema();
111 114
 		}
112 115
 
113 116
 		$this->db = $this->schema_proc->m_odb;
114
-		if (!$this->db->Link_ID) $this->db->connect();
117
+		if (!$this->db->Link_ID)
118
+		{
119
+			$this->db->connect();
120
+		}
115 121
 		$this->adodb = $this->db->Link_ID;
116
-		if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']))		// called from setup
122
+		if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']))
123
+		{
124
+			// called from setup
117 125
 		{
118 126
 			if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table)))
119 127
 			{
120 128
 				if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__)->fetchColumn()))
121 129
 				{
122 130
 					error_log(__METHOD__."->"."No files Directory set/found");
131
+		}
123 132
 				}
124 133
 				if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__)->fetchColumn()))
125 134
 				{
@@ -133,7 +142,10 @@  discard block
 block discarded – undo
133 142
 				// backup files too
134 143
 				$this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'",__LINE__,__FILE__)->fetchColumn();
135 144
 			}
136
-			if (!$this->charset) $this->charset = 'utf-8';
145
+			if (!$this->charset)
146
+			{
147
+				$this->charset = 'utf-8';
148
+			}
137 149
 		}
138 150
 		else	// called from eGW
139 151
 		{
@@ -230,8 +242,7 @@  discard block
 block discarded – undo
230 242
 		if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) &&
231 243
 	 		!($f = fopen("compress.zlib://$name.gz",$mode)) &&
232 244
  		 	!($f = fopen($name,$mode))
233
-		)
234
-		{
245
+		) {
235 246
 			//echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>';	// !
236 247
 			$lang_mode = $reading ? lang("reading") : lang("writing");
237 248
 			return lang("Cant open '%1' for %2", $name, $lang_mode)."<br>";
@@ -267,16 +278,22 @@  discard block
 block discarded – undo
267 278
 				$files[filectime($this->backup_dir.'/'.$file)] = $file;
268 279
 			}
269 280
 		}
270
-		if ($handle) closedir($handle);
281
+		if ($handle)
282
+		{
283
+			closedir($handle);
284
+		}
271 285
 
272 286
 		/* Sort the files by ctime. */
273 287
 		krsort($files);
274 288
 		$count = 0;
275 289
 		foreach($files as $file)
276 290
 		{
277
-			if ($count >= $this->backup_mincount)//
291
+			if ($count >= $this->backup_mincount)
292
+			{
293
+				//
278 294
 			{
279 295
 				$ret = unlink($this->backup_dir.'/'.$file);
296
+			}
280 297
 				if (($ret) && (is_array($files_return)))
281 298
 				{
282 299
 					array_push($files_return, $file);
@@ -340,7 +357,11 @@  discard block
 block discarded – undo
340 357
 		@set_time_limit(0);
341 358
 		ini_set('auto_detect_line_endings',true);
342 359
 
343
-		if (true) $convert_to_system_charset = true;	// enforce now utf-8 as system charset restores of old backups
360
+		if (true)
361
+		{
362
+			$convert_to_system_charset = true;
363
+		}
364
+		// enforce now utf-8 as system charset restores of old backups
344 365
 
345 366
 		if ($protect_system_config)
346 367
 		{
@@ -392,7 +413,7 @@  discard block
 block discarded – undo
392 413
 		$zip = NULL;
393 414
 		$_f = NULL;
394 415
 		if($type == 'zip')
395
-	    {
416
+		{
396 417
 			// has already been verified to be available in fopen_backup
397 418
 			$zip = new ZipArchive;
398 419
 			if(($zip->open($filename)) !== TRUE)
@@ -411,7 +432,9 @@  discard block
 block discarded – undo
411 432
 		}
412 433
 		$this->db_restore($f, $insert_n_rows);
413 434
 
414
-		if ($convert_to_system_charset)	// store the changed charset
435
+		if ($convert_to_system_charset)
436
+		{
437
+			// store the changed charset
415 438
 		{
416 439
 			$this->db->insert(Api\Config::TABLE, array(
417 440
 				'config_value' => $this->schema_proc->system_charset,
@@ -420,6 +443,7 @@  discard block
 block discarded – undo
420 443
 				'config_name' => 'system_charset',
421 444
 			),__LINE__,__FILE__);
422 445
 		}
446
+		}
423 447
 		// restore protected system config
424 448
 		if ($protect_system_config)
425 449
 		{
@@ -509,7 +533,10 @@  discard block
 block discarded – undo
509 533
 		{
510 534
 			$line = trim(fgets($f)); ++$n;
511 535
 
512
-			if (empty($line)) continue;
536
+			if (empty($line))
537
+			{
538
+				continue;
539
+			}
513 540
 
514 541
 			if (substr($line,0,9) == 'version: ')
515 542
 			{
@@ -551,35 +578,53 @@  discard block
 block discarded – undo
551 578
 			}
552 579
 			if (substr($line,0,7) == 'table: ')
553 580
 			{
554
-				if ($rows)	// flush pending rows of last table
581
+				if ($rows)
582
+				{
583
+					// flush pending rows of last table
555 584
 				{
556 585
 					$this->insert_multiple($table, $rows, $this->schemas[$table]);
557 586
 				}
587
+				}
558 588
 				$rows = array();
559 589
 				$table = substr($line,7);
560
-				if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table);
590
+				if (!isset($this->schemas[$table]))
591
+				{
592
+					$this->schemas[$table] = $this->db->get_table_definitions(true, $table);
593
+				}
561 594
 				$auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null;
562 595
 
563 596
 				$cols = self::csv_split($line=fgets($f)); ++$n;
564 597
 				$blobs = array();
565 598
 				foreach($this->schemas[$table]['fd'] as $col => $data)
566 599
 				{
567
-					if ($data['type'] == 'blob') $blobs[] = $col;
600
+					if ($data['type'] == 'blob')
601
+					{
602
+						$blobs[] = $col;
603
+					}
568 604
 				}
569 605
 				// check if we have an old PostgreSQL backup useing 't'/'f' for bool values
570 606
 				// --> convert them to MySQL and our new PostgreSQL format of 1/0
571 607
 				$bools = array();
572 608
 				foreach($this->schemas[$table]['fd'] as $col => $def)
573 609
 				{
574
-					if ($def['type'] === 'bool') $bools[] = $col;
610
+					if ($def['type'] === 'bool')
611
+					{
612
+						$bools[] = $col;
613
+					}
575 614
 				}
576 615
 
577
-				if (feof($f)) break;
616
+				if (feof($f))
617
+				{
618
+					break;
619
+				}
578 620
 				continue;
579 621
 			}
580
-			if ($table)	// do we already reached the data part
622
+			if ($table)
623
+			{
624
+				// do we already reached the data part
581 625
 			{
582 626
 				$import = true;
627
+			}
583 628
 				$data = self::csv_split($line, $cols, $blobs, $bools);
584 629
 
585 630
 				if ($table == 'egw_async' && in_array('##last-check-run##',$data))
@@ -617,7 +662,10 @@  discard block
 block discarded – undo
617 662
 						{
618 663
 							$where = array($insert_n_rows => $data[$insert_n_rows]);
619 664
 							unset($data[$insert_n_rows]);
620
-							if ($auto_id) unset($data[$auto_id]);
665
+							if ($auto_id)
666
+							{
667
+								unset($data[$auto_id]);
668
+							}
621 669
 							$this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]);
622 670
 						}
623 671
 						else
@@ -638,10 +686,13 @@  discard block
 block discarded – undo
638 686
 				}
639 687
 			}
640 688
 		}
641
-		if ($rows)	// flush pending rows
689
+		if ($rows)
690
+		{
691
+			// flush pending rows
642 692
 		{
643 693
 			$this->insert_multiple($table, $rows, $this->schemas[$table]);
644 694
 		}
695
+		}
645 696
 		// updated the sequences, if the DB uses them
646 697
 		foreach($this->schemas as $table => $schema)
647 698
 		{
@@ -699,9 +750,13 @@  discard block
 block discarded – undo
699 750
 		while($file = $list[0])
700 751
 		{
701 752
 			if(is_dir($file) && $file != '.' && $file != '..')
702
-			    self::remove_dir_content($dir.'/'.$file);
753
+			{
754
+						    self::remove_dir_content($dir.'/'.$file);
755
+			}
703 756
 			if(is_file($file) && $file != '.' && $file != '..')
704
-			    unlink($dir.'/'.$file);
757
+			{
758
+						    unlink($dir.'/'.$file);
759
+			}
705 760
 			array_shift($list);
706 761
 		}
707 762
 		//rmdir($dir);  // dont remove own dir
@@ -727,7 +782,9 @@  discard block
 block discarded – undo
727 782
 	 */
728 783
 	public static function csv_split($line, $keys=null, $blobs=array(), $bools=array())
729 784
 	{
730
-		if (function_exists('str_getcsv'))	// php5.3+
785
+		if (function_exists('str_getcsv'))
786
+		{
787
+			// php5.3+
731 788
 		{
732 789
 			// we need to take care of literal "NULL" values, replacing them we a special token as str_getcsv removes enclosures around strings
733 790
 			// str_getcsv uses '""' for '"' instead of '\\"' and does not unescape '\\n', '\\r' or '\\\\' (two backslashes)
@@ -737,6 +794,7 @@  discard block
 block discarded – undo
737 794
 				'\\"'    => '""',
738 795
 				'\\n'    => "\n",
739 796
 				'\\r'    => "\r")), ',', '"', '\0');
797
+		}
740 798
 			// replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash
741 799
 			foreach($fields as &$field)
742 800
 			{
@@ -753,9 +811,12 @@  discard block
 block discarded – undo
753 811
 						break;
754 812
 				}
755 813
 			}
756
-			if ($keys)	// if string keys are to be used --> combine keys and values
814
+			if ($keys)
815
+			{
816
+				// if string keys are to be used --> combine keys and values
757 817
 			{
758 818
 				$fields = array_combine($keys, $fields);
819
+			}
759 820
 				// base64-decode blob columns, if they are base64 encoded
760 821
 				foreach($blobs as $key)
761 822
 				{
@@ -767,10 +828,13 @@  discard block
 block discarded – undo
767 828
 				// decode bool columns, they might be 't'/'f' for old PostgreSQL backups
768 829
 				foreach($bools as $key)
769 830
 				{
770
-					if (isset($fields[$key]))	// do NOT replace NULL with false/0
831
+					if (isset($fields[$key]))
832
+					{
833
+						// do NOT replace NULL with false/0
771 834
 					{
772 835
 						$fields[$key] = Api\Db::from_bool($fields[$key]);
773 836
 					}
837
+					}
774 838
 				}
775 839
 			}
776 840
 			return $fields;
@@ -907,7 +971,11 @@  discard block
 block discarded – undo
907 971
 
908 972
 		foreach($this->schemas as $table => $schema)
909 973
 		{
910
-			if (in_array($table,$this->exclude_tables)) continue;	// dont backup
974
+			if (in_array($table,$this->exclude_tables))
975
+			{
976
+				continue;
977
+			}
978
+			// dont backup
911 979
 
912 980
 			// do we have a primary key?
913 981
 			// --> use it to order and limit rows, to kope with rows being added during backup
@@ -933,8 +1001,14 @@  discard block
 block discarded – undo
933 1001
 					empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC',
934 1002
 					false, self::ROW_CHUNK) as $row)
935 1003
 				{
936
-					if (!empty($pk)) $max = $row[$pk];
937
-					if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
1004
+					if (!empty($pk))
1005
+					{
1006
+						$max = $row[$pk];
1007
+					}
1008
+					if ($total === 0)
1009
+					{
1010
+						fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
1011
+					}
938 1012
 
939 1013
 					array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']);
940 1014
 					fwrite($f,implode(',',$row)."\n");
@@ -944,21 +1018,30 @@  discard block
 block discarded – undo
944 1018
 			}
945 1019
 			while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
946 1020
 
947
-			if (!$pk) $this->db->rollback_lock($table);
1021
+			if (!$pk)
1022
+			{
1023
+				$this->db->rollback_lock($table);
1024
+			}
948 1025
 		}
949 1026
 
950 1027
 		// let apps know that backup is finished
951 1028
 		Api\Hooks::process('backup_finished', array(), true);
952 1029
 
953
-		if(!$zippresent)  // save without files
1030
+		if(!$zippresent)
1031
+		{
1032
+			// save without files
954 1033
 		{
955 1034
 			if ($this->backup_files)
956 1035
 			{
957 1036
 				echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>';
1037
+		}
958 1038
 			}
959 1039
 
960 1040
 		    fclose($f);
961
-		    if (file_exists($name)) unlink($name);
1041
+		    if (file_exists($name))
1042
+		    {
1043
+		    	unlink($name);
1044
+		    }
962 1045
 			return TRUE;
963 1046
 		}
964 1047
 		// save files ....
@@ -970,9 +1053,12 @@  discard block
 block discarded – undo
970 1053
 			//echo substr($file,strlen($dir)+1).'<br>';
971 1054
 			//echo $file.'<br>';
972 1055
 			$zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file);
973
-			if(($count++) == 100) { // the file descriptor limit
1056
+			if(($count++) == 100)
1057
+			{
1058
+// the file descriptor limit
974 1059
 				$zip->close();
975
-				if(($zip = new ZipArchive())) {
1060
+				if(($zip = new ZipArchive()))
1061
+				{
976 1062
 					$zip->open($filename);
977 1063
 					$count =0;
978 1064
 				}
@@ -997,15 +1083,21 @@  discard block
 block discarded – undo
997 1083
 	{
998 1084
 		//chdir($f);
999 1085
 		//echo "Processing $f <br>";
1000
-		if ($path_name =='') $path_name = $f;
1086
+		if ($path_name =='')
1087
+		{
1088
+			$path_name = $f;
1089
+		}
1001 1090
 		$tlist = scandir($f);
1002 1091
 		$list = array();
1003 1092
 		$i = $cnt;
1004
-		while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1093
+		while($file = $tlist[0])
1094
+		{
1095
+			// remove all '.' and '..' and transfer to $list
1005 1096
 		{
1006 1097
 			if($file == '.' || $file == '..')
1007 1098
 			{
1008 1099
 				array_shift($tlist);
1100
+		}
1009 1101
 			}
1010 1102
 			elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false)
1011 1103
 			{
Please login to merge, or discard this patch.
api/src/Db/Exception.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@
 block discarded – undo
27 27
 	 * @param string $msg =null message, default "Database error!"
28 28
 	 * @param int $code =100
29 29
 	 */
30
-	function __construct($msg=null,$code=100)
30
+	function __construct($msg = null, $code = 100)
31 31
 	{
32 32
 		if (is_null($msg)) $msg = lang('Database error!');
33 33
 
34
-		parent::__construct($msg,$code);
34
+		parent::__construct($msg, $code);
35 35
 	}
36 36
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,10 @@
 block discarded – undo
29 29
 	 */
30 30
 	function __construct($msg=null,$code=100)
31 31
 	{
32
-		if (is_null($msg)) $msg = lang('Database error!');
32
+		if (is_null($msg))
33
+		{
34
+			$msg = lang('Database error!');
35
+		}
33 36
 
34 37
 		parent::__construct($msg,$code);
35 38
 	}
Please login to merge, or discard this patch.