@@ -31,10 +31,13 @@ |
||
| 31 | 31 | <?php if ($storage_selection): ?> |
| 32 | 32 | <option value="" |
| 33 | 33 | selected><?php echo __('Change To Local Storage...', 'xcloner-backup-and-restore') ?></option> |
| 34 | - <?php else: ?> |
|
| 34 | + <?php else { |
|
| 35 | + : ?> |
|
| 35 | 36 | <option value="" |
| 36 | 37 | selected><?php echo __('Change To Remote Storage...', 'xcloner-backup-and-restore') ?></option> |
| 37 | - <?php endif; ?> |
|
| 38 | + <?php endif; |
|
| 39 | +} |
|
| 40 | +?> |
|
| 38 | 41 | |
| 39 | 42 | <?php foreach ($available_storages as $storage => $text): ?> |
| 40 | 43 | <option value="<?php echo $storage ?>"<?php if ($storage == $storage_selection) |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | <label> |
| 27 | 27 | Off |
| 28 | 28 | <input type="checkbox" name="xcloner_ftp_enable" class="status" |
| 29 | - value="1" <?php if (get_option("xcloner_ftp_enable")) |
|
| 29 | + value="1" <?php if (get_option("xcloner_ftp_enable")) { |
|
| 30 | 30 | echo "checked" ?> \> |
| 31 | 31 | <span class="lever"></span> |
| 32 | 32 | On |
@@ -340,6 +340,7 @@ discard block |
||
| 340 | 340 | value=""><?php echo __("Please Select AWS S3 Region or Leave Unselected for Custom Endpoint") ?></option> |
| 341 | 341 | <?php |
| 342 | 342 | $aws_regions = $remote_storage->get_aws_regions(); |
| 343 | +} |
|
| 343 | 344 | |
| 344 | 345 | foreach ($aws_regions as $key => $region) { |
| 345 | 346 | ?> |
@@ -423,7 +424,7 @@ discard block |
||
| 423 | 424 | <label> |
| 424 | 425 | Off |
| 425 | 426 | <input type="checkbox" name="xcloner_dropbox_enable" class="status" |
| 426 | - value="1" <?php if (get_option("xcloner_dropbox_enable")) |
|
| 427 | + value="1" <?php if (get_option("xcloner_dropbox_enable")) { |
|
| 427 | 428 | echo "checked" ?> \> |
| 428 | 429 | <span class="lever"></span> |
| 429 | 430 | On |
@@ -957,6 +958,7 @@ discard block |
||
| 957 | 958 | <div class="center"> |
| 958 | 959 | <?php |
| 959 | 960 | $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=xcloner-google-drive'), 'install-plugin_xcloner-google-drive'); |
| 961 | +} |
|
| 960 | 962 | ?> |
| 961 | 963 | <h6><?php echo __("This storage option requires the XCloner-Google-Drive Wordpress Plugin to be installed and activated.") ?></h6> |
| 962 | 964 | <h6><?php echo __("PHP 5.5 minimum version is required.") ?></h6> |
@@ -110,7 +110,8 @@ discard block |
||
| 110 | 110 | echo date($date_format." ".$time_format, $latest_backup['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
| 111 | 111 | ?> |
| 112 | 112 | </div> |
| 113 | - <?php else: ?> |
|
| 113 | + <?php else { |
|
| 114 | + : ?> |
|
| 114 | 115 | <div class="item"> |
| 115 | 116 | <div class="title"><?php echo __("No Backup Yet", 'xcloner-backup-and-restore') ?></div> |
| 116 | 117 | </div> |
@@ -123,7 +124,9 @@ discard block |
||
| 123 | 124 | <div class="title"><?php echo __("Total Size", 'xcloner-backup-and-restore') ?> |
| 124 | 125 | : |
| 125 | 126 | </div> |
| 126 | - <?php echo size_format($xcloner_file_system->get_storage_usage()); ?> |
|
| 127 | + <?php echo size_format($xcloner_file_system->get_storage_usage()); |
|
| 128 | +} |
|
| 129 | +?> |
|
| 127 | 130 | </div> |
| 128 | 131 | </blockquote> |
| 129 | 132 | <h5><?php echo __("Next Scheduled Backup", 'xcloner-backup-and-restore') ?></h5> |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | if (is_a($xcloner_plugin, 'Xcloner')) { |
| 55 | 55 | try { |
| 56 | 56 | $xcloner_plugin->get_xcloner_filesystem()->cleanup_tmp_directories(); |
| 57 | - }catch (Exception $e) { |
|
| 57 | + } catch (Exception $e) { |
|
| 58 | 58 | $xcloner_plugin->trigger_message_notice($e->getMessage()); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -337,7 +337,7 @@ |
||
| 337 | 337 | |
| 338 | 338 | $result = $this->get_var("SELECT count(*) FROM $table;"); |
| 339 | 339 | |
| 340 | - return intval($result) ;// not max limit on 32 bit systems 2147483647; on 64 bit 999999999999 |
|
| 340 | + return intval($result); // not max limit on 32 bit systems 2147483647; on 64 bit 999999999999 |
|
| 341 | 341 | |
| 342 | 342 | } |
| 343 | 343 | |
@@ -44,11 +44,13 @@ discard block |
||
| 44 | 44 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
| 45 | 45 | $this->fs = $xcloner_container->get_xcloner_filesystem(); |
| 46 | 46 | |
| 47 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) |
|
| 48 | - $this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
| 47 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) { |
|
| 48 | + $this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
| 49 | + } |
|
| 49 | 50 | |
| 50 | - if (!$this->recordsPerSession) |
|
| 51 | - $this->recordsPerSession = 100; |
|
| 51 | + if (!$this->recordsPerSession) { |
|
| 52 | + $this->recordsPerSession = 100; |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | if (!$wp_user && !$wp_pass && !$wp_host && !$wp_db) |
| 54 | 56 | { |
@@ -108,37 +110,43 @@ discard block |
||
| 108 | 110 | { |
| 109 | 111 | foreach ($params['#'] as $database) |
| 110 | 112 | { |
| 111 | - if (!isset($params[$database]) or !is_array($params[$database])) |
|
| 112 | - $params[$database] = array(); |
|
| 113 | + if (!isset($params[$database]) or !is_array($params[$database])) { |
|
| 114 | + $params[$database] = array(); |
|
| 115 | + } |
|
| 113 | 116 | } |
| 114 | 117 | $db_count = -1; |
| 115 | 118 | } |
| 116 | 119 | |
| 117 | - if (isset($params) and is_array($params)) |
|
| 118 | - foreach ($params as $database=>$tables) |
|
| 120 | + if (isset($params) and is_array($params)) { |
|
| 121 | + foreach ($params as $database=>$tables) |
|
| 119 | 122 | { |
| 120 | 123 | if ($database != "#") |
| 121 | 124 | { |
| 122 | - $stats = $this->write_backup_process_list($database, $tables); |
|
| 125 | + $stats = $this->write_backup_process_list($database, $tables); |
|
| 126 | + } |
|
| 123 | 127 | $return['stats']['tables_count'] += $stats['tables_count']; |
| 124 | 128 | $return['stats']['total_records'] += $stats['total_records']; |
| 125 | 129 | } |
| 126 | 130 | } |
| 127 | 131 | |
| 128 | - if (sizeof($params)) |
|
| 129 | - $return['stats']['database_count'] = sizeof($params) + $db_count; |
|
| 130 | - else |
|
| 131 | - $return['stats']['database_count'] = 0; |
|
| 132 | + if (sizeof($params)) { |
|
| 133 | + $return['stats']['database_count'] = sizeof($params) + $db_count; |
|
| 134 | + } else { |
|
| 135 | + $return['stats']['database_count'] = 0; |
|
| 136 | + } |
|
| 132 | 137 | |
| 133 | 138 | return $return; |
| 134 | 139 | } |
| 135 | 140 | |
| 136 | - if (!isset($extra_params['startAtLine'])) |
|
| 137 | - $extra_params['startAtLine'] = 0; |
|
| 138 | - if (!isset($extra_params['startAtRecord'])) |
|
| 139 | - $extra_params['startAtRecord'] = 0; |
|
| 140 | - if (!isset($extra_params['dumpfile'])) |
|
| 141 | - $extra_params['dumpfile'] = ""; |
|
| 141 | + if (!isset($extra_params['startAtLine'])) { |
|
| 142 | + $extra_params['startAtLine'] = 0; |
|
| 143 | + } |
|
| 144 | + if (!isset($extra_params['startAtRecord'])) { |
|
| 145 | + $extra_params['startAtRecord'] = 0; |
|
| 146 | + } |
|
| 147 | + if (!isset($extra_params['dumpfile'])) { |
|
| 148 | + $extra_params['dumpfile'] = ""; |
|
| 149 | + } |
|
| 142 | 150 | |
| 143 | 151 | $return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']); |
| 144 | 152 | |
@@ -151,10 +159,12 @@ discard block |
||
| 151 | 159 | if ($message) { |
| 152 | 160 | $this->logger->info($message, array("")); |
| 153 | 161 | } else { |
| 154 | - if ($this->last_query) |
|
| 155 | - $this->logger->debug($this->last_query, array("")); |
|
| 156 | - if ($this->last_error) |
|
| 157 | - $this->logger->error($this->last_error, array("")); |
|
| 162 | + if ($this->last_query) { |
|
| 163 | + $this->logger->debug($this->last_query, array("")); |
|
| 164 | + } |
|
| 165 | + if ($this->last_error) { |
|
| 166 | + $this->logger->error($this->last_error, array("")); |
|
| 167 | + } |
|
| 158 | 168 | } |
| 159 | 169 | |
| 160 | 170 | return; |
@@ -225,11 +235,12 @@ discard block |
||
| 225 | 235 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname); |
| 226 | 236 | $i++; |
| 227 | 237 | |
| 228 | - if (is_array($databases)) |
|
| 229 | - foreach ($databases as $db) { |
|
| 238 | + if (is_array($databases)) { |
|
| 239 | + foreach ($databases as $db) { |
|
| 230 | 240 | if ($db->Database != $this->dbname) |
| 231 | 241 | { |
| 232 | 242 | $databases_list[$i]['name'] = $db->Database; |
| 243 | + } |
|
| 233 | 244 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database); |
| 234 | 245 | $i++; |
| 235 | 246 | } |
@@ -252,8 +263,9 @@ discard block |
||
| 252 | 263 | $tablesList[0] = array( ); |
| 253 | 264 | $inc = 0; |
| 254 | 265 | |
| 255 | - if (!$database) |
|
| 256 | - $database = $this->dbname; |
|
| 266 | + if (!$database) { |
|
| 267 | + $database = $this->dbname; |
|
| 268 | + } |
|
| 257 | 269 | |
| 258 | 270 | $this->logger->debug(sprintf(("Listing tables in %s database"), $database)); |
| 259 | 271 | |
@@ -277,10 +289,11 @@ discard block |
||
| 277 | 289 | |
| 278 | 290 | $tablesList[$inc]['excluded'] = 0; |
| 279 | 291 | |
| 280 | - if (sizeof($included) and is_array($included)) |
|
| 281 | - if (!in_array($table, $included)) |
|
| 292 | + if (sizeof($included) and is_array($included)) { |
|
| 293 | + if (!in_array($table, $included)) |
|
| 282 | 294 | { |
| 283 | 295 | $tablesList[$inc]['excluded'] = 1; |
| 296 | + } |
|
| 284 | 297 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
| 285 | 298 | } |
| 286 | 299 | $inc++; |
@@ -299,19 +312,21 @@ discard block |
||
| 299 | 312 | |
| 300 | 313 | $tables = $this->list_tables($dbname, $incl_tables, 1); |
| 301 | 314 | |
| 302 | - if ($this->dbname != $dbname) |
|
| 303 | - $dumpfile = $dbname."-backup.sql"; |
|
| 304 | - else |
|
| 305 | - $dumpfile = $this->TEMP_DUMP_FILE; |
|
| 315 | + if ($this->dbname != $dbname) { |
|
| 316 | + $dumpfile = $dbname."-backup.sql"; |
|
| 317 | + } else { |
|
| 318 | + $dumpfile = $this->TEMP_DUMP_FILE; |
|
| 319 | + } |
|
| 306 | 320 | |
| 307 | 321 | $line = sprintf("###newdump###\t%s\t%s\n", $dbname, $dumpfile); |
| 308 | 322 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
| 309 | 323 | |
| 310 | 324 | // write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records |
| 311 | - foreach ($tables as $key=>$table) |
|
| 312 | - if ($table != "" and !$tables[$key]['excluded']) { |
|
| 325 | + foreach ($tables as $key=>$table) { |
|
| 326 | + if ($table != "" and !$tables[$key]['excluded']) { |
|
| 313 | 327 | |
| 314 | 328 | $line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']); |
| 329 | + } |
|
| 315 | 330 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
| 316 | 331 | $return['tables_count']++; |
| 317 | 332 | $return['total_records'] += $tables[$key]['records']; |
@@ -359,8 +374,9 @@ discard block |
||
| 359 | 374 | $return['finished'] = 0; |
| 360 | 375 | $lines = array(); |
| 361 | 376 | |
| 362 | - if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 363 | - $lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
| 377 | + if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
| 378 | + $lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
| 379 | + } |
|
| 364 | 380 | |
| 365 | 381 | foreach ($lines as $buffer) { |
| 366 | 382 | |
@@ -387,12 +403,14 @@ discard block |
||
| 387 | 403 | //break; |
| 388 | 404 | } else { |
| 389 | 405 | //we export the table |
| 390 | - if ($tableInfo[0] == "###enddump###") |
|
| 391 | - $return['endDump'] = 1; |
|
| 406 | + if ($tableInfo[0] == "###enddump###") { |
|
| 407 | + $return['endDump'] = 1; |
|
| 408 | + } |
|
| 392 | 409 | |
| 393 | 410 | //table is excluded |
| 394 | - if ($tableInfo[2]) |
|
| 395 | - continue; |
|
| 411 | + if ($tableInfo[2]) { |
|
| 412 | + continue; |
|
| 413 | + } |
|
| 396 | 414 | |
| 397 | 415 | $next = $startAtRecord + $this->recordsPerSession; |
| 398 | 416 | |
@@ -408,14 +426,17 @@ discard block |
||
| 408 | 426 | |
| 409 | 427 | $processed_records = 0; |
| 410 | 428 | |
| 411 | - if (trim($tableName) != "" and !$tableInfo[2]) |
|
| 412 | - $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
|
| 429 | + if (trim($tableName) != "" and !$tableInfo[2]) { |
|
| 430 | + $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
|
| 431 | + } |
|
| 413 | 432 | |
| 414 | 433 | $return['processedRecords'] = $startAtRecord + $processed_records; |
| 415 | 434 | |
| 416 | - if ($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
| 435 | + if ($next >= $tableInfo[1]) { |
|
| 436 | + //we finished loading the records for next sessions, will go to the new record |
|
| 417 | 437 | { |
| 418 | 438 | $startAtLine++; |
| 439 | + } |
|
| 419 | 440 | $startAtRecord = 0; |
| 420 | 441 | } else { |
| 421 | 442 | $startAtRecord = $startAtRecord + $this->recordsPerSession; |
@@ -450,8 +471,9 @@ discard block |
||
| 450 | 471 | $return['finished'] = 1; |
| 451 | 472 | $return['startAtLine'] = $startAtLine; |
| 452 | 473 | |
| 453 | - if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 454 | - $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
|
| 474 | + if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
| 475 | + $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
|
| 476 | + } |
|
| 455 | 477 | |
| 456 | 478 | $this->logger->debug(sprintf(("Database backup finished!"))); |
| 457 | 479 | |
@@ -484,8 +506,9 @@ discard block |
||
| 484 | 506 | |
| 485 | 507 | $records = 0; |
| 486 | 508 | |
| 487 | - if ($start == 0) |
|
| 488 | - $this->dump_structure($databaseName, $tableName, $dumpfile); |
|
| 509 | + if ($start == 0) { |
|
| 510 | + $this->dump_structure($databaseName, $tableName, $dumpfile); |
|
| 511 | + } |
|
| 489 | 512 | |
| 490 | 513 | $start = intval($start); |
| 491 | 514 | $limit = intval($limit); |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | |
| 25 | 25 | try { |
| 26 | 26 | $option = Util::normalizePath($path); |
| 27 | - }catch (Exception $e) { |
|
| 27 | + } catch (Exception $e) { |
|
| 28 | 28 | add_settings_error('xcloner_error_message', '', __($e->getMessage()), 'error'); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -117,7 +117,7 @@ |
||
| 117 | 117 | |
| 118 | 118 | try { |
| 119 | 119 | $xcloner_plugin = run_xcloner(); |
| 120 | -}catch (Exception $e) { |
|
| 120 | +} catch (Exception $e) { |
|
| 121 | 121 | echo $e->getMessage(); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -387,6 +387,6 @@ |
||
| 387 | 387 | $xcloner_encryption->decrypt_file($argv[2], $argv[2].".dec", $argv[4], 0, 0, true); |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | -}catch (\Exception $e) { |
|
| 390 | +} catch (\Exception $e) { |
|
| 391 | 391 | echo "CAUGHT: ".$e->getMessage(); |
| 392 | 392 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @param integer $iv The IV key to use. |
| 107 | 107 | * @param bool $verification Weather we should we try to verify the decryption. |
| 108 | 108 | * @return array|false Returns array or FALSE if an error occured |
| 109 | - * @throws Exception |
|
| 109 | + * @throws Exception |
|
| 110 | 110 | */ |
| 111 | 111 | public function encrypt_file($source, $dest = "", $key = "", $start = 0, $iv = "", $verification = true, $recursive = false) |
| 112 | 112 | { |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @param int $start Start position for reading when doing incremental mode. |
| 238 | 238 | * @param integer $iv The IV key to use. |
| 239 | 239 | * @return array|false Returns array or FALSE if an error occured |
| 240 | - * @throws Exception |
|
| 240 | + * @throws Exception |
|
| 241 | 241 | */ |
| 242 | 242 | public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
| 243 | 243 | { |
@@ -45,8 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | |
| 47 | 47 | require_once($file); |
| 48 | -} |
|
| 49 | -elseif (file_exists("vendor.phar") and extension_loaded('phar')) |
|
| 48 | +} elseif (file_exists("vendor.phar") and extension_loaded('phar')) |
|
| 50 | 49 | { |
| 51 | 50 | require_once(__DIR__.DS."vendor.phar"); |
| 52 | 51 | } else { |
@@ -87,7 +86,7 @@ discard block |
||
| 87 | 86 | try { |
| 88 | 87 | $return = $xcloner_restore->init(); |
| 89 | 88 | $xcloner_restore->send_response(200, $return); |
| 90 | -}catch (Exception $e) { |
|
| 89 | +} catch (Exception $e) { |
|
| 91 | 90 | $xcloner_restore->send_response(417, $e->getMessage()); |
| 92 | 91 | } |
| 93 | 92 | |
@@ -231,13 +230,15 @@ discard block |
||
| 231 | 230 | { |
| 232 | 231 | $target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
| 233 | 232 | |
| 234 | - if (!$_POST['start']) |
|
| 235 | - $fp = fopen($target_file, "wb+"); |
|
| 236 | - else |
|
| 237 | - $fp = fopen($target_file, "ab+"); |
|
| 233 | + if (!$_POST['start']) { |
|
| 234 | + $fp = fopen($target_file, "wb+"); |
|
| 235 | + } else { |
|
| 236 | + $fp = fopen($target_file, "ab+"); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - if (!$fp) |
|
| 240 | - throw new Exception("Unable to open $target_file file for writing"); |
|
| 239 | + if (!$fp) { |
|
| 240 | + throw new Exception("Unable to open $target_file file for writing"); |
|
| 241 | + } |
|
| 241 | 242 | |
| 242 | 243 | fseek($fp, $_POST['start']); |
| 243 | 244 | |
@@ -247,22 +248,24 @@ discard block |
||
| 247 | 248 | |
| 248 | 249 | $blob = file_get_contents($_FILES['blob']['tmp_name']); |
| 249 | 250 | |
| 250 | - if (!$bytes_written = fwrite($fp, $blob)) |
|
| 251 | - throw new Exception("Unable to write data to file $target_file"); |
|
| 251 | + if (!$bytes_written = fwrite($fp, $blob)) { |
|
| 252 | + throw new Exception("Unable to write data to file $target_file"); |
|
| 253 | + } |
|
| 252 | 254 | |
| 253 | 255 | try { |
| 254 | 256 | unlink($_FILES['blob']['tmp_name']); |
| 255 | - }catch (Exception $e) { |
|
| 257 | + } catch (Exception $e) { |
|
| 256 | 258 | //silent message |
| 257 | 259 | } |
| 258 | 260 | |
| 259 | - }elseif (isset($_POST['blob'])) { |
|
| 261 | + } elseif (isset($_POST['blob'])) { |
|
| 260 | 262 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
| 261 | 263 | |
| 262 | 264 | $blob = $_POST['blob']; |
| 263 | 265 | |
| 264 | - if (!$bytes_written = fwrite($fp, $blob)) |
|
| 265 | - throw new Exception("Unable to write data to file $target_file"); |
|
| 266 | + if (!$bytes_written = fwrite($fp, $blob)) { |
|
| 267 | + throw new Exception("Unable to write data to file $target_file"); |
|
| 268 | + } |
|
| 266 | 269 | } else { |
| 267 | 270 | throw new Exception("Upload failed, did not receive any binary data"); |
| 268 | 271 | } |
@@ -297,10 +300,11 @@ discard block |
||
| 297 | 300 | |
| 298 | 301 | $mysqli->query("SET sql_mode='';"); |
| 299 | 302 | $mysqli->query("SET foreign_key_checks = 0;"); |
| 300 | - if (isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) |
|
| 301 | - $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
| 302 | - else |
|
| 303 | - $mysqli->query("SET NAMES utf8;"); |
|
| 303 | + if (isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) { |
|
| 304 | + $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
| 305 | + } else { |
|
| 306 | + $mysqli->query("SET NAMES utf8;"); |
|
| 307 | + } |
|
| 304 | 308 | |
| 305 | 309 | return $mysqli; |
| 306 | 310 | } |
@@ -330,8 +334,9 @@ discard block |
||
| 330 | 334 | |
| 331 | 335 | $mysql_backup_file = $remote_path.DS.$mysqldump_file; |
| 332 | 336 | |
| 333 | - if (!file_exists($mysql_backup_file)) |
|
| 334 | - throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file)); |
|
| 337 | + if (!file_exists($mysql_backup_file)) { |
|
| 338 | + throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file)); |
|
| 339 | + } |
|
| 335 | 340 | |
| 336 | 341 | |
| 337 | 342 | /*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
@@ -364,16 +369,18 @@ discard block |
||
| 364 | 369 | // process the line read. |
| 365 | 370 | |
| 366 | 371 | //check if line is comment |
| 367 | - if (substr($line, 0, 1) == "#") |
|
| 368 | - continue; |
|
| 372 | + if (substr($line, 0, 1) == "#") { |
|
| 373 | + continue; |
|
| 374 | + } |
|
| 369 | 375 | |
| 370 | 376 | //check if line is empty |
| 371 | - if ($line == "\n" or trim($line) == "") |
|
| 372 | - continue; |
|
| 377 | + if ($line == "\n" or trim($line) == "") { |
|
| 378 | + continue; |
|
| 379 | + } |
|
| 373 | 380 | |
| 374 | - if (substr($line, strlen($line) - 2, strlen($line)) == ";\n") |
|
| 375 | - $query .= $line; |
|
| 376 | - else { |
|
| 381 | + if (substr($line, strlen($line) - 2, strlen($line)) == ";\n") { |
|
| 382 | + $query .= $line; |
|
| 383 | + } else { |
|
| 377 | 384 | $query .= $line; |
| 378 | 385 | continue; |
| 379 | 386 | } |
@@ -497,7 +504,7 @@ discard block |
||
| 497 | 504 | $tar->open($this->backup_storage_dir.DS.$backup_file, $start); |
| 498 | 505 | |
| 499 | 506 | $data = $tar->contents($this->process_files_limit_list); |
| 500 | - }catch (Exception $e) |
|
| 507 | + } catch (Exception $e) |
|
| 501 | 508 | { |
| 502 | 509 | $return['error'] = true; |
| 503 | 510 | $return['message'] = $e->getMessage(); |
@@ -532,8 +539,9 @@ discard block |
||
| 532 | 539 | |
| 533 | 540 | ++$return['part']; |
| 534 | 541 | |
| 535 | - if ($return['part'] < sizeof($backup_parts)) |
|
| 536 | - $return['finished'] = 0; |
|
| 542 | + if ($return['part'] < sizeof($backup_parts)) { |
|
| 543 | + $return['finished'] = 0; |
|
| 544 | + } |
|
| 537 | 545 | |
| 538 | 546 | } |
| 539 | 547 | } |
@@ -674,19 +682,22 @@ discard block |
||
| 674 | 682 | { |
| 675 | 683 | $config = file_get_contents($wp_config); |
| 676 | 684 | preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches); |
| 677 | - if (isset($matches[1])) |
|
| 678 | - $table_prefix = $matches[1]; |
|
| 679 | - else |
|
| 680 | - throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
| 685 | + if (isset($matches[1])) { |
|
| 686 | + $table_prefix = $matches[1]; |
|
| 687 | + } else { |
|
| 688 | + throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
| 689 | + } |
|
| 690 | + } else { |
|
| 691 | + throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
| 681 | 692 | } |
| 682 | - else |
|
| 683 | - throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
| 684 | 693 | |
| 685 | - if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
| 686 | - throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
| 694 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) { |
|
| 695 | + throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
| 696 | + } |
|
| 687 | 697 | |
| 688 | - if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
| 689 | - throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
| 698 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) { |
|
| 699 | + throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
| 700 | + } |
|
| 690 | 701 | |
| 691 | 702 | return true; |
| 692 | 703 | } |
@@ -724,8 +735,9 @@ discard block |
||
| 724 | 735 | |
| 725 | 736 | $this->logger->info(sprintf('Updating wp-config.php file with the new mysql details')); |
| 726 | 737 | |
| 727 | - if (!file_put_contents($wp_config, $content)) |
|
| 728 | - throw new Exception("Could not write updated config data to ".$wp_config); |
|
| 738 | + if (!file_put_contents($wp_config, $content)) { |
|
| 739 | + throw new Exception("Could not write updated config data to ".$wp_config); |
|
| 740 | + } |
|
| 729 | 741 | |
| 730 | 742 | chmod($wp_config, $file_perms); |
| 731 | 743 | |
@@ -770,10 +782,11 @@ discard block |
||
| 770 | 782 | $mysqldump_list[$file['path']]['size'] = $file['size']; |
| 771 | 783 | $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i", $file['timestamp']); |
| 772 | 784 | |
| 773 | - if ($hash and $hash == $matches[1]) |
|
| 774 | - $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
| 775 | - else |
|
| 776 | - $mysqldump_list[$file['path']]['selected'] = ""; |
|
| 785 | + if ($hash and $hash == $matches[1]) { |
|
| 786 | + $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
| 787 | + } else { |
|
| 788 | + $mysqldump_list[$file['path']]['selected'] = ""; |
|
| 789 | + } |
|
| 777 | 790 | } |
| 778 | 791 | } |
| 779 | 792 | } |
@@ -794,13 +807,15 @@ discard block |
||
| 794 | 807 | */ |
| 795 | 808 | private function get_hash_from_backup($backup_file) |
| 796 | 809 | { |
| 797 | - if (!$backup_file) |
|
| 798 | - return false; |
|
| 810 | + if (!$backup_file) { |
|
| 811 | + return false; |
|
| 812 | + } |
|
| 799 | 813 | |
| 800 | 814 | $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file) - 10, strlen($backup_file)), $matches); |
| 801 | 815 | |
| 802 | - if ($result and isset($matches[1])) |
|
| 803 | - return ($matches[1]); |
|
| 816 | + if ($result and isset($matches[1])) { |
|
| 817 | + return ($matches[1]); |
|
| 818 | + } |
|
| 804 | 819 | |
| 805 | 820 | return false; |
| 806 | 821 | } |
@@ -825,10 +840,11 @@ discard block |
||
| 825 | 840 | if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
| 826 | 841 | { |
| 827 | 842 | $lines = explode(PHP_EOL, $this->filesystem->read($file_info['path'])); |
| 828 | - foreach ($lines as $line) |
|
| 829 | - if ($line) |
|
| 843 | + foreach ($lines as $line) { |
|
| 844 | + if ($line) |
|
| 830 | 845 | { |
| 831 | 846 | $data = str_getcsv($line); |
| 847 | + } |
|
| 832 | 848 | if (is_array($data)) { |
| 833 | 849 | $parents[$data[0]] = $file_info['path']; |
| 834 | 850 | $file_info['childs'][] = $data; |
@@ -838,20 +854,22 @@ discard block |
||
| 838 | 854 | |
| 839 | 855 | } |
| 840 | 856 | |
| 841 | - if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 842 | - $backup_files[$file_info['path']] = $file_info; |
|
| 857 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
| 858 | + $backup_files[$file_info['path']] = $file_info; |
|
| 859 | + } |
|
| 843 | 860 | } |
| 844 | 861 | |
| 845 | 862 | $new_list = array(); |
| 846 | 863 | |
| 847 | 864 | foreach ($backup_files as $key=>$file_info) |
| 848 | 865 | { |
| 849 | - if (isset($parents[$file_info['path']])) |
|
| 850 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 851 | - else { |
|
| 866 | + if (isset($parents[$file_info['path']])) { |
|
| 867 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 868 | + } else { |
|
| 852 | 869 | |
| 853 | - if ($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
| 854 | - $file_info['selected'] = 'selected'; |
|
| 870 | + if ($local_backup_file and ($file_info['basename'] == $local_backup_file)) { |
|
| 871 | + $file_info['selected'] = 'selected'; |
|
| 872 | + } |
|
| 855 | 873 | |
| 856 | 874 | $this->logger->info(sprintf('Found %s backup file', $file_info['path'])); |
| 857 | 875 | |
@@ -898,8 +916,9 @@ discard block |
||
| 898 | 916 | $backup_archive = new Tar(); |
| 899 | 917 | if ($this->is_multipart($backup_file)) |
| 900 | 918 | { |
| 901 | - if (!$return['part']) |
|
| 902 | - $return['processed'] += $this->filesystem->getSize($backup_file); |
|
| 919 | + if (!$return['part']) { |
|
| 920 | + $return['processed'] += $this->filesystem->getSize($backup_file); |
|
| 921 | + } |
|
| 903 | 922 | |
| 904 | 923 | $backup_parts = $this->get_multipart_files($backup_file); |
| 905 | 924 | $backup_file = $backup_parts[$return['part']]; |
@@ -919,10 +938,11 @@ discard block |
||
| 919 | 938 | } |
| 920 | 939 | } |
| 921 | 940 | |
| 922 | - if (isset($data['start'])) |
|
| 923 | - //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
| 941 | + if (isset($data['start'])) { |
|
| 942 | + //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
| 924 | 943 | { |
| 925 | 944 | $return['finished'] = 0; |
| 945 | + } |
|
| 926 | 946 | $return['start'] = $data['start']; |
| 927 | 947 | } else { |
| 928 | 948 | |
@@ -934,14 +954,16 @@ discard block |
||
| 934 | 954 | |
| 935 | 955 | ++$return['part']; |
| 936 | 956 | |
| 937 | - if ($return['part'] < sizeof($backup_parts)) |
|
| 938 | - $return['finished'] = 0; |
|
| 957 | + if ($return['part'] < sizeof($backup_parts)) { |
|
| 958 | + $return['finished'] = 0; |
|
| 959 | + } |
|
| 939 | 960 | |
| 940 | 961 | } |
| 941 | 962 | } |
| 942 | 963 | |
| 943 | - if ($return['finished']) |
|
| 944 | - $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
| 964 | + if ($return['finished']) { |
|
| 965 | + $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
| 966 | + } |
|
| 945 | 967 | |
| 946 | 968 | $return['backup_file'] = $backup_file; |
| 947 | 969 | |
@@ -973,8 +995,7 @@ discard block |
||
| 973 | 995 | $return['remote_mysql_user'] = $wpdb->dbuser; |
| 974 | 996 | $return['remote_mysql_pass'] = $wpdb->dbpassword; |
| 975 | 997 | $return['remote_mysql_db'] = $wpdb->dbname; |
| 976 | - } |
|
| 977 | - else { |
|
| 998 | + } else { |
|
| 978 | 999 | $return['dir'] = ($pathinfo['dirname']).DS.$suffix; |
| 979 | 1000 | $return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix; |
| 980 | 1001 | } |
@@ -993,11 +1014,13 @@ discard block |
||
| 993 | 1014 | { |
| 994 | 1015 | //check if i can write |
| 995 | 1016 | $tmp_file = md5(time()); |
| 996 | - if (!file_put_contents($tmp_file, "++")) |
|
| 997 | - throw new Exception("Could not write to new host"); |
|
| 1017 | + if (!file_put_contents($tmp_file, "++")) { |
|
| 1018 | + throw new Exception("Could not write to new host"); |
|
| 1019 | + } |
|
| 998 | 1020 | |
| 999 | - if (!unlink($tmp_file)) |
|
| 1000 | - throw new Exception("Could not delete temporary file from new host"); |
|
| 1021 | + if (!unlink($tmp_file)) { |
|
| 1022 | + throw new Exception("Could not delete temporary file from new host"); |
|
| 1023 | + } |
|
| 1001 | 1024 | |
| 1002 | 1025 | $max_upload = $this->return_bytes((ini_get('upload_max_filesize'))); |
| 1003 | 1026 | $max_post = $this->return_bytes((ini_get('post_max_size'))); |
@@ -1044,8 +1067,9 @@ discard block |
||
| 1044 | 1067 | */ |
| 1045 | 1068 | public function is_multipart($backup_name) |
| 1046 | 1069 | { |
| 1047 | - if (stristr($backup_name, "-multipart")) |
|
| 1048 | - return true; |
|
| 1070 | + if (stristr($backup_name, "-multipart")) { |
|
| 1071 | + return true; |
|
| 1072 | + } |
|
| 1049 | 1073 | |
| 1050 | 1074 | return false; |
| 1051 | 1075 | } |
@@ -1063,8 +1087,9 @@ discard block |
||
| 1063 | 1087 | if ($this->is_multipart($backup_name)) |
| 1064 | 1088 | { |
| 1065 | 1089 | $backup_parts = $this->get_multipart_files($backup_name); |
| 1066 | - foreach ($backup_parts as $part_file) |
|
| 1067 | - $backup_size += $this->filesystem->getSize($part_file); |
|
| 1090 | + foreach ($backup_parts as $part_file) { |
|
| 1091 | + $backup_size += $this->filesystem->getSize($part_file); |
|
| 1092 | + } |
|
| 1068 | 1093 | } |
| 1069 | 1094 | |
| 1070 | 1095 | return $backup_size; |
@@ -1126,15 +1151,13 @@ discard block |
||
| 1126 | 1151 | if ($direction == 'desc') { |
| 1127 | 1152 | if ($a > $b) { |
| 1128 | 1153 | return -1; |
| 1129 | - } |
|
| 1130 | - else { |
|
| 1154 | + } else { |
|
| 1131 | 1155 | return 1; |
| 1132 | 1156 | } |
| 1133 | 1157 | } else { |
| 1134 | 1158 | if ($a < $b) { |
| 1135 | 1159 | return -1; |
| 1136 | - } |
|
| 1137 | - else { |
|
| 1160 | + } else { |
|
| 1138 | 1161 | return 1; |
| 1139 | 1162 | } |
| 1140 | 1163 | } |
@@ -1164,7 +1187,7 @@ discard block |
||
| 1164 | 1187 | { |
| 1165 | 1188 | $return['statusText'] = $response['message']; |
| 1166 | 1189 | $return['error'] = true; |
| 1167 | - }elseif ($status != 200 and $status != 418) |
|
| 1190 | + } elseif ($status != 200 and $status != 418) |
|
| 1168 | 1191 | { |
| 1169 | 1192 | $return['error'] = true; |
| 1170 | 1193 | $return['message'] = $response; |
@@ -1188,8 +1211,9 @@ discard block |
||
| 1188 | 1211 | return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function($m) { |
| 1189 | 1212 | $data = ""; |
| 1190 | 1213 | |
| 1191 | - if (!isset($m[3])) |
|
| 1192 | - $m[3] = ""; |
|
| 1214 | + if (!isset($m[3])) { |
|
| 1215 | + $m[3] = ""; |
|
| 1216 | + } |
|
| 1193 | 1217 | |
| 1194 | 1218 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
| 1195 | 1219 | //return $this->unescape_quotes($data); |