@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @param boolean $debug true to echo a message for each copied file |
| 27 | 27 | */ |
| 28 | - static function migrate_db2fs($debug=true) |
|
| 28 | + static function migrate_db2fs($debug = true) |
|
| 29 | 29 | { |
| 30 | 30 | if (!is_object(self::$pdo)) |
| 31 | 31 | { |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | $fs_id = $fs_name = $fs_size = $fs_content = null; |
| 39 | 39 | $n = 0; |
| 40 | 40 | $stmt = self::$pdo->prepare($query); |
| 41 | - $stmt->bindColumn(1,$fs_id); |
|
| 42 | - $stmt->bindColumn(2,$fs_name); |
|
| 43 | - $stmt->bindColumn(3,$fs_size); |
|
| 44 | - $stmt->bindColumn(4,$fs_content,\PDO::PARAM_LOB); |
|
| 41 | + $stmt->bindColumn(1, $fs_id); |
|
| 42 | + $stmt->bindColumn(2, $fs_name); |
|
| 43 | + $stmt->bindColumn(3, $fs_size); |
|
| 44 | + $stmt->bindColumn(4, $fs_content, \PDO::PARAM_LOB); |
|
| 45 | 45 | $stmt->bindValue(':offset', $n, \PDO::PARAM_INT); |
| 46 | 46 | |
| 47 | 47 | while ($stmt->execute()) |
| 48 | 48 | { |
| 49 | - foreach($stmt as $row) |
|
| 49 | + foreach ($stmt as $row) |
|
| 50 | 50 | { |
| 51 | 51 | // hack to work around a current php bug (http://bugs.php.net/bug.php?id=40913) |
| 52 | 52 | // PDOStatement::bindColumn(,,\PDO::PARAM_LOB) is not working for MySQL, content is returned as string :-( |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $content = fopen('php://temp', 'wb'); |
| 56 | 56 | fwrite($content, $fs_content); |
| 57 | 57 | fseek($content, 0, SEEK_SET); |
| 58 | - $fs_content = ''; // can NOT unset it, at least in PHP 7 it looses bind to column! |
|
| 58 | + $fs_content = ''; // can NOT unset it, at least in PHP 7 it looses bind to column! |
|
| 59 | 59 | } |
| 60 | 60 | else |
| 61 | 61 | { |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | throw new Api\Exception\AssertionFailed(__METHOD__."(): fs_id=$fs_id ($fs_name, $fs_size bytes) content is NO resource! ".array2string($content)); |
| 67 | 67 | } |
| 68 | 68 | $filename = self::_fs_path($fs_id); |
| 69 | - if (!file_exists($fs_dir=Vfs::dirname($filename))) |
|
| 69 | + if (!file_exists($fs_dir = Vfs::dirname($filename))) |
|
| 70 | 70 | { |
| 71 | - self::mkdir_recursive($fs_dir,0700,true); |
|
| 71 | + self::mkdir_recursive($fs_dir, 0700, true); |
|
| 72 | 72 | } |
| 73 | - if (!($dest = fopen($filename,'w'))) |
|
| 73 | + if (!($dest = fopen($filename, 'w'))) |
|
| 74 | 74 | { |
| 75 | 75 | throw new Api\Exception\AssertionFailed(__METHOD__."(): fopen($filename,'w') failed!"); |
| 76 | 76 | } |
| 77 | - if (($bytes = stream_copy_to_stream($content,$dest)) != $fs_size) |
|
| 77 | + if (($bytes = stream_copy_to_stream($content, $dest)) != $fs_size) |
|
| 78 | 78 | { |
| 79 | 79 | throw new Api\Exception\AssertionFailed(__METHOD__."(): fs_id=$fs_id ($fs_name) $bytes bytes copied != size of $fs_size bytes!"); |
| 80 | 80 | } |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | ++$n; |
| 86 | 86 | } |
| 87 | - if (!$n) break; // just in case nothing is found, statement will execute just fine |
|
| 87 | + if (!$n) break; // just in case nothing is found, statement will execute just fine |
|
| 88 | 88 | |
| 89 | 89 | $stmt->bindValue(':offset', $n, \PDO::PARAM_INT); |
| 90 | 90 | } |
| 91 | - unset($row); // not used, as we access bound variables |
|
| 91 | + unset($row); // not used, as we access bound variables |
|
| 92 | 92 | unset($stmt); |
| 93 | 93 | |
| 94 | 94 | if ($n) // delete all content in DB, if there was some AND no error (exception thrown!) |
@@ -106,14 +106,14 @@ discard block |
||
| 106 | 106 | * @param boolean $check_only =true |
| 107 | 107 | * @return array with messages / found problems |
| 108 | 108 | */ |
| 109 | - public static function fsck($check_only=true) |
|
| 109 | + public static function fsck($check_only = true) |
|
| 110 | 110 | { |
| 111 | 111 | if (!is_object(self::$pdo)) |
| 112 | 112 | { |
| 113 | 113 | self::_pdo(); |
| 114 | 114 | } |
| 115 | 115 | $msgs = array(); |
| 116 | - foreach(array( |
|
| 116 | + foreach (array( |
|
| 117 | 117 | self::fsck_fix_required_nodes($check_only), |
| 118 | 118 | self::fsck_fix_multiple_active($check_only), |
| 119 | 119 | self::fsck_fix_unconnected($check_only), |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param boolean $check_only =true |
| 140 | 140 | * @return array with messages / found problems |
| 141 | 141 | */ |
| 142 | - private static function fsck_fix_required_nodes($check_only=true) |
|
| 142 | + private static function fsck_fix_required_nodes($check_only = true) |
|
| 143 | 143 | { |
| 144 | 144 | static $dirs = array( |
| 145 | 145 | '/' => 1, |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $stmt = $delete_stmt = null; |
| 150 | 150 | $msgs = array(); |
| 151 | 151 | $sqlfs = new StreamWrapper(); |
| 152 | - foreach($dirs as $path => $id) |
|
| 152 | + foreach ($dirs as $path => $id) |
|
| 153 | 153 | { |
| 154 | 154 | if (!($stat = $sqlfs->url_stat($path, STREAM_URL_STAT_LINK)) || $stat['ino'] != $id) |
| 155 | 155 | { |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | try { |
| 168 | 168 | $ok = $stmt->execute($data = array( |
| 169 | 169 | 'fs_id' => $id, |
| 170 | - 'fs_name' => substr($path,1), |
|
| 170 | + 'fs_name' => substr($path, 1), |
|
| 171 | 171 | 'fs_dir' => $path == '/' ? 0 : $dirs['/'], |
| 172 | 172 | 'fs_mode' => 05, |
| 173 | 173 | 'fs_uid' => 0, |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | catch (\PDOException $e) |
| 183 | 183 | { |
| 184 | 184 | $ok = false; |
| 185 | - unset($e); // ignore exception |
|
| 185 | + unset($e); // ignore exception |
|
| 186 | 186 | } |
| 187 | 187 | if (!$ok) // can not insert it, try deleting it first |
| 188 | 188 | { |
@@ -195,15 +195,14 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | catch (\PDOException $e) |
| 197 | 197 | { |
| 198 | - unset($e); // ignore exception |
|
| 198 | + unset($e); // ignore exception |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | - $msgs[] = $ok ? lang('Required directory "%1" created.', $path) : |
|
| 202 | - lang('Failed to create required directory "%1"!', $path); |
|
| 201 | + $msgs[] = $ok ? lang('Required directory "%1" created.', $path) : lang('Failed to create required directory "%1"!', $path); |
|
| 203 | 202 | } |
| 204 | 203 | } |
| 205 | 204 | // check if directory is at least world readable and executable (r-x), we allow more but not less |
| 206 | - elseif (($stat['mode'] & 05) != 05) |
|
| 205 | + elseif (($stat['mode']&05) != 05) |
|
| 207 | 206 | { |
| 208 | 207 | if ($check_only) |
| 209 | 208 | { |
@@ -243,20 +242,20 @@ discard block |
||
| 243 | 242 | * @param boolean $check_only =true |
| 244 | 243 | * @return array with messages / found problems |
| 245 | 244 | */ |
| 246 | - private static function fsck_fix_no_content($check_only=true) |
|
| 245 | + private static function fsck_fix_no_content($check_only = true) |
|
| 247 | 246 | { |
| 248 | 247 | $stmt = null; |
| 249 | 248 | $msgs = array(); |
| 250 | - foreach(self::$pdo->query('SELECT fs_id FROM '.self::TABLE. |
|
| 249 | + foreach (self::$pdo->query('SELECT fs_id FROM '.self::TABLE. |
|
| 251 | 250 | " WHERE fs_mime!='httpd/unix-directory' AND fs_content IS NULL AND fs_link IS NULL") as $row) |
| 252 | 251 | { |
| 253 | - if (!file_exists($phy_path=self::_fs_path($row['fs_id']))) |
|
| 252 | + if (!file_exists($phy_path = self::_fs_path($row['fs_id']))) |
|
| 254 | 253 | { |
| 255 | 254 | $path = self::id2path($row['fs_id']); |
| 256 | 255 | if ($check_only) |
| 257 | 256 | { |
| 258 | 257 | $msgs[] = lang('File %1 has no content in physical filesystem %2!', |
| 259 | - $path.' (#'.$row['fs_id'].')',$phy_path); |
|
| 258 | + $path.' (#'.$row['fs_id'].')', $phy_path); |
|
| 260 | 259 | } |
| 261 | 260 | else |
| 262 | 261 | { |
@@ -268,12 +267,12 @@ discard block |
||
| 268 | 267 | if ($stmt->execute(array('fs_id' => $row['fs_id'])) && |
| 269 | 268 | $stmt_props->execute(array('fs_id' => $row['fs_id']))) |
| 270 | 269 | { |
| 271 | - $msgs[] = lang('File %1 has no content in physical filesystem %2 --> file removed!',$path,$phy_path); |
|
| 270 | + $msgs[] = lang('File %1 has no content in physical filesystem %2 --> file removed!', $path, $phy_path); |
|
| 272 | 271 | } |
| 273 | 272 | else |
| 274 | 273 | { |
| 275 | 274 | $msgs[] = lang('File %1 has no content in physical filesystem %2 --> failed to remove file!', |
| 276 | - $path.' (#'.$row['fs_id'].')',$phy_path); |
|
| 275 | + $path.' (#'.$row['fs_id'].')', $phy_path); |
|
| 277 | 276 | } |
| 278 | 277 | } |
| 279 | 278 | } |
@@ -303,12 +302,12 @@ discard block |
||
| 303 | 302 | * @param boolean $check_only =true |
| 304 | 303 | * @return array with messages / found problems |
| 305 | 304 | */ |
| 306 | - private static function fsck_fix_unconnected($check_only=true) |
|
| 305 | + private static function fsck_fix_unconnected($check_only = true) |
|
| 307 | 306 | { |
| 308 | 307 | $lostnfound = null; |
| 309 | 308 | $msgs = array(); |
| 310 | 309 | $sqlfs = new StreamWrapper(); |
| 311 | - foreach(self::$pdo->query('SELECT fs.* FROM '.self::TABLE.' fs'. |
|
| 310 | + foreach (self::$pdo->query('SELECT fs.* FROM '.self::TABLE.' fs'. |
|
| 312 | 311 | ' LEFT JOIN '.self::TABLE.' dir ON dir.fs_id=fs.fs_dir'. |
| 313 | 312 | ' WHERE fs.fs_id > 1 AND dir.fs_id IS NULL') as $row) |
| 314 | 313 | { |
@@ -327,14 +326,14 @@ discard block |
||
| 327 | 326 | Vfs::$is_root = true; |
| 328 | 327 | if (!$sqlfs->mkdir(self::LOST_N_FOUND, self::LOST_N_FOUND_MOD, 0) || |
| 329 | 328 | !(!($admins = $GLOBALS['egw']->accounts->name2id(self::LOST_N_FOUND_GRP)) || |
| 330 | - self::chgrp(self::LOST_N_FOUND, $admins) && self::chmod(self::LOST_N_FOUND,self::LOST_N_FOUND_MOD)) || |
|
| 329 | + self::chgrp(self::LOST_N_FOUND, $admins) && self::chmod(self::LOST_N_FOUND, self::LOST_N_FOUND_MOD)) || |
|
| 331 | 330 | !($lostnfound = $sqlfs->url_stat(self::LOST_N_FOUND, STREAM_URL_STAT_QUIET))) |
| 332 | 331 | { |
| 333 | - $msgs[] = lang("Can't create directory %1 to connect found unconnected nodes to it!",self::LOST_N_FOUND); |
|
| 332 | + $msgs[] = lang("Can't create directory %1 to connect found unconnected nodes to it!", self::LOST_N_FOUND); |
|
| 334 | 333 | } |
| 335 | 334 | else |
| 336 | 335 | { |
| 337 | - $msgs[] = lang('Successful created new directory %1 for unconnected nods.',self::LOST_N_FOUND); |
|
| 336 | + $msgs[] = lang('Successful created new directory %1 for unconnected nods.', self::LOST_N_FOUND); |
|
| 338 | 337 | } |
| 339 | 338 | Vfs::$is_root = false; |
| 340 | 339 | if (!$lostnfound) break; |
@@ -359,7 +358,7 @@ discard block |
||
| 359 | 358 | } |
| 360 | 359 | if ($check_only && $msgs) |
| 361 | 360 | { |
| 362 | - $msgs[] = lang('Unconnected nodes will be moved to %1.',self::LOST_N_FOUND); |
|
| 361 | + $msgs[] = lang('Unconnected nodes will be moved to %1.', self::LOST_N_FOUND); |
|
| 363 | 362 | } |
| 364 | 363 | return $msgs; |
| 365 | 364 | } |
@@ -372,20 +371,20 @@ discard block |
||
| 372 | 371 | * @param boolean $check_only =true |
| 373 | 372 | * @return array with messages / found problems |
| 374 | 373 | */ |
| 375 | - private static function fsck_fix_multiple_active($check_only=true) |
|
| 374 | + private static function fsck_fix_multiple_active($check_only = true) |
|
| 376 | 375 | { |
| 377 | 376 | $stmt = $inactivate_msg_added = null; |
| 378 | 377 | $msgs = array(); |
| 379 | - foreach(self::$pdo->query('SELECT fs_dir,fs_name,COUNT(*) FROM '.self::TABLE. |
|
| 378 | + foreach (self::$pdo->query('SELECT fs_dir,fs_name,COUNT(*) FROM '.self::TABLE. |
|
| 380 | 379 | ' WHERE fs_active='.self::_pdo_boolean(true)." OR fs_mime='httpd/unix-directory'". |
| 381 | - ' GROUP BY fs_dir,'.(self::$pdo_type == 'mysql' ? 'BINARY ' : '').'fs_name'. // fs_name is casesensitive! |
|
| 380 | + ' GROUP BY fs_dir,'.(self::$pdo_type == 'mysql' ? 'BINARY ' : '').'fs_name'.// fs_name is casesensitive! |
|
| 382 | 381 | ' HAVING COUNT(*) > 1') as $row) |
| 383 | 382 | { |
| 384 | 383 | if (!isset($stmt)) |
| 385 | 384 | { |
| 386 | 385 | $stmt = self::$pdo->prepare('SELECT *,(SELECT COUNT(*) FROM '.self::TABLE.' sub WHERE sub.fs_dir=fs.fs_id) AS children'. |
| 387 | 386 | ' FROM '.self::TABLE.' fs'. |
| 388 | - ' WHERE fs.fs_dir=:fs_dir AND (fs.fs_active='.self::_pdo_boolean(true)." OR fs_mime='httpd/unix-directory')" . |
|
| 387 | + ' WHERE fs.fs_dir=:fs_dir AND (fs.fs_active='.self::_pdo_boolean(true)." OR fs_mime='httpd/unix-directory')". |
|
| 389 | 388 | ' AND fs.fs_name'.self::$case_sensitive_equal.':fs_name'. |
| 390 | 389 | " ORDER BY fs.fs_mime='httpd/unix-directory' DESC,fs.fs_active DESC,children DESC,fs.fs_modified DESC"); |
| 391 | 390 | $inactivate_stmt = self::$pdo->prepare('UPDATE '.self::TABLE. |
@@ -399,14 +398,14 @@ discard block |
||
| 399 | 398 | 'fs_dir' => $row['fs_dir'], |
| 400 | 399 | 'fs_name' => $row['fs_name'], |
| 401 | 400 | )); |
| 402 | - foreach($stmt as $n => $entry) |
|
| 401 | + foreach ($stmt as $n => $entry) |
|
| 403 | 402 | { |
| 404 | 403 | if ($entry['fs_mime'] == 'httpd/unix-directory') |
| 405 | 404 | { |
| 406 | 405 | // by sorting active directores first (fs.fs_active DESC), we make sure active one is kept |
| 407 | 406 | if (!$n) |
| 408 | 407 | { |
| 409 | - $dir = $entry; // directory to keep |
|
| 408 | + $dir = $entry; // directory to keep |
|
| 410 | 409 | $msgs[] = lang('%1 directories %2 found!', $row[2], self::id2path($entry['fs_id'])); |
| 411 | 410 | if ($check_only) break; |
| 412 | 411 | } |
@@ -422,7 +421,7 @@ discard block |
||
| 422 | 421 | $dir['children'] += $children; |
| 423 | 422 | } |
| 424 | 423 | self::$pdo->query('DELETE FROM '.self::TABLE.' WHERE fs_id='.(int)$entry['fs_id']); |
| 425 | - $msgs[] = lang('Removed (now) empty directory fs_id=%1',$entry['fs_id']); |
|
| 424 | + $msgs[] = lang('Removed (now) empty directory fs_id=%1', $entry['fs_id']); |
|
| 426 | 425 | } |
| 427 | 426 | } |
| 428 | 427 | elseif (isset($dir)) // file and directory with same name exist! |
@@ -438,9 +437,9 @@ discard block |
||
| 438 | 437 | } |
| 439 | 438 | else |
| 440 | 439 | { |
| 441 | - $cnt = ucfirst(lang('none of %1', $row[2]-1)); |
|
| 440 | + $cnt = ucfirst(lang('none of %1', $row[2] - 1)); |
|
| 442 | 441 | } |
| 443 | - $msgs[] = lang('%1 active file(s) with same name as directory inactivated!',$cnt); |
|
| 442 | + $msgs[] = lang('%1 active file(s) with same name as directory inactivated!', $cnt); |
|
| 444 | 443 | break; |
| 445 | 444 | } |
| 446 | 445 | else // newest file --> set for all other fs_active=false |
@@ -456,7 +455,7 @@ discard block |
||
| 456 | 455 | } |
| 457 | 456 | else |
| 458 | 457 | { |
| 459 | - $cnt = lang('none of %1', $row[2]-1); |
|
| 458 | + $cnt = lang('none of %1', $row[2] - 1); |
|
| 460 | 459 | } |
| 461 | 460 | $msgs[] = lang('More then one active file %1 found, inactivating %2 older revisions!', |
| 462 | 461 | self::id2path($entry['fs_id']), $cnt); |