@@ -21,12 +21,12 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | |
| 24 | -class XCloner_Database extends wpdb{ |
|
| 24 | +class XCloner_Database extends wpdb { |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - public $debug = 0; |
|
| 28 | - public $recordsPerSession = 10000; |
|
| 29 | - public $dbCompatibility = ""; |
|
| 27 | + public $debug = 0; |
|
| 28 | + public $recordsPerSession = 10000; |
|
| 29 | + public $dbCompatibility = ""; |
|
| 30 | 30 | public $dbDropSyntax = 1; |
| 31 | 31 | public $countRecords = 0; |
| 32 | 32 | |
@@ -38,22 +38,22 @@ discard block |
||
| 38 | 38 | private $TEMP_DBPROCESS_FILE = ".database"; |
| 39 | 39 | private $TEMP_DUMP_FILE = "database-backup.sql"; |
| 40 | 40 | |
| 41 | - public function __construct($hash="", $wp_user="", $wp_pass="", $wp_db="", $wp_host="") |
|
| 41 | + public function __construct($hash = "", $wp_user = "", $wp_pass = "", $wp_db = "", $wp_host = "") |
|
| 42 | 42 | { |
| 43 | - $this->logger = new XCloner_Logger("xcloner_database", $hash); |
|
| 44 | - $this->xcloner_settings = new Xcloner_Settings($hash); |
|
| 45 | - $this->fs = new Xcloner_File_System($hash); |
|
| 43 | + $this->logger = new XCloner_Logger("xcloner_database", $hash); |
|
| 44 | + $this->xcloner_settings = new Xcloner_Settings($hash); |
|
| 45 | + $this->fs = new Xcloner_File_System($hash); |
|
| 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 | - if(!$this->recordsPerSession) |
|
| 50 | + if (!$this->recordsPerSession) |
|
| 51 | 51 | $this->recordsPerSession = 100; |
| 52 | 52 | |
| 53 | 53 | $wp_host = $this->xcloner_settings->get_db_hostname(); |
| 54 | 54 | $wp_user = $this->xcloner_settings->get_db_username(); |
| 55 | 55 | $wp_pass = $this->xcloner_settings->get_db_password(); |
| 56 | - $wp_db = $this->xcloner_settings->get_db_database(); |
|
| 56 | + $wp_db = $this->xcloner_settings->get_db_database(); |
|
| 57 | 57 | |
| 58 | 58 | parent::__construct($wp_user, $wp_pass, $wp_db, $wp_host); |
| 59 | 59 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function init($data, $start = 0) |
| 70 | 70 | { |
| 71 | - if($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)){ |
|
| 71 | + if ($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
| 72 | 72 | $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | "database_count"=>0, |
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - if(!$this->xcloner_settings->get_enable_mysql_backup()) |
|
| 90 | + if (!$this->xcloner_settings->get_enable_mysql_backup()) |
|
| 91 | 91 | { |
| 92 | 92 | $return['finished'] = 1; |
| 93 | 93 | return $return; |
@@ -97,44 +97,44 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | $this->init($params, $init); |
| 99 | 99 | |
| 100 | - if($init) |
|
| 100 | + if ($init) |
|
| 101 | 101 | { |
| 102 | 102 | $db_count = 0; |
| 103 | 103 | |
| 104 | - if(isset($params['#'])) |
|
| 104 | + if (isset($params['#'])) |
|
| 105 | 105 | { |
| 106 | - foreach($params['#'] as $database) |
|
| 106 | + foreach ($params['#'] as $database) |
|
| 107 | 107 | { |
| 108 | - if(!isset($params[$database]) or !is_array($params[$database])) |
|
| 108 | + if (!isset($params[$database]) or !is_array($params[$database])) |
|
| 109 | 109 | $params[$database] = array(); |
| 110 | 110 | } |
| 111 | 111 | $db_count = -1; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if(isset($params) and is_array($params)) |
|
| 115 | - foreach($params as $database=>$tables) |
|
| 114 | + if (isset($params) and is_array($params)) |
|
| 115 | + foreach ($params as $database=>$tables) |
|
| 116 | 116 | { |
| 117 | - if($database != "#") |
|
| 117 | + if ($database != "#") |
|
| 118 | 118 | { |
| 119 | 119 | $stats = $this->write_backup_process_list($database, $tables); |
| 120 | - $return['stats']['tables_count'] += $stats['tables_count']; |
|
| 121 | - $return['stats']['total_records'] += $stats['total_records']; |
|
| 120 | + $return['stats']['tables_count'] += $stats['tables_count']; |
|
| 121 | + $return['stats']['total_records'] += $stats['total_records']; |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if(sizeof($params)) |
|
| 126 | - $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
| 125 | + if (sizeof($params)) |
|
| 126 | + $return['stats']['database_count'] = sizeof($params) + $db_count; |
|
| 127 | 127 | else |
| 128 | 128 | $return['stats']['database_count'] = 0; |
| 129 | 129 | |
| 130 | 130 | return $return; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if(!isset($extra_params['startAtLine'])) |
|
| 133 | + if (!isset($extra_params['startAtLine'])) |
|
| 134 | 134 | $extra_params['startAtLine'] = 0; |
| 135 | - if(!isset($extra_params['startAtRecord'])) |
|
| 135 | + if (!isset($extra_params['startAtRecord'])) |
|
| 136 | 136 | $extra_params['startAtRecord'] = 0; |
| 137 | - if(!isset($extra_params['dumpfile'])) |
|
| 137 | + if (!isset($extra_params['dumpfile'])) |
|
| 138 | 138 | $extra_params['dumpfile'] = ""; |
| 139 | 139 | |
| 140 | 140 | $return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']); |
@@ -145,13 +145,13 @@ discard block |
||
| 145 | 145 | public function log($message = "") |
| 146 | 146 | { |
| 147 | 147 | |
| 148 | - if($message){ |
|
| 149 | - $this->logger->info( $message, array("")); |
|
| 150 | - }else{ |
|
| 151 | - if($this->last_query) |
|
| 152 | - $this->logger->debug( $this->last_query, array("")); |
|
| 153 | - if($this->last_error) |
|
| 154 | - $this->logger->error( $this->last_error, array("")); |
|
| 148 | + if ($message) { |
|
| 149 | + $this->logger->info($message, array("")); |
|
| 150 | + } else { |
|
| 151 | + if ($this->last_query) |
|
| 152 | + $this->logger->debug($this->last_query, array("")); |
|
| 153 | + if ($this->last_error) |
|
| 154 | + $this->logger->error($this->last_error, array("")); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | return; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function error($message) |
| 168 | 168 | { |
| 169 | - $this->logger->error( $message, array("")); |
|
| 169 | + $this->logger->error($message, array("")); |
|
| 170 | 170 | |
| 171 | 171 | return; |
| 172 | 172 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $query = "show tables in `".$database."`"; |
| 201 | 201 | |
| 202 | - $res = $this->get_results($query); |
|
| 202 | + $res = $this->get_results($query); |
|
| 203 | 203 | $this->log(); |
| 204 | 204 | |
| 205 | 205 | return count($res); |
@@ -222,9 +222,9 @@ discard block |
||
| 222 | 222 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname); |
| 223 | 223 | $i++; |
| 224 | 224 | |
| 225 | - if(is_array($databases)) |
|
| 226 | - foreach( $databases as $db){ |
|
| 227 | - if($db->Database != $this->dbname) |
|
| 225 | + if (is_array($databases)) |
|
| 226 | + foreach ($databases as $db) { |
|
| 227 | + if ($db->Database != $this->dbname) |
|
| 228 | 228 | { |
| 229 | 229 | $databases_list[$i]['name'] = $db->Database; |
| 230 | 230 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $tablesList[0] = array( ); |
| 248 | 248 | $inc = 0; |
| 249 | 249 | |
| 250 | - if(!$database) |
|
| 250 | + if (!$database) |
|
| 251 | 251 | $database = $this->dbname; |
| 252 | 252 | |
| 253 | 253 | $this->logger->debug(sprintf(("Listing tables in %s database"), $database)); |
@@ -255,14 +255,14 @@ discard block |
||
| 255 | 255 | $tables = $this->get_results("SHOW TABLES in `".$database."`"); |
| 256 | 256 | $this->log(); |
| 257 | 257 | |
| 258 | - foreach ($tables as $table){ |
|
| 258 | + foreach ($tables as $table) { |
|
| 259 | 259 | |
| 260 | 260 | $table = array_values((array)$table)[0]; |
| 261 | 261 | |
| 262 | 262 | $tablesList[$inc]['name'] = $table; |
| 263 | 263 | $tablesList[$inc]['database'] = $database; |
| 264 | 264 | |
| 265 | - if($get_num_records) |
|
| 265 | + if ($get_num_records) |
|
| 266 | 266 | { |
| 267 | 267 | $records_num_result = $this->get_var("SELECT count(*) FROM `".$database."`.`".$table."`"); |
| 268 | 268 | $this->log(); |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | $tablesList[$inc]['excluded'] = 0; |
| 274 | 274 | |
| 275 | - if(sizeof($included) and is_array($included)) |
|
| 276 | - if(!in_array($table, $included) ) |
|
| 275 | + if (sizeof($included) and is_array($included)) |
|
| 276 | + if (!in_array($table, $included)) |
|
| 277 | 277 | { |
| 278 | 278 | $tablesList[$inc]['excluded'] = 1; |
| 279 | 279 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | |
| 295 | 295 | $tables = $this->list_tables($dbname, $incl_tables, 1); |
| 296 | 296 | |
| 297 | - if($this->dbname != $dbname) |
|
| 297 | + if ($this->dbname != $dbname) |
|
| 298 | 298 | $dumpfile = $dbname."-backup.sql"; |
| 299 | 299 | else |
| 300 | 300 | $dumpfile = $this->TEMP_DUMP_FILE; |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
| 304 | 304 | |
| 305 | 305 | // write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records |
| 306 | - foreach($tables as $key=>$table) |
|
| 307 | - if($table!= "" and !$tables[$key]['excluded']){ |
|
| 306 | + foreach ($tables as $key=>$table) |
|
| 307 | + if ($table != "" and !$tables[$key]['excluded']) { |
|
| 308 | 308 | |
| 309 | 309 | $line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']); |
| 310 | 310 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | |
| 333 | 333 | $result = $this->get_var("SELECT count(*) FROM $table;"); |
| 334 | 334 | |
| 335 | - return intval($result) ;// not max limit on 32 bit systems 2147483647; on 64 bit 999999999999 |
|
| 335 | + return intval($result); // not max limit on 32 bit systems 2147483647; on 64 bit 999999999999 |
|
| 336 | 336 | |
| 337 | 337 | } |
| 338 | 338 | |
@@ -348,25 +348,25 @@ discard block |
||
| 348 | 348 | * int $dbDropSyntax - check if the DROP TABLE syntax should be added |
| 349 | 349 | * @return array $return |
| 350 | 350 | */ |
| 351 | - public function process_incremental($startAtLine= 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility= ""){ |
|
| 351 | + public function process_incremental($startAtLine = 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility = "") { |
|
| 352 | 352 | |
| 353 | 353 | $count = 0; |
| 354 | 354 | $return['finished'] = 0; |
| 355 | 355 | $lines = array(); |
| 356 | 356 | |
| 357 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 358 | - $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
| 357 | + if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 358 | + $lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
| 359 | 359 | |
| 360 | - foreach ($lines as $buffer){ |
|
| 360 | + foreach ($lines as $buffer) { |
|
| 361 | 361 | |
| 362 | - if($count == $startAtLine) |
|
| 362 | + if ($count == $startAtLine) |
|
| 363 | 363 | { |
| 364 | 364 | |
| 365 | - $tableInfo =explode("\t", $buffer); |
|
| 365 | + $tableInfo = explode("\t", $buffer); |
|
| 366 | 366 | |
| 367 | - if($tableInfo[0] == "###newdump###"){ |
|
| 367 | + if ($tableInfo[0] == "###newdump###") { |
|
| 368 | 368 | // we create a new mysql dump file |
| 369 | - if($dumpfile != ""){ |
|
| 369 | + if ($dumpfile != "") { |
|
| 370 | 370 | // we finished a previous one and write the footers |
| 371 | 371 | $return['dumpsize'] = $this->data_footers($dumpfile); |
| 372 | 372 | } |
@@ -380,13 +380,13 @@ discard block |
||
| 380 | 380 | $startAtLine++; |
| 381 | 381 | $return['new_dump'] = 1; |
| 382 | 382 | //break; |
| 383 | - }else{ |
|
| 383 | + } else { |
|
| 384 | 384 | //we export the table |
| 385 | - if($tableInfo[0] == "###enddump###") |
|
| 385 | + if ($tableInfo[0] == "###enddump###") |
|
| 386 | 386 | $return['endDump'] = 1; |
| 387 | 387 | |
| 388 | 388 | //table is excluded |
| 389 | - if($tableInfo[2]) |
|
| 389 | + if ($tableInfo[2]) |
|
| 390 | 390 | continue; |
| 391 | 391 | |
| 392 | 392 | $next = $startAtRecord + $this->recordsPerSession; |
@@ -398,28 +398,28 @@ discard block |
||
| 398 | 398 | |
| 399 | 399 | //return something to the browser |
| 400 | 400 | $return['databaseName'] = $databaseName; |
| 401 | - $return['tableName'] = $tableName; |
|
| 401 | + $return['tableName'] = $tableName; |
|
| 402 | 402 | $return['totalRecords'] = $tableInfo[1]; |
| 403 | 403 | |
| 404 | 404 | $processed_records = 0; |
| 405 | 405 | |
| 406 | - if(trim($tableName) !="" and !$tableInfo[2]) |
|
| 406 | + if (trim($tableName) != "" and !$tableInfo[2]) |
|
| 407 | 407 | $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
| 408 | 408 | |
| 409 | - $return['processedRecords'] = $startAtRecord+$processed_records; |
|
| 409 | + $return['processedRecords'] = $startAtRecord + $processed_records; |
|
| 410 | 410 | |
| 411 | - if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
| 411 | + if ($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
| 412 | 412 | { |
| 413 | - $startAtLine ++; |
|
| 413 | + $startAtLine++; |
|
| 414 | 414 | $startAtRecord = 0; |
| 415 | - }else{ |
|
| 415 | + } else { |
|
| 416 | 416 | $startAtRecord = $startAtRecord + $this->recordsPerSession; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | //$return['dbCompatibility'] = self::$dbCompatibility; |
| 420 | 420 | |
| 421 | - $return['startAtLine'] = $startAtLine; |
|
| 422 | - $return['startAtRecord'] = $startAtRecord; |
|
| 421 | + $return['startAtLine'] = $startAtLine; |
|
| 422 | + $return['startAtRecord'] = $startAtRecord; |
|
| 423 | 423 | $return['dumpfile'] = $dumpfile; |
| 424 | 424 | $return['dumpsize'] = $this->fs->get_tmp_filesystem_append()->getSize($dumpfile); |
| 425 | 425 | |
@@ -437,15 +437,15 @@ discard block |
||
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | //while is finished, lets go home... |
| 440 | - if($dumpfile != ""){ |
|
| 440 | + if ($dumpfile != "") { |
|
| 441 | 441 | // we finished a previous one and write the footers |
| 442 | 442 | $return['dumpsize'] = $this->data_footers($dumpfile); |
| 443 | 443 | $return['dumpfile'] = ($dumpfile); |
| 444 | 444 | } |
| 445 | 445 | $return['finished'] = 1; |
| 446 | - $return['startAtLine'] = $startAtLine; |
|
| 446 | + $return['startAtLine'] = $startAtLine; |
|
| 447 | 447 | |
| 448 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 448 | + if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 449 | 449 | $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
| 450 | 450 | |
| 451 | 451 | $this->logger->debug(sprintf(("Database backup finished!"))); |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | |
| 475 | 475 | $records = 0; |
| 476 | 476 | |
| 477 | - if($start == 0) |
|
| 477 | + if ($start == 0) |
|
| 478 | 478 | $this->dump_structure($databaseName, $tableName, $dumpfile); |
| 479 | 479 | |
| 480 | 480 | $start = intval($start); |
@@ -482,20 +482,20 @@ discard block |
||
| 482 | 482 | //exporting the table content now |
| 483 | 483 | |
| 484 | 484 | $query = "SELECT * from `$databaseName`.`$tableName` Limit $start, $limit ;"; |
| 485 | - if($this->use_mysqli) |
|
| 485 | + if ($this->use_mysqli) |
|
| 486 | 486 | { |
| 487 | 487 | $result = mysqli_query($this->dbh, $query); |
| 488 | 488 | $mysql_fetch_function = "mysqli_fetch_array"; |
| 489 | 489 | |
| 490 | - }else{ |
|
| 490 | + } else { |
|
| 491 | 491 | $result = mysql_query($query, $this->dbh); |
| 492 | 492 | $mysql_fetch_function = "mysql_fetch_array"; |
| 493 | 493 | } |
| 494 | 494 | //$result = $this->get_results($query, ARRAY_N); |
| 495 | 495 | //print_r($result); exit; |
| 496 | 496 | |
| 497 | - if($result){ |
|
| 498 | - while($row = $mysql_fetch_function($result, MYSQLI_ASSOC)){ |
|
| 497 | + if ($result) { |
|
| 498 | + while ($row = $mysql_fetch_function($result, MYSQLI_ASSOC)) { |
|
| 499 | 499 | |
| 500 | 500 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, "INSERT INTO `$tableName` VALUES ("); |
| 501 | 501 | $arr = $row; |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | $value = $this->_real_escape($value); |
| 507 | 507 | $buffer .= "'".$value."', "; |
| 508 | 508 | } |
| 509 | - $buffer = rtrim($buffer, ', ') . ");\n"; |
|
| 509 | + $buffer = rtrim($buffer, ', ').");\n"; |
|
| 510 | 510 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $buffer); |
| 511 | 511 | unset($buffer); |
| 512 | 512 | |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - public function dump_structure($databaseName, $tableName ,$dumpfile) |
|
| 524 | + public function dump_structure($databaseName, $tableName, $dumpfile) |
|
| 525 | 525 | { |
| 526 | 526 | $this->log(sprintf(__("Dumping the structure for %s.%s table"), $databaseName, $tableName)); |
| 527 | 527 | |
@@ -536,14 +536,14 @@ discard block |
||
| 536 | 536 | |
| 537 | 537 | //$result = mysqli_query($this->dbh,"SHOW CREATE table `$databaseName`.`$tableName`;"); |
| 538 | 538 | $result = $this->get_row("SHOW CREATE table `$databaseName`.`$tableName`;", ARRAY_N); |
| 539 | - if($result){ |
|
| 539 | + if ($result) { |
|
| 540 | 540 | //$row = mysqli_fetch_row( $result); |
| 541 | 541 | $line = ($result[1].";\n"); |
| 542 | 542 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - $line = ( "\n#\n# End Structure for table `$tableName`\n#\n\n"); |
|
| 546 | - $line .=("#\n# Dumping data for table `$tableName`\n#\n\n"); |
|
| 545 | + $line = ("\n#\n# End Structure for table `$tableName`\n#\n\n"); |
|
| 546 | + $line .= ("#\n# Dumping data for table `$tableName`\n#\n\n"); |
|
| 547 | 547 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
| 548 | 548 | |
| 549 | 549 | return; |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - public function resetcountRecords(){ |
|
| 569 | + public function resetcountRecords() { |
|
| 570 | 570 | |
| 571 | 571 | $this->countRecords = 0; |
| 572 | 572 | |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - public function getcountRecords(){ |
|
| 577 | + public function getcountRecords() { |
|
| 578 | 578 | |
| 579 | 579 | return $this->countRecords; |
| 580 | 580 | |
@@ -591,14 +591,14 @@ discard block |
||
| 591 | 591 | $return .= "# Powered by XCloner Site Backup\n"; |
| 592 | 592 | $return .= "# http://www.xcloner.com\n"; |
| 593 | 593 | $return .= "#\n"; |
| 594 | - $return .= "# Host: " . $_SERVER['HTTP_HOST'] . "\n"; |
|
| 595 | - $return .= "# Generation Time: " . date("M j, Y \a\\t H:i") . "\n"; |
|
| 596 | - $return .= "# PHP Version: " . phpversion() . "\n"; |
|
| 597 | - $return .= "# Database Charset: ". $this->charset . "\n"; |
|
| 594 | + $return .= "# Host: ".$_SERVER['HTTP_HOST']."\n"; |
|
| 595 | + $return .= "# Generation Time: ".date("M j, Y \a\\t H:i")."\n"; |
|
| 596 | + $return .= "# PHP Version: ".phpversion()."\n"; |
|
| 597 | + $return .= "# Database Charset: ".$this->charset."\n"; |
|
| 598 | 598 | |
| 599 | 599 | $results = $this->get_results("SHOW VARIABLES LIKE \"%version%\";", ARRAY_N); |
| 600 | - if(isset($results)){ |
|
| 601 | - foreach($results as $result){ |
|
| 600 | + if (isset($results)) { |
|
| 601 | + foreach ($results as $result) { |
|
| 602 | 602 | |
| 603 | 603 | $return .= "# MYSQL ".$result[0].": ".$result[1]."\n"; |
| 604 | 604 | |
@@ -608,13 +608,13 @@ discard block |
||
| 608 | 608 | $results = $this->get_results("SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME |
| 609 | 609 | FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".$database."';"); |
| 610 | 610 | |
| 611 | - if(isset($results[0])){ |
|
| 611 | + if (isset($results[0])) { |
|
| 612 | 612 | |
| 613 | 613 | $return .= "# MYSQL DEFAULT_CHARACTER_SET_NAME: ".$results[0]->DEFAULT_CHARACTER_SET_NAME."\n"; |
| 614 | 614 | $return .= "# MYSQL SCHEMA_NAME: ".$results[0]->DEFAULT_COLLATION_NAME."\n"; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - $return .= "#\n# Database : `" . $database . "`\n# --------------------------------------------------------\n\n"; |
|
| 617 | + $return .= "#\n# Database : `".$database."`\n# --------------------------------------------------------\n\n"; |
|
| 618 | 618 | |
| 619 | 619 | $this->log(sprintf(__("Writing %s database dump headers"), $database)); |
| 620 | 620 | |
@@ -44,11 +44,13 @@ discard block |
||
| 44 | 44 | $this->xcloner_settings = new Xcloner_Settings($hash); |
| 45 | 45 | $this->fs = new Xcloner_File_System($hash); |
| 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 | $wp_host = $this->xcloner_settings->get_db_hostname(); |
| 54 | 56 | $wp_user = $this->xcloner_settings->get_db_username(); |
@@ -105,37 +107,43 @@ discard block |
||
| 105 | 107 | { |
| 106 | 108 | foreach($params['#'] as $database) |
| 107 | 109 | { |
| 108 | - if(!isset($params[$database]) or !is_array($params[$database])) |
|
| 109 | - $params[$database] = array(); |
|
| 110 | + if(!isset($params[$database]) or !is_array($params[$database])) { |
|
| 111 | + $params[$database] = array(); |
|
| 112 | + } |
|
| 110 | 113 | } |
| 111 | 114 | $db_count = -1; |
| 112 | 115 | } |
| 113 | 116 | |
| 114 | - if(isset($params) and is_array($params)) |
|
| 115 | - foreach($params as $database=>$tables) |
|
| 117 | + if(isset($params) and is_array($params)) { |
|
| 118 | + foreach($params as $database=>$tables) |
|
| 116 | 119 | { |
| 117 | 120 | if($database != "#") |
| 118 | 121 | { |
| 119 | - $stats = $this->write_backup_process_list($database, $tables); |
|
| 122 | + $stats = $this->write_backup_process_list($database, $tables); |
|
| 123 | + } |
|
| 120 | 124 | $return['stats']['tables_count'] += $stats['tables_count']; |
| 121 | 125 | $return['stats']['total_records'] += $stats['total_records']; |
| 122 | 126 | } |
| 123 | 127 | } |
| 124 | 128 | |
| 125 | - if(sizeof($params)) |
|
| 126 | - $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
| 127 | - else |
|
| 128 | - $return['stats']['database_count'] = 0; |
|
| 129 | + if(sizeof($params)) { |
|
| 130 | + $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
| 131 | + } else { |
|
| 132 | + $return['stats']['database_count'] = 0; |
|
| 133 | + } |
|
| 129 | 134 | |
| 130 | 135 | return $return; |
| 131 | 136 | } |
| 132 | 137 | |
| 133 | - if(!isset($extra_params['startAtLine'])) |
|
| 134 | - $extra_params['startAtLine'] = 0; |
|
| 135 | - if(!isset($extra_params['startAtRecord'])) |
|
| 136 | - $extra_params['startAtRecord'] = 0; |
|
| 137 | - if(!isset($extra_params['dumpfile'])) |
|
| 138 | - $extra_params['dumpfile'] = ""; |
|
| 138 | + if(!isset($extra_params['startAtLine'])) { |
|
| 139 | + $extra_params['startAtLine'] = 0; |
|
| 140 | + } |
|
| 141 | + if(!isset($extra_params['startAtRecord'])) { |
|
| 142 | + $extra_params['startAtRecord'] = 0; |
|
| 143 | + } |
|
| 144 | + if(!isset($extra_params['dumpfile'])) { |
|
| 145 | + $extra_params['dumpfile'] = ""; |
|
| 146 | + } |
|
| 139 | 147 | |
| 140 | 148 | $return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']); |
| 141 | 149 | |
@@ -147,11 +155,13 @@ discard block |
||
| 147 | 155 | |
| 148 | 156 | if($message){ |
| 149 | 157 | $this->logger->info( $message, array("")); |
| 150 | - }else{ |
|
| 151 | - if($this->last_query) |
|
| 152 | - $this->logger->debug( $this->last_query, array("")); |
|
| 153 | - if($this->last_error) |
|
| 154 | - $this->logger->error( $this->last_error, array("")); |
|
| 158 | + } else{ |
|
| 159 | + if($this->last_query) { |
|
| 160 | + $this->logger->debug( $this->last_query, array("")); |
|
| 161 | + } |
|
| 162 | + if($this->last_error) { |
|
| 163 | + $this->logger->error( $this->last_error, array("")); |
|
| 164 | + } |
|
| 155 | 165 | } |
| 156 | 166 | |
| 157 | 167 | return; |
@@ -222,11 +232,12 @@ discard block |
||
| 222 | 232 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname); |
| 223 | 233 | $i++; |
| 224 | 234 | |
| 225 | - if(is_array($databases)) |
|
| 226 | - foreach( $databases as $db){ |
|
| 235 | + if(is_array($databases)) { |
|
| 236 | + foreach( $databases as $db){ |
|
| 227 | 237 | if($db->Database != $this->dbname) |
| 228 | 238 | { |
| 229 | 239 | $databases_list[$i]['name'] = $db->Database; |
| 240 | + } |
|
| 230 | 241 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database); |
| 231 | 242 | $i++; |
| 232 | 243 | } |
@@ -247,8 +258,9 @@ discard block |
||
| 247 | 258 | $tablesList[0] = array( ); |
| 248 | 259 | $inc = 0; |
| 249 | 260 | |
| 250 | - if(!$database) |
|
| 251 | - $database = $this->dbname; |
|
| 261 | + if(!$database) { |
|
| 262 | + $database = $this->dbname; |
|
| 263 | + } |
|
| 252 | 264 | |
| 253 | 265 | $this->logger->debug(sprintf(("Listing tables in %s database"), $database)); |
| 254 | 266 | |
@@ -272,10 +284,11 @@ discard block |
||
| 272 | 284 | |
| 273 | 285 | $tablesList[$inc]['excluded'] = 0; |
| 274 | 286 | |
| 275 | - if(sizeof($included) and is_array($included)) |
|
| 276 | - if(!in_array($table, $included) ) |
|
| 287 | + if(sizeof($included) and is_array($included)) { |
|
| 288 | + if(!in_array($table, $included) ) |
|
| 277 | 289 | { |
| 278 | 290 | $tablesList[$inc]['excluded'] = 1; |
| 291 | + } |
|
| 279 | 292 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
| 280 | 293 | } |
| 281 | 294 | $inc++; |
@@ -294,19 +307,21 @@ discard block |
||
| 294 | 307 | |
| 295 | 308 | $tables = $this->list_tables($dbname, $incl_tables, 1); |
| 296 | 309 | |
| 297 | - if($this->dbname != $dbname) |
|
| 298 | - $dumpfile = $dbname."-backup.sql"; |
|
| 299 | - else |
|
| 300 | - $dumpfile = $this->TEMP_DUMP_FILE; |
|
| 310 | + if($this->dbname != $dbname) { |
|
| 311 | + $dumpfile = $dbname."-backup.sql"; |
|
| 312 | + } else { |
|
| 313 | + $dumpfile = $this->TEMP_DUMP_FILE; |
|
| 314 | + } |
|
| 301 | 315 | |
| 302 | 316 | $line = sprintf("###newdump###\t%s\t%s\n", $dbname, $dumpfile); |
| 303 | 317 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
| 304 | 318 | |
| 305 | 319 | // write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records |
| 306 | - foreach($tables as $key=>$table) |
|
| 307 | - if($table!= "" and !$tables[$key]['excluded']){ |
|
| 320 | + foreach($tables as $key=>$table) { |
|
| 321 | + if($table!= "" and !$tables[$key]['excluded']){ |
|
| 308 | 322 | |
| 309 | 323 | $line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']); |
| 324 | + } |
|
| 310 | 325 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
| 311 | 326 | $return['tables_count']++; |
| 312 | 327 | $return['total_records'] += $tables[$key]['records']; |
@@ -354,8 +369,9 @@ discard block |
||
| 354 | 369 | $return['finished'] = 0; |
| 355 | 370 | $lines = array(); |
| 356 | 371 | |
| 357 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 358 | - $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
| 372 | + if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
| 373 | + $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
| 374 | + } |
|
| 359 | 375 | |
| 360 | 376 | foreach ($lines as $buffer){ |
| 361 | 377 | |
@@ -380,14 +396,16 @@ discard block |
||
| 380 | 396 | $startAtLine++; |
| 381 | 397 | $return['new_dump'] = 1; |
| 382 | 398 | //break; |
| 383 | - }else{ |
|
| 399 | + } else{ |
|
| 384 | 400 | //we export the table |
| 385 | - if($tableInfo[0] == "###enddump###") |
|
| 386 | - $return['endDump'] = 1; |
|
| 401 | + if($tableInfo[0] == "###enddump###") { |
|
| 402 | + $return['endDump'] = 1; |
|
| 403 | + } |
|
| 387 | 404 | |
| 388 | 405 | //table is excluded |
| 389 | - if($tableInfo[2]) |
|
| 390 | - continue; |
|
| 406 | + if($tableInfo[2]) { |
|
| 407 | + continue; |
|
| 408 | + } |
|
| 391 | 409 | |
| 392 | 410 | $next = $startAtRecord + $this->recordsPerSession; |
| 393 | 411 | |
@@ -403,16 +421,19 @@ discard block |
||
| 403 | 421 | |
| 404 | 422 | $processed_records = 0; |
| 405 | 423 | |
| 406 | - if(trim($tableName) !="" and !$tableInfo[2]) |
|
| 407 | - $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
|
| 424 | + if(trim($tableName) !="" and !$tableInfo[2]) { |
|
| 425 | + $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
|
| 426 | + } |
|
| 408 | 427 | |
| 409 | 428 | $return['processedRecords'] = $startAtRecord+$processed_records; |
| 410 | 429 | |
| 411 | - if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
| 430 | + if($next >= $tableInfo[1]) { |
|
| 431 | + //we finished loading the records for next sessions, will go to the new record |
|
| 412 | 432 | { |
| 413 | 433 | $startAtLine ++; |
| 434 | + } |
|
| 414 | 435 | $startAtRecord = 0; |
| 415 | - }else{ |
|
| 436 | + } else{ |
|
| 416 | 437 | $startAtRecord = $startAtRecord + $this->recordsPerSession; |
| 417 | 438 | } |
| 418 | 439 | |
@@ -445,8 +466,9 @@ discard block |
||
| 445 | 466 | $return['finished'] = 1; |
| 446 | 467 | $return['startAtLine'] = $startAtLine; |
| 447 | 468 | |
| 448 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 449 | - $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
|
| 469 | + if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
| 470 | + $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
|
| 471 | + } |
|
| 450 | 472 | |
| 451 | 473 | $this->logger->debug(sprintf(("Database backup finished!"))); |
| 452 | 474 | |
@@ -474,8 +496,9 @@ discard block |
||
| 474 | 496 | |
| 475 | 497 | $records = 0; |
| 476 | 498 | |
| 477 | - if($start == 0) |
|
| 478 | - $this->dump_structure($databaseName, $tableName, $dumpfile); |
|
| 499 | + if($start == 0) { |
|
| 500 | + $this->dump_structure($databaseName, $tableName, $dumpfile); |
|
| 501 | + } |
|
| 479 | 502 | |
| 480 | 503 | $start = intval($start); |
| 481 | 504 | $limit = intval($limit); |
@@ -487,7 +510,7 @@ discard block |
||
| 487 | 510 | $result = mysqli_query($this->dbh, $query); |
| 488 | 511 | $mysql_fetch_function = "mysqli_fetch_array"; |
| 489 | 512 | |
| 490 | - }else{ |
|
| 513 | + } else{ |
|
| 491 | 514 | $result = mysql_query($query, $this->dbh); |
| 492 | 515 | $mysql_fetch_function = "mysql_fetch_array"; |
| 493 | 516 | } |
@@ -4,32 +4,32 @@ discard block |
||
| 4 | 4 | use Monolog\Handler\StreamHandler; |
| 5 | 5 | use Monolog\Handler\RotatingFileHandler; |
| 6 | 6 | |
| 7 | -class Xcloner_Logger extends Logger{ |
|
| 7 | +class Xcloner_Logger extends Logger { |
|
| 8 | 8 | |
| 9 | - private $logger_path ; |
|
| 9 | + private $logger_path; |
|
| 10 | 10 | private $max_logger_files = 15; |
| 11 | 11 | private $main_logger_url; |
| 12 | 12 | |
| 13 | - public function __construct($logger_name = "xcloner_logger", $hash="") |
|
| 13 | + public function __construct($logger_name = "xcloner_logger", $hash = "") |
|
| 14 | 14 | { |
| 15 | - $xcloner_settings = new Xcloner_Settings($hash); |
|
| 16 | - $logger_path = $xcloner_settings->get_xcloner_store_path().DS.$xcloner_settings->get_logger_filename(); |
|
| 15 | + $xcloner_settings = new Xcloner_Settings($hash); |
|
| 16 | + $logger_path = $xcloner_settings->get_xcloner_store_path().DS.$xcloner_settings->get_logger_filename(); |
|
| 17 | 17 | $logger_path_tmp = ""; |
| 18 | 18 | |
| 19 | - if($hash) |
|
| 19 | + if ($hash) |
|
| 20 | 20 | $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1); |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | $this->logger_path = $logger_path; |
| 24 | 24 | //$this->logger_path_tmp = $logger_path_tmp; |
| 25 | 25 | |
| 26 | - if(!is_dir($xcloner_settings->get_xcloner_store_path()) or !is_writable($xcloner_settings->get_xcloner_store_path())) |
|
| 26 | + if (!is_dir($xcloner_settings->get_xcloner_store_path()) or !is_writable($xcloner_settings->get_xcloner_store_path())) |
|
| 27 | 27 | { |
| 28 | 28 | $logger_path = "php://stderr"; |
| 29 | 29 | $logger_path_tmp = ""; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if(!$xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 32 | + if (!$xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 33 | 33 | { |
| 34 | 34 | $logger_path = "php://stderr"; |
| 35 | 35 | $logger_path_tmp = ""; |
@@ -40,19 +40,19 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | $debug_level = Logger::INFO; |
| 42 | 42 | |
| 43 | - if(WP_DEBUG) |
|
| 43 | + if (WP_DEBUG) |
|
| 44 | 44 | $debug_level = Logger::DEBUG; |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - if($logger_path) |
|
| 47 | + if ($logger_path) |
|
| 48 | 48 | { |
| 49 | 49 | $stream = new RotatingFileHandler($logger_path, $this->max_logger_files, $debug_level); |
| 50 | 50 | $this->pushHandler($stream); |
| 51 | 51 | |
| 52 | - $this->main_logger_url = $stream->getUrl(); |
|
| 52 | + $this->main_logger_url = $stream->getUrl(); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if($hash and $logger_path_tmp) |
|
| 55 | + if ($hash and $logger_path_tmp) |
|
| 56 | 56 | $this->pushHandler(new StreamHandler($logger_path_tmp, $debug_level)); |
| 57 | 57 | |
| 58 | 58 | //return $this; |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $lines = array(); |
| 69 | 69 | |
| 70 | 70 | //if(!file_exists($this->logger_path) or !is_readable($this->logger_path)) |
| 71 | - if(!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) |
|
| 71 | + if (!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) |
|
| 72 | 72 | return false; |
| 73 | 73 | |
| 74 | 74 | //$fp = fopen($this->logger_path, 'r'); |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | $lastLine = ""; |
| 79 | 79 | |
| 80 | 80 | // Loop backword until we have our lines or we reach the start |
| 81 | - while($pos > 0 && count($lines) < $totalLines) { |
|
| 81 | + while ($pos > 0 && count($lines) < $totalLines) { |
|
| 82 | 82 | |
| 83 | 83 | $C = fgetc($fp); |
| 84 | - if($C == "\n") { |
|
| 84 | + if ($C == "\n") { |
|
| 85 | 85 | // skip empty lines |
| 86 | - if(trim($lastLine) != "") { |
|
| 86 | + if (trim($lastLine) != "") { |
|
| 87 | 87 | $lines[] = $lastLine; |
| 88 | 88 | } |
| 89 | 89 | $lastLine = ''; |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | $logger_path = $xcloner_settings->get_xcloner_store_path().DS.$xcloner_settings->get_logger_filename(); |
| 17 | 17 | $logger_path_tmp = ""; |
| 18 | 18 | |
| 19 | - if($hash) |
|
| 20 | - $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1); |
|
| 19 | + if($hash) { |
|
| 20 | + $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1); |
|
| 21 | + } |
|
| 21 | 22 | |
| 22 | 23 | |
| 23 | 24 | $this->logger_path = $logger_path; |
@@ -40,8 +41,9 @@ discard block |
||
| 40 | 41 | |
| 41 | 42 | $debug_level = Logger::INFO; |
| 42 | 43 | |
| 43 | - if(WP_DEBUG) |
|
| 44 | - $debug_level = Logger::DEBUG; |
|
| 44 | + if(WP_DEBUG) { |
|
| 45 | + $debug_level = Logger::DEBUG; |
|
| 46 | + } |
|
| 45 | 47 | |
| 46 | 48 | |
| 47 | 49 | if($logger_path) |
@@ -52,8 +54,9 @@ discard block |
||
| 52 | 54 | $this->main_logger_url = $stream->getUrl(); |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | - if($hash and $logger_path_tmp) |
|
| 56 | - $this->pushHandler(new StreamHandler($logger_path_tmp, $debug_level)); |
|
| 57 | + if($hash and $logger_path_tmp) { |
|
| 58 | + $this->pushHandler(new StreamHandler($logger_path_tmp, $debug_level)); |
|
| 59 | + } |
|
| 57 | 60 | |
| 58 | 61 | //return $this; |
| 59 | 62 | } |
@@ -68,8 +71,9 @@ discard block |
||
| 68 | 71 | $lines = array(); |
| 69 | 72 | |
| 70 | 73 | //if(!file_exists($this->logger_path) or !is_readable($this->logger_path)) |
| 71 | - if(!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) |
|
| 72 | - return false; |
|
| 74 | + if(!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 73 | 77 | |
| 74 | 78 | //$fp = fopen($this->logger_path, 'r'); |
| 75 | 79 | $fp = fopen($this->main_logger_url, 'r'); |
@@ -55,19 +55,19 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function xcloner_backup_add_admin_menu() |
| 57 | 57 | { |
| 58 | - if ( function_exists('add_menu_page') ) |
|
| 59 | - add_menu_page( __('Site Backup','xcloner-backup-and-restore'), __('Site Backup','xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page', 'xcloner_display', 'dashicons-backup'); |
|
| 58 | + if (function_exists('add_menu_page')) |
|
| 59 | + add_menu_page(__('Site Backup', 'xcloner-backup-and-restore'), __('Site Backup', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page', 'xcloner_display', 'dashicons-backup'); |
|
| 60 | 60 | |
| 61 | - if ( function_exists('add_submenu_page') ) |
|
| 61 | + if (function_exists('add_submenu_page')) |
|
| 62 | 62 | { |
| 63 | 63 | |
| 64 | - add_submenu_page( 'xcloner_init_page', __('XCloner Dashboard','xcloner-backup-and-restore'), __('Dashboard','xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page', 'xcloner_display'); |
|
| 65 | - add_submenu_page( 'xcloner_init_page', __('XCloner Backup Settings','xcloner-backup-and-restore'), __('Settings','xcloner-backup-and-restore'), 'manage_options', 'xcloner_settings_page', 'xcloner_display'); |
|
| 66 | - add_submenu_page( 'xcloner_init_page', __('Remote Storage Settings','xcloner-backup-and-restore'), __('Remote Storage','xcloner-backup-and-restore'), 'manage_options', 'xcloner_remote_storage_page', 'xcloner_display'); |
|
| 67 | - add_submenu_page( 'xcloner_init_page', __('Manage Backups','xcloner-backup-and-restore'), __('Manage Backups','xcloner-backup-and-restore'), 'manage_options', 'xcloner_manage_backups_page', 'xcloner_display'); |
|
| 68 | - add_submenu_page( 'xcloner_init_page', __('Scheduled Backups','xcloner-backup-and-restore'), __('Scheduled Backups','xcloner-backup-and-restore'), 'manage_options', 'xcloner_scheduled_backups_page', 'xcloner_display'); |
|
| 69 | - add_submenu_page( 'xcloner_init_page', __('Generate Backups','xcloner-backup-and-restore'), __('Generate Backups','xcloner-backup-and-restore'), 'manage_options', 'xcloner_generate_backups_page', 'xcloner_display'); |
|
| 70 | - add_submenu_page( 'xcloner_init_page', __('Restore Backups','xcloner-backup-and-restore'), __('Restore Backups','xcloner-backup-and-restore'), 'manage_options', 'xcloner_restore_page', 'xcloner_display'); |
|
| 64 | + add_submenu_page('xcloner_init_page', __('XCloner Dashboard', 'xcloner-backup-and-restore'), __('Dashboard', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page', 'xcloner_display'); |
|
| 65 | + add_submenu_page('xcloner_init_page', __('XCloner Backup Settings', 'xcloner-backup-and-restore'), __('Settings', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_settings_page', 'xcloner_display'); |
|
| 66 | + add_submenu_page('xcloner_init_page', __('Remote Storage Settings', 'xcloner-backup-and-restore'), __('Remote Storage', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_remote_storage_page', 'xcloner_display'); |
|
| 67 | + add_submenu_page('xcloner_init_page', __('Manage Backups', 'xcloner-backup-and-restore'), __('Manage Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_manage_backups_page', 'xcloner_display'); |
|
| 68 | + add_submenu_page('xcloner_init_page', __('Scheduled Backups', 'xcloner-backup-and-restore'), __('Scheduled Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_scheduled_backups_page', 'xcloner_display'); |
|
| 69 | + add_submenu_page('xcloner_init_page', __('Generate Backups', 'xcloner-backup-and-restore'), __('Generate Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_generate_backups_page', 'xcloner_display'); |
|
| 70 | + add_submenu_page('xcloner_init_page', __('Restore Backups', 'xcloner-backup-and-restore'), __('Restore Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_restore_page', 'xcloner_display'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | } |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
| 83 | 83 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
| 84 | 84 | */ |
| 85 | - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 86 | - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 85 | + public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) { |
|
| 86 | + $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
| 97 | 97 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
| 98 | 98 | */ |
| 99 | - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 100 | - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 99 | + public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) { |
|
| 100 | + $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @param int $accepted_args The number of arguments that should be passed to the $callback. |
| 115 | 115 | * @return array The collection of actions and filters registered with WordPress. |
| 116 | 116 | */ |
| 117 | - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
|
| 117 | + private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) { |
|
| 118 | 118 | |
| 119 | 119 | $hooks[] = array( |
| 120 | 120 | 'hook' => $hook, |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function run() { |
| 137 | 137 | |
| 138 | - foreach ( $this->filters as $hook ) { |
|
| 139 | - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 138 | + foreach ($this->filters as $hook) { |
|
| 139 | + add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - foreach ( $this->actions as $hook ) { |
|
| 143 | - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 142 | + foreach ($this->actions as $hook) { |
|
| 143 | + add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | } |
@@ -55,8 +55,9 @@ |
||
| 55 | 55 | |
| 56 | 56 | public function xcloner_backup_add_admin_menu() |
| 57 | 57 | { |
| 58 | - if ( function_exists('add_menu_page') ) |
|
| 59 | - add_menu_page( __('Site Backup','xcloner-backup-and-restore'), __('Site Backup','xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page', 'xcloner_display', 'dashicons-backup'); |
|
| 58 | + if ( function_exists('add_menu_page') ) { |
|
| 59 | + add_menu_page( __('Site Backup','xcloner-backup-and-restore'), __('Site Backup','xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page', 'xcloner_display', 'dashicons-backup'); |
|
| 60 | + } |
|
| 60 | 61 | |
| 61 | 62 | if ( function_exists('add_submenu_page') ) |
| 62 | 63 | { |