@@ -4,12 +4,12 @@ discard block |
||
| 4 | 4 | use League\Flysystem\Util; |
| 5 | 5 | use League\Flysystem\Adapter\Local; |
| 6 | 6 | |
| 7 | -class Xcloner_File_System{ |
|
| 7 | +class Xcloner_File_System { |
|
| 8 | 8 | |
| 9 | - private $excluded_files = ""; |
|
| 10 | - private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
| 11 | - private $included_files_handler = "backup_files.csv"; |
|
| 12 | - private $temp_dir_handler = ".dir"; |
|
| 9 | + private $excluded_files = ""; |
|
| 10 | + private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
| 11 | + private $included_files_handler = "backup_files.csv"; |
|
| 12 | + private $temp_dir_handler = ".dir"; |
|
| 13 | 13 | public $filesystem; |
| 14 | 14 | public $tmp_filesystem; |
| 15 | 15 | public $storage_filesystem; |
@@ -37,39 +37,39 @@ discard block |
||
| 37 | 37 | $this->logger = new XCloner_Logger('xcloner_file_system', $hash); |
| 38 | 38 | $this->xcloner_requirements = new Xcloner_Requirements(); |
| 39 | 39 | |
| 40 | - $this->xcloner_settings = new Xcloner_Settings($hash); |
|
| 40 | + $this->xcloner_settings = new Xcloner_Settings($hash); |
|
| 41 | 41 | |
| 42 | - try{ |
|
| 42 | + try { |
|
| 43 | 43 | |
| 44 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 44 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 45 | 45 | $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
| 46 | 46 | 'disable_asserts' => true, |
| 47 | 47 | ])); |
| 48 | 48 | |
| 49 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 49 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 50 | 50 | $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
| 51 | 51 | 'disable_asserts' => true, |
| 52 | 52 | ])); |
| 53 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); |
|
| 53 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
| 54 | 54 | $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
| 55 | 55 | 'disable_asserts' => true, |
| 56 | 56 | ])); |
| 57 | 57 | |
| 58 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 58 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 59 | 59 | $this->storage_filesystem = new Filesystem($adapter, new Config([ |
| 60 | 60 | 'disable_asserts' => true, |
| 61 | 61 | ])); |
| 62 | 62 | |
| 63 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS'); |
|
| 63 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS'); |
|
| 64 | 64 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
| 65 | 65 | 'disable_asserts' => true, |
| 66 | 66 | ])); |
| 67 | - }catch(Exception $e){ |
|
| 67 | + }catch (Exception $e) { |
|
| 68 | 68 | $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
| 72 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 72 | + if ($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 73 | 73 | $this->folders_to_process_per_session = $value; |
| 74 | 74 | |
| 75 | 75 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | public function get_start_path_file_info($file) |
| 123 | 123 | { |
| 124 | - $info= $this->getMetadataFull('start_adapter', $file); |
|
| 124 | + $info = $this->getMetadataFull('start_adapter', $file); |
|
| 125 | 125 | return $this->start_filesystem->normalizeFileInfo($info); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | return $this->getMetadataFull('storage_adapter', $file); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - public function get_included_files_handler($metadata = 0) |
|
| 133 | + public function get_included_files_handler($metadata = 0) |
|
| 134 | 134 | { |
| 135 | 135 | $path = $this->included_files_handler; |
| 136 | - if(!$metadata) |
|
| 136 | + if (!$metadata) |
|
| 137 | 137 | return $path; |
| 138 | 138 | |
| 139 | 139 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
@@ -150,16 +150,16 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $files = $this->get_backup_archives_list(); |
| 152 | 152 | |
| 153 | - if(is_array($files)) |
|
| 154 | - $this->sort_by($files, "timestamp","desc"); |
|
| 153 | + if (is_array($files)) |
|
| 154 | + $this->sort_by($files, "timestamp", "desc"); |
|
| 155 | 155 | |
| 156 | 156 | $new_list = array(); |
| 157 | 157 | |
| 158 | - foreach($files as $key=>$file) |
|
| 159 | - if(!isset($file['parent'])) |
|
| 158 | + foreach ($files as $key=>$file) |
|
| 159 | + if (!isset($file['parent'])) |
|
| 160 | 160 | $new_list[] = ($files[$key]); |
| 161 | 161 | |
| 162 | - if(isset($new_list[0])) |
|
| 162 | + if (isset($new_list[0])) |
|
| 163 | 163 | return $new_list[0]; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -167,13 +167,13 @@ discard block |
||
| 167 | 167 | { |
| 168 | 168 | $files = $this->get_backup_archives_list(); |
| 169 | 169 | |
| 170 | - if(is_array($files)) |
|
| 171 | - $this->sort_by($files, "timestamp","desc"); |
|
| 170 | + if (is_array($files)) |
|
| 171 | + $this->sort_by($files, "timestamp", "desc"); |
|
| 172 | 172 | |
| 173 | 173 | $new_list = array(); |
| 174 | 174 | |
| 175 | - foreach($files as $key=>$file) |
|
| 176 | - if(!isset($file['parent'])) |
|
| 175 | + foreach ($files as $key=>$file) |
|
| 176 | + if (!isset($file['parent'])) |
|
| 177 | 177 | $new_list[] = ($files[$key]); |
| 178 | 178 | |
| 179 | 179 | return $new_list; |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | $files = $this->get_backup_archives_list(); |
| 185 | 185 | $total = 0; |
| 186 | 186 | |
| 187 | - if(is_array($files)) |
|
| 188 | - foreach($files as $file) |
|
| 187 | + if (is_array($files)) |
|
| 188 | + foreach ($files as $file) |
|
| 189 | 189 | $total += $file['size']; |
| 190 | 190 | |
| 191 | 191 | return $total; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | public function is_part($backup_name) |
| 195 | 195 | { |
| 196 | - if(stristr($backup_name, "-part")) |
|
| 196 | + if (stristr($backup_name, "-part")) |
|
| 197 | 197 | return true; |
| 198 | 198 | |
| 199 | 199 | return false; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | public function is_multipart($backup_name) |
| 203 | 203 | { |
| 204 | - if(stristr($backup_name, "-multipart")) |
|
| 204 | + if (stristr($backup_name, "-multipart")) |
|
| 205 | 205 | return true; |
| 206 | 206 | |
| 207 | 207 | return false; |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | public function get_backup_size($backup_name) |
| 211 | 211 | { |
| 212 | 212 | $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
| 213 | - if($this->is_multipart($backup_name)) |
|
| 213 | + if ($this->is_multipart($backup_name)) |
|
| 214 | 214 | { |
| 215 | 215 | $backup_parts = $this->get_multipart_files($backup_name); |
| 216 | - foreach($backup_parts as $part_file) |
|
| 216 | + foreach ($backup_parts as $part_file) |
|
| 217 | 217 | $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
| 218 | 218 | } |
| 219 | 219 | |
@@ -224,12 +224,12 @@ discard block |
||
| 224 | 224 | { |
| 225 | 225 | $files = array(); |
| 226 | 226 | |
| 227 | - if($this->is_multipart($backup_name)) |
|
| 227 | + if ($this->is_multipart($backup_name)) |
|
| 228 | 228 | { |
| 229 | 229 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); |
| 230 | - foreach($lines as $line) |
|
| 230 | + foreach ($lines as $line) |
|
| 231 | 231 | { |
| 232 | - if($line) |
|
| 232 | + if ($line) |
|
| 233 | 233 | { |
| 234 | 234 | $data = str_getcsv($line); |
| 235 | 235 | $files[] = $data[0]; |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | public function delete_backup_by_name($backup_name) |
| 244 | 244 | { |
| 245 | - if($this->is_multipart($backup_name)) |
|
| 245 | + if ($this->is_multipart($backup_name)) |
|
| 246 | 246 | { |
| 247 | 247 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); |
| 248 | - foreach($lines as $line) |
|
| 248 | + foreach ($lines as $line) |
|
| 249 | 249 | { |
| 250 | - if($line) |
|
| 250 | + if ($line) |
|
| 251 | 251 | { |
| 252 | 252 | $data = str_getcsv($line); |
| 253 | 253 | $this->get_storage_filesystem()->delete($data[0]); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if($this->get_storage_filesystem()->delete($backup_name)) |
|
| 258 | + if ($this->get_storage_filesystem()->delete($backup_name)) |
|
| 259 | 259 | $return = true; |
| 260 | 260 | else |
| 261 | 261 | $return = false; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | return $return; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - public function getMetadataFull($adapter = "storage_adapter" , $path) |
|
| 266 | + public function getMetadataFull($adapter = "storage_adapter", $path) |
|
| 267 | 267 | { |
| 268 | 268 | $location = $this->$adapter->applyPathPrefix($path); |
| 269 | 269 | $spl_info = new SplFileInfo($location); |
@@ -276,25 +276,25 @@ discard block |
||
| 276 | 276 | { |
| 277 | 277 | $list = array(); |
| 278 | 278 | |
| 279 | - if(method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 279 | + if (method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 280 | 280 | $list = $this->get_storage_filesystem()->listContents(); |
| 281 | 281 | |
| 282 | 282 | |
| 283 | 283 | $backup_files = array(); |
| 284 | 284 | $parents = array(); |
| 285 | 285 | |
| 286 | - foreach($list as $file_info) |
|
| 286 | + foreach ($list as $file_info) |
|
| 287 | 287 | { |
| 288 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
| 288 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
| 289 | 289 | { |
| 290 | 290 | $data = array(); |
| 291 | 291 | |
| 292 | 292 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); |
| 293 | - foreach($lines as $line) |
|
| 294 | - if($line) |
|
| 293 | + foreach ($lines as $line) |
|
| 294 | + if ($line) |
|
| 295 | 295 | { |
| 296 | 296 | $data = str_getcsv($line); |
| 297 | - if(is_array($data)){ |
|
| 297 | + if (is_array($data)) { |
|
| 298 | 298 | $parents[$data[0]] = $file_info['path']; |
| 299 | 299 | $file_info['childs'][] = $data; |
| 300 | 300 | $file_info['size'] += $data[2]; |
@@ -303,13 +303,13 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 306 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 307 | 307 | $backup_files[$file_info['path']] = $file_info; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - foreach($backup_files as $key=>$file_info) |
|
| 310 | + foreach ($backup_files as $key=>$file_info) |
|
| 311 | 311 | { |
| 312 | - if(isset($parents[$file_info['path']])) |
|
| 312 | + if (isset($parents[$file_info['path']])) |
|
| 313 | 313 | $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -318,40 +318,40 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | public function start_file_recursion($init = 0) |
| 320 | 320 | { |
| 321 | - if($init) |
|
| 321 | + if ($init) |
|
| 322 | 322 | { |
| 323 | 323 | $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path())); |
| 324 | 324 | $this->do_system_init(); |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())){ |
|
| 327 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 328 | 328 | //.dir exists, we presume we have files to iterate |
| 329 | 329 | $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
| 330 | 330 | $files = array_filter(explode("\n", $content)); |
| 331 | 331 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 332 | 332 | |
| 333 | 333 | $counter = 0; |
| 334 | - foreach($files as $file) |
|
| 334 | + foreach ($files as $file) |
|
| 335 | 335 | { |
| 336 | - if($counter < $this->folders_to_process_per_session){ |
|
| 336 | + if ($counter < $this->folders_to_process_per_session) { |
|
| 337 | 337 | $this->build_files_list($file); |
| 338 | 338 | $counter++; |
| 339 | - }else{ |
|
| 339 | + } else { |
|
| 340 | 340 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | - }else{ |
|
| 343 | + } else { |
|
| 344 | 344 | $this->build_files_list(); |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - if($this->scan_finished()) |
|
| 347 | + if ($this->scan_finished()) |
|
| 348 | 348 | { |
| 349 | 349 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
| 350 | 350 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
| 351 | 351 | $this->files_counter++; |
| 352 | 352 | |
| 353 | 353 | //adding included dump file to the included files list |
| 354 | - if($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
| 354 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
| 355 | 355 | { |
| 356 | 356 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
| 357 | 357 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -359,13 +359,13 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | //adding a default index.html to the temp xcloner folder |
| 362 | - if(!$this->get_tmp_filesystem()->has("index.html")) |
|
| 362 | + if (!$this->get_tmp_filesystem()->has("index.html")) |
|
| 363 | 363 | { |
| 364 | - $this->get_tmp_filesystem()->write("index.html",""); |
|
| 364 | + $this->get_tmp_filesystem()->write("index.html", ""); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | //adding the default log file |
| 368 | - if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
| 368 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
| 369 | 369 | { |
| 370 | 370 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
| 371 | 371 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | { |
| 383 | 383 | $return = array(); |
| 384 | 384 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
| 385 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 385 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 386 | 386 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
| 387 | 387 | |
| 388 | 388 | return $return; |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | |
| 396 | 396 | $contents = $this->get_tmp_filesystem()->listContents(); |
| 397 | 397 | |
| 398 | - if(is_array($contents)) |
|
| 399 | - foreach($contents as $file_info) |
|
| 398 | + if (is_array($contents)) |
|
| 399 | + foreach ($contents as $file_info) |
|
| 400 | 400 | $this->get_tmp_filesystem()->delete($file_info['path']); |
| 401 | 401 | |
| 402 | 402 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
@@ -408,16 +408,16 @@ discard block |
||
| 408 | 408 | { |
| 409 | 409 | $this->files_counter = 0; |
| 410 | 410 | |
| 411 | - if(!$this->storage_filesystem->has("index.html")) |
|
| 412 | - $this->storage_filesystem->write("index.html",""); |
|
| 411 | + if (!$this->storage_filesystem->has("index.html")) |
|
| 412 | + $this->storage_filesystem->write("index.html", ""); |
|
| 413 | 413 | |
| 414 | - if(!$this->tmp_filesystem->has("index.html")) |
|
| 415 | - $this->tmp_filesystem->write("index.html",""); |
|
| 414 | + if (!$this->tmp_filesystem->has("index.html")) |
|
| 415 | + $this->tmp_filesystem->write("index.html", ""); |
|
| 416 | 416 | |
| 417 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 417 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 418 | 418 | $this->tmp_filesystem->delete($this->get_included_files_handler()); |
| 419 | 419 | |
| 420 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 420 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 421 | 421 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 422 | 422 | } |
| 423 | 423 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | public function set_excluded_files($excluded_files = array()) |
| 440 | 440 | { |
| 441 | - if(!is_array($excluded_files)) |
|
| 441 | + if (!is_array($excluded_files)) |
|
| 442 | 442 | $excluded_files = array(); |
| 443 | 443 | |
| 444 | 444 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
@@ -461,33 +461,33 @@ discard block |
||
| 461 | 461 | $this->logger->debug(sprintf(("Building the files system list"))); |
| 462 | 462 | |
| 463 | 463 | //if we start with the root folder(empty value), we initializa the file system |
| 464 | - if(!$folder){ |
|
| 464 | + if (!$folder) { |
|
| 465 | 465 | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - try{ |
|
| 468 | + try { |
|
| 469 | 469 | |
| 470 | 470 | $files = $this->start_filesystem->listContents($folder); |
| 471 | - foreach($files as $file) |
|
| 471 | + foreach ($files as $file) |
|
| 472 | 472 | { |
| 473 | - if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
| 473 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
| 474 | 474 | { |
| 475 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
|
| 475 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE")); |
|
| 476 | 476 | } |
| 477 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 478 | - $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
|
| 477 | + elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
| 478 | + $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE")); |
|
| 479 | 479 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
| 480 | 480 | $this->store_file($file); |
| 481 | 481 | $this->files_counter++; |
| 482 | - if(isset($file['size'])) |
|
| 482 | + if (isset($file['size'])) |
|
| 483 | 483 | $this->files_size += $file['size']; |
| 484 | 484 | |
| 485 | - }else{ |
|
| 486 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
|
| 485 | + } else { |
|
| 486 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE")); |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - }catch(Exception $e){ |
|
| 490 | + }catch (Exception $e) { |
|
| 491 | 491 | |
| 492 | 492 | $this->logger->error($e->getMessage()); |
| 493 | 493 | |
@@ -501,9 +501,9 @@ discard block |
||
| 501 | 501 | |
| 502 | 502 | $start_time = microtime(); |
| 503 | 503 | |
| 504 | - $data = str_repeat(rand(0,9), 1024*1024); //write 1MB data |
|
| 504 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
| 505 | 505 | |
| 506 | - try{ |
|
| 506 | + try { |
|
| 507 | 507 | $this->tmp_filesystem->write($tmp_file, $data); |
| 508 | 508 | |
| 509 | 509 | $end_time = microtime() - $start_time; |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | $this->tmp_filesystem->delete($tmp_file); |
| 516 | 516 | |
| 517 | - }catch(Exception $e){ |
|
| 517 | + }catch (Exception $e) { |
|
| 518 | 518 | |
| 519 | 519 | $this->logger->error($e->getMessage()); |
| 520 | 520 | |
@@ -535,10 +535,10 @@ discard block |
||
| 535 | 535 | |
| 536 | 536 | $files = $this->storage_filesystem->listContents(); |
| 537 | 537 | |
| 538 | - if(is_array($files)) |
|
| 539 | - foreach($files as $file) |
|
| 538 | + if (is_array($files)) |
|
| 539 | + foreach ($files as $file) |
|
| 540 | 540 | { |
| 541 | - if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
| 541 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
| 542 | 542 | { |
| 543 | 543 | $_storage_size += $file['size']; //bytes |
| 544 | 544 | $_backup_files_list[] = $file; |
@@ -546,15 +546,15 @@ discard block |
||
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | |
| 549 | - $this->sort_by($_backup_files_list, "timestamp","asc"); |
|
| 549 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
| 550 | 550 | |
| 551 | 551 | $_backups_counter = sizeof($_backup_files_list); |
| 552 | 552 | |
| 553 | - foreach($_backup_files_list as $file) |
|
| 553 | + foreach ($_backup_files_list as $file) |
|
| 554 | 554 | { |
| 555 | 555 | //processing rule folder capacity |
| 556 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
| 557 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 556 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
| 557 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 558 | 558 | { |
| 559 | 559 | $this->storage_filesystem->delete($file['path']); |
| 560 | 560 | $_storage_size -= $file['size']; |
@@ -562,14 +562,14 @@ discard block |
||
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | //processing rule days limit |
| 565 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
| 565 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
| 566 | 566 | { |
| 567 | 567 | $this->storage_filesystem->delete($file['path']); |
| 568 | 568 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("RETENTION LIMIT TIMESTAMP", $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days'))); |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | //processing backup countert limit |
| 572 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) |
|
| 572 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) |
|
| 573 | 573 | { |
| 574 | 574 | $this->storage_filesystem->delete($file['path']); |
| 575 | 575 | $_backups_counter--; |
@@ -595,33 +595,33 @@ discard block |
||
| 595 | 595 | |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | - public function process_backup_name($name = "", $max_length=100) |
|
| 598 | + public function process_backup_name($name = "", $max_length = 100) |
|
| 599 | 599 | { |
| 600 | - if(!$name) |
|
| 600 | + if (!$name) |
|
| 601 | 601 | $name = $this->xcloner_settings->get_default_backup_name(); |
| 602 | 602 | |
| 603 | - foreach($this->backup_name_tags as $tag) |
|
| 603 | + foreach ($this->backup_name_tags as $tag) |
|
| 604 | 604 | { |
| 605 | - if($tag == '[time]') |
|
| 606 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 607 | - elseif($tag == '[hostname]') |
|
| 608 | - $name = str_replace($tag, gethostname() ,$name); |
|
| 609 | - elseif($tag == '[domain]') |
|
| 605 | + if ($tag == '[time]') |
|
| 606 | + $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
| 607 | + elseif ($tag == '[hostname]') |
|
| 608 | + $name = str_replace($tag, gethostname(), $name); |
|
| 609 | + elseif ($tag == '[domain]') |
|
| 610 | 610 | { |
| 611 | 611 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
| 612 | - $name = str_replace($tag, $domain ,$name); |
|
| 612 | + $name = str_replace($tag, $domain, $name); |
|
| 613 | 613 | } |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - if($max_length) |
|
| 616 | + if ($max_length) |
|
| 617 | 617 | $name = substr($name, 0, $max_length); |
| 618 | 618 | |
| 619 | 619 | return $name; |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | - public function sort_by( &$array, $field, $direction = 'asc') |
|
| 622 | + public function sort_by(&$array, $field, $direction = 'asc') |
|
| 623 | 623 | { |
| 624 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
| 624 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
| 625 | 625 | $direction = SORT_DESC; |
| 626 | 626 | else |
| 627 | 627 | $direction = SORT_ASC; |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | $tmp = array(); |
| 642 | 642 | foreach ($data as $key => $row) |
| 643 | 643 | { |
| 644 | - if(is_array($row)) |
|
| 644 | + if (is_array($row)) |
|
| 645 | 645 | $tmp[$key] = $row[$field]; |
| 646 | 646 | else |
| 647 | 647 | $tmp[$key] = $row->$field; |
@@ -660,29 +660,29 @@ discard block |
||
| 660 | 660 | { |
| 661 | 661 | $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
| 662 | 662 | |
| 663 | - if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
| 663 | + if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
| 664 | 664 | { |
| 665 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 665 | + if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 666 | 666 | return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - if(!sizeof($this->excluded_files)) |
|
| 669 | + if (!sizeof($this->excluded_files)) |
|
| 670 | 670 | $this->set_excluded_files(); |
| 671 | 671 | |
| 672 | - if(is_array($this->excluded_files)) |
|
| 673 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
| 672 | + if (is_array($this->excluded_files)) |
|
| 673 | + foreach ($this->excluded_files as $excluded_file_pattern) |
|
| 674 | 674 | { |
| 675 | - if($excluded_file_pattern == "/") |
|
| 675 | + if ($excluded_file_pattern == "/") |
|
| 676 | 676 | $needle = "$"; |
| 677 | 677 | else |
| 678 | 678 | $needle = "$".$excluded_file_pattern; |
| 679 | 679 | |
| 680 | - if(strstr("$".$file['path'], $needle)){ |
|
| 680 | + if (strstr("$".$file['path'], $needle)) { |
|
| 681 | 681 | return $excluded_file_pattern; |
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - if( $regex = $this->is_excluded_regex($file)) |
|
| 685 | + if ($regex = $this->is_excluded_regex($file)) |
|
| 686 | 686 | return $regex; |
| 687 | 687 | |
| 688 | 688 | return false; |
@@ -728,25 +728,25 @@ discard block |
||
| 728 | 728 | |
| 729 | 729 | //print_r($regex_patterns);exit; |
| 730 | 730 | |
| 731 | - if(is_array($regex_patterns)) |
|
| 731 | + if (is_array($regex_patterns)) |
|
| 732 | 732 | { |
| 733 | 733 | //$this->excluded_files = array(); |
| 734 | 734 | //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
| 735 | 735 | //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
| 736 | 736 | |
| 737 | - foreach($regex_patterns as $excluded_file_pattern) |
|
| 737 | + foreach ($regex_patterns as $excluded_file_pattern) |
|
| 738 | 738 | { |
| 739 | 739 | |
| 740 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
| 741 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 740 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r") |
|
| 741 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
| 742 | 742 | |
| 743 | - if($file['path'] == "/") |
|
| 743 | + if ($file['path'] == "/") |
|
| 744 | 744 | $needle = "/"; |
| 745 | 745 | else |
| 746 | 746 | $needle = "/".$file['path']; |
| 747 | 747 | //echo $needle."---".$excluded_file_pattern."---\n"; |
| 748 | 748 | |
| 749 | - if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
|
| 749 | + if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
| 750 | 750 | return $excluded_file_pattern; |
| 751 | 751 | } |
| 752 | 752 | } |
@@ -759,27 +759,27 @@ discard block |
||
| 759 | 759 | { |
| 760 | 760 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
| 761 | 761 | |
| 762 | - if(!isset($file['size'])) |
|
| 762 | + if (!isset($file['size'])) |
|
| 763 | 763 | $file['size'] = 0; |
| 764 | - if(!isset($file['visibility'])) |
|
| 764 | + if (!isset($file['visibility'])) |
|
| 765 | 765 | $file['visibility'] = "private"; |
| 766 | 766 | |
| 767 | 767 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
| 768 | 768 | |
| 769 | 769 | $this->last_logged_file = $file['path']; |
| 770 | 770 | |
| 771 | - try{ |
|
| 771 | + try { |
|
| 772 | 772 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
| 773 | 773 | |
| 774 | - }catch(Exception $e){ |
|
| 774 | + }catch (Exception $e) { |
|
| 775 | 775 | |
| 776 | 776 | $this->logger->error($e->getMessage()); |
| 777 | 777 | } |
| 778 | 778 | |
| 779 | - if($file['type'] == "dir"){ |
|
| 780 | - try{ |
|
| 779 | + if ($file['type'] == "dir") { |
|
| 780 | + try { |
|
| 781 | 781 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
| 782 | - }catch(Exception $e){ |
|
| 782 | + }catch (Exception $e) { |
|
| 783 | 783 | $this->logger->error($e->getMessage()); |
| 784 | 784 | } |
| 785 | 785 | } |
@@ -792,13 +792,13 @@ discard block |
||
| 792 | 792 | |
| 793 | 793 | public function get_filesystem($system = "") |
| 794 | 794 | { |
| 795 | - if($system == "storage_filesystem_append") |
|
| 795 | + if ($system == "storage_filesystem_append") |
|
| 796 | 796 | return $this->storage_filesystem_append; |
| 797 | - elseif($system == "tmp_filesystem_append") |
|
| 797 | + elseif ($system == "tmp_filesystem_append") |
|
| 798 | 798 | return $this->tmp_filesystem_append; |
| 799 | - elseif($system == "tmp_filesystem") |
|
| 799 | + elseif ($system == "tmp_filesystem") |
|
| 800 | 800 | return $this->tmp_filesystem; |
| 801 | - elseif($system == "storage_filesystem") |
|
| 801 | + elseif ($system == "storage_filesystem") |
|
| 802 | 802 | return $this->storage_filesystem; |
| 803 | 803 | else |
| 804 | 804 | return $this->start_filesystem; |
@@ -806,9 +806,9 @@ discard block |
||
| 806 | 806 | |
| 807 | 807 | public function get_adapter($system) |
| 808 | 808 | { |
| 809 | - if($system == "tmp_filesystem") |
|
| 809 | + if ($system == "tmp_filesystem") |
|
| 810 | 810 | return $this->tmp_adapter; |
| 811 | - elseif($system == "storage_filesystem") |
|
| 811 | + elseif ($system == "storage_filesystem") |
|
| 812 | 812 | return $this->storage_adapter; |
| 813 | 813 | else |
| 814 | 814 | return $this->start_adapter; |
@@ -816,10 +816,10 @@ discard block |
||
| 816 | 816 | |
| 817 | 817 | private function scan_finished() |
| 818 | 818 | { |
| 819 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 819 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 820 | 820 | return false; |
| 821 | 821 | |
| 822 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 822 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 823 | 823 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 824 | 824 | |
| 825 | 825 | $this->logger->debug(sprintf(("File scan finished"))); |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | |
| 830 | 830 | private function calc_to_bytes($mb_size) |
| 831 | 831 | { |
| 832 | - return $mb_size*(1024*1024); |
|
| 832 | + return $mb_size * (1024 * 1024); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | } |
@@ -64,13 +64,14 @@ discard block |
||
| 64 | 64 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
| 65 | 65 | 'disable_asserts' => true, |
| 66 | 66 | ])); |
| 67 | - }catch(Exception $e){ |
|
| 67 | + } catch(Exception $e){ |
|
| 68 | 68 | $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
| 72 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 73 | - $this->folders_to_process_per_session = $value; |
|
| 72 | + if($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
| 73 | + $this->folders_to_process_per_session = $value; |
|
| 74 | + } |
|
| 74 | 75 | |
| 75 | 76 | } |
| 76 | 77 | |
@@ -133,8 +134,9 @@ discard block |
||
| 133 | 134 | public function get_included_files_handler($metadata = 0) |
| 134 | 135 | { |
| 135 | 136 | $path = $this->included_files_handler; |
| 136 | - if(!$metadata) |
|
| 137 | - return $path; |
|
| 137 | + if(!$metadata) { |
|
| 138 | + return $path; |
|
| 139 | + } |
|
| 138 | 140 | |
| 139 | 141 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
| 140 | 142 | return $spl_info; |
@@ -150,31 +152,36 @@ discard block |
||
| 150 | 152 | { |
| 151 | 153 | $files = $this->get_backup_archives_list(); |
| 152 | 154 | |
| 153 | - if(is_array($files)) |
|
| 154 | - $this->sort_by($files, "timestamp","desc"); |
|
| 155 | + if(is_array($files)) { |
|
| 156 | + $this->sort_by($files, "timestamp","desc"); |
|
| 157 | + } |
|
| 155 | 158 | |
| 156 | 159 | $new_list = array(); |
| 157 | 160 | |
| 158 | - foreach($files as $key=>$file) |
|
| 159 | - if(!isset($file['parent'])) |
|
| 161 | + foreach($files as $key=>$file) { |
|
| 162 | + if(!isset($file['parent'])) |
|
| 160 | 163 | $new_list[] = ($files[$key]); |
| 164 | + } |
|
| 161 | 165 | |
| 162 | - if(isset($new_list[0])) |
|
| 163 | - return $new_list[0]; |
|
| 166 | + if(isset($new_list[0])) { |
|
| 167 | + return $new_list[0]; |
|
| 168 | + } |
|
| 164 | 169 | } |
| 165 | 170 | |
| 166 | 171 | public function get_latest_backups() |
| 167 | 172 | { |
| 168 | 173 | $files = $this->get_backup_archives_list(); |
| 169 | 174 | |
| 170 | - if(is_array($files)) |
|
| 171 | - $this->sort_by($files, "timestamp","desc"); |
|
| 175 | + if(is_array($files)) { |
|
| 176 | + $this->sort_by($files, "timestamp","desc"); |
|
| 177 | + } |
|
| 172 | 178 | |
| 173 | 179 | $new_list = array(); |
| 174 | 180 | |
| 175 | - foreach($files as $key=>$file) |
|
| 176 | - if(!isset($file['parent'])) |
|
| 181 | + foreach($files as $key=>$file) { |
|
| 182 | + if(!isset($file['parent'])) |
|
| 177 | 183 | $new_list[] = ($files[$key]); |
| 184 | + } |
|
| 178 | 185 | |
| 179 | 186 | return $new_list; |
| 180 | 187 | } |
@@ -184,25 +191,28 @@ discard block |
||
| 184 | 191 | $files = $this->get_backup_archives_list(); |
| 185 | 192 | $total = 0; |
| 186 | 193 | |
| 187 | - if(is_array($files)) |
|
| 188 | - foreach($files as $file) |
|
| 194 | + if(is_array($files)) { |
|
| 195 | + foreach($files as $file) |
|
| 189 | 196 | $total += $file['size']; |
| 197 | + } |
|
| 190 | 198 | |
| 191 | 199 | return $total; |
| 192 | 200 | } |
| 193 | 201 | |
| 194 | 202 | public function is_part($backup_name) |
| 195 | 203 | { |
| 196 | - if(stristr($backup_name, "-part")) |
|
| 197 | - return true; |
|
| 204 | + if(stristr($backup_name, "-part")) { |
|
| 205 | + return true; |
|
| 206 | + } |
|
| 198 | 207 | |
| 199 | 208 | return false; |
| 200 | 209 | } |
| 201 | 210 | |
| 202 | 211 | public function is_multipart($backup_name) |
| 203 | 212 | { |
| 204 | - if(stristr($backup_name, "-multipart")) |
|
| 205 | - return true; |
|
| 213 | + if(stristr($backup_name, "-multipart")) { |
|
| 214 | + return true; |
|
| 215 | + } |
|
| 206 | 216 | |
| 207 | 217 | return false; |
| 208 | 218 | } |
@@ -213,8 +223,9 @@ discard block |
||
| 213 | 223 | if($this->is_multipart($backup_name)) |
| 214 | 224 | { |
| 215 | 225 | $backup_parts = $this->get_multipart_files($backup_name); |
| 216 | - foreach($backup_parts as $part_file) |
|
| 217 | - $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
| 226 | + foreach($backup_parts as $part_file) { |
|
| 227 | + $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
| 228 | + } |
|
| 218 | 229 | } |
| 219 | 230 | |
| 220 | 231 | return $backup_size; |
@@ -255,10 +266,11 @@ discard block |
||
| 255 | 266 | } |
| 256 | 267 | } |
| 257 | 268 | |
| 258 | - if($this->get_storage_filesystem()->delete($backup_name)) |
|
| 259 | - $return = true; |
|
| 260 | - else |
|
| 261 | - $return = false; |
|
| 269 | + if($this->get_storage_filesystem()->delete($backup_name)) { |
|
| 270 | + $return = true; |
|
| 271 | + } else { |
|
| 272 | + $return = false; |
|
| 273 | + } |
|
| 262 | 274 | |
| 263 | 275 | return $return; |
| 264 | 276 | } |
@@ -276,8 +288,9 @@ discard block |
||
| 276 | 288 | { |
| 277 | 289 | $list = array(); |
| 278 | 290 | |
| 279 | - if(method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 280 | - $list = $this->get_storage_filesystem()->listContents(); |
|
| 291 | + if(method_exists($this->get_storage_filesystem(), "listContents")) { |
|
| 292 | + $list = $this->get_storage_filesystem()->listContents(); |
|
| 293 | + } |
|
| 281 | 294 | |
| 282 | 295 | |
| 283 | 296 | $backup_files = array(); |
@@ -290,10 +303,11 @@ discard block |
||
| 290 | 303 | $data = array(); |
| 291 | 304 | |
| 292 | 305 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); |
| 293 | - foreach($lines as $line) |
|
| 294 | - if($line) |
|
| 306 | + foreach($lines as $line) { |
|
| 307 | + if($line) |
|
| 295 | 308 | { |
| 296 | 309 | $data = str_getcsv($line); |
| 310 | + } |
|
| 297 | 311 | if(is_array($data)){ |
| 298 | 312 | $parents[$data[0]] = $file_info['path']; |
| 299 | 313 | $file_info['childs'][] = $data; |
@@ -303,14 +317,16 @@ discard block |
||
| 303 | 317 | |
| 304 | 318 | } |
| 305 | 319 | |
| 306 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 307 | - $backup_files[$file_info['path']] = $file_info; |
|
| 320 | + if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
| 321 | + $backup_files[$file_info['path']] = $file_info; |
|
| 322 | + } |
|
| 308 | 323 | } |
| 309 | 324 | |
| 310 | 325 | foreach($backup_files as $key=>$file_info) |
| 311 | 326 | { |
| 312 | - if(isset($parents[$file_info['path']])) |
|
| 313 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 327 | + if(isset($parents[$file_info['path']])) { |
|
| 328 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 329 | + } |
|
| 314 | 330 | } |
| 315 | 331 | |
| 316 | 332 | return $backup_files; |
@@ -336,11 +352,11 @@ discard block |
||
| 336 | 352 | if($counter < $this->folders_to_process_per_session){ |
| 337 | 353 | $this->build_files_list($file); |
| 338 | 354 | $counter++; |
| 339 | - }else{ |
|
| 355 | + } else{ |
|
| 340 | 356 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
| 341 | 357 | } |
| 342 | 358 | } |
| 343 | - }else{ |
|
| 359 | + } else{ |
|
| 344 | 360 | $this->build_files_list(); |
| 345 | 361 | } |
| 346 | 362 | |
@@ -382,8 +398,9 @@ discard block |
||
| 382 | 398 | { |
| 383 | 399 | $return = array(); |
| 384 | 400 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
| 385 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 386 | - $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
| 401 | + if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
| 402 | + $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
| 403 | + } |
|
| 387 | 404 | |
| 388 | 405 | return $return; |
| 389 | 406 | } |
@@ -395,9 +412,10 @@ discard block |
||
| 395 | 412 | |
| 396 | 413 | $contents = $this->get_tmp_filesystem()->listContents(); |
| 397 | 414 | |
| 398 | - if(is_array($contents)) |
|
| 399 | - foreach($contents as $file_info) |
|
| 415 | + if(is_array($contents)) { |
|
| 416 | + foreach($contents as $file_info) |
|
| 400 | 417 | $this->get_tmp_filesystem()->delete($file_info['path']); |
| 418 | + } |
|
| 401 | 419 | |
| 402 | 420 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
| 403 | 421 | |
@@ -408,17 +426,21 @@ discard block |
||
| 408 | 426 | { |
| 409 | 427 | $this->files_counter = 0; |
| 410 | 428 | |
| 411 | - if(!$this->storage_filesystem->has("index.html")) |
|
| 412 | - $this->storage_filesystem->write("index.html",""); |
|
| 429 | + if(!$this->storage_filesystem->has("index.html")) { |
|
| 430 | + $this->storage_filesystem->write("index.html",""); |
|
| 431 | + } |
|
| 413 | 432 | |
| 414 | - if(!$this->tmp_filesystem->has("index.html")) |
|
| 415 | - $this->tmp_filesystem->write("index.html",""); |
|
| 433 | + if(!$this->tmp_filesystem->has("index.html")) { |
|
| 434 | + $this->tmp_filesystem->write("index.html",""); |
|
| 435 | + } |
|
| 416 | 436 | |
| 417 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 418 | - $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
| 437 | + if($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
| 438 | + $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
| 439 | + } |
|
| 419 | 440 | |
| 420 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 421 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 441 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 442 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 443 | + } |
|
| 422 | 444 | } |
| 423 | 445 | |
| 424 | 446 | public function get_scanned_files_num() |
@@ -438,8 +460,9 @@ discard block |
||
| 438 | 460 | |
| 439 | 461 | public function set_excluded_files($excluded_files = array()) |
| 440 | 462 | { |
| 441 | - if(!is_array($excluded_files)) |
|
| 442 | - $excluded_files = array(); |
|
| 463 | + if(!is_array($excluded_files)) { |
|
| 464 | + $excluded_files = array(); |
|
| 465 | + } |
|
| 443 | 466 | |
| 444 | 467 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
| 445 | 468 | |
@@ -473,21 +496,21 @@ discard block |
||
| 473 | 496 | if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
| 474 | 497 | { |
| 475 | 498 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
| 476 | - } |
|
| 477 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 499 | + } elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 478 | 500 | $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
| 479 | 501 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
| 480 | 502 | $this->store_file($file); |
| 481 | 503 | $this->files_counter++; |
| 482 | - if(isset($file['size'])) |
|
| 483 | - $this->files_size += $file['size']; |
|
| 504 | + if(isset($file['size'])) { |
|
| 505 | + $this->files_size += $file['size']; |
|
| 506 | + } |
|
| 484 | 507 | |
| 485 | - }else{ |
|
| 508 | + } else{ |
|
| 486 | 509 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
| 487 | 510 | } |
| 488 | 511 | } |
| 489 | 512 | |
| 490 | - }catch(Exception $e){ |
|
| 513 | + } catch(Exception $e){ |
|
| 491 | 514 | |
| 492 | 515 | $this->logger->error($e->getMessage()); |
| 493 | 516 | |
@@ -514,7 +537,7 @@ discard block |
||
| 514 | 537 | |
| 515 | 538 | $this->tmp_filesystem->delete($tmp_file); |
| 516 | 539 | |
| 517 | - }catch(Exception $e){ |
|
| 540 | + } catch(Exception $e){ |
|
| 518 | 541 | |
| 519 | 542 | $this->logger->error($e->getMessage()); |
| 520 | 543 | |
@@ -535,12 +558,14 @@ discard block |
||
| 535 | 558 | |
| 536 | 559 | $files = $this->storage_filesystem->listContents(); |
| 537 | 560 | |
| 538 | - if(is_array($files)) |
|
| 539 | - foreach($files as $file) |
|
| 561 | + if(is_array($files)) { |
|
| 562 | + foreach($files as $file) |
|
| 540 | 563 | { |
| 541 | 564 | if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
| 542 | 565 | { |
| 543 | - $_storage_size += $file['size']; //bytes |
|
| 566 | + $_storage_size += $file['size']; |
|
| 567 | + } |
|
| 568 | + //bytes |
|
| 544 | 569 | $_backup_files_list[] = $file; |
| 545 | 570 | } |
| 546 | 571 | } |
@@ -554,9 +579,11 @@ discard block |
||
| 554 | 579 | { |
| 555 | 580 | //processing rule folder capacity |
| 556 | 581 | if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
| 557 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 582 | + $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) { |
|
| 583 | + //bytes |
|
| 558 | 584 | { |
| 559 | 585 | $this->storage_filesystem->delete($file['path']); |
| 586 | + } |
|
| 560 | 587 | $_storage_size -= $file['size']; |
| 561 | 588 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit)); |
| 562 | 589 | } |
@@ -597,34 +624,37 @@ discard block |
||
| 597 | 624 | |
| 598 | 625 | public function process_backup_name($name = "", $max_length=100) |
| 599 | 626 | { |
| 600 | - if(!$name) |
|
| 601 | - $name = $this->xcloner_settings->get_default_backup_name(); |
|
| 627 | + if(!$name) { |
|
| 628 | + $name = $this->xcloner_settings->get_default_backup_name(); |
|
| 629 | + } |
|
| 602 | 630 | |
| 603 | 631 | foreach($this->backup_name_tags as $tag) |
| 604 | 632 | { |
| 605 | - if($tag == '[time]') |
|
| 606 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 607 | - elseif($tag == '[hostname]') |
|
| 608 | - $name = str_replace($tag, gethostname() ,$name); |
|
| 609 | - elseif($tag == '[domain]') |
|
| 633 | + if($tag == '[time]') { |
|
| 634 | + $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 635 | + } elseif($tag == '[hostname]') { |
|
| 636 | + $name = str_replace($tag, gethostname() ,$name); |
|
| 637 | + } elseif($tag == '[domain]') |
|
| 610 | 638 | { |
| 611 | 639 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
| 612 | 640 | $name = str_replace($tag, $domain ,$name); |
| 613 | 641 | } |
| 614 | 642 | } |
| 615 | 643 | |
| 616 | - if($max_length) |
|
| 617 | - $name = substr($name, 0, $max_length); |
|
| 644 | + if($max_length) { |
|
| 645 | + $name = substr($name, 0, $max_length); |
|
| 646 | + } |
|
| 618 | 647 | |
| 619 | 648 | return $name; |
| 620 | 649 | } |
| 621 | 650 | |
| 622 | 651 | public function sort_by( &$array, $field, $direction = 'asc') |
| 623 | 652 | { |
| 624 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
| 625 | - $direction = SORT_DESC; |
|
| 626 | - else |
|
| 627 | - $direction = SORT_ASC; |
|
| 653 | + if(strtolower($direction) == "desc" || $direction == SORT_DESC) { |
|
| 654 | + $direction = SORT_DESC; |
|
| 655 | + } else { |
|
| 656 | + $direction = SORT_ASC; |
|
| 657 | + } |
|
| 628 | 658 | |
| 629 | 659 | $array = $this->array_orderby($array, $field, $direction); |
| 630 | 660 | |
@@ -641,10 +671,11 @@ discard block |
||
| 641 | 671 | $tmp = array(); |
| 642 | 672 | foreach ($data as $key => $row) |
| 643 | 673 | { |
| 644 | - if(is_array($row)) |
|
| 645 | - $tmp[$key] = $row[$field]; |
|
| 646 | - else |
|
| 647 | - $tmp[$key] = $row->$field; |
|
| 674 | + if(is_array($row)) { |
|
| 675 | + $tmp[$key] = $row[$field]; |
|
| 676 | + } else { |
|
| 677 | + $tmp[$key] = $row->$field; |
|
| 678 | + } |
|
| 648 | 679 | } |
| 649 | 680 | $args[$n] = $tmp; |
| 650 | 681 | } |
@@ -662,28 +693,32 @@ discard block |
||
| 662 | 693 | |
| 663 | 694 | if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
| 664 | 695 | { |
| 665 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 666 | - return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
| 696 | + if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
| 697 | + return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
| 698 | + } |
|
| 667 | 699 | } |
| 668 | 700 | |
| 669 | - if(!sizeof($this->excluded_files)) |
|
| 670 | - $this->set_excluded_files(); |
|
| 701 | + if(!sizeof($this->excluded_files)) { |
|
| 702 | + $this->set_excluded_files(); |
|
| 703 | + } |
|
| 671 | 704 | |
| 672 | - if(is_array($this->excluded_files)) |
|
| 673 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
| 705 | + if(is_array($this->excluded_files)) { |
|
| 706 | + foreach($this->excluded_files as $excluded_file_pattern) |
|
| 674 | 707 | { |
| 675 | 708 | if($excluded_file_pattern == "/") |
| 676 | 709 | $needle = "$"; |
| 677 | - else |
|
| 678 | - $needle = "$".$excluded_file_pattern; |
|
| 710 | + } else { |
|
| 711 | + $needle = "$".$excluded_file_pattern; |
|
| 712 | + } |
|
| 679 | 713 | |
| 680 | 714 | if(strstr("$".$file['path'], $needle)){ |
| 681 | 715 | return $excluded_file_pattern; |
| 682 | 716 | } |
| 683 | 717 | } |
| 684 | 718 | |
| 685 | - if( $regex = $this->is_excluded_regex($file)) |
|
| 686 | - return $regex; |
|
| 719 | + if( $regex = $this->is_excluded_regex($file)) { |
|
| 720 | + return $regex; |
|
| 721 | + } |
|
| 687 | 722 | |
| 688 | 723 | return false; |
| 689 | 724 | } |
@@ -737,13 +772,15 @@ discard block |
||
| 737 | 772 | foreach($regex_patterns as $excluded_file_pattern) |
| 738 | 773 | { |
| 739 | 774 | |
| 740 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
| 741 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 775 | + if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") { |
|
| 776 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 777 | + } |
|
| 742 | 778 | |
| 743 | - if($file['path'] == "/") |
|
| 744 | - $needle = "/"; |
|
| 745 | - else |
|
| 746 | - $needle = "/".$file['path']; |
|
| 779 | + if($file['path'] == "/") { |
|
| 780 | + $needle = "/"; |
|
| 781 | + } else { |
|
| 782 | + $needle = "/".$file['path']; |
|
| 783 | + } |
|
| 747 | 784 | //echo $needle."---".$excluded_file_pattern."---\n"; |
| 748 | 785 | |
| 749 | 786 | if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
@@ -759,10 +796,12 @@ discard block |
||
| 759 | 796 | { |
| 760 | 797 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
| 761 | 798 | |
| 762 | - if(!isset($file['size'])) |
|
| 763 | - $file['size'] = 0; |
|
| 764 | - if(!isset($file['visibility'])) |
|
| 765 | - $file['visibility'] = "private"; |
|
| 799 | + if(!isset($file['size'])) { |
|
| 800 | + $file['size'] = 0; |
|
| 801 | + } |
|
| 802 | + if(!isset($file['visibility'])) { |
|
| 803 | + $file['visibility'] = "private"; |
|
| 804 | + } |
|
| 766 | 805 | |
| 767 | 806 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
| 768 | 807 | |
@@ -771,7 +810,7 @@ discard block |
||
| 771 | 810 | try{ |
| 772 | 811 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
| 773 | 812 | |
| 774 | - }catch(Exception $e){ |
|
| 813 | + } catch(Exception $e){ |
|
| 775 | 814 | |
| 776 | 815 | $this->logger->error($e->getMessage()); |
| 777 | 816 | } |
@@ -779,7 +818,7 @@ discard block |
||
| 779 | 818 | if($file['type'] == "dir"){ |
| 780 | 819 | try{ |
| 781 | 820 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
| 782 | - }catch(Exception $e){ |
|
| 821 | + } catch(Exception $e){ |
|
| 783 | 822 | $this->logger->error($e->getMessage()); |
| 784 | 823 | } |
| 785 | 824 | } |
@@ -792,35 +831,39 @@ discard block |
||
| 792 | 831 | |
| 793 | 832 | public function get_filesystem($system = "") |
| 794 | 833 | { |
| 795 | - if($system == "storage_filesystem_append") |
|
| 796 | - return $this->storage_filesystem_append; |
|
| 797 | - elseif($system == "tmp_filesystem_append") |
|
| 798 | - return $this->tmp_filesystem_append; |
|
| 799 | - elseif($system == "tmp_filesystem") |
|
| 800 | - return $this->tmp_filesystem; |
|
| 801 | - elseif($system == "storage_filesystem") |
|
| 802 | - return $this->storage_filesystem; |
|
| 803 | - else |
|
| 804 | - return $this->start_filesystem; |
|
| 834 | + if($system == "storage_filesystem_append") { |
|
| 835 | + return $this->storage_filesystem_append; |
|
| 836 | + } elseif($system == "tmp_filesystem_append") { |
|
| 837 | + return $this->tmp_filesystem_append; |
|
| 838 | + } elseif($system == "tmp_filesystem") { |
|
| 839 | + return $this->tmp_filesystem; |
|
| 840 | + } elseif($system == "storage_filesystem") { |
|
| 841 | + return $this->storage_filesystem; |
|
| 842 | + } else { |
|
| 843 | + return $this->start_filesystem; |
|
| 844 | + } |
|
| 805 | 845 | } |
| 806 | 846 | |
| 807 | 847 | public function get_adapter($system) |
| 808 | 848 | { |
| 809 | - if($system == "tmp_filesystem") |
|
| 810 | - return $this->tmp_adapter; |
|
| 811 | - elseif($system == "storage_filesystem") |
|
| 812 | - return $this->storage_adapter; |
|
| 813 | - else |
|
| 814 | - return $this->start_adapter; |
|
| 849 | + if($system == "tmp_filesystem") { |
|
| 850 | + return $this->tmp_adapter; |
|
| 851 | + } elseif($system == "storage_filesystem") { |
|
| 852 | + return $this->storage_adapter; |
|
| 853 | + } else { |
|
| 854 | + return $this->start_adapter; |
|
| 855 | + } |
|
| 815 | 856 | } |
| 816 | 857 | |
| 817 | 858 | private function scan_finished() |
| 818 | 859 | { |
| 819 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 820 | - return false; |
|
| 860 | + if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
| 861 | + return false; |
|
| 862 | + } |
|
| 821 | 863 | |
| 822 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 823 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 864 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 865 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 866 | + } |
|
| 824 | 867 | |
| 825 | 868 | $this->logger->debug(sprintf(("File scan finished"))); |
| 826 | 869 | |