@@ -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; |
@@ -33,39 +33,39 @@ discard block |
||
| 33 | 33 | $this->logger = new XCloner_Logger('xcloner_file_system', $hash); |
| 34 | 34 | $this->xcloner_requirements = new Xcloner_Requirements(); |
| 35 | 35 | |
| 36 | - $this->xcloner_settings = new Xcloner_Settings($hash); |
|
| 36 | + $this->xcloner_settings = new Xcloner_Settings($hash); |
|
| 37 | 37 | |
| 38 | - try{ |
|
| 38 | + try { |
|
| 39 | 39 | |
| 40 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 40 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 41 | 41 | $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
| 42 | 42 | 'disable_asserts' => true, |
| 43 | 43 | ])); |
| 44 | 44 | |
| 45 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 45 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 46 | 46 | $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
| 47 | 47 | 'disable_asserts' => true, |
| 48 | 48 | ])); |
| 49 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); |
|
| 49 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
| 50 | 50 | $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
| 51 | 51 | 'disable_asserts' => true, |
| 52 | 52 | ])); |
| 53 | 53 | |
| 54 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 54 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 55 | 55 | $this->storage_filesystem = new Filesystem($adapter, new Config([ |
| 56 | 56 | 'disable_asserts' => true, |
| 57 | 57 | ])); |
| 58 | 58 | |
| 59 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS'); |
|
| 59 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS'); |
|
| 60 | 60 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
| 61 | 61 | 'disable_asserts' => true, |
| 62 | 62 | ])); |
| 63 | - }catch(Exception $e){ |
|
| 63 | + }catch (Exception $e) { |
|
| 64 | 64 | return false; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
| 68 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 68 | + if ($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 69 | 69 | $this->folders_to_process_per_session = $value; |
| 70 | 70 | |
| 71 | 71 | } |
@@ -126,10 +126,10 @@ discard block |
||
| 126 | 126 | return $this->getMetadataFull('storage_adapter', $file); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - public function get_included_files_handler($metadata = 0) |
|
| 129 | + public function get_included_files_handler($metadata = 0) |
|
| 130 | 130 | { |
| 131 | 131 | $path = $this->included_files_handler; |
| 132 | - if(!$metadata) |
|
| 132 | + if (!$metadata) |
|
| 133 | 133 | return $path; |
| 134 | 134 | |
| 135 | 135 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
@@ -146,16 +146,16 @@ discard block |
||
| 146 | 146 | { |
| 147 | 147 | $files = $this->get_backup_archives_list(); |
| 148 | 148 | |
| 149 | - if(is_array($files)) |
|
| 150 | - $this->sort_by($files, "timestamp","desc"); |
|
| 149 | + if (is_array($files)) |
|
| 150 | + $this->sort_by($files, "timestamp", "desc"); |
|
| 151 | 151 | |
| 152 | 152 | $new_list = array(); |
| 153 | 153 | |
| 154 | - foreach($files as $key=>$file) |
|
| 155 | - if(!isset($file['parent'])) |
|
| 154 | + foreach ($files as $key=>$file) |
|
| 155 | + if (!isset($file['parent'])) |
|
| 156 | 156 | $new_list[] = ($files[$key]); |
| 157 | 157 | |
| 158 | - if(isset($new_list[0])) |
|
| 158 | + if (isset($new_list[0])) |
|
| 159 | 159 | return $new_list[0]; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | $files = $this->get_backup_archives_list(); |
| 165 | 165 | |
| 166 | - if(is_array($files)) |
|
| 167 | - $this->sort_by($files, "timestamp","desc"); |
|
| 166 | + if (is_array($files)) |
|
| 167 | + $this->sort_by($files, "timestamp", "desc"); |
|
| 168 | 168 | |
| 169 | 169 | $new_list = array(); |
| 170 | 170 | |
| 171 | - foreach($files as $key=>$file) |
|
| 172 | - if(!isset($file['parent'])) |
|
| 171 | + foreach ($files as $key=>$file) |
|
| 172 | + if (!isset($file['parent'])) |
|
| 173 | 173 | $new_list[] = ($files[$key]); |
| 174 | 174 | |
| 175 | 175 | return $new_list; |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | $files = $this->get_backup_archives_list(); |
| 181 | 181 | $total = 0; |
| 182 | 182 | |
| 183 | - if(is_array($files)) |
|
| 184 | - foreach($files as $file) |
|
| 183 | + if (is_array($files)) |
|
| 184 | + foreach ($files as $file) |
|
| 185 | 185 | $total += $file['size']; |
| 186 | 186 | |
| 187 | 187 | return $total; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | public function is_part($backup_name) |
| 191 | 191 | { |
| 192 | - if(stristr($backup_name, "-part")) |
|
| 192 | + if (stristr($backup_name, "-part")) |
|
| 193 | 193 | return true; |
| 194 | 194 | |
| 195 | 195 | return false; |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | public function is_multipart($backup_name) |
| 199 | 199 | { |
| 200 | - if(stristr($backup_name, "-multipart")) |
|
| 200 | + if (stristr($backup_name, "-multipart")) |
|
| 201 | 201 | return true; |
| 202 | 202 | |
| 203 | 203 | return false; |
@@ -206,10 +206,10 @@ discard block |
||
| 206 | 206 | public function get_backup_size($backup_name) |
| 207 | 207 | { |
| 208 | 208 | $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
| 209 | - if($this->is_multipart($backup_name)) |
|
| 209 | + if ($this->is_multipart($backup_name)) |
|
| 210 | 210 | { |
| 211 | 211 | $backup_parts = $this->get_multipart_files($backup_name); |
| 212 | - foreach($backup_parts as $part_file) |
|
| 212 | + foreach ($backup_parts as $part_file) |
|
| 213 | 213 | $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
| 214 | 214 | } |
| 215 | 215 | |
@@ -220,12 +220,12 @@ discard block |
||
| 220 | 220 | { |
| 221 | 221 | $files = array(); |
| 222 | 222 | |
| 223 | - if($this->is_multipart($backup_name)) |
|
| 223 | + if ($this->is_multipart($backup_name)) |
|
| 224 | 224 | { |
| 225 | 225 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); |
| 226 | - foreach($lines as $line) |
|
| 226 | + foreach ($lines as $line) |
|
| 227 | 227 | { |
| 228 | - if($line) |
|
| 228 | + if ($line) |
|
| 229 | 229 | { |
| 230 | 230 | $data = str_getcsv($line); |
| 231 | 231 | $files[] = $data[0]; |
@@ -238,12 +238,12 @@ discard block |
||
| 238 | 238 | |
| 239 | 239 | public function delete_backup_by_name($backup_name) |
| 240 | 240 | { |
| 241 | - if($this->is_multipart($backup_name)) |
|
| 241 | + if ($this->is_multipart($backup_name)) |
|
| 242 | 242 | { |
| 243 | 243 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); |
| 244 | - foreach($lines as $line) |
|
| 244 | + foreach ($lines as $line) |
|
| 245 | 245 | { |
| 246 | - if($line) |
|
| 246 | + if ($line) |
|
| 247 | 247 | { |
| 248 | 248 | $data = str_getcsv($line); |
| 249 | 249 | $this->get_storage_filesystem()->delete($data[0]); |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - if($this->get_storage_filesystem()->delete($backup_name)) |
|
| 254 | + if ($this->get_storage_filesystem()->delete($backup_name)) |
|
| 255 | 255 | $return = true; |
| 256 | 256 | else |
| 257 | 257 | $return = false; |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | return $return; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - public function getMetadataFull($adapter = "storage_adapter" , $path) |
|
| 262 | + public function getMetadataFull($adapter = "storage_adapter", $path) |
|
| 263 | 263 | { |
| 264 | 264 | $location = $this->$adapter->applyPathPrefix($path); |
| 265 | 265 | $spl_info = new SplFileInfo($location); |
@@ -272,25 +272,25 @@ discard block |
||
| 272 | 272 | { |
| 273 | 273 | $list = array(); |
| 274 | 274 | |
| 275 | - if(method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 275 | + if (method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 276 | 276 | $list = $this->get_storage_filesystem()->listContents(); |
| 277 | 277 | |
| 278 | 278 | |
| 279 | 279 | $backup_files = array(); |
| 280 | 280 | $parents = array(); |
| 281 | 281 | |
| 282 | - foreach($list as $file_info) |
|
| 282 | + foreach ($list as $file_info) |
|
| 283 | 283 | { |
| 284 | 284 | $data = array(); |
| 285 | 285 | |
| 286 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
| 286 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
| 287 | 287 | { |
| 288 | 288 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); |
| 289 | - foreach($lines as $line) |
|
| 290 | - if($line) |
|
| 289 | + foreach ($lines as $line) |
|
| 290 | + if ($line) |
|
| 291 | 291 | { |
| 292 | 292 | $data = str_getcsv($line); |
| 293 | - if(is_array($data)){ |
|
| 293 | + if (is_array($data)) { |
|
| 294 | 294 | $parents[$data[0]] = $file_info['path']; |
| 295 | 295 | $file_info['childs'][] = $data; |
| 296 | 296 | $file_info['size'] += $data[2]; |
@@ -299,13 +299,13 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 302 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 303 | 303 | $backup_files[$file_info['path']] = $file_info; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - foreach($backup_files as $key=>$file_info) |
|
| 306 | + foreach ($backup_files as $key=>$file_info) |
|
| 307 | 307 | { |
| 308 | - if(isset($parents[$file_info['path']])) |
|
| 308 | + if (isset($parents[$file_info['path']])) |
|
| 309 | 309 | $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
| 310 | 310 | } |
| 311 | 311 | |
@@ -314,40 +314,40 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | public function start_file_recursion($init = 0) |
| 316 | 316 | { |
| 317 | - if($init) |
|
| 317 | + if ($init) |
|
| 318 | 318 | { |
| 319 | 319 | $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path())); |
| 320 | 320 | $this->do_system_init(); |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())){ |
|
| 323 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 324 | 324 | //.dir exists, we presume we have files to iterate |
| 325 | 325 | $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
| 326 | 326 | $files = array_filter(explode("\n", $content)); |
| 327 | 327 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 328 | 328 | |
| 329 | 329 | $counter = 0; |
| 330 | - foreach($files as $file) |
|
| 330 | + foreach ($files as $file) |
|
| 331 | 331 | { |
| 332 | - if($counter < $this->folders_to_process_per_session){ |
|
| 332 | + if ($counter < $this->folders_to_process_per_session) { |
|
| 333 | 333 | $this->build_files_list($file); |
| 334 | 334 | $counter++; |
| 335 | - }else{ |
|
| 335 | + } else { |
|
| 336 | 336 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | - }else{ |
|
| 339 | + } else { |
|
| 340 | 340 | $this->build_files_list(); |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if($this->scan_finished()) |
|
| 343 | + if ($this->scan_finished()) |
|
| 344 | 344 | { |
| 345 | 345 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
| 346 | 346 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
| 347 | 347 | $this->files_counter++; |
| 348 | 348 | |
| 349 | 349 | //adding included dump file to the included files list |
| 350 | - if($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
| 350 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
| 351 | 351 | { |
| 352 | 352 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
| 353 | 353 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -355,13 +355,13 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | //adding a default index.html to the temp xcloner folder |
| 358 | - if(!$this->get_tmp_filesystem()->has("index.html")) |
|
| 358 | + if (!$this->get_tmp_filesystem()->has("index.html")) |
|
| 359 | 359 | { |
| 360 | - $this->get_tmp_filesystem()->write("index.html",""); |
|
| 360 | + $this->get_tmp_filesystem()->write("index.html", ""); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | //adding the default log file |
| 364 | - if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
| 364 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
| 365 | 365 | { |
| 366 | 366 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
| 367 | 367 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | { |
| 379 | 379 | $return = array(); |
| 380 | 380 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
| 381 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 381 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 382 | 382 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
| 383 | 383 | |
| 384 | 384 | return $return; |
@@ -391,8 +391,8 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | $contents = $this->get_tmp_filesystem()->listContents(); |
| 393 | 393 | |
| 394 | - if(is_array($contents)) |
|
| 395 | - foreach($contents as $file_info) |
|
| 394 | + if (is_array($contents)) |
|
| 395 | + foreach ($contents as $file_info) |
|
| 396 | 396 | $this->get_tmp_filesystem()->delete($file_info['path']); |
| 397 | 397 | |
| 398 | 398 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
@@ -404,16 +404,16 @@ discard block |
||
| 404 | 404 | { |
| 405 | 405 | $this->files_counter = 0; |
| 406 | 406 | |
| 407 | - if(!$this->storage_filesystem->has("index.html")) |
|
| 408 | - $this->storage_filesystem->write("index.html",""); |
|
| 407 | + if (!$this->storage_filesystem->has("index.html")) |
|
| 408 | + $this->storage_filesystem->write("index.html", ""); |
|
| 409 | 409 | |
| 410 | - if(!$this->tmp_filesystem->has("index.html")) |
|
| 411 | - $this->tmp_filesystem->write("index.html",""); |
|
| 410 | + if (!$this->tmp_filesystem->has("index.html")) |
|
| 411 | + $this->tmp_filesystem->write("index.html", ""); |
|
| 412 | 412 | |
| 413 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 413 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 414 | 414 | $this->tmp_filesystem->delete($this->get_included_files_handler()); |
| 415 | 415 | |
| 416 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 416 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 417 | 417 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 418 | 418 | } |
| 419 | 419 | |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | public function set_excluded_files($excluded_files = array()) |
| 436 | 436 | { |
| 437 | - if(!is_array($excluded_files)) |
|
| 437 | + if (!is_array($excluded_files)) |
|
| 438 | 438 | $excluded_files = array(); |
| 439 | 439 | |
| 440 | 440 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
@@ -457,33 +457,33 @@ discard block |
||
| 457 | 457 | $this->logger->debug(sprintf(("Building the files system list"))); |
| 458 | 458 | |
| 459 | 459 | //if we start with the root folder(empty value), we initializa the file system |
| 460 | - if(!$folder){ |
|
| 460 | + if (!$folder) { |
|
| 461 | 461 | |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - try{ |
|
| 464 | + try { |
|
| 465 | 465 | |
| 466 | 466 | $files = $this->start_filesystem->listContents($folder); |
| 467 | - foreach($files as $file) |
|
| 467 | + foreach ($files as $file) |
|
| 468 | 468 | { |
| 469 | - if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
| 469 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
| 470 | 470 | { |
| 471 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
|
| 471 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE")); |
|
| 472 | 472 | } |
| 473 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 474 | - $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
|
| 473 | + elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
| 474 | + $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE")); |
|
| 475 | 475 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
| 476 | 476 | $this->store_file($file); |
| 477 | 477 | $this->files_counter++; |
| 478 | - if(isset($file['size'])) |
|
| 478 | + if (isset($file['size'])) |
|
| 479 | 479 | $this->files_size += $file['size']; |
| 480 | 480 | |
| 481 | - }else{ |
|
| 482 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
|
| 481 | + } else { |
|
| 482 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE")); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - }catch(Exception $e){ |
|
| 486 | + }catch (Exception $e) { |
|
| 487 | 487 | |
| 488 | 488 | $this->logger->error($e->getMessage()); |
| 489 | 489 | |
@@ -497,9 +497,9 @@ discard block |
||
| 497 | 497 | |
| 498 | 498 | $start_time = microtime(); |
| 499 | 499 | |
| 500 | - $data = str_repeat(rand(0,9), 1024*1024); //write 1MB data |
|
| 500 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
| 501 | 501 | |
| 502 | - try{ |
|
| 502 | + try { |
|
| 503 | 503 | $this->tmp_filesystem->write($tmp_file, $data); |
| 504 | 504 | |
| 505 | 505 | $end_time = microtime() - $start_time; |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | |
| 511 | 511 | $this->tmp_filesystem->delete($tmp_file); |
| 512 | 512 | |
| 513 | - }catch(Exception $e){ |
|
| 513 | + }catch (Exception $e) { |
|
| 514 | 514 | |
| 515 | 515 | $this->logger->error($e->getMessage()); |
| 516 | 516 | |
@@ -531,10 +531,10 @@ discard block |
||
| 531 | 531 | |
| 532 | 532 | $files = $this->storage_filesystem->listContents(); |
| 533 | 533 | |
| 534 | - if(is_array($files)) |
|
| 535 | - foreach($files as $file) |
|
| 534 | + if (is_array($files)) |
|
| 535 | + foreach ($files as $file) |
|
| 536 | 536 | { |
| 537 | - if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
| 537 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
| 538 | 538 | { |
| 539 | 539 | $_storage_size += $file['size']; //bytes |
| 540 | 540 | $_backup_files_list[] = $file; |
@@ -542,15 +542,15 @@ discard block |
||
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | |
| 545 | - $this->sort_by($_backup_files_list, "timestamp","asc"); |
|
| 545 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
| 546 | 546 | |
| 547 | 547 | $_backups_counter = sizeof($_backup_files_list); |
| 548 | 548 | |
| 549 | - foreach($_backup_files_list as $file) |
|
| 549 | + foreach ($_backup_files_list as $file) |
|
| 550 | 550 | { |
| 551 | 551 | //processing rule folder capacity |
| 552 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
| 553 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 552 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
| 553 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 554 | 554 | { |
| 555 | 555 | $this->storage_filesystem->delete($file['path']); |
| 556 | 556 | $_storage_size -= $file['size']; |
@@ -558,14 +558,14 @@ discard block |
||
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | //processing rule days limit |
| 561 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
| 561 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
| 562 | 562 | { |
| 563 | 563 | $this->storage_filesystem->delete($file['path']); |
| 564 | 564 | $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'))); |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | //processing backup countert limit |
| 568 | - 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')) |
|
| 568 | + 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')) |
|
| 569 | 569 | { |
| 570 | 570 | $this->storage_filesystem->delete($file['path']); |
| 571 | 571 | $_backups_counter--; |
@@ -591,33 +591,33 @@ discard block |
||
| 591 | 591 | |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - public function process_backup_name($name = "", $max_length=100) |
|
| 594 | + public function process_backup_name($name = "", $max_length = 100) |
|
| 595 | 595 | { |
| 596 | - if(!$name) |
|
| 596 | + if (!$name) |
|
| 597 | 597 | $name = $this->xcloner_settings->get_default_backup_name(); |
| 598 | 598 | |
| 599 | - foreach($this->backup_name_tags as $tag) |
|
| 599 | + foreach ($this->backup_name_tags as $tag) |
|
| 600 | 600 | { |
| 601 | - if($tag == '[time]') |
|
| 602 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 603 | - elseif($tag == '[hostname]') |
|
| 604 | - $name = str_replace($tag, gethostname() ,$name); |
|
| 605 | - elseif($tag == '[domain]') |
|
| 601 | + if ($tag == '[time]') |
|
| 602 | + $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
| 603 | + elseif ($tag == '[hostname]') |
|
| 604 | + $name = str_replace($tag, gethostname(), $name); |
|
| 605 | + elseif ($tag == '[domain]') |
|
| 606 | 606 | { |
| 607 | 607 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
| 608 | - $name = str_replace($tag, $domain ,$name); |
|
| 608 | + $name = str_replace($tag, $domain, $name); |
|
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - if($max_length) |
|
| 612 | + if ($max_length) |
|
| 613 | 613 | $name = substr($name, 0, $max_length); |
| 614 | 614 | |
| 615 | 615 | return $name; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - public function sort_by( &$array, $field, $direction = 'asc') |
|
| 618 | + public function sort_by(&$array, $field, $direction = 'asc') |
|
| 619 | 619 | { |
| 620 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
| 620 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
| 621 | 621 | $direction = SORT_DESC; |
| 622 | 622 | else |
| 623 | 623 | $direction = SORT_ASC; |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | $tmp = array(); |
| 638 | 638 | foreach ($data as $key => $row) |
| 639 | 639 | { |
| 640 | - if(is_array($row)) |
|
| 640 | + if (is_array($row)) |
|
| 641 | 641 | $tmp[$key] = $row[$field]; |
| 642 | 642 | else |
| 643 | 643 | $tmp[$key] = $row->$field; |
@@ -656,29 +656,29 @@ discard block |
||
| 656 | 656 | { |
| 657 | 657 | $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
| 658 | 658 | |
| 659 | - if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
| 659 | + if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
| 660 | 660 | { |
| 661 | - if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 661 | + if (isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 662 | 662 | return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | - if(!sizeof($this->excluded_files)) |
|
| 665 | + if (!sizeof($this->excluded_files)) |
|
| 666 | 666 | $this->set_excluded_files(); |
| 667 | 667 | |
| 668 | - if(is_array($this->excluded_files)) |
|
| 669 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
| 668 | + if (is_array($this->excluded_files)) |
|
| 669 | + foreach ($this->excluded_files as $excluded_file_pattern) |
|
| 670 | 670 | { |
| 671 | - if($excluded_file_pattern == "/") |
|
| 671 | + if ($excluded_file_pattern == "/") |
|
| 672 | 672 | $needle = "$"; |
| 673 | 673 | else |
| 674 | 674 | $needle = "$".$excluded_file_pattern; |
| 675 | 675 | |
| 676 | - if(strstr("$".$file['path'], $needle)){ |
|
| 676 | + if (strstr("$".$file['path'], $needle)) { |
|
| 677 | 677 | return $excluded_file_pattern; |
| 678 | 678 | } |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - if( $regex = $this->is_excluded_regex($file)) |
|
| 681 | + if ($regex = $this->is_excluded_regex($file)) |
|
| 682 | 682 | return $regex; |
| 683 | 683 | |
| 684 | 684 | return false; |
@@ -724,25 +724,25 @@ discard block |
||
| 724 | 724 | |
| 725 | 725 | //print_r($regex_patterns);exit; |
| 726 | 726 | |
| 727 | - if(is_array($regex_patterns)) |
|
| 727 | + if (is_array($regex_patterns)) |
|
| 728 | 728 | { |
| 729 | 729 | //$this->excluded_files = array(); |
| 730 | 730 | //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
| 731 | 731 | //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
| 732 | 732 | |
| 733 | - foreach($regex_patterns as $excluded_file_pattern) |
|
| 733 | + foreach ($regex_patterns as $excluded_file_pattern) |
|
| 734 | 734 | { |
| 735 | 735 | |
| 736 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
| 737 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 736 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r") |
|
| 737 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
| 738 | 738 | |
| 739 | - if($file['path'] == "/") |
|
| 739 | + if ($file['path'] == "/") |
|
| 740 | 740 | $needle = "/"; |
| 741 | 741 | else |
| 742 | 742 | $needle = "/".$file['path']; |
| 743 | 743 | //echo $needle."---".$excluded_file_pattern."---\n"; |
| 744 | 744 | |
| 745 | - if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
|
| 745 | + if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
| 746 | 746 | return $excluded_file_pattern; |
| 747 | 747 | } |
| 748 | 748 | } |
@@ -755,27 +755,27 @@ discard block |
||
| 755 | 755 | { |
| 756 | 756 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
| 757 | 757 | |
| 758 | - if(!isset($file['size'])) |
|
| 758 | + if (!isset($file['size'])) |
|
| 759 | 759 | $file['size'] = 0; |
| 760 | - if(!isset($file['visibility'])) |
|
| 760 | + if (!isset($file['visibility'])) |
|
| 761 | 761 | $file['visibility'] = "private"; |
| 762 | 762 | |
| 763 | 763 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
| 764 | 764 | |
| 765 | 765 | $this->last_logged_file = $file['path']; |
| 766 | 766 | |
| 767 | - try{ |
|
| 767 | + try { |
|
| 768 | 768 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
| 769 | 769 | |
| 770 | - }catch(Exception $e){ |
|
| 770 | + }catch (Exception $e) { |
|
| 771 | 771 | |
| 772 | 772 | $this->logger->error($e->getMessage()); |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | - if($file['type'] == "dir"){ |
|
| 776 | - try{ |
|
| 775 | + if ($file['type'] == "dir") { |
|
| 776 | + try { |
|
| 777 | 777 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
| 778 | - }catch(Exception $e){ |
|
| 778 | + }catch (Exception $e) { |
|
| 779 | 779 | $this->logger->error($e->getMessage()); |
| 780 | 780 | } |
| 781 | 781 | } |
@@ -788,13 +788,13 @@ discard block |
||
| 788 | 788 | |
| 789 | 789 | public function get_filesystem($system = "") |
| 790 | 790 | { |
| 791 | - if($system == "storage_filesystem_append") |
|
| 791 | + if ($system == "storage_filesystem_append") |
|
| 792 | 792 | return $this->storage_filesystem_append; |
| 793 | - elseif($system == "tmp_filesystem_append") |
|
| 793 | + elseif ($system == "tmp_filesystem_append") |
|
| 794 | 794 | return $this->tmp_filesystem_append; |
| 795 | - elseif($system == "tmp_filesystem") |
|
| 795 | + elseif ($system == "tmp_filesystem") |
|
| 796 | 796 | return $this->tmp_filesystem; |
| 797 | - elseif($system == "storage_filesystem") |
|
| 797 | + elseif ($system == "storage_filesystem") |
|
| 798 | 798 | return $this->storage_filesystem; |
| 799 | 799 | else |
| 800 | 800 | return $this->start_filesystem; |
@@ -802,9 +802,9 @@ discard block |
||
| 802 | 802 | |
| 803 | 803 | public function get_adapter($system) |
| 804 | 804 | { |
| 805 | - if($system == "tmp_filesystem") |
|
| 805 | + if ($system == "tmp_filesystem") |
|
| 806 | 806 | return $this->tmp_adapter; |
| 807 | - elseif($system == "storage_filesystem") |
|
| 807 | + elseif ($system == "storage_filesystem") |
|
| 808 | 808 | return $this->storage_adapter; |
| 809 | 809 | else |
| 810 | 810 | return $this->start_adapter; |
@@ -812,10 +812,10 @@ discard block |
||
| 812 | 812 | |
| 813 | 813 | private function scan_finished() |
| 814 | 814 | { |
| 815 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 815 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 816 | 816 | return false; |
| 817 | 817 | |
| 818 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 818 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 819 | 819 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 820 | 820 | |
| 821 | 821 | $this->logger->debug(sprintf(("File scan finished"))); |
@@ -825,7 +825,7 @@ discard block |
||
| 825 | 825 | |
| 826 | 826 | private function calc_to_bytes($mb_size) |
| 827 | 827 | { |
| 828 | - return $mb_size*(1024*1024); |
|
| 828 | + return $mb_size * (1024 * 1024); |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | } |