@@ -2,13 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | use League\Flysystem\Config; |
| 4 | 4 | use League\Flysystem\Filesystem; |
| 5 | -use League\Flysystem\Util; |
|
| 6 | 5 | use League\Flysystem\Adapter\Local; |
| 7 | - |
|
| 8 | 6 | use splitbrain\PHPArchive\Tar; |
| 9 | -use splitbrain\PHPArchive\Zip; |
|
| 10 | -use splitbrain\PHPArchive\Archive; |
|
| 11 | -use splitbrain\PHPArchive\FileInfo; |
|
| 12 | 7 | |
| 13 | 8 | |
| 14 | 9 | class Xcloner_Api{ |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | $scheduler->update_cron_hook($_POST['id']); |
| 201 | 201 | |
| 202 | 202 | if( $wpdb->last_error ) { |
| 203 | - $response['error'] = 1; |
|
| 204 | - $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/; |
|
| 203 | + $response['error'] = 1; |
|
| 204 | + $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/; |
|
| 205 | 205 | |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - $scheduler->update_wp_cron_hooks(); |
|
| 208 | + $scheduler->update_wp_cron_hooks(); |
|
| 209 | 209 | $response['finished'] = 1; |
| 210 | 210 | |
| 211 | 211 | $this->send_response($response); |
@@ -851,14 +851,14 @@ discard block |
||
| 851 | 851 | $tar->close(); |
| 852 | 852 | |
| 853 | 853 | if (file_exists($tmp_file)) { |
| 854 | - header('Content-Description: File Transfer'); |
|
| 855 | - header('Content-Type: application/octet-stream'); |
|
| 856 | - header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"'); |
|
| 857 | - header('Expires: 0'); |
|
| 858 | - header('Cache-Control: must-revalidate'); |
|
| 859 | - header('Pragma: public'); |
|
| 860 | - header('Content-Length: ' . filesize($tmp_file)); |
|
| 861 | - readfile($tmp_file); |
|
| 854 | + header('Content-Description: File Transfer'); |
|
| 855 | + header('Content-Type: application/octet-stream'); |
|
| 856 | + header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"'); |
|
| 857 | + header('Expires: 0'); |
|
| 858 | + header('Cache-Control: must-revalidate'); |
|
| 859 | + header('Pragma: public'); |
|
| 860 | + header('Content-Length: ' . filesize($tmp_file)); |
|
| 861 | + readfile($tmp_file); |
|
| 862 | 862 | |
| 863 | 863 | } |
| 864 | 864 | |
@@ -888,25 +888,25 @@ discard block |
||
| 888 | 888 | |
| 889 | 889 | |
| 890 | 890 | header('Pragma: public'); |
| 891 | - header('Expires: 0'); |
|
| 892 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 893 | - header('Cache-Control: private', false); |
|
| 894 | - header('Content-Transfer-Encoding: binary'); |
|
| 895 | - header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
|
| 896 | - //header('Content-Type: ' . $mimetype); |
|
| 897 | - header('Content-Type: application/octet-stream'); |
|
| 898 | - header('Content-Length: ' . $metadata['size']); |
|
| 891 | + header('Expires: 0'); |
|
| 892 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
| 893 | + header('Cache-Control: private', false); |
|
| 894 | + header('Content-Transfer-Encoding: binary'); |
|
| 895 | + header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
|
| 896 | + //header('Content-Type: ' . $mimetype); |
|
| 897 | + header('Content-Type: application/octet-stream'); |
|
| 898 | + header('Content-Length: ' . $metadata['size']); |
|
| 899 | 899 | |
| 900 | - @ob_end_clean(); |
|
| 900 | + @ob_end_clean(); |
|
| 901 | 901 | |
| 902 | - $chunkSize = 1024 * 1024; |
|
| 903 | - while (!feof($read_stream)) |
|
| 904 | - { |
|
| 905 | - $buffer = fread($read_stream, $chunkSize); |
|
| 906 | - echo $buffer; |
|
| 907 | - } |
|
| 908 | - fclose($read_stream); |
|
| 909 | - exit; |
|
| 902 | + $chunkSize = 1024 * 1024; |
|
| 903 | + while (!feof($read_stream)) |
|
| 904 | + { |
|
| 905 | + $buffer = fread($read_stream, $chunkSize); |
|
| 906 | + echo $buffer; |
|
| 907 | + } |
|
| 908 | + fclose($read_stream); |
|
| 909 | + exit; |
|
| 910 | 910 | |
| 911 | 911 | } |
| 912 | 912 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | use splitbrain\PHPArchive\FileInfo; |
| 12 | 12 | |
| 13 | 13 | |
| 14 | -class Xcloner_Api{ |
|
| 14 | +class Xcloner_Api { |
|
| 15 | 15 | |
| 16 | 16 | private $xcloner_database; |
| 17 | 17 | private $xcloner_settings; |
@@ -27,33 +27,33 @@ discard block |
||
| 27 | 27 | global $wpdb; |
| 28 | 28 | |
| 29 | 29 | error_reporting(0); |
| 30 | - if( ob_get_length() ) |
|
| 30 | + if (ob_get_length()) |
|
| 31 | 31 | ob_end_clean(); |
| 32 | 32 | ob_start(); |
| 33 | 33 | |
| 34 | - $wpdb->show_errors = false; |
|
| 34 | + $wpdb->show_errors = false; |
|
| 35 | 35 | |
| 36 | - $this->xcloner_settings = new Xcloner_Settings(); |
|
| 36 | + $this->xcloner_settings = new Xcloner_Settings(); |
|
| 37 | 37 | |
| 38 | 38 | //generating the hash suffix for tmp xcloner store folder |
| 39 | - if(isset($_POST['hash'])){ |
|
| 39 | + if (isset($_POST['hash'])) { |
|
| 40 | 40 | |
| 41 | - if($_POST['hash'] == "generate_hash") |
|
| 41 | + if ($_POST['hash'] == "generate_hash") |
|
| 42 | 42 | $this->xcloner_settings->generate_new_hash(); |
| 43 | 43 | else |
| 44 | 44 | $this->xcloner_settings->set_hash($_POST['hash']); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - $this->logger = new XCloner_Logger("xcloner_api", $this->xcloner_settings->get_hash()); |
|
| 47 | + $this->logger = new XCloner_Logger("xcloner_api", $this->xcloner_settings->get_hash()); |
|
| 48 | 48 | $this->xcloner_file_system = new Xcloner_File_System($this->xcloner_settings->get_hash()); |
| 49 | 49 | $this->xcloner_sanitization = new Xcloner_Sanitization(); |
| 50 | 50 | $this->xcloner_requirements = new XCloner_Requirements(); |
| 51 | - $this->archive_system = new Xcloner_Archive($this->xcloner_settings->get_hash()); |
|
| 52 | - $this->xcloner_database = new XCloner_Database($this->xcloner_settings->get_hash()); |
|
| 51 | + $this->archive_system = new Xcloner_Archive($this->xcloner_settings->get_hash()); |
|
| 52 | + $this->xcloner_database = new XCloner_Database($this->xcloner_settings->get_hash()); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - if(isset($_POST['API_ID'])){ |
|
| 56 | - $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0 , 15)); |
|
| 55 | + if (isset($_POST['API_ID'])) { |
|
| 56 | + $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0, 15)); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } |
@@ -69,16 +69,16 @@ discard block |
||
| 69 | 69 | $data['dbDatabase'] = $this->xcloner_settings->get_db_database(); |
| 70 | 70 | |
| 71 | 71 | |
| 72 | - $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
| 73 | - $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
| 74 | - $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
| 72 | + $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
| 73 | + $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
| 74 | + $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
| 75 | 75 | |
| 76 | 76 | try |
| 77 | 77 | { |
| 78 | 78 | //$xcloner_db = new XCloner_Database($data['dbUsername'], $data['dbPassword'], $data['dbDatabase'], $data['dbHostname']); |
| 79 | 79 | $this->xcloner_database->init($data); |
| 80 | 80 | |
| 81 | - }catch(Exception $e) |
|
| 81 | + }catch (Exception $e) |
|
| 82 | 82 | { |
| 83 | 83 | $this->send_response($e->getMessage()); |
| 84 | 84 | $this->logger->error($e->getMessage()); |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | $params = array(); |
| 107 | 107 | $schedule = array(); |
| 108 | 108 | |
| 109 | - if(isset($_POST['data'])) |
|
| 109 | + if (isset($_POST['data'])) |
|
| 110 | 110 | $params = json_decode(stripslashes($_POST['data'])); |
| 111 | 111 | |
| 112 | 112 | $this->process_params($params); |
| 113 | 113 | |
| 114 | - if(isset($_POST['id'])) |
|
| 114 | + if (isset($_POST['id'])) |
|
| 115 | 115 | { |
| 116 | 116 | |
| 117 | 117 | $this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']); |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | $tables = explode(PHP_EOL, $this->form_params['database']); |
| 127 | 127 | $return = array(); |
| 128 | 128 | |
| 129 | - foreach($tables as $table) |
|
| 129 | + foreach ($tables as $table) |
|
| 130 | 130 | { |
| 131 | - $table = str_replace("\r","", $table); |
|
| 131 | + $table = str_replace("\r", "", $table); |
|
| 132 | 132 | $data = explode(".", $table); |
| 133 | - if(isset($data[1])) |
|
| 133 | + if (isset($data[1])) |
|
| 134 | 134 | $return[$data[0]][] = $data[1]; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | $excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']); |
| 140 | 140 | $return = array(); |
| 141 | 141 | |
| 142 | - foreach($excluded_files as $file) |
|
| 142 | + foreach ($excluded_files as $file) |
|
| 143 | 143 | { |
| 144 | - $file = str_replace("\r","", $file); |
|
| 145 | - if($file) |
|
| 144 | + $file = str_replace("\r", "", $file); |
|
| 145 | + if ($file) |
|
| 146 | 146 | $return[] = $file; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -151,20 +151,20 @@ discard block |
||
| 151 | 151 | //print_r($this->form_params['database'] ); |
| 152 | 152 | //print_r($this->form_params['excluded_files']); |
| 153 | 153 | |
| 154 | - $schedule['start_at'] = $this->form_params['backup_params']['start_at'] ; |
|
| 154 | + $schedule['start_at'] = $this->form_params['backup_params']['start_at']; |
|
| 155 | 155 | |
| 156 | - if(!isset($_POST['status'])) |
|
| 156 | + if (!isset($_POST['status'])) |
|
| 157 | 157 | $schedule['status'] = 0; |
| 158 | 158 | else |
| 159 | 159 | $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
| 160 | - }else{ |
|
| 160 | + } else { |
|
| 161 | 161 | |
| 162 | 162 | $schedule['status'] = 1; |
| 163 | - $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
|
| 163 | + $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date']. |
|
| 164 | 164 | " ".$this->form_params['backup_params']['schedule_start_time']); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - if(!$schedule['start_at']) |
|
| 167 | + if (!$schedule['start_at']) |
|
| 168 | 168 | $schedule['start_at'] = time(); |
| 169 | 169 | |
| 170 | 170 | $schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at']); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $schedule['params'] = json_encode($this->form_params); |
| 177 | 177 | |
| 178 | - if(!isset($_POST['id'])) |
|
| 178 | + if (!isset($_POST['id'])) |
|
| 179 | 179 | { |
| 180 | 180 | $insert = $wpdb->insert( |
| 181 | 181 | $wpdb->prefix.'xcloner_scheduler', |
@@ -185,21 +185,21 @@ discard block |
||
| 185 | 185 | '%s' |
| 186 | 186 | ) |
| 187 | 187 | ); |
| 188 | - }else { |
|
| 188 | + } else { |
|
| 189 | 189 | $insert = $wpdb->update( |
| 190 | 190 | $wpdb->prefix.'xcloner_scheduler', |
| 191 | 191 | $schedule, |
| 192 | - array( 'id' => $_POST['id'] ), |
|
| 192 | + array('id' => $_POST['id']), |
|
| 193 | 193 | array( |
| 194 | 194 | '%s', |
| 195 | 195 | '%s' |
| 196 | 196 | ) |
| 197 | 197 | ); |
| 198 | 198 | } |
| 199 | - if(isset($_POST['id'])) |
|
| 199 | + if (isset($_POST['id'])) |
|
| 200 | 200 | $scheduler->update_cron_hook($_POST['id']); |
| 201 | 201 | |
| 202 | - if( $wpdb->last_error ) { |
|
| 202 | + if ($wpdb->last_error) { |
|
| 203 | 203 | $response['error'] = 1; |
| 204 | 204 | $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/; |
| 205 | 205 | |
@@ -224,19 +224,19 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | $params = json_decode(stripslashes($_POST['data'])); |
| 226 | 226 | |
| 227 | - $init = (int)$_POST['init']; |
|
| 227 | + $init = (int)$_POST['init']; |
|
| 228 | 228 | |
| 229 | - if($params === NULL) |
|
| 230 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 229 | + if ($params === NULL) |
|
| 230 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
| 231 | 231 | |
| 232 | 232 | $this->process_params($params); |
| 233 | 233 | |
| 234 | 234 | $return['finished'] = 1; |
| 235 | 235 | |
| 236 | 236 | //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
| 237 | - try{ |
|
| 237 | + try { |
|
| 238 | 238 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
| 239 | - }catch(Exception $e) |
|
| 239 | + }catch (Exception $e) |
|
| 240 | 240 | { |
| 241 | 241 | $return = array(); |
| 242 | 242 | $return['error'] = true; |
@@ -245,25 +245,25 @@ discard block |
||
| 245 | 245 | return $this->send_response($return, $hash = 1); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if($return['finished']) |
|
| 248 | + if ($return['finished']) |
|
| 249 | 249 | { |
| 250 | 250 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
| 251 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
| 251 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
| 252 | 252 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | $data = $return; |
| 256 | 256 | |
| 257 | 257 | //check if backup is finished |
| 258 | - if($return['finished'] ) |
|
| 258 | + if ($return['finished']) |
|
| 259 | 259 | { |
| 260 | - if(isset($this->form_params['backup_params']['email_notification']) and $to=$this->form_params['backup_params']['email_notification']) |
|
| 260 | + if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) |
|
| 261 | 261 | { |
| 262 | - try{ |
|
| 262 | + try { |
|
| 263 | 263 | $from = ""; |
| 264 | 264 | $subject = ""; |
| 265 | 265 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params); |
| 266 | - }catch(Exception $e) |
|
| 266 | + }catch (Exception $e) |
|
| 267 | 267 | { |
| 268 | 268 | $this->logger->error($e->getMessage()); |
| 269 | 269 | } |
@@ -287,17 +287,17 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | $params = json_decode(stripslashes($_POST['data'])); |
| 289 | 289 | |
| 290 | - $init = (int)$_POST['init']; |
|
| 290 | + $init = (int)$_POST['init']; |
|
| 291 | 291 | |
| 292 | - if($params === NULL) |
|
| 293 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 292 | + if ($params === NULL) |
|
| 293 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
| 294 | 294 | |
| 295 | 295 | $this->process_params($params); |
| 296 | 296 | |
| 297 | 297 | //$xcloner_database = $this->init_db(); |
| 298 | 298 | $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init); |
| 299 | 299 | |
| 300 | - if(isset($return['error']) and $return['error']) |
|
| 300 | + if (isset($return['error']) and $return['error']) |
|
| 301 | 301 | $data['finished'] = 1; |
| 302 | 302 | else |
| 303 | 303 | $data['finished'] = $return['finished']; |
@@ -319,10 +319,10 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | $params = json_decode(stripslashes($_POST['data'])); |
| 322 | - $init = (int)$_POST['init']; |
|
| 322 | + $init = (int)$_POST['init']; |
|
| 323 | 323 | |
| 324 | - if($params === NULL) |
|
| 325 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 324 | + if ($params === NULL) |
|
| 325 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
| 326 | 326 | |
| 327 | 327 | $hash = $this->process_params($params); |
| 328 | 328 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $data["finished"] = !$return; |
| 334 | 334 | $data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num(); |
| 335 | 335 | $data["last_logged_file"] = $this->xcloner_file_system->last_logged_file(); |
| 336 | - $data["total_files_size"] = sprintf("%.2f",$this->xcloner_file_system->get_scanned_files_total_size()/(1024*1024)); |
|
| 336 | + $data["total_files_size"] = sprintf("%.2f", $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024)); |
|
| 337 | 337 | |
| 338 | 338 | return $this->send_response($data, $hash = 1); |
| 339 | 339 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | private function process_params($params) |
| 347 | 347 | { |
| 348 | - if(isset($params->hash)) |
|
| 348 | + if (isset($params->hash)) |
|
| 349 | 349 | $this->xcloner_settings->set_hash($params->hash); |
| 350 | 350 | |
| 351 | 351 | $this->form_params['extra'] = array(); |
@@ -353,9 +353,9 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | $this->form_params['database'] = array(); |
| 355 | 355 | |
| 356 | - if(isset($params->backup_params)) |
|
| 356 | + if (isset($params->backup_params)) |
|
| 357 | 357 | { |
| 358 | - foreach($params->backup_params as $param) |
|
| 358 | + foreach ($params->backup_params as $param) |
|
| 359 | 359 | { |
| 360 | 360 | $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value); |
| 361 | 361 | $this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array('POST', 'fields filter')); |
@@ -364,28 +364,28 @@ discard block |
||
| 364 | 364 | |
| 365 | 365 | $this->form_params['database'] = array(); |
| 366 | 366 | |
| 367 | - if(isset($params->table_params)) |
|
| 367 | + if (isset($params->table_params)) |
|
| 368 | 368 | { |
| 369 | - foreach($params->table_params as $param) |
|
| 369 | + foreach ($params->table_params as $param) |
|
| 370 | 370 | { |
| 371 | 371 | $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id); |
| 372 | 372 | $this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array('POST', 'database filter')); |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - $this->form_params['excluded_files'] = array(); |
|
| 377 | - if(isset($params->files_params)) |
|
| 376 | + $this->form_params['excluded_files'] = array(); |
|
| 377 | + if (isset($params->files_params)) |
|
| 378 | 378 | { |
| 379 | - foreach($params->files_params as $param) |
|
| 379 | + foreach ($params->files_params as $param) |
|
| 380 | 380 | { |
| 381 | 381 | $this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | $unique_exclude_files = array(); |
| 385 | 385 | |
| 386 | - foreach($params->files_params as $key=>$param) |
|
| 386 | + foreach ($params->files_params as $key=>$param) |
|
| 387 | 387 | { |
| 388 | - if(!in_array($param->parent, $this->form_params['excluded_files'])){ |
|
| 388 | + if (!in_array($param->parent, $this->form_params['excluded_files'])) { |
|
| 389 | 389 | //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
| 390 | 390 | $unique_exclude_files[] = $param->id; |
| 391 | 391 | $this->logger->debug("Adding file filter ".$param->id."\n", array('POST', 'exclude files filter')); |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | |
| 398 | 398 | //$this->form_params['excluded_files'] = array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default); |
| 399 | 399 | |
| 400 | - if(isset($params->extra)) |
|
| 400 | + if (isset($params->extra)) |
|
| 401 | 401 | { |
| 402 | - foreach($params->extra as $key=>$value) |
|
| 402 | + foreach ($params->extra as $key=>$value) |
|
| 403 | 403 | $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | |
| 422 | 422 | $data = array(); |
| 423 | 423 | |
| 424 | - if($folder == "#"){ |
|
| 424 | + if ($folder == "#") { |
|
| 425 | 425 | |
| 426 | 426 | $folder = "/"; |
| 427 | 427 | //$list_directory = $this->xcloner_settings->get_xcloner_start_path(); |
@@ -435,9 +435,9 @@ discard block |
||
| 435 | 435 | ); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - try{ |
|
| 438 | + try { |
|
| 439 | 439 | $files = $this->xcloner_file_system->list_directory($folder); |
| 440 | - }catch(Exception $e){ |
|
| 440 | + }catch (Exception $e) { |
|
| 441 | 441 | |
| 442 | 442 | print $e->getMessage(); |
| 443 | 443 | $this->logger->error($e->getMessage()); |
@@ -452,19 +452,19 @@ discard block |
||
| 452 | 452 | } |
| 453 | 453 | array_multisort($type, SORT_ASC, $files); |
| 454 | 454 | |
| 455 | - foreach($files as $file) |
|
| 455 | + foreach ($files as $file) |
|
| 456 | 456 | { |
| 457 | 457 | $children = false; |
| 458 | 458 | $text = $file['basename']; |
| 459 | 459 | |
| 460 | - if($file['type'] == "dir") |
|
| 460 | + if ($file['type'] == "dir") |
|
| 461 | 461 | $children = true; |
| 462 | 462 | else |
| 463 | - $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
| 463 | + $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")"; |
|
| 464 | 464 | |
| 465 | 465 | //if(in_array($file['path'], $this->xcloner_file_system->get_excluded_files())) |
| 466 | 466 | //echo $file['path']."--".$this->xcloner_file_system->is_excluded($file); |
| 467 | - if($excluded_pattern = $this->xcloner_file_system->is_excluded($file)) |
|
| 467 | + if ($excluded_pattern = $this->xcloner_file_system->is_excluded($file)) |
|
| 468 | 468 | $selected = true; |
| 469 | 469 | else |
| 470 | 470 | $selected = false; |
@@ -501,25 +501,25 @@ discard block |
||
| 501 | 501 | |
| 502 | 502 | $xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables'); |
| 503 | 503 | |
| 504 | - if($database == "#") |
|
| 504 | + if ($database == "#") |
|
| 505 | 505 | { |
| 506 | - try{ |
|
| 506 | + try { |
|
| 507 | 507 | $return = $this->xcloner_database->get_all_databases(); |
| 508 | - }catch(Exception $e){ |
|
| 508 | + }catch (Exception $e) { |
|
| 509 | 509 | $this->logger->error($e->getMessage()); |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - foreach($return as $database) |
|
| 512 | + foreach ($return as $database) |
|
| 513 | 513 | { |
| 514 | - if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
| 514 | + if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
| 515 | 515 | continue; |
| 516 | 516 | |
| 517 | 517 | $state = array(); |
| 518 | 518 | |
| 519 | - if($database['name'] == $this->xcloner_settings->get_db_database()) |
|
| 519 | + if ($database['name'] == $this->xcloner_settings->get_db_database()) |
|
| 520 | 520 | { |
| 521 | 521 | $state['selected'] = true; |
| 522 | - if($database['num_tables'] < 25) |
|
| 522 | + if ($database['num_tables'] < 25) |
|
| 523 | 523 | $state['opened'] = false; |
| 524 | 524 | } |
| 525 | 525 | |
@@ -535,22 +535,22 @@ discard block |
||
| 535 | 535 | |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - else{ |
|
| 538 | + else { |
|
| 539 | 539 | |
| 540 | - try{ |
|
| 540 | + try { |
|
| 541 | 541 | $return = $this->xcloner_database->list_tables($database, "", 1); |
| 542 | - }catch(Exception $e){ |
|
| 542 | + }catch (Exception $e) { |
|
| 543 | 543 | $this->logger->error($e->getMessage()); |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - foreach($return as $table) |
|
| 546 | + foreach ($return as $table) |
|
| 547 | 547 | { |
| 548 | 548 | $state = array(); |
| 549 | 549 | |
| 550 | - if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
| 550 | + if ($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
| 551 | 551 | continue; |
| 552 | 552 | |
| 553 | - if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
| 553 | + if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
| 554 | 554 | $state = array('selected' => true); |
| 555 | 555 | |
| 556 | 556 | $data[] = array( |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | |
| 581 | 581 | $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
| 582 | 582 | $scheduler = new Xcloner_Scheduler(); |
| 583 | - $data = $scheduler->get_schedule_by_id($schedule_id); |
|
| 583 | + $data = $scheduler->get_schedule_by_id($schedule_id); |
|
| 584 | 584 | |
| 585 | 585 | return $this->send_response($data); |
| 586 | 586 | } |
@@ -597,14 +597,14 @@ discard block |
||
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | $scheduler = new Xcloner_Scheduler(); |
| 600 | - $data = $scheduler->get_scheduler_list(); |
|
| 600 | + $data = $scheduler->get_scheduler_list(); |
|
| 601 | 601 | $return['data'] = array(); |
| 602 | 602 | |
| 603 | - foreach($data as $res) |
|
| 603 | + foreach ($data as $res) |
|
| 604 | 604 | { |
| 605 | 605 | $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
| 606 | 606 | <a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
| 607 | - if($res->status) |
|
| 607 | + if ($res->status) |
|
| 608 | 608 | $status = '<i class="material-icons active status">timer</i>'; |
| 609 | 609 | else |
| 610 | 610 | $status = '<i class="material-icons status inactive">timer_off</i>'; |
@@ -615,14 +615,14 @@ discard block |
||
| 615 | 615 | |
| 616 | 616 | $remote_storage = $res->remote_storage; |
| 617 | 617 | |
| 618 | - if(!$next_run_time >= time()) |
|
| 618 | + if (!$next_run_time >= time()) |
|
| 619 | 619 | $next_run = " "; |
| 620 | 620 | |
| 621 | - if(trim($next_run)) |
|
| 621 | + if (trim($next_run)) |
|
| 622 | 622 | { |
| 623 | 623 | $date_text = $next_run; |
| 624 | 624 | |
| 625 | - if($next_run_time >= time()) |
|
| 625 | + if ($next_run_time >= time()) |
|
| 626 | 626 | $next_run = "in ".human_time_diff($next_run_time, time()); |
| 627 | 627 | else |
| 628 | 628 | $next_run = __("executed", 'xcloner-backup-and-restore'); |
@@ -635,9 +635,9 @@ discard block |
||
| 635 | 635 | $backup_size = ""; |
| 636 | 636 | $backup_time = ""; |
| 637 | 637 | |
| 638 | - if($res->last_backup) |
|
| 638 | + if ($res->last_backup) |
|
| 639 | 639 | { |
| 640 | - if( $this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) |
|
| 640 | + if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) |
|
| 641 | 641 | { |
| 642 | 642 | $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup); |
| 643 | 643 | $backup_size = size_format($metadata['size']); |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | $backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>"; |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $return['data'][] = array($res->id, $res->name, $res->recurrence,/*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action); |
|
| 650 | + $return['data'][] = array($res->id, $res->name, $res->recurrence, /*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | return $this->send_response($return, 0); |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | |
| 667 | 667 | $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
| 668 | 668 | $scheduler = new Xcloner_Scheduler(); |
| 669 | - $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id); |
|
| 669 | + $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id); |
|
| 670 | 670 | |
| 671 | 671 | return $this->send_response($data); |
| 672 | 672 | } |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | |
| 685 | 685 | $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']); |
| 686 | 686 | |
| 687 | - $data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name); |
|
| 687 | + $data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name); |
|
| 688 | 688 | |
| 689 | 689 | return $this->send_response($data); |
| 690 | 690 | } |
@@ -701,32 +701,32 @@ discard block |
||
| 701 | 701 | |
| 702 | 702 | $backup_file = $source_backup_file; |
| 703 | 703 | |
| 704 | - if($this->xcloner_file_system->is_multipart($backup_file)) |
|
| 704 | + if ($this->xcloner_file_system->is_multipart($backup_file)) |
|
| 705 | 705 | { |
| 706 | 706 | $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
| 707 | 707 | $backup_file = $backup_parts[$return['part']]; |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | - try{ |
|
| 710 | + try { |
|
| 711 | 711 | $tar = new Tar(); |
| 712 | 712 | $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
| 713 | 713 | |
| 714 | 714 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
| 715 | - }catch(Exception $e) |
|
| 715 | + }catch (Exception $e) |
|
| 716 | 716 | { |
| 717 | 717 | $return['error'] = true; |
| 718 | 718 | $return['message'] = $e->getMessage(); |
| 719 | 719 | $this->send_response($return, 0); |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | - $return['files'] = array(); |
|
| 723 | - $return['finished'] = 1; |
|
| 724 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
| 722 | + $return['files'] = array(); |
|
| 723 | + $return['finished'] = 1; |
|
| 724 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
| 725 | 725 | $i = 0; |
| 726 | 726 | |
| 727 | - if(isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
| 727 | + if (isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
| 728 | 728 | { |
| 729 | - foreach($data['extracted_files'] as $file) |
|
| 729 | + foreach ($data['extracted_files'] as $file) |
|
| 730 | 730 | { |
| 731 | 731 | $return['files'][$i]['path'] = $file->getPath(); |
| 732 | 732 | $return['files'][$i]['size'] = $file->getSize(); |
@@ -736,18 +736,18 @@ discard block |
||
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - if(isset($data['start'])) |
|
| 739 | + if (isset($data['start'])) |
|
| 740 | 740 | { |
| 741 | 741 | $return['start'] = $data['start']; |
| 742 | 742 | $return['finished'] = 0; |
| 743 | - }else{ |
|
| 744 | - if($this->xcloner_file_system->is_multipart($source_backup_file)) |
|
| 743 | + } else { |
|
| 744 | + if ($this->xcloner_file_system->is_multipart($source_backup_file)) |
|
| 745 | 745 | { |
| 746 | 746 | $return['start'] = 0; |
| 747 | 747 | |
| 748 | 748 | ++$return['part']; |
| 749 | 749 | |
| 750 | - if($return['part'] < sizeof($backup_parts)) |
|
| 750 | + if ($return['part'] < sizeof($backup_parts)) |
|
| 751 | 751 | $return['finished'] = 0; |
| 752 | 752 | |
| 753 | 753 | } |
@@ -776,17 +776,17 @@ discard block |
||
| 776 | 776 | |
| 777 | 777 | try |
| 778 | 778 | { |
| 779 | - if(method_exists($xcloner_remote_storage, "upload_backup_to_storage")) |
|
| 779 | + if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) |
|
| 780 | 780 | { |
| 781 | 781 | $return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type)); |
| 782 | 782 | } |
| 783 | - }catch(Exception $e){ |
|
| 783 | + }catch (Exception $e) { |
|
| 784 | 784 | |
| 785 | 785 | $return['error'] = 1; |
| 786 | 786 | $return['message'] = $e->getMessage(); |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | - if(!$return) |
|
| 789 | + if (!$return) |
|
| 790 | 790 | { |
| 791 | 791 | $return['error'] = 1; |
| 792 | 792 | $return['message'] = "Upload failed, please check the error log for more information!"; |
@@ -824,7 +824,7 @@ discard block |
||
| 824 | 824 | |
| 825 | 825 | @ob_end_clean(); |
| 826 | 826 | |
| 827 | - $adapter = new Local(dirname(__DIR__) ,LOCK_EX, 'SKIP_LINKS'); |
|
| 827 | + $adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS'); |
|
| 828 | 828 | $xcloner_plugin_filesystem = new Filesystem($adapter, new Config([ |
| 829 | 829 | 'disable_asserts' => true, |
| 830 | 830 | ])); |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz"); |
| 839 | 839 | |
| 840 | 840 | $files = $xcloner_plugin_filesystem->listContents("vendor/", true); |
| 841 | - foreach($files as $file) |
|
| 841 | + foreach ($files as $file) |
|
| 842 | 842 | { |
| 843 | 843 | $tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']); |
| 844 | 844 | } |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | header('Expires: 0'); |
| 858 | 858 | header('Cache-Control: must-revalidate'); |
| 859 | 859 | header('Pragma: public'); |
| 860 | - header('Content-Length: ' . filesize($tmp_file)); |
|
| 860 | + header('Content-Length: '.filesize($tmp_file)); |
|
| 861 | 861 | readfile($tmp_file); |
| 862 | 862 | |
| 863 | 863 | } |
@@ -882,9 +882,9 @@ discard block |
||
| 882 | 882 | $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']); |
| 883 | 883 | |
| 884 | 884 | |
| 885 | - $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name); |
|
| 885 | + $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name); |
|
| 886 | 886 | //$mimetype = $this->xcloner_file_system->get_storage_filesystem()->getMimetype($backup_name); |
| 887 | - $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name); |
|
| 887 | + $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name); |
|
| 888 | 888 | |
| 889 | 889 | |
| 890 | 890 | header('Pragma: public'); |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
| 896 | 896 | //header('Content-Type: ' . $mimetype); |
| 897 | 897 | header('Content-Type: application/octet-stream'); |
| 898 | - header('Content-Length: ' . $metadata['size']); |
|
| 898 | + header('Content-Length: '.$metadata['size']); |
|
| 899 | 899 | |
| 900 | 900 | @ob_end_clean(); |
| 901 | 901 | |
@@ -925,10 +925,10 @@ discard block |
||
| 925 | 925 | $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
| 926 | 926 | $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); |
| 927 | 927 | |
| 928 | - if(isset($_POST['part'])) |
|
| 928 | + if (isset($_POST['part'])) |
|
| 929 | 929 | $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
| 930 | 930 | |
| 931 | - if(isset($_POST['uploaded_size'])) |
|
| 931 | + if (isset($_POST['uploaded_size'])) |
|
| 932 | 932 | $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
| 933 | 933 | |
| 934 | 934 | $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); |
@@ -936,46 +936,46 @@ discard block |
||
| 936 | 936 | |
| 937 | 937 | $return['total_size'] = $this->xcloner_file_system->get_backup_size($file); |
| 938 | 938 | |
| 939 | - if($this->xcloner_file_system->is_multipart($file)) |
|
| 939 | + if ($this->xcloner_file_system->is_multipart($file)) |
|
| 940 | 940 | { |
| 941 | 941 | $backup_parts = $this->xcloner_file_system->get_multipart_files($file); |
| 942 | 942 | |
| 943 | - $return['total_parts'] = sizeof($backup_parts)+1; |
|
| 943 | + $return['total_parts'] = sizeof($backup_parts) + 1; |
|
| 944 | 944 | |
| 945 | - if($return['part'] and isset($backup_parts[$return['part']-1])) |
|
| 945 | + if ($return['part'] and isset($backup_parts[$return['part'] - 1])) |
|
| 946 | 946 | { |
| 947 | - $file = $backup_parts[$return['part']-1]; |
|
| 947 | + $file = $backup_parts[$return['part'] - 1]; |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | $is_multipart = 1; |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | - try{ |
|
| 953 | + try { |
|
| 954 | 954 | |
| 955 | 955 | $xcloner_file_transfer = new Xcloner_File_Transfer(); |
| 956 | 956 | $xcloner_file_transfer->set_target($target_url); |
| 957 | 957 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
| 958 | 958 | |
| 959 | - }catch(Exception $e){ |
|
| 959 | + }catch (Exception $e) { |
|
| 960 | 960 | |
| 961 | 961 | $return = array(); |
| 962 | 962 | $return['error'] = true; |
| 963 | 963 | $return['status'] = 500; |
| 964 | 964 | $return['message'] = "CURL communication error with the restore host. ".$e->getMessage(); |
| 965 | - $this->send_response( $return, 0); |
|
| 965 | + $this->send_response($return, 0); |
|
| 966 | 966 | |
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | $return['status'] = 200; |
| 970 | 970 | |
| 971 | 971 | //we have finished the upload |
| 972 | - if(!$return['start'] and $is_multipart) |
|
| 972 | + if (!$return['start'] and $is_multipart) |
|
| 973 | 973 | { |
| 974 | 974 | $return['part']++; |
| 975 | 975 | $return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file); |
| 976 | 976 | } |
| 977 | 977 | |
| 978 | - $this->send_response( $return, 0); |
|
| 978 | + $this->send_response($return, 0); |
|
| 979 | 979 | } |
| 980 | 980 | /* |
| 981 | 981 | * |
@@ -985,12 +985,12 @@ discard block |
||
| 985 | 985 | private function send_response($data, $attach_hash = 1) |
| 986 | 986 | { |
| 987 | 987 | |
| 988 | - if($attach_hash and null !== $this->xcloner_settings->get_hash()) |
|
| 988 | + if ($attach_hash and null !== $this->xcloner_settings->get_hash()) |
|
| 989 | 989 | { |
| 990 | 990 | $data['hash'] = $this->xcloner_settings->get_hash(); |
| 991 | 991 | } |
| 992 | 992 | |
| 993 | - if( ob_get_length() ) |
|
| 993 | + if (ob_get_length()) |
|
| 994 | 994 | ob_clean(); |
| 995 | 995 | wp_send_json($data); |
| 996 | 996 | |
@@ -27,8 +27,9 @@ discard block |
||
| 27 | 27 | global $wpdb; |
| 28 | 28 | |
| 29 | 29 | error_reporting(0); |
| 30 | - if( ob_get_length() ) |
|
| 31 | - ob_end_clean(); |
|
| 30 | + if( ob_get_length() ) { |
|
| 31 | + ob_end_clean(); |
|
| 32 | + } |
|
| 32 | 33 | ob_start(); |
| 33 | 34 | |
| 34 | 35 | $wpdb->show_errors = false; |
@@ -38,10 +39,11 @@ discard block |
||
| 38 | 39 | //generating the hash suffix for tmp xcloner store folder |
| 39 | 40 | if(isset($_POST['hash'])){ |
| 40 | 41 | |
| 41 | - if($_POST['hash'] == "generate_hash") |
|
| 42 | - $this->xcloner_settings->generate_new_hash(); |
|
| 43 | - else |
|
| 44 | - $this->xcloner_settings->set_hash($_POST['hash']); |
|
| 42 | + if($_POST['hash'] == "generate_hash") { |
|
| 43 | + $this->xcloner_settings->generate_new_hash(); |
|
| 44 | + } else { |
|
| 45 | + $this->xcloner_settings->set_hash($_POST['hash']); |
|
| 46 | + } |
|
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | $this->logger = new XCloner_Logger("xcloner_api", $this->xcloner_settings->get_hash()); |
@@ -78,7 +80,7 @@ discard block |
||
| 78 | 80 | //$xcloner_db = new XCloner_Database($data['dbUsername'], $data['dbPassword'], $data['dbDatabase'], $data['dbHostname']); |
| 79 | 81 | $this->xcloner_database->init($data); |
| 80 | 82 | |
| 81 | - }catch(Exception $e) |
|
| 83 | + } catch(Exception $e) |
|
| 82 | 84 | { |
| 83 | 85 | $this->send_response($e->getMessage()); |
| 84 | 86 | $this->logger->error($e->getMessage()); |
@@ -106,8 +108,9 @@ discard block |
||
| 106 | 108 | $params = array(); |
| 107 | 109 | $schedule = array(); |
| 108 | 110 | |
| 109 | - if(isset($_POST['data'])) |
|
| 110 | - $params = json_decode(stripslashes($_POST['data'])); |
|
| 111 | + if(isset($_POST['data'])) { |
|
| 112 | + $params = json_decode(stripslashes($_POST['data'])); |
|
| 113 | + } |
|
| 111 | 114 | |
| 112 | 115 | $this->process_params($params); |
| 113 | 116 | |
@@ -130,8 +133,9 @@ discard block |
||
| 130 | 133 | { |
| 131 | 134 | $table = str_replace("\r","", $table); |
| 132 | 135 | $data = explode(".", $table); |
| 133 | - if(isset($data[1])) |
|
| 134 | - $return[$data[0]][] = $data[1]; |
|
| 136 | + if(isset($data[1])) { |
|
| 137 | + $return[$data[0]][] = $data[1]; |
|
| 138 | + } |
|
| 135 | 139 | } |
| 136 | 140 | |
| 137 | 141 | $this->form_params['database'] = ($return); |
@@ -142,8 +146,9 @@ discard block |
||
| 142 | 146 | foreach($excluded_files as $file) |
| 143 | 147 | { |
| 144 | 148 | $file = str_replace("\r","", $file); |
| 145 | - if($file) |
|
| 146 | - $return[] = $file; |
|
| 149 | + if($file) { |
|
| 150 | + $return[] = $file; |
|
| 151 | + } |
|
| 147 | 152 | } |
| 148 | 153 | |
| 149 | 154 | $this->form_params['excluded_files'] = ($return); |
@@ -153,19 +158,21 @@ discard block |
||
| 153 | 158 | |
| 154 | 159 | $schedule['start_at'] = $this->form_params['backup_params']['start_at'] ; |
| 155 | 160 | |
| 156 | - if(!isset($_POST['status'])) |
|
| 157 | - $schedule['status'] = 0; |
|
| 158 | - else |
|
| 159 | - $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
|
| 160 | - }else{ |
|
| 161 | + if(!isset($_POST['status'])) { |
|
| 162 | + $schedule['status'] = 0; |
|
| 163 | + } else { |
|
| 164 | + $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
|
| 165 | + } |
|
| 166 | + } else{ |
|
| 161 | 167 | |
| 162 | 168 | $schedule['status'] = 1; |
| 163 | 169 | $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
| 164 | 170 | " ".$this->form_params['backup_params']['schedule_start_time']); |
| 165 | 171 | } |
| 166 | 172 | |
| 167 | - if(!$schedule['start_at']) |
|
| 168 | - $schedule['start_at'] = time(); |
|
| 173 | + if(!$schedule['start_at']) { |
|
| 174 | + $schedule['start_at'] = time(); |
|
| 175 | + } |
|
| 169 | 176 | |
| 170 | 177 | $schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at']); |
| 171 | 178 | |
@@ -185,7 +192,7 @@ discard block |
||
| 185 | 192 | '%s' |
| 186 | 193 | ) |
| 187 | 194 | ); |
| 188 | - }else { |
|
| 195 | + } else { |
|
| 189 | 196 | $insert = $wpdb->update( |
| 190 | 197 | $wpdb->prefix.'xcloner_scheduler', |
| 191 | 198 | $schedule, |
@@ -196,8 +203,9 @@ discard block |
||
| 196 | 203 | ) |
| 197 | 204 | ); |
| 198 | 205 | } |
| 199 | - if(isset($_POST['id'])) |
|
| 200 | - $scheduler->update_cron_hook($_POST['id']); |
|
| 206 | + if(isset($_POST['id'])) { |
|
| 207 | + $scheduler->update_cron_hook($_POST['id']); |
|
| 208 | + } |
|
| 201 | 209 | |
| 202 | 210 | if( $wpdb->last_error ) { |
| 203 | 211 | $response['error'] = 1; |
@@ -226,8 +234,9 @@ discard block |
||
| 226 | 234 | |
| 227 | 235 | $init = (int)$_POST['init']; |
| 228 | 236 | |
| 229 | - if($params === NULL) |
|
| 230 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 237 | + if($params === NULL) { |
|
| 238 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 239 | + } |
|
| 231 | 240 | |
| 232 | 241 | $this->process_params($params); |
| 233 | 242 | |
@@ -236,7 +245,7 @@ discard block |
||
| 236 | 245 | //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
| 237 | 246 | try{ |
| 238 | 247 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
| 239 | - }catch(Exception $e) |
|
| 248 | + } catch(Exception $e) |
|
| 240 | 249 | { |
| 241 | 250 | $return = array(); |
| 242 | 251 | $return['error'] = true; |
@@ -248,8 +257,9 @@ discard block |
||
| 248 | 257 | if($return['finished']) |
| 249 | 258 | { |
| 250 | 259 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
| 251 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
| 252 | - $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
|
| 260 | + if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
| 261 | + $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
|
| 262 | + } |
|
| 253 | 263 | } |
| 254 | 264 | |
| 255 | 265 | $data = $return; |
@@ -263,7 +273,7 @@ discard block |
||
| 263 | 273 | $from = ""; |
| 264 | 274 | $subject = ""; |
| 265 | 275 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params); |
| 266 | - }catch(Exception $e) |
|
| 276 | + } catch(Exception $e) |
|
| 267 | 277 | { |
| 268 | 278 | $this->logger->error($e->getMessage()); |
| 269 | 279 | } |
@@ -289,18 +299,20 @@ discard block |
||
| 289 | 299 | |
| 290 | 300 | $init = (int)$_POST['init']; |
| 291 | 301 | |
| 292 | - if($params === NULL) |
|
| 293 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 302 | + if($params === NULL) { |
|
| 303 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 304 | + } |
|
| 294 | 305 | |
| 295 | 306 | $this->process_params($params); |
| 296 | 307 | |
| 297 | 308 | //$xcloner_database = $this->init_db(); |
| 298 | 309 | $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init); |
| 299 | 310 | |
| 300 | - if(isset($return['error']) and $return['error']) |
|
| 301 | - $data['finished'] = 1; |
|
| 302 | - else |
|
| 303 | - $data['finished'] = $return['finished']; |
|
| 311 | + if(isset($return['error']) and $return['error']) { |
|
| 312 | + $data['finished'] = 1; |
|
| 313 | + } else { |
|
| 314 | + $data['finished'] = $return['finished']; |
|
| 315 | + } |
|
| 304 | 316 | |
| 305 | 317 | $data['extra'] = $return; |
| 306 | 318 | |
@@ -321,8 +333,9 @@ discard block |
||
| 321 | 333 | $params = json_decode(stripslashes($_POST['data'])); |
| 322 | 334 | $init = (int)$_POST['init']; |
| 323 | 335 | |
| 324 | - if($params === NULL) |
|
| 325 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 336 | + if($params === NULL) { |
|
| 337 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 338 | + } |
|
| 326 | 339 | |
| 327 | 340 | $hash = $this->process_params($params); |
| 328 | 341 | |
@@ -345,8 +358,9 @@ discard block |
||
| 345 | 358 | */ |
| 346 | 359 | private function process_params($params) |
| 347 | 360 | { |
| 348 | - if(isset($params->hash)) |
|
| 349 | - $this->xcloner_settings->set_hash($params->hash); |
|
| 361 | + if(isset($params->hash)) { |
|
| 362 | + $this->xcloner_settings->set_hash($params->hash); |
|
| 363 | + } |
|
| 350 | 364 | |
| 351 | 365 | $this->form_params['extra'] = array(); |
| 352 | 366 | $this->form_params['backup_params'] = array(); |
@@ -399,8 +413,9 @@ discard block |
||
| 399 | 413 | |
| 400 | 414 | if(isset($params->extra)) |
| 401 | 415 | { |
| 402 | - foreach($params->extra as $key=>$value) |
|
| 403 | - $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
|
| 416 | + foreach($params->extra as $key=>$value) { |
|
| 417 | + $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
|
| 418 | + } |
|
| 404 | 419 | } |
| 405 | 420 | |
| 406 | 421 | return $this->xcloner_settings->get_hash(); |
@@ -437,7 +452,7 @@ discard block |
||
| 437 | 452 | |
| 438 | 453 | try{ |
| 439 | 454 | $files = $this->xcloner_file_system->list_directory($folder); |
| 440 | - }catch(Exception $e){ |
|
| 455 | + } catch(Exception $e){ |
|
| 441 | 456 | |
| 442 | 457 | print $e->getMessage(); |
| 443 | 458 | $this->logger->error($e->getMessage()); |
@@ -457,17 +472,19 @@ discard block |
||
| 457 | 472 | $children = false; |
| 458 | 473 | $text = $file['basename']; |
| 459 | 474 | |
| 460 | - if($file['type'] == "dir") |
|
| 461 | - $children = true; |
|
| 462 | - else |
|
| 463 | - $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
| 475 | + if($file['type'] == "dir") { |
|
| 476 | + $children = true; |
|
| 477 | + } else { |
|
| 478 | + $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
| 479 | + } |
|
| 464 | 480 | |
| 465 | 481 | //if(in_array($file['path'], $this->xcloner_file_system->get_excluded_files())) |
| 466 | 482 | //echo $file['path']."--".$this->xcloner_file_system->is_excluded($file); |
| 467 | - if($excluded_pattern = $this->xcloner_file_system->is_excluded($file)) |
|
| 468 | - $selected = true; |
|
| 469 | - else |
|
| 470 | - $selected = false; |
|
| 483 | + if($excluded_pattern = $this->xcloner_file_system->is_excluded($file)) { |
|
| 484 | + $selected = true; |
|
| 485 | + } else { |
|
| 486 | + $selected = false; |
|
| 487 | + } |
|
| 471 | 488 | |
| 472 | 489 | $data[] = array( |
| 473 | 490 | 'id' => $file['path'], |
@@ -505,22 +522,24 @@ discard block |
||
| 505 | 522 | { |
| 506 | 523 | try{ |
| 507 | 524 | $return = $this->xcloner_database->get_all_databases(); |
| 508 | - }catch(Exception $e){ |
|
| 525 | + } catch(Exception $e){ |
|
| 509 | 526 | $this->logger->error($e->getMessage()); |
| 510 | 527 | } |
| 511 | 528 | |
| 512 | 529 | foreach($return as $database) |
| 513 | 530 | { |
| 514 | - if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
| 515 | - continue; |
|
| 531 | + if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) { |
|
| 532 | + continue; |
|
| 533 | + } |
|
| 516 | 534 | |
| 517 | 535 | $state = array(); |
| 518 | 536 | |
| 519 | 537 | if($database['name'] == $this->xcloner_settings->get_db_database()) |
| 520 | 538 | { |
| 521 | 539 | $state['selected'] = true; |
| 522 | - if($database['num_tables'] < 25) |
|
| 523 | - $state['opened'] = false; |
|
| 540 | + if($database['num_tables'] < 25) { |
|
| 541 | + $state['opened'] = false; |
|
| 542 | + } |
|
| 524 | 543 | } |
| 525 | 544 | |
| 526 | 545 | $data[] = array( |
@@ -533,13 +552,11 @@ discard block |
||
| 533 | 552 | ); |
| 534 | 553 | } |
| 535 | 554 | |
| 536 | - } |
|
| 537 | - |
|
| 538 | - else{ |
|
| 555 | + } else{ |
|
| 539 | 556 | |
| 540 | 557 | try{ |
| 541 | 558 | $return = $this->xcloner_database->list_tables($database, "", 1); |
| 542 | - }catch(Exception $e){ |
|
| 559 | + } catch(Exception $e){ |
|
| 543 | 560 | $this->logger->error($e->getMessage()); |
| 544 | 561 | } |
| 545 | 562 | |
@@ -547,11 +564,13 @@ discard block |
||
| 547 | 564 | { |
| 548 | 565 | $state = array(); |
| 549 | 566 | |
| 550 | - if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
| 551 | - continue; |
|
| 567 | + if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) { |
|
| 568 | + continue; |
|
| 569 | + } |
|
| 552 | 570 | |
| 553 | - if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
| 554 | - $state = array('selected' => true); |
|
| 571 | + if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) { |
|
| 572 | + $state = array('selected' => true); |
|
| 573 | + } |
|
| 555 | 574 | |
| 556 | 575 | $data[] = array( |
| 557 | 576 | 'id' => $table['name'], |
@@ -604,10 +623,11 @@ discard block |
||
| 604 | 623 | { |
| 605 | 624 | $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
| 606 | 625 | <a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
| 607 | - if($res->status) |
|
| 608 | - $status = '<i class="material-icons active status">timer</i>'; |
|
| 609 | - else |
|
| 610 | - $status = '<i class="material-icons status inactive">timer_off</i>'; |
|
| 626 | + if($res->status) { |
|
| 627 | + $status = '<i class="material-icons active status">timer</i>'; |
|
| 628 | + } else { |
|
| 629 | + $status = '<i class="material-icons status inactive">timer_off</i>'; |
|
| 630 | + } |
|
| 611 | 631 | |
| 612 | 632 | $next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)); |
| 613 | 633 | |
@@ -615,17 +635,19 @@ discard block |
||
| 615 | 635 | |
| 616 | 636 | $remote_storage = $res->remote_storage; |
| 617 | 637 | |
| 618 | - if(!$next_run_time >= time()) |
|
| 619 | - $next_run = " "; |
|
| 638 | + if(!$next_run_time >= time()) { |
|
| 639 | + $next_run = " "; |
|
| 640 | + } |
|
| 620 | 641 | |
| 621 | 642 | if(trim($next_run)) |
| 622 | 643 | { |
| 623 | 644 | $date_text = $next_run; |
| 624 | 645 | |
| 625 | - if($next_run_time >= time()) |
|
| 626 | - $next_run = "in ".human_time_diff($next_run_time, time()); |
|
| 627 | - else |
|
| 628 | - $next_run = __("executed", 'xcloner-backup-and-restore'); |
|
| 646 | + if($next_run_time >= time()) { |
|
| 647 | + $next_run = "in ".human_time_diff($next_run_time, time()); |
|
| 648 | + } else { |
|
| 649 | + $next_run = __("executed", 'xcloner-backup-and-restore'); |
|
| 650 | + } |
|
| 629 | 651 | |
| 630 | 652 | $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>"; |
| 631 | 653 | //$next_run .=" ($date_text)"; |
@@ -712,7 +734,7 @@ discard block |
||
| 712 | 734 | $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
| 713 | 735 | |
| 714 | 736 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
| 715 | - }catch(Exception $e) |
|
| 737 | + } catch(Exception $e) |
|
| 716 | 738 | { |
| 717 | 739 | $return['error'] = true; |
| 718 | 740 | $return['message'] = $e->getMessage(); |
@@ -740,15 +762,16 @@ discard block |
||
| 740 | 762 | { |
| 741 | 763 | $return['start'] = $data['start']; |
| 742 | 764 | $return['finished'] = 0; |
| 743 | - }else{ |
|
| 765 | + } else{ |
|
| 744 | 766 | if($this->xcloner_file_system->is_multipart($source_backup_file)) |
| 745 | 767 | { |
| 746 | 768 | $return['start'] = 0; |
| 747 | 769 | |
| 748 | 770 | ++$return['part']; |
| 749 | 771 | |
| 750 | - if($return['part'] < sizeof($backup_parts)) |
|
| 751 | - $return['finished'] = 0; |
|
| 772 | + if($return['part'] < sizeof($backup_parts)) { |
|
| 773 | + $return['finished'] = 0; |
|
| 774 | + } |
|
| 752 | 775 | |
| 753 | 776 | } |
| 754 | 777 | } |
@@ -780,7 +803,7 @@ discard block |
||
| 780 | 803 | { |
| 781 | 804 | $return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type)); |
| 782 | 805 | } |
| 783 | - }catch(Exception $e){ |
|
| 806 | + } catch(Exception $e){ |
|
| 784 | 807 | |
| 785 | 808 | $return['error'] = 1; |
| 786 | 809 | $return['message'] = $e->getMessage(); |
@@ -925,11 +948,13 @@ discard block |
||
| 925 | 948 | $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
| 926 | 949 | $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); |
| 927 | 950 | |
| 928 | - if(isset($_POST['part'])) |
|
| 929 | - $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
| 951 | + if(isset($_POST['part'])) { |
|
| 952 | + $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
| 953 | + } |
|
| 930 | 954 | |
| 931 | - if(isset($_POST['uploaded_size'])) |
|
| 932 | - $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
|
| 955 | + if(isset($_POST['uploaded_size'])) { |
|
| 956 | + $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
|
| 957 | + } |
|
| 933 | 958 | |
| 934 | 959 | $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); |
| 935 | 960 | $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']); |
@@ -956,7 +981,7 @@ discard block |
||
| 956 | 981 | $xcloner_file_transfer->set_target($target_url); |
| 957 | 982 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
| 958 | 983 | |
| 959 | - }catch(Exception $e){ |
|
| 984 | + } catch(Exception $e){ |
|
| 960 | 985 | |
| 961 | 986 | $return = array(); |
| 962 | 987 | $return['error'] = true; |
@@ -990,8 +1015,9 @@ discard block |
||
| 990 | 1015 | $data['hash'] = $this->xcloner_settings->get_hash(); |
| 991 | 1016 | } |
| 992 | 1017 | |
| 993 | - if( ob_get_length() ) |
|
| 994 | - ob_clean(); |
|
| 1018 | + if( ob_get_length() ) { |
|
| 1019 | + ob_clean(); |
|
| 1020 | + } |
|
| 995 | 1021 | wp_send_json($data); |
| 996 | 1022 | |
| 997 | 1023 | die(); |
@@ -1,6 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | use splitbrain\PHPArchive\Tar; |
| 3 | -use splitbrain\PHPArchive\Archive; |
|
| 4 | 3 | use splitbrain\PHPArchive\FileInfo; |
| 5 | 4 | |
| 6 | 5 | class Xcloner_Archive extends Tar |
@@ -555,15 +555,15 @@ discard block |
||
| 555 | 555 | return array($bytes_wrote, $last_position); |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - /** |
|
| 559 | - * Open a TAR archive and put the file cursor at the end for data appending |
|
| 560 | - * |
|
| 561 | - * If $file is empty, the tar file will be created in memory |
|
| 562 | - * |
|
| 563 | - * @param string $file |
|
| 564 | - * @throws ArchiveIOException |
|
| 565 | - */ |
|
| 566 | - /* |
|
| 558 | + /** |
|
| 559 | + * Open a TAR archive and put the file cursor at the end for data appending |
|
| 560 | + * |
|
| 561 | + * If $file is empty, the tar file will be created in memory |
|
| 562 | + * |
|
| 563 | + * @param string $file |
|
| 564 | + * @throws ArchiveIOException |
|
| 565 | + */ |
|
| 566 | + /* |
|
| 567 | 567 | public function openForAppend($file = '') |
| 568 | 568 | { |
| 569 | 569 | $this->file = $file; |
@@ -593,16 +593,16 @@ discard block |
||
| 593 | 593 | } |
| 594 | 594 | */ |
| 595 | 595 | |
| 596 | - /** |
|
| 597 | - * Append data to a file to the current TAR archive using an existing file in the filesystem |
|
| 598 | - * |
|
| 599 | - * @param string $file path to the original file |
|
| 600 | - * @param int $start starting reading position in file |
|
| 601 | - * @param int $end end position in reading multiple with 512 |
|
| 602 | - * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original |
|
| 603 | - * @throws ArchiveIOException |
|
| 604 | - */ |
|
| 605 | - /* |
|
| 596 | + /** |
|
| 597 | + * Append data to a file to the current TAR archive using an existing file in the filesystem |
|
| 598 | + * |
|
| 599 | + * @param string $file path to the original file |
|
| 600 | + * @param int $start starting reading position in file |
|
| 601 | + * @param int $end end position in reading multiple with 512 |
|
| 602 | + * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original |
|
| 603 | + * @throws ArchiveIOException |
|
| 604 | + */ |
|
| 605 | + /* |
|
| 606 | 606 | * public function appendFileData($file, $fileinfo = '', $start = 0, $limit = 0) |
| 607 | 607 | { |
| 608 | 608 | $end = $start+($limit*512); |
@@ -658,14 +658,14 @@ discard block |
||
| 658 | 658 | return $last_position; |
| 659 | 659 | }*/ |
| 660 | 660 | |
| 661 | - /** |
|
| 662 | - * Adds a file to a TAR archive by appending it's data |
|
| 663 | - * |
|
| 664 | - * @param string $archive name of the archive file |
|
| 665 | - * @param string $file name of the file to read data from |
|
| 666 | - * @param string $start start position from where to start reading data |
|
| 667 | - * @throws ArchiveIOException |
|
| 668 | - */ |
|
| 661 | + /** |
|
| 662 | + * Adds a file to a TAR archive by appending it's data |
|
| 663 | + * |
|
| 664 | + * @param string $archive name of the archive file |
|
| 665 | + * @param string $file name of the file to read data from |
|
| 666 | + * @param string $start start position from where to start reading data |
|
| 667 | + * @throws ArchiveIOException |
|
| 668 | + */ |
|
| 669 | 669 | /*public function addFileToArchive($archive, $file, $start = 0) |
| 670 | 670 | { |
| 671 | 671 | $this->openForAppend($archive); |
@@ -45,6 +45,11 @@ discard block |
||
| 45 | 45 | * Rename backup archive |
| 46 | 46 | * |
| 47 | 47 | */ |
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $old_name |
|
| 51 | + * @param string $new_name |
|
| 52 | + */ |
|
| 48 | 53 | public function rename_archive($old_name, $new_name) |
| 49 | 54 | { |
| 50 | 55 | $this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name)); |
@@ -109,6 +114,10 @@ discard block |
||
| 109 | 114 | * Send notification error by E-Mail |
| 110 | 115 | * |
| 111 | 116 | */ |
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param string $error_message |
|
| 120 | + */ |
|
| 112 | 121 | public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
| 113 | 122 | { |
| 114 | 123 | |
@@ -133,6 +142,11 @@ discard block |
||
| 133 | 142 | * Send backup archive notfication by E-Mail |
| 134 | 143 | * |
| 135 | 144 | */ |
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param string $from |
|
| 148 | + * @param string $subject |
|
| 149 | + */ |
|
| 136 | 150 | public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="") |
| 137 | 151 | { |
| 138 | 152 | if(!$from) |
@@ -205,6 +219,10 @@ discard block |
||
| 205 | 219 | * Incremental Backup method |
| 206 | 220 | * |
| 207 | 221 | */ |
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @param integer $init |
|
| 225 | + */ |
|
| 208 | 226 | public function start_incremental_backup($backup_params, $extra_params, $init) |
| 209 | 227 | { |
| 210 | 228 | $return = array(); |
@@ -413,6 +431,10 @@ discard block |
||
| 413 | 431 | * Write multipart file components |
| 414 | 432 | * |
| 415 | 433 | */ |
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @param string $path |
|
| 437 | + */ |
|
| 416 | 438 | private function write_multipart_file($path) |
| 417 | 439 | { |
| 418 | 440 | $path = $this->get_archive_name_with_extension(); |
@@ -472,6 +494,10 @@ discard block |
||
| 472 | 494 | * Add file to archive |
| 473 | 495 | * |
| 474 | 496 | */ |
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * @param integer $append |
|
| 500 | + */ |
|
| 475 | 501 | public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem) |
| 476 | 502 | { |
| 477 | 503 | |
@@ -8,9 +8,9 @@ discard block |
||
| 8 | 8 | /* |
| 9 | 9 | * bytes |
| 10 | 10 | */ |
| 11 | - private $file_size_per_request_limit = 52428800 ; //50MB = 52428800; 1MB = 1048576 |
|
| 12 | - private $files_to_process_per_request = 250; //block of 512 bytes |
|
| 13 | - private $compression_level = 0; //0-9 , 0 uncompressed |
|
| 11 | + private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576 |
|
| 12 | + private $files_to_process_per_request = 250; //block of 512 bytes |
|
| 13 | + private $compression_level = 0; //0-9 , 0 uncompressed |
|
| 14 | 14 | private $xcloner_split_backup_limit = 2048; //2048MB |
| 15 | 15 | |
| 16 | 16 | private $archive_name; |
@@ -18,25 +18,25 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function __construct($hash = "", $archive_name = "") |
| 20 | 20 | { |
| 21 | - $this->filesystem = new Xcloner_File_System($hash); |
|
| 22 | - $this->logger = new XCloner_Logger('xcloner_archive', $hash); |
|
| 21 | + $this->filesystem = new Xcloner_File_System($hash); |
|
| 22 | + $this->logger = new XCloner_Logger('xcloner_archive', $hash); |
|
| 23 | 23 | $this->xcloner_settings = new Xcloner_Settings($hash); |
| 24 | 24 | |
| 25 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
| 26 | - $this->file_size_per_request_limit = $value*1024*1024; //MB |
|
| 25 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
| 26 | + $this->file_size_per_request_limit = $value * 1024 * 1024; //MB |
|
| 27 | 27 | |
| 28 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
| 28 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
| 29 | 29 | $this->files_to_process_per_request = $value; |
| 30 | 30 | |
| 31 | - if($value = get_option('xcloner_backup_compression_level')) |
|
| 31 | + if ($value = get_option('xcloner_backup_compression_level')) |
|
| 32 | 32 | $this->compression_level = $value; |
| 33 | 33 | |
| 34 | - if($value = get_option('xcloner_split_backup_limit')) |
|
| 34 | + if ($value = get_option('xcloner_split_backup_limit')) |
|
| 35 | 35 | $this->xcloner_split_backup_limit = $value; |
| 36 | 36 | |
| 37 | - $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes |
|
| 37 | + $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes |
|
| 38 | 38 | |
| 39 | - if(isset($archive_name)) |
|
| 39 | + if (isset($archive_name)) |
|
| 40 | 40 | $this->set_archive_name($archive_name); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $this->archive_name = $this->filesystem->process_backup_name($name); |
| 63 | 63 | |
| 64 | - if(isset($part) and $part) |
|
| 64 | + if (isset($part) and $part) |
|
| 65 | 65 | { |
| 66 | - $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
|
| 67 | - if(!stristr($new_name, "-part")) |
|
| 68 | - $new_name = $this->archive_name . "-part".$part; |
|
| 66 | + $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
|
| 67 | + if (!stristr($new_name, "-part")) |
|
| 68 | + $new_name = $this->archive_name."-part".$part; |
|
| 69 | 69 | |
| 70 | 70 | $this->archive_name = $new_name; |
| 71 | 71 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function get_archive_name_multipart() |
| 92 | 92 | { |
| 93 | - $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
| 93 | + $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
| 94 | 94 | return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv"); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
| 113 | 113 | { |
| 114 | 114 | |
| 115 | - $body = $error_message; |
|
| 115 | + $body = $error_message; |
|
| 116 | 116 | |
| 117 | 117 | $this->logger->info(sprintf("Sending backup error notification to %s", $to)); |
| 118 | 118 | |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
| 122 | 122 | |
| 123 | - if($admin_email and $from ) |
|
| 123 | + if ($admin_email and $from) |
|
| 124 | 124 | $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
| 125 | 125 | |
| 126 | - $return = wp_mail( $to, $subject, $body, $headers ); |
|
| 126 | + $return = wp_mail($to, $subject, $body, $headers); |
|
| 127 | 127 | |
| 128 | 128 | return $return; |
| 129 | 129 | } |
@@ -133,47 +133,47 @@ discard block |
||
| 133 | 133 | * Send backup archive notfication by E-Mail |
| 134 | 134 | * |
| 135 | 135 | */ |
| 136 | - public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="") |
|
| 136 | + public function send_notification($to, $from, $subject, $backup_name, $params, $error_message = "") |
|
| 137 | 137 | { |
| 138 | - if(!$from) |
|
| 138 | + if (!$from) |
|
| 139 | 139 | $from = "XCloner Backup"; |
| 140 | 140 | |
| 141 | - if(($error_message)) |
|
| 141 | + if (($error_message)) |
|
| 142 | 142 | { |
| 143 | 143 | return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $params = (array)$params; |
| 147 | 147 | |
| 148 | - if(!$subject) |
|
| 149 | - $subject = sprintf(__("New backup generated %s") ,$backup_name); |
|
| 148 | + if (!$subject) |
|
| 149 | + $subject = sprintf(__("New backup generated %s"), $backup_name); |
|
| 150 | 150 | |
| 151 | 151 | $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
| 152 | 152 | $body .= "<br /><br />"; |
| 153 | 153 | |
| 154 | 154 | $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
| 155 | 155 | |
| 156 | - if(!$backups_counter = sizeof($backup_parts)) |
|
| 156 | + if (!$backups_counter = sizeof($backup_parts)) |
|
| 157 | 157 | $backups_counter = 1; |
| 158 | 158 | |
| 159 | 159 | $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
| 160 | 160 | $body .= "<br />"; |
| 161 | 161 | |
| 162 | - if(sizeof($backup_parts)) |
|
| 162 | + if (sizeof($backup_parts)) |
|
| 163 | 163 | { |
| 164 | - $body .= implode("<br />",$backup_parts); |
|
| 164 | + $body .= implode("<br />", $backup_parts); |
|
| 165 | 165 | $body .= "<br />"; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $body.= "<br />"; |
|
| 168 | + $body .= "<br />"; |
|
| 169 | 169 | |
| 170 | - if(isset($params['backup_params']->backup_comments)) |
|
| 170 | + if (isset($params['backup_params']->backup_comments)) |
|
| 171 | 171 | { |
| 172 | 172 | $body .= __("Backup Comments: ").$params['backup_params']->backup_comments; |
| 173 | 173 | $body .= "<br /><br />"; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 176 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 177 | 177 | $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
| 178 | 178 | |
| 179 | 179 | $attachments = $this->filesystem->get_backup_attachments(); |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $tar = new Tar(); |
| 184 | 184 | $tar->create($attachments_archive); |
| 185 | 185 | |
| 186 | - foreach($attachments as $key => $file) |
|
| 186 | + foreach ($attachments as $key => $file) |
|
| 187 | 187 | { |
| 188 | 188 | $tar->addFile($file, basename($file)); |
| 189 | 189 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>'); |
| 197 | 197 | |
| 198 | - $return = wp_mail( $to, $subject, $body, $headers, array($attachments_archive) ); |
|
| 198 | + $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
|
| 199 | 199 | |
| 200 | 200 | return $return; |
| 201 | 201 | } |
@@ -209,17 +209,17 @@ discard block |
||
| 209 | 209 | { |
| 210 | 210 | $return = array(); |
| 211 | 211 | |
| 212 | - if(!isset($extra_params['backup_part'])) |
|
| 212 | + if (!isset($extra_params['backup_part'])) |
|
| 213 | 213 | $extra_params['backup_part'] = 0; |
| 214 | 214 | |
| 215 | 215 | $return['extra']['backup_part'] = $extra_params['backup_part']; |
| 216 | 216 | |
| 217 | - if(isset( $extra_params['backup_archive_name'])) |
|
| 217 | + if (isset($extra_params['backup_archive_name'])) |
|
| 218 | 218 | $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
| 219 | 219 | else |
| 220 | 220 | $this->set_archive_name($backup_params['backup_name']); |
| 221 | 221 | |
| 222 | - if(!$this->get_archive_name()) |
|
| 222 | + if (!$this->get_archive_name()) |
|
| 223 | 223 | $this->set_archive_name(); |
| 224 | 224 | |
| 225 | 225 | $this->backup_archive = new Tar(); |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
| 229 | 229 | |
| 230 | - if($init) |
|
| 230 | + if ($init) |
|
| 231 | 231 | { |
| 232 | 232 | $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
| 233 | 233 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | $return['extra']['backup_init'] = 1; |
| 237 | 237 | |
| 238 | - }else{ |
|
| 238 | + } else { |
|
| 239 | 239 | $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
| 240 | 240 | |
| 241 | 241 | $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
| 248 | 248 | $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
| 249 | 249 | |
| 250 | - if(!isset($extra_params['start_at_line'])) |
|
| 250 | + if (!isset($extra_params['start_at_line'])) |
|
| 251 | 251 | $extra_params['start_at_line'] = 0; |
| 252 | 252 | |
| 253 | - if(!isset($extra_params['start_at_byte'])) |
|
| 253 | + if (!isset($extra_params['start_at_byte'])) |
|
| 254 | 254 | $extra_params['start_at_byte'] = 0; |
| 255 | 255 | |
| 256 | - if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
|
| 256 | + if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
|
| 257 | 257 | { |
| 258 | 258 | $this->logger->error(sprintf("Missing the includes file handler %s, aborting...", $this->filesystem->get_included_files_handler())); |
| 259 | 259 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | $byte_limit = 0; |
| 281 | 281 | |
| 282 | - while(!$file->eof() and $counter<=$this->files_to_process_per_request) |
|
| 282 | + while (!$file->eof() and $counter <= $this->files_to_process_per_request) |
|
| 283 | 283 | { |
| 284 | 284 | $line = str_getcsv($file->current()); |
| 285 | 285 | |
@@ -287,13 +287,13 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | $start_filesystem = "start_filesystem"; |
| 289 | 289 | |
| 290 | - if(isset($line[4])){ |
|
| 290 | + if (isset($line[4])) { |
|
| 291 | 291 | $start_filesystem = $line[4]; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | //$adapter = $this->filesystem->get_adapter($start_filesystem); |
| 295 | 295 | |
| 296 | - if(!$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) |
|
| 296 | + if (!$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) |
|
| 297 | 297 | { |
| 298 | 298 | $extra_params['start_at_line']++; |
| 299 | 299 | $file->next(); |
@@ -302,35 +302,35 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
| 304 | 304 | |
| 305 | - if(!isset($file_info['size'])) |
|
| 305 | + if (!isset($file_info['size'])) |
|
| 306 | 306 | $file_info['size'] = 0; |
| 307 | 307 | |
| 308 | - if($start_filesystem == "tmp_filesystem") |
|
| 308 | + if ($start_filesystem == "tmp_filesystem") |
|
| 309 | 309 | $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
| 310 | 310 | |
| 311 | - $byte_limit = (int)$this->file_size_per_request_limit/512; |
|
| 311 | + $byte_limit = (int)$this->file_size_per_request_limit / 512; |
|
| 312 | 312 | |
| 313 | 313 | $append = 0; |
| 314 | 314 | |
| 315 | - if($file_info['size'] > $byte_limit*512 or $start_byte) |
|
| 315 | + if ($file_info['size'] > $byte_limit * 512 or $start_byte) |
|
| 316 | 316 | $append = 1; |
| 317 | 317 | |
| 318 | - if(!isset($return['extra']['backup_size'])) |
|
| 319 | - $return['extra']['backup_size'] =0; |
|
| 318 | + if (!isset($return['extra']['backup_size'])) |
|
| 319 | + $return['extra']['backup_size'] = 0; |
|
| 320 | 320 | |
| 321 | 321 | $return['extra']['backup_size'] = $archive_info->getSize(); |
| 322 | 322 | |
| 323 | 323 | $estimated_new_size = $return['extra']['backup_size'] + $file_info['size']; |
| 324 | 324 | |
| 325 | 325 | //we create a new backup part if we reach the Split Achive Limit |
| 326 | - if($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) |
|
| 326 | + if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) |
|
| 327 | 327 | { |
| 328 | - $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",$this->xcloner_split_backup_limit, $estimated_new_size)); |
|
| 328 | + $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", $this->xcloner_split_backup_limit, $estimated_new_size)); |
|
| 329 | 329 | list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']); |
| 330 | 330 | |
| 331 | - if($file_info['size'] > $this->xcloner_split_backup_limit) |
|
| 331 | + if ($file_info['size'] > $this->xcloner_split_backup_limit) |
|
| 332 | 332 | { |
| 333 | - $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file",$file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
| 333 | + $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file", $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
| 334 | 334 | $extra_params['start_at_line']++; |
| 335 | 335 | } |
| 336 | 336 | |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | return $return; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - list($bytes_wrote, $last_position) = $this->add_file_to_archive( $file_info, $start_byte, $byte_limit, $append, $start_filesystem); |
|
| 345 | + list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, $append, $start_filesystem); |
|
| 346 | 346 | $this->processed_size_bytes += $bytes_wrote; |
| 347 | 347 | |
| 348 | 348 | //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n"; |
@@ -350,17 +350,17 @@ discard block |
||
| 350 | 350 | $return['extra']['processed_file_size'] = $file_info['size']; |
| 351 | 351 | $return['extra']['backup_size'] = $archive_info->getSize(); |
| 352 | 352 | |
| 353 | - if($last_position>0){ |
|
| 353 | + if ($last_position > 0) { |
|
| 354 | 354 | $start_byte = $last_position; |
| 355 | 355 | } |
| 356 | - else{ |
|
| 356 | + else { |
|
| 357 | 357 | $extra_params['start_at_line']++; |
| 358 | 358 | $file->next(); |
| 359 | 359 | $start_byte = 0; |
| 360 | 360 | $counter++; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if($this->processed_size_bytes >= $this->file_size_per_request_limit) |
|
| 363 | + if ($this->processed_size_bytes >= $this->file_size_per_request_limit) |
|
| 364 | 364 | { |
| 365 | 365 | clearstatcache(); |
| 366 | 366 | $return['extra']['backup_size'] = $archive_info->getSize(); |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - if(!$file->eof()) |
|
| 376 | + if (!$file->eof()) |
|
| 377 | 377 | { |
| 378 | 378 | clearstatcache(); |
| 379 | 379 | $return['extra']['backup_size'] = $archive_info->getSize(); |
@@ -390,12 +390,12 @@ discard block |
||
| 390 | 390 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
| 391 | 391 | $this->backup_archive->close(); |
| 392 | 392 | |
| 393 | - if($return['extra']['backup_part']) |
|
| 393 | + if ($return['extra']['backup_part']) |
|
| 394 | 394 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
| 395 | 395 | |
| 396 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']-1; |
|
| 396 | + $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1; |
|
| 397 | 397 | |
| 398 | - if(isset($file_info)) |
|
| 398 | + if (isset($file_info)) |
|
| 399 | 399 | { |
| 400 | 400 | $return['extra']['processed_file'] = $file_info['path']; |
| 401 | 401 | $return['extra']['processed_file_size'] = $file_info['size']; |
@@ -437,20 +437,20 @@ discard block |
||
| 437 | 437 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
| 438 | 438 | $this->backup_archive->close(); |
| 439 | 439 | |
| 440 | - if(!$part) |
|
| 440 | + if (!$part) |
|
| 441 | 441 | { |
| 442 | 442 | $old_name = $this->get_archive_name_with_extension(); |
| 443 | 443 | $this->set_archive_name($this->get_archive_name(), ++$part); |
| 444 | 444 | $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
| 445 | 445 | |
| 446 | - if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
| 446 | + if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
| 447 | 447 | $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
| 448 | 448 | |
| 449 | 449 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
| 450 | 450 | |
| 451 | - }else |
|
| 451 | + } else |
|
| 452 | 452 | { |
| 453 | - $this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension())); |
|
| 453 | + $this->logger->info(sprintf("Creating new multipart info file %s", $this->get_archive_name_with_extension())); |
|
| 454 | 454 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
| 455 | 455 | } |
| 456 | 456 | |
@@ -478,10 +478,10 @@ discard block |
||
| 478 | 478 | $start_adapter = $this->filesystem->get_adapter($filesystem); |
| 479 | 479 | $start_filesystem = $this->filesystem->get_adapter($filesystem); |
| 480 | 480 | |
| 481 | - if(!$file_info['path']) |
|
| 481 | + if (!$file_info['path']) |
|
| 482 | 482 | return; |
| 483 | 483 | |
| 484 | - if(isset($file_info['archive_prefix_path'])) |
|
| 484 | + if (isset($file_info['archive_prefix_path'])) |
|
| 485 | 485 | $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
| 486 | 486 | else |
| 487 | 487 | $file_info['target_path'] = $file_info['path']; |
@@ -490,36 +490,36 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | //$start_adapter = $this->filesystem->get_start_adapter(); |
| 492 | 492 | |
| 493 | - if(!$append){ |
|
| 493 | + if (!$append) { |
|
| 494 | 494 | $bytes_wrote = $file_info['size']; |
| 495 | 495 | $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, $file_info['target_path'], $this->get_archive_name_with_extension())); |
| 496 | 496 | $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']); |
| 497 | 497 | } |
| 498 | - else{ |
|
| 498 | + else { |
|
| 499 | 499 | $tmp_file = md5($file_info['path']); |
| 500 | 500 | |
| 501 | 501 | //we isolate file to tmp if we are at byte 0, the starting point of file reading |
| 502 | - if(!$start_at_byte) |
|
| 502 | + if (!$start_at_byte) |
|
| 503 | 503 | { |
| 504 | 504 | $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file)); |
| 505 | 505 | $file_stream = $start_filesystem->readStream($file_info['path']); |
| 506 | 506 | |
| 507 | - if(is_resource($file_stream['stream'])) |
|
| 507 | + if (is_resource($file_stream['stream'])) |
|
| 508 | 508 | $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - if($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
|
| 511 | + if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
|
| 512 | 512 | { |
| 513 | 513 | $is_tmp = 1; |
| 514 | 514 | $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit); |
| 515 | 515 | } |
| 516 | - else{ |
|
| 516 | + else { |
|
| 517 | 517 | $is_tmp = 0; |
| 518 | 518 | $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | |
| 522 | - if($last_position == -1) |
|
| 522 | + if ($last_position == -1) |
|
| 523 | 523 | { |
| 524 | 524 | $bytes_wrote = $file_info['size'] - $start_at_byte; |
| 525 | 525 | } |
@@ -529,18 +529,18 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | |
| 532 | - if($is_tmp) |
|
| 532 | + if ($is_tmp) |
|
| 533 | 533 | { |
| 534 | 534 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
| 535 | 535 | } |
| 536 | - else{ |
|
| 536 | + else { |
|
| 537 | 537 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | //we delete here the isolated tmp file |
| 541 | - if($last_position == -1) |
|
| 541 | + if ($last_position == -1) |
|
| 542 | 542 | { |
| 543 | - if($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) |
|
| 543 | + if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) |
|
| 544 | 544 | { |
| 545 | 545 | $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file)); |
| 546 | 546 | $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file); |
@@ -22,22 +22,28 @@ discard block |
||
| 22 | 22 | $this->logger = new XCloner_Logger('xcloner_archive', $hash); |
| 23 | 23 | $this->xcloner_settings = new Xcloner_Settings($hash); |
| 24 | 24 | |
| 25 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
| 26 | - $this->file_size_per_request_limit = $value*1024*1024; //MB |
|
| 25 | + if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) { |
|
| 26 | + $this->file_size_per_request_limit = $value*1024*1024; |
|
| 27 | + } |
|
| 28 | + //MB |
|
| 27 | 29 | |
| 28 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
| 29 | - $this->files_to_process_per_request = $value; |
|
| 30 | + if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) { |
|
| 31 | + $this->files_to_process_per_request = $value; |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | - if($value = get_option('xcloner_backup_compression_level')) |
|
| 32 | - $this->compression_level = $value; |
|
| 34 | + if($value = get_option('xcloner_backup_compression_level')) { |
|
| 35 | + $this->compression_level = $value; |
|
| 36 | + } |
|
| 33 | 37 | |
| 34 | - if($value = get_option('xcloner_split_backup_limit')) |
|
| 35 | - $this->xcloner_split_backup_limit = $value; |
|
| 38 | + if($value = get_option('xcloner_split_backup_limit')) { |
|
| 39 | + $this->xcloner_split_backup_limit = $value; |
|
| 40 | + } |
|
| 36 | 41 | |
| 37 | 42 | $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes |
| 38 | 43 | |
| 39 | - if(isset($archive_name)) |
|
| 40 | - $this->set_archive_name($archive_name); |
|
| 44 | + if(isset($archive_name)) { |
|
| 45 | + $this->set_archive_name($archive_name); |
|
| 46 | + } |
|
| 41 | 47 | } |
| 42 | 48 | |
| 43 | 49 | /* |
@@ -64,8 +70,9 @@ discard block |
||
| 64 | 70 | if(isset($part) and $part) |
| 65 | 71 | { |
| 66 | 72 | $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
| 67 | - if(!stristr($new_name, "-part")) |
|
| 68 | - $new_name = $this->archive_name . "-part".$part; |
|
| 73 | + if(!stristr($new_name, "-part")) { |
|
| 74 | + $new_name = $this->archive_name . "-part".$part; |
|
| 75 | + } |
|
| 69 | 76 | |
| 70 | 77 | $this->archive_name = $new_name; |
| 71 | 78 | } |
@@ -120,8 +127,9 @@ discard block |
||
| 120 | 127 | |
| 121 | 128 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
| 122 | 129 | |
| 123 | - if($admin_email and $from ) |
|
| 124 | - $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
|
| 130 | + if($admin_email and $from ) { |
|
| 131 | + $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
|
| 132 | + } |
|
| 125 | 133 | |
| 126 | 134 | $return = wp_mail( $to, $subject, $body, $headers ); |
| 127 | 135 | |
@@ -135,8 +143,9 @@ discard block |
||
| 135 | 143 | */ |
| 136 | 144 | public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="") |
| 137 | 145 | { |
| 138 | - if(!$from) |
|
| 139 | - $from = "XCloner Backup"; |
|
| 146 | + if(!$from) { |
|
| 147 | + $from = "XCloner Backup"; |
|
| 148 | + } |
|
| 140 | 149 | |
| 141 | 150 | if(($error_message)) |
| 142 | 151 | { |
@@ -145,16 +154,18 @@ discard block |
||
| 145 | 154 | |
| 146 | 155 | $params = (array)$params; |
| 147 | 156 | |
| 148 | - if(!$subject) |
|
| 149 | - $subject = sprintf(__("New backup generated %s") ,$backup_name); |
|
| 157 | + if(!$subject) { |
|
| 158 | + $subject = sprintf(__("New backup generated %s") ,$backup_name); |
|
| 159 | + } |
|
| 150 | 160 | |
| 151 | 161 | $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
| 152 | 162 | $body .= "<br /><br />"; |
| 153 | 163 | |
| 154 | 164 | $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
| 155 | 165 | |
| 156 | - if(!$backups_counter = sizeof($backup_parts)) |
|
| 157 | - $backups_counter = 1; |
|
| 166 | + if(!$backups_counter = sizeof($backup_parts)) { |
|
| 167 | + $backups_counter = 1; |
|
| 168 | + } |
|
| 158 | 169 | |
| 159 | 170 | $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
| 160 | 171 | $body .= "<br />"; |
@@ -173,8 +184,9 @@ discard block |
||
| 173 | 184 | $body .= "<br /><br />"; |
| 174 | 185 | } |
| 175 | 186 | |
| 176 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 177 | - $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
|
| 187 | + if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
| 188 | + $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
|
| 189 | + } |
|
| 178 | 190 | |
| 179 | 191 | $attachments = $this->filesystem->get_backup_attachments(); |
| 180 | 192 | |
@@ -209,18 +221,21 @@ discard block |
||
| 209 | 221 | { |
| 210 | 222 | $return = array(); |
| 211 | 223 | |
| 212 | - if(!isset($extra_params['backup_part'])) |
|
| 213 | - $extra_params['backup_part'] = 0; |
|
| 224 | + if(!isset($extra_params['backup_part'])) { |
|
| 225 | + $extra_params['backup_part'] = 0; |
|
| 226 | + } |
|
| 214 | 227 | |
| 215 | 228 | $return['extra']['backup_part'] = $extra_params['backup_part']; |
| 216 | 229 | |
| 217 | - if(isset( $extra_params['backup_archive_name'])) |
|
| 218 | - $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
| 219 | - else |
|
| 220 | - $this->set_archive_name($backup_params['backup_name']); |
|
| 230 | + if(isset( $extra_params['backup_archive_name'])) { |
|
| 231 | + $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
| 232 | + } else { |
|
| 233 | + $this->set_archive_name($backup_params['backup_name']); |
|
| 234 | + } |
|
| 221 | 235 | |
| 222 | - if(!$this->get_archive_name()) |
|
| 223 | - $this->set_archive_name(); |
|
| 236 | + if(!$this->get_archive_name()) { |
|
| 237 | + $this->set_archive_name(); |
|
| 238 | + } |
|
| 224 | 239 | |
| 225 | 240 | $this->backup_archive = new Tar(); |
| 226 | 241 | $this->backup_archive->setCompression($this->compression_level); |
@@ -235,7 +250,7 @@ discard block |
||
| 235 | 250 | |
| 236 | 251 | $return['extra']['backup_init'] = 1; |
| 237 | 252 | |
| 238 | - }else{ |
|
| 253 | + } else{ |
|
| 239 | 254 | $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
| 240 | 255 | |
| 241 | 256 | $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
@@ -247,11 +262,13 @@ discard block |
||
| 247 | 262 | $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
| 248 | 263 | $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
| 249 | 264 | |
| 250 | - if(!isset($extra_params['start_at_line'])) |
|
| 251 | - $extra_params['start_at_line'] = 0; |
|
| 265 | + if(!isset($extra_params['start_at_line'])) { |
|
| 266 | + $extra_params['start_at_line'] = 0; |
|
| 267 | + } |
|
| 252 | 268 | |
| 253 | - if(!isset($extra_params['start_at_byte'])) |
|
| 254 | - $extra_params['start_at_byte'] = 0; |
|
| 269 | + if(!isset($extra_params['start_at_byte'])) { |
|
| 270 | + $extra_params['start_at_byte'] = 0; |
|
| 271 | + } |
|
| 255 | 272 | |
| 256 | 273 | if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
| 257 | 274 | { |
@@ -302,21 +319,25 @@ discard block |
||
| 302 | 319 | |
| 303 | 320 | $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
| 304 | 321 | |
| 305 | - if(!isset($file_info['size'])) |
|
| 306 | - $file_info['size'] = 0; |
|
| 322 | + if(!isset($file_info['size'])) { |
|
| 323 | + $file_info['size'] = 0; |
|
| 324 | + } |
|
| 307 | 325 | |
| 308 | - if($start_filesystem == "tmp_filesystem") |
|
| 309 | - $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
|
| 326 | + if($start_filesystem == "tmp_filesystem") { |
|
| 327 | + $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
|
| 328 | + } |
|
| 310 | 329 | |
| 311 | 330 | $byte_limit = (int)$this->file_size_per_request_limit/512; |
| 312 | 331 | |
| 313 | 332 | $append = 0; |
| 314 | 333 | |
| 315 | - if($file_info['size'] > $byte_limit*512 or $start_byte) |
|
| 316 | - $append = 1; |
|
| 334 | + if($file_info['size'] > $byte_limit*512 or $start_byte) { |
|
| 335 | + $append = 1; |
|
| 336 | + } |
|
| 317 | 337 | |
| 318 | - if(!isset($return['extra']['backup_size'])) |
|
| 319 | - $return['extra']['backup_size'] =0; |
|
| 338 | + if(!isset($return['extra']['backup_size'])) { |
|
| 339 | + $return['extra']['backup_size'] =0; |
|
| 340 | + } |
|
| 320 | 341 | |
| 321 | 342 | $return['extra']['backup_size'] = $archive_info->getSize(); |
| 322 | 343 | |
@@ -352,8 +373,7 @@ discard block |
||
| 352 | 373 | |
| 353 | 374 | if($last_position>0){ |
| 354 | 375 | $start_byte = $last_position; |
| 355 | - } |
|
| 356 | - else{ |
|
| 376 | + } else{ |
|
| 357 | 377 | $extra_params['start_at_line']++; |
| 358 | 378 | $file->next(); |
| 359 | 379 | $start_byte = 0; |
@@ -390,8 +410,9 @@ discard block |
||
| 390 | 410 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
| 391 | 411 | $this->backup_archive->close(); |
| 392 | 412 | |
| 393 | - if($return['extra']['backup_part']) |
|
| 394 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
| 413 | + if($return['extra']['backup_part']) { |
|
| 414 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
| 415 | + } |
|
| 395 | 416 | |
| 396 | 417 | $return['extra']['start_at_line'] = $extra_params['start_at_line']-1; |
| 397 | 418 | |
@@ -443,12 +464,13 @@ discard block |
||
| 443 | 464 | $this->set_archive_name($this->get_archive_name(), ++$part); |
| 444 | 465 | $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
| 445 | 466 | |
| 446 | - if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
| 447 | - $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
| 467 | + if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) { |
|
| 468 | + $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
| 469 | + } |
|
| 448 | 470 | |
| 449 | 471 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
| 450 | 472 | |
| 451 | - }else |
|
| 473 | + } else |
|
| 452 | 474 | { |
| 453 | 475 | $this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension())); |
| 454 | 476 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
@@ -478,13 +500,15 @@ discard block |
||
| 478 | 500 | $start_adapter = $this->filesystem->get_adapter($filesystem); |
| 479 | 501 | $start_filesystem = $this->filesystem->get_adapter($filesystem); |
| 480 | 502 | |
| 481 | - if(!$file_info['path']) |
|
| 482 | - return; |
|
| 503 | + if(!$file_info['path']) { |
|
| 504 | + return; |
|
| 505 | + } |
|
| 483 | 506 | |
| 484 | - if(isset($file_info['archive_prefix_path'])) |
|
| 485 | - $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
| 486 | - else |
|
| 487 | - $file_info['target_path'] = $file_info['path']; |
|
| 507 | + if(isset($file_info['archive_prefix_path'])) { |
|
| 508 | + $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
| 509 | + } else { |
|
| 510 | + $file_info['target_path'] = $file_info['path']; |
|
| 511 | + } |
|
| 488 | 512 | |
| 489 | 513 | $last_position = $start_at_byte; |
| 490 | 514 | |
@@ -494,8 +518,7 @@ discard block |
||
| 494 | 518 | $bytes_wrote = $file_info['size']; |
| 495 | 519 | $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, $file_info['target_path'], $this->get_archive_name_with_extension())); |
| 496 | 520 | $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']); |
| 497 | - } |
|
| 498 | - else{ |
|
| 521 | + } else{ |
|
| 499 | 522 | $tmp_file = md5($file_info['path']); |
| 500 | 523 | |
| 501 | 524 | //we isolate file to tmp if we are at byte 0, the starting point of file reading |
@@ -504,16 +527,16 @@ discard block |
||
| 504 | 527 | $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file)); |
| 505 | 528 | $file_stream = $start_filesystem->readStream($file_info['path']); |
| 506 | 529 | |
| 507 | - if(is_resource($file_stream['stream'])) |
|
| 508 | - $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
| 530 | + if(is_resource($file_stream['stream'])) { |
|
| 531 | + $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
| 532 | + } |
|
| 509 | 533 | } |
| 510 | 534 | |
| 511 | 535 | if($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
| 512 | 536 | { |
| 513 | 537 | $is_tmp = 1; |
| 514 | 538 | $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit); |
| 515 | - } |
|
| 516 | - else{ |
|
| 539 | + } else{ |
|
| 517 | 540 | $is_tmp = 0; |
| 518 | 541 | $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit); |
| 519 | 542 | } |
@@ -522,8 +545,7 @@ discard block |
||
| 522 | 545 | if($last_position == -1) |
| 523 | 546 | { |
| 524 | 547 | $bytes_wrote = $file_info['size'] - $start_at_byte; |
| 525 | - } |
|
| 526 | - else |
|
| 548 | + } else |
|
| 527 | 549 | { |
| 528 | 550 | $bytes_wrote = $last_position - $start_at_byte; |
| 529 | 551 | } |
@@ -532,8 +554,7 @@ discard block |
||
| 532 | 554 | if($is_tmp) |
| 533 | 555 | { |
| 534 | 556 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
| 535 | - } |
|
| 536 | - else{ |
|
| 557 | + } else{ |
|
| 537 | 558 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
| 538 | 559 | } |
| 539 | 560 | |
@@ -469,6 +469,11 @@ |
||
| 469 | 469 | * handler $fd - file handler where to write the records |
| 470 | 470 | * @return |
| 471 | 471 | */ |
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * @param integer $start |
|
| 475 | + * @param integer $limit |
|
| 476 | + */ |
|
| 472 | 477 | public function export_table($databaseName, $tableName, $start, $limit, $dumpfile) |
| 473 | 478 | { |
| 474 | 479 | $this->logger->debug(sprintf(("Exporting table %s.%s data"), $databaseName, $tableName)); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
| 280 | 280 | } |
| 281 | 281 | $inc++; |
| 282 | - } |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | 284 | return $tablesList; |
| 285 | 285 | |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | $buffer = ""; |
| 504 | 504 | $this->countRecords++; |
| 505 | 505 | |
| 506 | - foreach ($arr as $key => $value) { |
|
| 506 | + foreach ($arr as $key => $value) { |
|
| 507 | 507 | $value = $this->_real_escape($value); |
| 508 | 508 | $buffer .= "'".$value."', "; |
| 509 | 509 | } |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | $line = ("\n#\n# Table structure for table `$tableName`\n#\n\n"); |
| 530 | 530 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
| 531 | 531 | |
| 532 | - if ($this->dbDropSyntax) |
|
| 533 | - { |
|
| 532 | + if ($this->dbDropSyntax) |
|
| 533 | + { |
|
| 534 | 534 | $line = ("\nDROP table IF EXISTS `$tableName`;\n"); |
| 535 | 535 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
| 536 | 536 | } |
@@ -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 | } |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | use League\Flysystem\Config; |
| 3 | 3 | use League\Flysystem\Filesystem; |
| 4 | -use League\Flysystem\Util; |
|
| 5 | 4 | use League\Flysystem\Adapter\Local; |
| 6 | 5 | |
| 7 | 6 | class Xcloner_File_System{ |
@@ -187,6 +187,9 @@ discard block |
||
| 187 | 187 | return $total; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | + /** |
|
| 191 | + * @param string $backup_name |
|
| 192 | + */ |
|
| 190 | 193 | public function is_part($backup_name) |
| 191 | 194 | { |
| 192 | 195 | if(stristr($backup_name, "-part")) |
@@ -577,6 +580,9 @@ discard block |
||
| 577 | 580 | |
| 578 | 581 | } |
| 579 | 582 | |
| 583 | + /** |
|
| 584 | + * @param string $tmp_file |
|
| 585 | + */ |
|
| 580 | 586 | public function estimate_reading_time($tmp_file) |
| 581 | 587 | { |
| 582 | 588 | $this->logger->debug(sprintf(("Estimating file system reading time"))); |
@@ -615,6 +621,9 @@ discard block |
||
| 615 | 621 | return $name; |
| 616 | 622 | } |
| 617 | 623 | |
| 624 | + /** |
|
| 625 | + * @param string $field |
|
| 626 | + */ |
|
| 618 | 627 | public function sort_by( &$array, $field, $direction = 'asc') |
| 619 | 628 | { |
| 620 | 629 | if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
@@ -260,12 +260,12 @@ discard block |
||
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | public function getMetadataFull($adapter = "storage_adapter" , $path) |
| 263 | - { |
|
| 264 | - $location = $this->$adapter->applyPathPrefix($path); |
|
| 265 | - $spl_info = new SplFileInfo($location); |
|
| 263 | + { |
|
| 264 | + $location = $this->$adapter->applyPathPrefix($path); |
|
| 265 | + $spl_info = new SplFileInfo($location); |
|
| 266 | 266 | |
| 267 | - return ($spl_info); |
|
| 268 | - } |
|
| 267 | + return ($spl_info); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | 270 | |
| 271 | 271 | public function get_backup_archives_list() |
@@ -629,27 +629,27 @@ discard block |
||
| 629 | 629 | |
| 630 | 630 | private function array_orderby() |
| 631 | 631 | { |
| 632 | - $args = func_get_args(); |
|
| 633 | - $data = array_shift($args); |
|
| 632 | + $args = func_get_args(); |
|
| 633 | + $data = array_shift($args); |
|
| 634 | 634 | |
| 635 | - foreach ($args as $n => $field) { |
|
| 636 | - if (is_string($field)) { |
|
| 637 | - $tmp = array(); |
|
| 638 | - foreach ($data as $key => $row) |
|
| 639 | - { |
|
| 635 | + foreach ($args as $n => $field) { |
|
| 636 | + if (is_string($field)) { |
|
| 637 | + $tmp = array(); |
|
| 638 | + foreach ($data as $key => $row) |
|
| 639 | + { |
|
| 640 | 640 | if(is_array($row)) |
| 641 | 641 | $tmp[$key] = $row[$field]; |
| 642 | 642 | else |
| 643 | 643 | $tmp[$key] = $row->$field; |
| 644 | 644 | } |
| 645 | - $args[$n] = $tmp; |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - $args[] = &$data; |
|
| 645 | + $args[$n] = $tmp; |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + $args[] = &$data; |
|
| 649 | 649 | |
| 650 | - call_user_func_array('array_multisort', $args); |
|
| 650 | + call_user_func_array('array_multisort', $args); |
|
| 651 | 651 | |
| 652 | - return array_pop($args); |
|
| 652 | + return array_pop($args); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | public function is_excluded($file) |
@@ -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; |
@@ -34,39 +34,39 @@ discard block |
||
| 34 | 34 | $this->logger = new XCloner_Logger('xcloner_file_system', $hash); |
| 35 | 35 | $this->xcloner_requirements = new Xcloner_Requirements(); |
| 36 | 36 | |
| 37 | - $this->xcloner_settings = new Xcloner_Settings($hash); |
|
| 37 | + $this->xcloner_settings = new Xcloner_Settings($hash); |
|
| 38 | 38 | |
| 39 | - try{ |
|
| 39 | + try { |
|
| 40 | 40 | |
| 41 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 41 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 42 | 42 | $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
| 43 | 43 | 'disable_asserts' => true, |
| 44 | 44 | ])); |
| 45 | 45 | |
| 46 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 46 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 47 | 47 | $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
| 48 | 48 | 'disable_asserts' => true, |
| 49 | 49 | ])); |
| 50 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); |
|
| 50 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
| 51 | 51 | $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
| 52 | 52 | 'disable_asserts' => true, |
| 53 | 53 | ])); |
| 54 | 54 | |
| 55 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS'); |
|
| 55 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
| 56 | 56 | $this->storage_filesystem = new Filesystem($adapter, new Config([ |
| 57 | 57 | 'disable_asserts' => true, |
| 58 | 58 | ])); |
| 59 | 59 | |
| 60 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS'); |
|
| 60 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS'); |
|
| 61 | 61 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
| 62 | 62 | 'disable_asserts' => true, |
| 63 | 63 | ])); |
| 64 | - }catch(Exception $e){ |
|
| 64 | + }catch (Exception $e) { |
|
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
| 69 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 69 | + if ($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 70 | 70 | $this->folders_to_process_per_session = $value; |
| 71 | 71 | |
| 72 | 72 | } |
@@ -127,10 +127,10 @@ discard block |
||
| 127 | 127 | return $this->getMetadataFull('storage_adapter', $file); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public function get_included_files_handler($metadata = 0) |
|
| 130 | + public function get_included_files_handler($metadata = 0) |
|
| 131 | 131 | { |
| 132 | 132 | $path = $this->included_files_handler; |
| 133 | - if(!$metadata) |
|
| 133 | + if (!$metadata) |
|
| 134 | 134 | return $path; |
| 135 | 135 | |
| 136 | 136 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
@@ -147,16 +147,16 @@ discard block |
||
| 147 | 147 | { |
| 148 | 148 | $files = $this->get_backup_archives_list(); |
| 149 | 149 | |
| 150 | - if(is_array($files)) |
|
| 151 | - $this->sort_by($files, "timestamp","desc"); |
|
| 150 | + if (is_array($files)) |
|
| 151 | + $this->sort_by($files, "timestamp", "desc"); |
|
| 152 | 152 | |
| 153 | 153 | $new_list = array(); |
| 154 | 154 | |
| 155 | - foreach($files as $key=>$file) |
|
| 156 | - if(!isset($file['parent'])) |
|
| 155 | + foreach ($files as $key=>$file) |
|
| 156 | + if (!isset($file['parent'])) |
|
| 157 | 157 | $new_list[] = ($files[$key]); |
| 158 | 158 | |
| 159 | - if(isset($new_list[0])) |
|
| 159 | + if (isset($new_list[0])) |
|
| 160 | 160 | return $new_list[0]; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -164,13 +164,13 @@ discard block |
||
| 164 | 164 | { |
| 165 | 165 | $files = $this->get_backup_archives_list(); |
| 166 | 166 | |
| 167 | - if(is_array($files)) |
|
| 168 | - $this->sort_by($files, "timestamp","desc"); |
|
| 167 | + if (is_array($files)) |
|
| 168 | + $this->sort_by($files, "timestamp", "desc"); |
|
| 169 | 169 | |
| 170 | 170 | $new_list = array(); |
| 171 | 171 | |
| 172 | - foreach($files as $key=>$file) |
|
| 173 | - if(!isset($file['parent'])) |
|
| 172 | + foreach ($files as $key=>$file) |
|
| 173 | + if (!isset($file['parent'])) |
|
| 174 | 174 | $new_list[] = ($files[$key]); |
| 175 | 175 | |
| 176 | 176 | return $new_list; |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | $files = $this->get_backup_archives_list(); |
| 182 | 182 | $total = 0; |
| 183 | 183 | |
| 184 | - if(is_array($files)) |
|
| 185 | - foreach($files as $file) |
|
| 184 | + if (is_array($files)) |
|
| 185 | + foreach ($files as $file) |
|
| 186 | 186 | $total += $file['size']; |
| 187 | 187 | |
| 188 | 188 | return $total; |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | public function is_part($backup_name) |
| 192 | 192 | { |
| 193 | - if(stristr($backup_name, "-part")) |
|
| 193 | + if (stristr($backup_name, "-part")) |
|
| 194 | 194 | return true; |
| 195 | 195 | |
| 196 | 196 | return false; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | public function is_multipart($backup_name) |
| 200 | 200 | { |
| 201 | - if(stristr($backup_name, "-multipart")) |
|
| 201 | + if (stristr($backup_name, "-multipart")) |
|
| 202 | 202 | return true; |
| 203 | 203 | |
| 204 | 204 | return false; |
@@ -207,10 +207,10 @@ discard block |
||
| 207 | 207 | public function get_backup_size($backup_name) |
| 208 | 208 | { |
| 209 | 209 | $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
| 210 | - if($this->is_multipart($backup_name)) |
|
| 210 | + if ($this->is_multipart($backup_name)) |
|
| 211 | 211 | { |
| 212 | 212 | $backup_parts = $this->get_multipart_files($backup_name); |
| 213 | - foreach($backup_parts as $part_file) |
|
| 213 | + foreach ($backup_parts as $part_file) |
|
| 214 | 214 | $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | { |
| 222 | 222 | $files = array(); |
| 223 | 223 | |
| 224 | - if($this->is_multipart($backup_name)) |
|
| 224 | + if ($this->is_multipart($backup_name)) |
|
| 225 | 225 | { |
| 226 | 226 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); |
| 227 | - foreach($lines as $line) |
|
| 227 | + foreach ($lines as $line) |
|
| 228 | 228 | { |
| 229 | - if($line) |
|
| 229 | + if ($line) |
|
| 230 | 230 | { |
| 231 | 231 | $data = str_getcsv($line); |
| 232 | 232 | $files[] = $data[0]; |
@@ -239,12 +239,12 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | public function delete_backup_by_name($backup_name) |
| 241 | 241 | { |
| 242 | - if($this->is_multipart($backup_name)) |
|
| 242 | + if ($this->is_multipart($backup_name)) |
|
| 243 | 243 | { |
| 244 | 244 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); |
| 245 | - foreach($lines as $line) |
|
| 245 | + foreach ($lines as $line) |
|
| 246 | 246 | { |
| 247 | - if($line) |
|
| 247 | + if ($line) |
|
| 248 | 248 | { |
| 249 | 249 | $data = str_getcsv($line); |
| 250 | 250 | $this->get_storage_filesystem()->delete($data[0]); |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - if($this->get_storage_filesystem()->delete($backup_name)) |
|
| 255 | + if ($this->get_storage_filesystem()->delete($backup_name)) |
|
| 256 | 256 | $return = true; |
| 257 | 257 | else |
| 258 | 258 | $return = false; |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | return $return; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - public function getMetadataFull($adapter = "storage_adapter" , $path) |
|
| 263 | + public function getMetadataFull($adapter = "storage_adapter", $path) |
|
| 264 | 264 | { |
| 265 | 265 | $location = $this->$adapter->applyPathPrefix($path); |
| 266 | 266 | $spl_info = new SplFileInfo($location); |
@@ -273,25 +273,25 @@ discard block |
||
| 273 | 273 | { |
| 274 | 274 | $list = array(); |
| 275 | 275 | |
| 276 | - if(method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 276 | + if (method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 277 | 277 | $list = $this->get_storage_filesystem()->listContents(); |
| 278 | 278 | |
| 279 | 279 | |
| 280 | 280 | $backup_files = array(); |
| 281 | 281 | $parents = array(); |
| 282 | 282 | |
| 283 | - foreach($list as $file_info) |
|
| 283 | + foreach ($list as $file_info) |
|
| 284 | 284 | { |
| 285 | 285 | $data = array(); |
| 286 | 286 | |
| 287 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
| 287 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
| 288 | 288 | { |
| 289 | 289 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); |
| 290 | - foreach($lines as $line) |
|
| 291 | - if($line) |
|
| 290 | + foreach ($lines as $line) |
|
| 291 | + if ($line) |
|
| 292 | 292 | { |
| 293 | 293 | $data = str_getcsv($line); |
| 294 | - if(is_array($data)){ |
|
| 294 | + if (is_array($data)) { |
|
| 295 | 295 | $parents[$data[0]] = $file_info['path']; |
| 296 | 296 | $file_info['childs'][] = $data; |
| 297 | 297 | $file_info['size'] += $data[2]; |
@@ -300,13 +300,13 @@ discard block |
||
| 300 | 300 | |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 303 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 304 | 304 | $backup_files[$file_info['path']] = $file_info; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - foreach($backup_files as $key=>$file_info) |
|
| 307 | + foreach ($backup_files as $key=>$file_info) |
|
| 308 | 308 | { |
| 309 | - if(isset($parents[$file_info['path']])) |
|
| 309 | + if (isset($parents[$file_info['path']])) |
|
| 310 | 310 | $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -315,40 +315,40 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | public function start_file_recursion($init = 0) |
| 317 | 317 | { |
| 318 | - if($init) |
|
| 318 | + if ($init) |
|
| 319 | 319 | { |
| 320 | 320 | $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path())); |
| 321 | 321 | $this->do_system_init(); |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())){ |
|
| 324 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 325 | 325 | //.dir exists, we presume we have files to iterate |
| 326 | 326 | $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
| 327 | 327 | $files = array_filter(explode("\n", $content)); |
| 328 | 328 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 329 | 329 | |
| 330 | 330 | $counter = 0; |
| 331 | - foreach($files as $file) |
|
| 331 | + foreach ($files as $file) |
|
| 332 | 332 | { |
| 333 | - if($counter < $this->folders_to_process_per_session){ |
|
| 333 | + if ($counter < $this->folders_to_process_per_session) { |
|
| 334 | 334 | $this->build_files_list($file); |
| 335 | 335 | $counter++; |
| 336 | - }else{ |
|
| 336 | + } else { |
|
| 337 | 337 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | - }else{ |
|
| 340 | + } else { |
|
| 341 | 341 | $this->build_files_list(); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if($this->scan_finished()) |
|
| 344 | + if ($this->scan_finished()) |
|
| 345 | 345 | { |
| 346 | 346 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
| 347 | 347 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
| 348 | 348 | $this->files_counter++; |
| 349 | 349 | |
| 350 | 350 | //adding included dump file to the included files list |
| 351 | - if($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
| 351 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
| 352 | 352 | { |
| 353 | 353 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
| 354 | 354 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -356,13 +356,13 @@ discard block |
||
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | //adding a default index.html to the temp xcloner folder |
| 359 | - if(!$this->get_tmp_filesystem()->has("index.html")) |
|
| 359 | + if (!$this->get_tmp_filesystem()->has("index.html")) |
|
| 360 | 360 | { |
| 361 | - $this->get_tmp_filesystem()->write("index.html",""); |
|
| 361 | + $this->get_tmp_filesystem()->write("index.html", ""); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | //adding the default log file |
| 365 | - if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
| 365 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
| 366 | 366 | { |
| 367 | 367 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
| 368 | 368 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | { |
| 380 | 380 | $return = array(); |
| 381 | 381 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
| 382 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 382 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 383 | 383 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
| 384 | 384 | |
| 385 | 385 | return $return; |
@@ -392,8 +392,8 @@ discard block |
||
| 392 | 392 | |
| 393 | 393 | $contents = $this->get_tmp_filesystem()->listContents(); |
| 394 | 394 | |
| 395 | - if(is_array($contents)) |
|
| 396 | - foreach($contents as $file_info) |
|
| 395 | + if (is_array($contents)) |
|
| 396 | + foreach ($contents as $file_info) |
|
| 397 | 397 | $this->get_tmp_filesystem()->delete($file_info['path']); |
| 398 | 398 | |
| 399 | 399 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
@@ -405,16 +405,16 @@ discard block |
||
| 405 | 405 | { |
| 406 | 406 | $this->files_counter = 0; |
| 407 | 407 | |
| 408 | - if(!$this->storage_filesystem->has("index.html")) |
|
| 409 | - $this->storage_filesystem->write("index.html",""); |
|
| 408 | + if (!$this->storage_filesystem->has("index.html")) |
|
| 409 | + $this->storage_filesystem->write("index.html", ""); |
|
| 410 | 410 | |
| 411 | - if(!$this->tmp_filesystem->has("index.html")) |
|
| 412 | - $this->tmp_filesystem->write("index.html",""); |
|
| 411 | + if (!$this->tmp_filesystem->has("index.html")) |
|
| 412 | + $this->tmp_filesystem->write("index.html", ""); |
|
| 413 | 413 | |
| 414 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 414 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 415 | 415 | $this->tmp_filesystem->delete($this->get_included_files_handler()); |
| 416 | 416 | |
| 417 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 417 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 418 | 418 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 419 | 419 | } |
| 420 | 420 | |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | |
| 436 | 436 | public function set_excluded_files($excluded_files = array()) |
| 437 | 437 | { |
| 438 | - if(!is_array($excluded_files)) |
|
| 438 | + if (!is_array($excluded_files)) |
|
| 439 | 439 | $excluded_files = array(); |
| 440 | 440 | |
| 441 | 441 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
@@ -458,33 +458,33 @@ discard block |
||
| 458 | 458 | $this->logger->debug(sprintf(("Building the files system list"))); |
| 459 | 459 | |
| 460 | 460 | //if we start with the root folder(empty value), we initializa the file system |
| 461 | - if(!$folder){ |
|
| 461 | + if (!$folder) { |
|
| 462 | 462 | |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - try{ |
|
| 465 | + try { |
|
| 466 | 466 | |
| 467 | 467 | $files = $this->start_filesystem->listContents($folder); |
| 468 | - foreach($files as $file) |
|
| 468 | + foreach ($files as $file) |
|
| 469 | 469 | { |
| 470 | - if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
| 470 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
| 471 | 471 | { |
| 472 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
|
| 472 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE")); |
|
| 473 | 473 | } |
| 474 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 475 | - $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
|
| 474 | + elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
| 475 | + $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE")); |
|
| 476 | 476 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
| 477 | 477 | $this->store_file($file); |
| 478 | 478 | $this->files_counter++; |
| 479 | - if(isset($file['size'])) |
|
| 479 | + if (isset($file['size'])) |
|
| 480 | 480 | $this->files_size += $file['size']; |
| 481 | 481 | |
| 482 | - }else{ |
|
| 483 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
|
| 482 | + } else { |
|
| 483 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE")); |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - }catch(Exception $e){ |
|
| 487 | + }catch (Exception $e) { |
|
| 488 | 488 | |
| 489 | 489 | $this->logger->error($e->getMessage()); |
| 490 | 490 | |
@@ -498,9 +498,9 @@ discard block |
||
| 498 | 498 | |
| 499 | 499 | $start_time = microtime(); |
| 500 | 500 | |
| 501 | - $data = str_repeat(rand(0,9), 1024*1024); //write 1MB data |
|
| 501 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
| 502 | 502 | |
| 503 | - try{ |
|
| 503 | + try { |
|
| 504 | 504 | $this->tmp_filesystem->write($tmp_file, $data); |
| 505 | 505 | |
| 506 | 506 | $end_time = microtime() - $start_time; |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | |
| 512 | 512 | $this->tmp_filesystem->delete($tmp_file); |
| 513 | 513 | |
| 514 | - }catch(Exception $e){ |
|
| 514 | + }catch (Exception $e) { |
|
| 515 | 515 | |
| 516 | 516 | $this->logger->error($e->getMessage()); |
| 517 | 517 | |
@@ -532,10 +532,10 @@ discard block |
||
| 532 | 532 | |
| 533 | 533 | $files = $this->storage_filesystem->listContents(); |
| 534 | 534 | |
| 535 | - if(is_array($files)) |
|
| 536 | - foreach($files as $file) |
|
| 535 | + if (is_array($files)) |
|
| 536 | + foreach ($files as $file) |
|
| 537 | 537 | { |
| 538 | - if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
| 538 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
| 539 | 539 | { |
| 540 | 540 | $_storage_size += $file['size']; //bytes |
| 541 | 541 | $_backup_files_list[] = $file; |
@@ -543,15 +543,15 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
| 546 | - $this->sort_by($_backup_files_list, "timestamp","asc"); |
|
| 546 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
| 547 | 547 | |
| 548 | 548 | $_backups_counter = sizeof($_backup_files_list); |
| 549 | 549 | |
| 550 | - foreach($_backup_files_list as $file) |
|
| 550 | + foreach ($_backup_files_list as $file) |
|
| 551 | 551 | { |
| 552 | 552 | //processing rule folder capacity |
| 553 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
| 554 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 553 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
| 554 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 555 | 555 | { |
| 556 | 556 | $this->storage_filesystem->delete($file['path']); |
| 557 | 557 | $_storage_size -= $file['size']; |
@@ -559,14 +559,14 @@ discard block |
||
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | //processing rule days limit |
| 562 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
| 562 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
| 563 | 563 | { |
| 564 | 564 | $this->storage_filesystem->delete($file['path']); |
| 565 | 565 | $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'))); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | //processing backup countert limit |
| 569 | - 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 | + 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')) |
|
| 570 | 570 | { |
| 571 | 571 | $this->storage_filesystem->delete($file['path']); |
| 572 | 572 | $_backups_counter--; |
@@ -592,33 +592,33 @@ discard block |
||
| 592 | 592 | |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | - public function process_backup_name($name = "", $max_length=100) |
|
| 595 | + public function process_backup_name($name = "", $max_length = 100) |
|
| 596 | 596 | { |
| 597 | - if(!$name) |
|
| 597 | + if (!$name) |
|
| 598 | 598 | $name = $this->xcloner_settings->get_default_backup_name(); |
| 599 | 599 | |
| 600 | - foreach($this->backup_name_tags as $tag) |
|
| 600 | + foreach ($this->backup_name_tags as $tag) |
|
| 601 | 601 | { |
| 602 | - if($tag == '[time]') |
|
| 603 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 604 | - elseif($tag == '[hostname]') |
|
| 605 | - $name = str_replace($tag, gethostname() ,$name); |
|
| 606 | - elseif($tag == '[domain]') |
|
| 602 | + if ($tag == '[time]') |
|
| 603 | + $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
| 604 | + elseif ($tag == '[hostname]') |
|
| 605 | + $name = str_replace($tag, gethostname(), $name); |
|
| 606 | + elseif ($tag == '[domain]') |
|
| 607 | 607 | { |
| 608 | 608 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
| 609 | - $name = str_replace($tag, $domain ,$name); |
|
| 609 | + $name = str_replace($tag, $domain, $name); |
|
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - if($max_length) |
|
| 613 | + if ($max_length) |
|
| 614 | 614 | $name = substr($name, 0, $max_length); |
| 615 | 615 | |
| 616 | 616 | return $name; |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | - public function sort_by( &$array, $field, $direction = 'asc') |
|
| 619 | + public function sort_by(&$array, $field, $direction = 'asc') |
|
| 620 | 620 | { |
| 621 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
| 621 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
| 622 | 622 | $direction = SORT_DESC; |
| 623 | 623 | else |
| 624 | 624 | $direction = SORT_ASC; |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | $tmp = array(); |
| 639 | 639 | foreach ($data as $key => $row) |
| 640 | 640 | { |
| 641 | - if(is_array($row)) |
|
| 641 | + if (is_array($row)) |
|
| 642 | 642 | $tmp[$key] = $row[$field]; |
| 643 | 643 | else |
| 644 | 644 | $tmp[$key] = $row->$field; |
@@ -657,29 +657,29 @@ discard block |
||
| 657 | 657 | { |
| 658 | 658 | $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
| 659 | 659 | |
| 660 | - if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
| 660 | + if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
| 661 | 661 | { |
| 662 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 662 | + if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 663 | 663 | return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - if(!sizeof($this->excluded_files)) |
|
| 666 | + if (!sizeof($this->excluded_files)) |
|
| 667 | 667 | $this->set_excluded_files(); |
| 668 | 668 | |
| 669 | - if(is_array($this->excluded_files)) |
|
| 670 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
| 669 | + if (is_array($this->excluded_files)) |
|
| 670 | + foreach ($this->excluded_files as $excluded_file_pattern) |
|
| 671 | 671 | { |
| 672 | - if($excluded_file_pattern == "/") |
|
| 672 | + if ($excluded_file_pattern == "/") |
|
| 673 | 673 | $needle = "$"; |
| 674 | 674 | else |
| 675 | 675 | $needle = "$".$excluded_file_pattern; |
| 676 | 676 | |
| 677 | - if(strstr("$".$file['path'], $needle)){ |
|
| 677 | + if (strstr("$".$file['path'], $needle)) { |
|
| 678 | 678 | return $excluded_file_pattern; |
| 679 | 679 | } |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | - if( $regex = $this->is_excluded_regex($file)) |
|
| 682 | + if ($regex = $this->is_excluded_regex($file)) |
|
| 683 | 683 | return $regex; |
| 684 | 684 | |
| 685 | 685 | return false; |
@@ -725,25 +725,25 @@ discard block |
||
| 725 | 725 | |
| 726 | 726 | //print_r($regex_patterns);exit; |
| 727 | 727 | |
| 728 | - if(is_array($regex_patterns)) |
|
| 728 | + if (is_array($regex_patterns)) |
|
| 729 | 729 | { |
| 730 | 730 | //$this->excluded_files = array(); |
| 731 | 731 | //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
| 732 | 732 | //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
| 733 | 733 | |
| 734 | - foreach($regex_patterns as $excluded_file_pattern) |
|
| 734 | + foreach ($regex_patterns as $excluded_file_pattern) |
|
| 735 | 735 | { |
| 736 | 736 | |
| 737 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
| 738 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 737 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r") |
|
| 738 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
| 739 | 739 | |
| 740 | - if($file['path'] == "/") |
|
| 740 | + if ($file['path'] == "/") |
|
| 741 | 741 | $needle = "/"; |
| 742 | 742 | else |
| 743 | 743 | $needle = "/".$file['path']; |
| 744 | 744 | //echo $needle."---".$excluded_file_pattern."---\n"; |
| 745 | 745 | |
| 746 | - if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
|
| 746 | + if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
| 747 | 747 | return $excluded_file_pattern; |
| 748 | 748 | } |
| 749 | 749 | } |
@@ -756,27 +756,27 @@ discard block |
||
| 756 | 756 | { |
| 757 | 757 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
| 758 | 758 | |
| 759 | - if(!isset($file['size'])) |
|
| 759 | + if (!isset($file['size'])) |
|
| 760 | 760 | $file['size'] = 0; |
| 761 | - if(!isset($file['visibility'])) |
|
| 761 | + if (!isset($file['visibility'])) |
|
| 762 | 762 | $file['visibility'] = "private"; |
| 763 | 763 | |
| 764 | 764 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
| 765 | 765 | |
| 766 | 766 | $this->last_logged_file = $file['path']; |
| 767 | 767 | |
| 768 | - try{ |
|
| 768 | + try { |
|
| 769 | 769 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
| 770 | 770 | |
| 771 | - }catch(Exception $e){ |
|
| 771 | + }catch (Exception $e) { |
|
| 772 | 772 | |
| 773 | 773 | $this->logger->error($e->getMessage()); |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - if($file['type'] == "dir"){ |
|
| 777 | - try{ |
|
| 776 | + if ($file['type'] == "dir") { |
|
| 777 | + try { |
|
| 778 | 778 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
| 779 | - }catch(Exception $e){ |
|
| 779 | + }catch (Exception $e) { |
|
| 780 | 780 | $this->logger->error($e->getMessage()); |
| 781 | 781 | } |
| 782 | 782 | } |
@@ -789,13 +789,13 @@ discard block |
||
| 789 | 789 | |
| 790 | 790 | public function get_filesystem($system = "") |
| 791 | 791 | { |
| 792 | - if($system == "storage_filesystem_append") |
|
| 792 | + if ($system == "storage_filesystem_append") |
|
| 793 | 793 | return $this->storage_filesystem_append; |
| 794 | - elseif($system == "tmp_filesystem_append") |
|
| 794 | + elseif ($system == "tmp_filesystem_append") |
|
| 795 | 795 | return $this->tmp_filesystem_append; |
| 796 | - elseif($system == "tmp_filesystem") |
|
| 796 | + elseif ($system == "tmp_filesystem") |
|
| 797 | 797 | return $this->tmp_filesystem; |
| 798 | - elseif($system == "storage_filesystem") |
|
| 798 | + elseif ($system == "storage_filesystem") |
|
| 799 | 799 | return $this->storage_filesystem; |
| 800 | 800 | else |
| 801 | 801 | return $this->start_filesystem; |
@@ -803,9 +803,9 @@ discard block |
||
| 803 | 803 | |
| 804 | 804 | public function get_adapter($system) |
| 805 | 805 | { |
| 806 | - if($system == "tmp_filesystem") |
|
| 806 | + if ($system == "tmp_filesystem") |
|
| 807 | 807 | return $this->tmp_adapter; |
| 808 | - elseif($system == "storage_filesystem") |
|
| 808 | + elseif ($system == "storage_filesystem") |
|
| 809 | 809 | return $this->storage_adapter; |
| 810 | 810 | else |
| 811 | 811 | return $this->start_adapter; |
@@ -813,10 +813,10 @@ discard block |
||
| 813 | 813 | |
| 814 | 814 | private function scan_finished() |
| 815 | 815 | { |
| 816 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 816 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 817 | 817 | return false; |
| 818 | 818 | |
| 819 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 819 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 820 | 820 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
| 821 | 821 | |
| 822 | 822 | $this->logger->debug(sprintf(("File scan finished"))); |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | |
| 827 | 827 | private function calc_to_bytes($mb_size) |
| 828 | 828 | { |
| 829 | - return $mb_size*(1024*1024); |
|
| 829 | + return $mb_size * (1024 * 1024); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | } |
@@ -61,13 +61,14 @@ discard block |
||
| 61 | 61 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
| 62 | 62 | 'disable_asserts' => true, |
| 63 | 63 | ])); |
| 64 | - }catch(Exception $e){ |
|
| 64 | + } catch(Exception $e){ |
|
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
| 69 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 70 | - $this->folders_to_process_per_session = $value; |
|
| 69 | + if($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
| 70 | + $this->folders_to_process_per_session = $value; |
|
| 71 | + } |
|
| 71 | 72 | |
| 72 | 73 | } |
| 73 | 74 | |
@@ -130,8 +131,9 @@ discard block |
||
| 130 | 131 | public function get_included_files_handler($metadata = 0) |
| 131 | 132 | { |
| 132 | 133 | $path = $this->included_files_handler; |
| 133 | - if(!$metadata) |
|
| 134 | - return $path; |
|
| 134 | + if(!$metadata) { |
|
| 135 | + return $path; |
|
| 136 | + } |
|
| 135 | 137 | |
| 136 | 138 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
| 137 | 139 | return $spl_info; |
@@ -147,31 +149,36 @@ discard block |
||
| 147 | 149 | { |
| 148 | 150 | $files = $this->get_backup_archives_list(); |
| 149 | 151 | |
| 150 | - if(is_array($files)) |
|
| 151 | - $this->sort_by($files, "timestamp","desc"); |
|
| 152 | + if(is_array($files)) { |
|
| 153 | + $this->sort_by($files, "timestamp","desc"); |
|
| 154 | + } |
|
| 152 | 155 | |
| 153 | 156 | $new_list = array(); |
| 154 | 157 | |
| 155 | - foreach($files as $key=>$file) |
|
| 156 | - if(!isset($file['parent'])) |
|
| 158 | + foreach($files as $key=>$file) { |
|
| 159 | + if(!isset($file['parent'])) |
|
| 157 | 160 | $new_list[] = ($files[$key]); |
| 161 | + } |
|
| 158 | 162 | |
| 159 | - if(isset($new_list[0])) |
|
| 160 | - return $new_list[0]; |
|
| 163 | + if(isset($new_list[0])) { |
|
| 164 | + return $new_list[0]; |
|
| 165 | + } |
|
| 161 | 166 | } |
| 162 | 167 | |
| 163 | 168 | public function get_latest_backups() |
| 164 | 169 | { |
| 165 | 170 | $files = $this->get_backup_archives_list(); |
| 166 | 171 | |
| 167 | - if(is_array($files)) |
|
| 168 | - $this->sort_by($files, "timestamp","desc"); |
|
| 172 | + if(is_array($files)) { |
|
| 173 | + $this->sort_by($files, "timestamp","desc"); |
|
| 174 | + } |
|
| 169 | 175 | |
| 170 | 176 | $new_list = array(); |
| 171 | 177 | |
| 172 | - foreach($files as $key=>$file) |
|
| 173 | - if(!isset($file['parent'])) |
|
| 178 | + foreach($files as $key=>$file) { |
|
| 179 | + if(!isset($file['parent'])) |
|
| 174 | 180 | $new_list[] = ($files[$key]); |
| 181 | + } |
|
| 175 | 182 | |
| 176 | 183 | return $new_list; |
| 177 | 184 | } |
@@ -181,25 +188,28 @@ discard block |
||
| 181 | 188 | $files = $this->get_backup_archives_list(); |
| 182 | 189 | $total = 0; |
| 183 | 190 | |
| 184 | - if(is_array($files)) |
|
| 185 | - foreach($files as $file) |
|
| 191 | + if(is_array($files)) { |
|
| 192 | + foreach($files as $file) |
|
| 186 | 193 | $total += $file['size']; |
| 194 | + } |
|
| 187 | 195 | |
| 188 | 196 | return $total; |
| 189 | 197 | } |
| 190 | 198 | |
| 191 | 199 | public function is_part($backup_name) |
| 192 | 200 | { |
| 193 | - if(stristr($backup_name, "-part")) |
|
| 194 | - return true; |
|
| 201 | + if(stristr($backup_name, "-part")) { |
|
| 202 | + return true; |
|
| 203 | + } |
|
| 195 | 204 | |
| 196 | 205 | return false; |
| 197 | 206 | } |
| 198 | 207 | |
| 199 | 208 | public function is_multipart($backup_name) |
| 200 | 209 | { |
| 201 | - if(stristr($backup_name, "-multipart")) |
|
| 202 | - return true; |
|
| 210 | + if(stristr($backup_name, "-multipart")) { |
|
| 211 | + return true; |
|
| 212 | + } |
|
| 203 | 213 | |
| 204 | 214 | return false; |
| 205 | 215 | } |
@@ -210,8 +220,9 @@ discard block |
||
| 210 | 220 | if($this->is_multipart($backup_name)) |
| 211 | 221 | { |
| 212 | 222 | $backup_parts = $this->get_multipart_files($backup_name); |
| 213 | - foreach($backup_parts as $part_file) |
|
| 214 | - $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
| 223 | + foreach($backup_parts as $part_file) { |
|
| 224 | + $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
| 225 | + } |
|
| 215 | 226 | } |
| 216 | 227 | |
| 217 | 228 | return $backup_size; |
@@ -252,10 +263,11 @@ discard block |
||
| 252 | 263 | } |
| 253 | 264 | } |
| 254 | 265 | |
| 255 | - if($this->get_storage_filesystem()->delete($backup_name)) |
|
| 256 | - $return = true; |
|
| 257 | - else |
|
| 258 | - $return = false; |
|
| 266 | + if($this->get_storage_filesystem()->delete($backup_name)) { |
|
| 267 | + $return = true; |
|
| 268 | + } else { |
|
| 269 | + $return = false; |
|
| 270 | + } |
|
| 259 | 271 | |
| 260 | 272 | return $return; |
| 261 | 273 | } |
@@ -273,8 +285,9 @@ discard block |
||
| 273 | 285 | { |
| 274 | 286 | $list = array(); |
| 275 | 287 | |
| 276 | - if(method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 277 | - $list = $this->get_storage_filesystem()->listContents(); |
|
| 288 | + if(method_exists($this->get_storage_filesystem(), "listContents")) { |
|
| 289 | + $list = $this->get_storage_filesystem()->listContents(); |
|
| 290 | + } |
|
| 278 | 291 | |
| 279 | 292 | |
| 280 | 293 | $backup_files = array(); |
@@ -287,10 +300,11 @@ discard block |
||
| 287 | 300 | if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
| 288 | 301 | { |
| 289 | 302 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); |
| 290 | - foreach($lines as $line) |
|
| 291 | - if($line) |
|
| 303 | + foreach($lines as $line) { |
|
| 304 | + if($line) |
|
| 292 | 305 | { |
| 293 | 306 | $data = str_getcsv($line); |
| 307 | + } |
|
| 294 | 308 | if(is_array($data)){ |
| 295 | 309 | $parents[$data[0]] = $file_info['path']; |
| 296 | 310 | $file_info['childs'][] = $data; |
@@ -300,14 +314,16 @@ discard block |
||
| 300 | 314 | |
| 301 | 315 | } |
| 302 | 316 | |
| 303 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 304 | - $backup_files[$file_info['path']] = $file_info; |
|
| 317 | + if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
| 318 | + $backup_files[$file_info['path']] = $file_info; |
|
| 319 | + } |
|
| 305 | 320 | } |
| 306 | 321 | |
| 307 | 322 | foreach($backup_files as $key=>$file_info) |
| 308 | 323 | { |
| 309 | - if(isset($parents[$file_info['path']])) |
|
| 310 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 324 | + if(isset($parents[$file_info['path']])) { |
|
| 325 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 326 | + } |
|
| 311 | 327 | } |
| 312 | 328 | |
| 313 | 329 | return $backup_files; |
@@ -333,11 +349,11 @@ discard block |
||
| 333 | 349 | if($counter < $this->folders_to_process_per_session){ |
| 334 | 350 | $this->build_files_list($file); |
| 335 | 351 | $counter++; |
| 336 | - }else{ |
|
| 352 | + } else{ |
|
| 337 | 353 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
| 338 | 354 | } |
| 339 | 355 | } |
| 340 | - }else{ |
|
| 356 | + } else{ |
|
| 341 | 357 | $this->build_files_list(); |
| 342 | 358 | } |
| 343 | 359 | |
@@ -379,8 +395,9 @@ discard block |
||
| 379 | 395 | { |
| 380 | 396 | $return = array(); |
| 381 | 397 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
| 382 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 383 | - $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
| 398 | + if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
| 399 | + $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
| 400 | + } |
|
| 384 | 401 | |
| 385 | 402 | return $return; |
| 386 | 403 | } |
@@ -392,9 +409,10 @@ discard block |
||
| 392 | 409 | |
| 393 | 410 | $contents = $this->get_tmp_filesystem()->listContents(); |
| 394 | 411 | |
| 395 | - if(is_array($contents)) |
|
| 396 | - foreach($contents as $file_info) |
|
| 412 | + if(is_array($contents)) { |
|
| 413 | + foreach($contents as $file_info) |
|
| 397 | 414 | $this->get_tmp_filesystem()->delete($file_info['path']); |
| 415 | + } |
|
| 398 | 416 | |
| 399 | 417 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
| 400 | 418 | |
@@ -405,17 +423,21 @@ discard block |
||
| 405 | 423 | { |
| 406 | 424 | $this->files_counter = 0; |
| 407 | 425 | |
| 408 | - if(!$this->storage_filesystem->has("index.html")) |
|
| 409 | - $this->storage_filesystem->write("index.html",""); |
|
| 426 | + if(!$this->storage_filesystem->has("index.html")) { |
|
| 427 | + $this->storage_filesystem->write("index.html",""); |
|
| 428 | + } |
|
| 410 | 429 | |
| 411 | - if(!$this->tmp_filesystem->has("index.html")) |
|
| 412 | - $this->tmp_filesystem->write("index.html",""); |
|
| 430 | + if(!$this->tmp_filesystem->has("index.html")) { |
|
| 431 | + $this->tmp_filesystem->write("index.html",""); |
|
| 432 | + } |
|
| 413 | 433 | |
| 414 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 415 | - $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
| 434 | + if($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
| 435 | + $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
| 436 | + } |
|
| 416 | 437 | |
| 417 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 418 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 438 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 439 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 440 | + } |
|
| 419 | 441 | } |
| 420 | 442 | |
| 421 | 443 | public function get_scanned_files_num() |
@@ -435,8 +457,9 @@ discard block |
||
| 435 | 457 | |
| 436 | 458 | public function set_excluded_files($excluded_files = array()) |
| 437 | 459 | { |
| 438 | - if(!is_array($excluded_files)) |
|
| 439 | - $excluded_files = array(); |
|
| 460 | + if(!is_array($excluded_files)) { |
|
| 461 | + $excluded_files = array(); |
|
| 462 | + } |
|
| 440 | 463 | |
| 441 | 464 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
| 442 | 465 | |
@@ -470,21 +493,21 @@ discard block |
||
| 470 | 493 | if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
| 471 | 494 | { |
| 472 | 495 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
| 473 | - } |
|
| 474 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 496 | + } elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 475 | 497 | $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
| 476 | 498 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
| 477 | 499 | $this->store_file($file); |
| 478 | 500 | $this->files_counter++; |
| 479 | - if(isset($file['size'])) |
|
| 480 | - $this->files_size += $file['size']; |
|
| 501 | + if(isset($file['size'])) { |
|
| 502 | + $this->files_size += $file['size']; |
|
| 503 | + } |
|
| 481 | 504 | |
| 482 | - }else{ |
|
| 505 | + } else{ |
|
| 483 | 506 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
| 484 | 507 | } |
| 485 | 508 | } |
| 486 | 509 | |
| 487 | - }catch(Exception $e){ |
|
| 510 | + } catch(Exception $e){ |
|
| 488 | 511 | |
| 489 | 512 | $this->logger->error($e->getMessage()); |
| 490 | 513 | |
@@ -511,7 +534,7 @@ discard block |
||
| 511 | 534 | |
| 512 | 535 | $this->tmp_filesystem->delete($tmp_file); |
| 513 | 536 | |
| 514 | - }catch(Exception $e){ |
|
| 537 | + } catch(Exception $e){ |
|
| 515 | 538 | |
| 516 | 539 | $this->logger->error($e->getMessage()); |
| 517 | 540 | |
@@ -532,12 +555,14 @@ discard block |
||
| 532 | 555 | |
| 533 | 556 | $files = $this->storage_filesystem->listContents(); |
| 534 | 557 | |
| 535 | - if(is_array($files)) |
|
| 536 | - foreach($files as $file) |
|
| 558 | + if(is_array($files)) { |
|
| 559 | + foreach($files as $file) |
|
| 537 | 560 | { |
| 538 | 561 | if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
| 539 | 562 | { |
| 540 | - $_storage_size += $file['size']; //bytes |
|
| 563 | + $_storage_size += $file['size']; |
|
| 564 | + } |
|
| 565 | + //bytes |
|
| 541 | 566 | $_backup_files_list[] = $file; |
| 542 | 567 | } |
| 543 | 568 | } |
@@ -551,9 +576,11 @@ discard block |
||
| 551 | 576 | { |
| 552 | 577 | //processing rule folder capacity |
| 553 | 578 | if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
| 554 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 579 | + $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) { |
|
| 580 | + //bytes |
|
| 555 | 581 | { |
| 556 | 582 | $this->storage_filesystem->delete($file['path']); |
| 583 | + } |
|
| 557 | 584 | $_storage_size -= $file['size']; |
| 558 | 585 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit)); |
| 559 | 586 | } |
@@ -594,34 +621,37 @@ discard block |
||
| 594 | 621 | |
| 595 | 622 | public function process_backup_name($name = "", $max_length=100) |
| 596 | 623 | { |
| 597 | - if(!$name) |
|
| 598 | - $name = $this->xcloner_settings->get_default_backup_name(); |
|
| 624 | + if(!$name) { |
|
| 625 | + $name = $this->xcloner_settings->get_default_backup_name(); |
|
| 626 | + } |
|
| 599 | 627 | |
| 600 | 628 | foreach($this->backup_name_tags as $tag) |
| 601 | 629 | { |
| 602 | - if($tag == '[time]') |
|
| 603 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 604 | - elseif($tag == '[hostname]') |
|
| 605 | - $name = str_replace($tag, gethostname() ,$name); |
|
| 606 | - elseif($tag == '[domain]') |
|
| 630 | + if($tag == '[time]') { |
|
| 631 | + $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 632 | + } elseif($tag == '[hostname]') { |
|
| 633 | + $name = str_replace($tag, gethostname() ,$name); |
|
| 634 | + } elseif($tag == '[domain]') |
|
| 607 | 635 | { |
| 608 | 636 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
| 609 | 637 | $name = str_replace($tag, $domain ,$name); |
| 610 | 638 | } |
| 611 | 639 | } |
| 612 | 640 | |
| 613 | - if($max_length) |
|
| 614 | - $name = substr($name, 0, $max_length); |
|
| 641 | + if($max_length) { |
|
| 642 | + $name = substr($name, 0, $max_length); |
|
| 643 | + } |
|
| 615 | 644 | |
| 616 | 645 | return $name; |
| 617 | 646 | } |
| 618 | 647 | |
| 619 | 648 | public function sort_by( &$array, $field, $direction = 'asc') |
| 620 | 649 | { |
| 621 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
| 622 | - $direction = SORT_DESC; |
|
| 623 | - else |
|
| 624 | - $direction = SORT_ASC; |
|
| 650 | + if(strtolower($direction) == "desc" || $direction == SORT_DESC) { |
|
| 651 | + $direction = SORT_DESC; |
|
| 652 | + } else { |
|
| 653 | + $direction = SORT_ASC; |
|
| 654 | + } |
|
| 625 | 655 | |
| 626 | 656 | $array = $this->array_orderby($array, $field, $direction); |
| 627 | 657 | |
@@ -638,10 +668,11 @@ discard block |
||
| 638 | 668 | $tmp = array(); |
| 639 | 669 | foreach ($data as $key => $row) |
| 640 | 670 | { |
| 641 | - if(is_array($row)) |
|
| 642 | - $tmp[$key] = $row[$field]; |
|
| 643 | - else |
|
| 644 | - $tmp[$key] = $row->$field; |
|
| 671 | + if(is_array($row)) { |
|
| 672 | + $tmp[$key] = $row[$field]; |
|
| 673 | + } else { |
|
| 674 | + $tmp[$key] = $row->$field; |
|
| 675 | + } |
|
| 645 | 676 | } |
| 646 | 677 | $args[$n] = $tmp; |
| 647 | 678 | } |
@@ -659,28 +690,32 @@ discard block |
||
| 659 | 690 | |
| 660 | 691 | if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
| 661 | 692 | { |
| 662 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 663 | - return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
| 693 | + if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
| 694 | + return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
| 695 | + } |
|
| 664 | 696 | } |
| 665 | 697 | |
| 666 | - if(!sizeof($this->excluded_files)) |
|
| 667 | - $this->set_excluded_files(); |
|
| 698 | + if(!sizeof($this->excluded_files)) { |
|
| 699 | + $this->set_excluded_files(); |
|
| 700 | + } |
|
| 668 | 701 | |
| 669 | - if(is_array($this->excluded_files)) |
|
| 670 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
| 702 | + if(is_array($this->excluded_files)) { |
|
| 703 | + foreach($this->excluded_files as $excluded_file_pattern) |
|
| 671 | 704 | { |
| 672 | 705 | if($excluded_file_pattern == "/") |
| 673 | 706 | $needle = "$"; |
| 674 | - else |
|
| 675 | - $needle = "$".$excluded_file_pattern; |
|
| 707 | + } else { |
|
| 708 | + $needle = "$".$excluded_file_pattern; |
|
| 709 | + } |
|
| 676 | 710 | |
| 677 | 711 | if(strstr("$".$file['path'], $needle)){ |
| 678 | 712 | return $excluded_file_pattern; |
| 679 | 713 | } |
| 680 | 714 | } |
| 681 | 715 | |
| 682 | - if( $regex = $this->is_excluded_regex($file)) |
|
| 683 | - return $regex; |
|
| 716 | + if( $regex = $this->is_excluded_regex($file)) { |
|
| 717 | + return $regex; |
|
| 718 | + } |
|
| 684 | 719 | |
| 685 | 720 | return false; |
| 686 | 721 | } |
@@ -734,13 +769,15 @@ discard block |
||
| 734 | 769 | foreach($regex_patterns as $excluded_file_pattern) |
| 735 | 770 | { |
| 736 | 771 | |
| 737 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
| 738 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 772 | + if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") { |
|
| 773 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 774 | + } |
|
| 739 | 775 | |
| 740 | - if($file['path'] == "/") |
|
| 741 | - $needle = "/"; |
|
| 742 | - else |
|
| 743 | - $needle = "/".$file['path']; |
|
| 776 | + if($file['path'] == "/") { |
|
| 777 | + $needle = "/"; |
|
| 778 | + } else { |
|
| 779 | + $needle = "/".$file['path']; |
|
| 780 | + } |
|
| 744 | 781 | //echo $needle."---".$excluded_file_pattern."---\n"; |
| 745 | 782 | |
| 746 | 783 | if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
@@ -756,10 +793,12 @@ discard block |
||
| 756 | 793 | { |
| 757 | 794 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
| 758 | 795 | |
| 759 | - if(!isset($file['size'])) |
|
| 760 | - $file['size'] = 0; |
|
| 761 | - if(!isset($file['visibility'])) |
|
| 762 | - $file['visibility'] = "private"; |
|
| 796 | + if(!isset($file['size'])) { |
|
| 797 | + $file['size'] = 0; |
|
| 798 | + } |
|
| 799 | + if(!isset($file['visibility'])) { |
|
| 800 | + $file['visibility'] = "private"; |
|
| 801 | + } |
|
| 763 | 802 | |
| 764 | 803 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
| 765 | 804 | |
@@ -768,7 +807,7 @@ discard block |
||
| 768 | 807 | try{ |
| 769 | 808 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
| 770 | 809 | |
| 771 | - }catch(Exception $e){ |
|
| 810 | + } catch(Exception $e){ |
|
| 772 | 811 | |
| 773 | 812 | $this->logger->error($e->getMessage()); |
| 774 | 813 | } |
@@ -776,7 +815,7 @@ discard block |
||
| 776 | 815 | if($file['type'] == "dir"){ |
| 777 | 816 | try{ |
| 778 | 817 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
| 779 | - }catch(Exception $e){ |
|
| 818 | + } catch(Exception $e){ |
|
| 780 | 819 | $this->logger->error($e->getMessage()); |
| 781 | 820 | } |
| 782 | 821 | } |
@@ -789,35 +828,39 @@ discard block |
||
| 789 | 828 | |
| 790 | 829 | public function get_filesystem($system = "") |
| 791 | 830 | { |
| 792 | - if($system == "storage_filesystem_append") |
|
| 793 | - return $this->storage_filesystem_append; |
|
| 794 | - elseif($system == "tmp_filesystem_append") |
|
| 795 | - return $this->tmp_filesystem_append; |
|
| 796 | - elseif($system == "tmp_filesystem") |
|
| 797 | - return $this->tmp_filesystem; |
|
| 798 | - elseif($system == "storage_filesystem") |
|
| 799 | - return $this->storage_filesystem; |
|
| 800 | - else |
|
| 801 | - return $this->start_filesystem; |
|
| 831 | + if($system == "storage_filesystem_append") { |
|
| 832 | + return $this->storage_filesystem_append; |
|
| 833 | + } elseif($system == "tmp_filesystem_append") { |
|
| 834 | + return $this->tmp_filesystem_append; |
|
| 835 | + } elseif($system == "tmp_filesystem") { |
|
| 836 | + return $this->tmp_filesystem; |
|
| 837 | + } elseif($system == "storage_filesystem") { |
|
| 838 | + return $this->storage_filesystem; |
|
| 839 | + } else { |
|
| 840 | + return $this->start_filesystem; |
|
| 841 | + } |
|
| 802 | 842 | } |
| 803 | 843 | |
| 804 | 844 | public function get_adapter($system) |
| 805 | 845 | { |
| 806 | - if($system == "tmp_filesystem") |
|
| 807 | - return $this->tmp_adapter; |
|
| 808 | - elseif($system == "storage_filesystem") |
|
| 809 | - return $this->storage_adapter; |
|
| 810 | - else |
|
| 811 | - return $this->start_adapter; |
|
| 846 | + if($system == "tmp_filesystem") { |
|
| 847 | + return $this->tmp_adapter; |
|
| 848 | + } elseif($system == "storage_filesystem") { |
|
| 849 | + return $this->storage_adapter; |
|
| 850 | + } else { |
|
| 851 | + return $this->start_adapter; |
|
| 852 | + } |
|
| 812 | 853 | } |
| 813 | 854 | |
| 814 | 855 | private function scan_finished() |
| 815 | 856 | { |
| 816 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 817 | - return false; |
|
| 857 | + if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
| 858 | + return false; |
|
| 859 | + } |
|
| 818 | 860 | |
| 819 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 820 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 861 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 862 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 863 | + } |
|
| 821 | 864 | |
| 822 | 865 | $this->logger->debug(sprintf(("File scan finished"))); |
| 823 | 866 | |
@@ -87,6 +87,9 @@ |
||
| 87 | 87 | return ftell($fp); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | + /** |
|
| 91 | + * @param string $filename |
|
| 92 | + */ |
|
| 90 | 93 | function curl_file_create($filename, $mimetype = '', $postname = '') { |
| 91 | 94 | if (!function_exists('curl_file_create')) { |
| 92 | 95 | |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | curl_setopt($ch, CURLOPT_POST, 1); |
| 56 | 56 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
| 57 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 58 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); |
|
| 59 | - curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
|
| 60 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 57 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 58 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); |
|
| 59 | + curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
|
| 60 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 61 | 61 | |
| 62 | 62 | curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array ); |
| 63 | 63 | curl_setopt($ch, CURLOPT_VERBOSE, true); |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | function curl_file_create($filename, $mimetype = '', $postname = '') { |
| 91 | 91 | if (!function_exists('curl_file_create')) { |
| 92 | 92 | |
| 93 | - return "@$filename;filename=" |
|
| 94 | - . ($postname ?: basename($filename)) |
|
| 95 | - . ($mimetype ? ";type=$mimetype" : ''); |
|
| 93 | + return "@$filename;filename=" |
|
| 94 | + . ($postname ?: basename($filename)) |
|
| 95 | + . ($mimetype ? ";type=$mimetype" : ''); |
|
| 96 | 96 | |
| 97 | 97 | }else{ |
| 98 | 98 | |
@@ -19,8 +19,9 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function transfer_file($file, $start = 0, $hash = "") |
| 21 | 21 | { |
| 22 | - if(!$this->target_url) |
|
| 23 | - throw new Exception("Please setup a target url for upload"); |
|
| 22 | + if(!$this->target_url) { |
|
| 23 | + throw new Exception("Please setup a target url for upload"); |
|
| 24 | + } |
|
| 24 | 25 | |
| 25 | 26 | |
| 26 | 27 | $fp = $this->get_storage_filesystem()->readStream($file); |
@@ -68,8 +69,9 @@ discard block |
||
| 68 | 69 | |
| 69 | 70 | $result = json_decode($original_result); |
| 70 | 71 | |
| 71 | - if(!$result) |
|
| 72 | - throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); |
|
| 72 | + if(!$result) { |
|
| 73 | + throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); |
|
| 74 | + } |
|
| 73 | 75 | |
| 74 | 76 | if($result->status != 200) |
| 75 | 77 | { |
@@ -94,7 +96,7 @@ discard block |
||
| 94 | 96 | . ($postname ?: basename($filename)) |
| 95 | 97 | . ($mimetype ? ";type=$mimetype" : ''); |
| 96 | 98 | |
| 97 | - }else{ |
|
| 99 | + } else{ |
|
| 98 | 100 | |
| 99 | 101 | return curl_file_create($filename, $mimetype, $postname); |
| 100 | 102 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -class Xcloner_File_Transfer extends Xcloner_File_System{ |
|
| 3 | +class Xcloner_File_Transfer extends Xcloner_File_System { |
|
| 4 | 4 | |
| 5 | 5 | private $target_url; |
| 6 | 6 | private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400 |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public function set_target($target_url) |
| 10 | 10 | { |
| 11 | - return $this->target_url= $target_url; |
|
| 11 | + return $this->target_url = $target_url; |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | public function get_target() |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function transfer_file($file, $start = 0, $hash = "") |
| 21 | 21 | { |
| 22 | - if(!$this->target_url) |
|
| 22 | + if (!$this->target_url) |
|
| 23 | 23 | throw new Exception("Please setup a target url for upload"); |
| 24 | 24 | |
| 25 | 25 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | fseek($fp, $start, SEEK_SET); |
| 29 | 29 | |
| 30 | - $binary_data = fread($fp, $this->transfer_limit); |
|
| 30 | + $binary_data = fread($fp, $this->transfer_limit); |
|
| 31 | 31 | |
| 32 | 32 | $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5); |
| 33 | 33 | |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | $send_array = array(); |
| 39 | 39 | |
| 40 | 40 | $send_array['file'] = $file; |
| 41 | - $send_array['start'] = $start; |
|
| 42 | - $send_array['action'] = "write_file"; |
|
| 41 | + $send_array['start'] = $start; |
|
| 42 | + $send_array['action'] = "write_file"; |
|
| 43 | 43 | $send_array['hash'] = $hash; |
| 44 | 44 | #$send_array['blob'] = $binary_data; |
| 45 | - $send_array['blob'] = $this->curl_file_create($tmp_file_path,'application/x-binary',$tmp_filename); |
|
| 45 | + $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename); |
|
| 46 | 46 | |
| 47 | 47 | //$data = http_build_query($send_array); |
| 48 | 48 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | $ch = curl_init(); |
| 53 | - curl_setopt($ch, CURLOPT_URL,$this->target_url); |
|
| 53 | + curl_setopt($ch, CURLOPT_URL, $this->target_url); |
|
| 54 | 54 | |
| 55 | 55 | curl_setopt($ch, CURLOPT_POST, 1); |
| 56 | 56 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
@@ -59,24 +59,24 @@ discard block |
||
| 59 | 59 | curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
| 60 | 60 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 61 | 61 | |
| 62 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array ); |
|
| 62 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array); |
|
| 63 | 63 | curl_setopt($ch, CURLOPT_VERBOSE, true); |
| 64 | 64 | |
| 65 | - $original_result = curl_exec ($ch); |
|
| 65 | + $original_result = curl_exec($ch); |
|
| 66 | 66 | |
| 67 | 67 | $this->get_tmp_filesystem()->delete($tmp_filename); |
| 68 | 68 | |
| 69 | 69 | $result = json_decode($original_result); |
| 70 | 70 | |
| 71 | - if(!$result) |
|
| 72 | - throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); |
|
| 71 | + if (!$result) |
|
| 72 | + throw new Exception("We have received no valid response from the remote host, original message: ".$original_result); |
|
| 73 | 73 | |
| 74 | - if($result->status != 200) |
|
| 74 | + if ($result->status != 200) |
|
| 75 | 75 | { |
| 76 | 76 | throw new Exception($result->response); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if(ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) |
|
| 79 | + if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) |
|
| 80 | 80 | { |
| 81 | 81 | $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", $file, $this->target_url, ftell($fp))); |
| 82 | 82 | $this->remove_tmp_filesystem(); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | . ($postname ?: basename($filename)) |
| 94 | 94 | . ($mimetype ? ";type=$mimetype" : ''); |
| 95 | 95 | |
| 96 | - }else{ |
|
| 96 | + } else { |
|
| 97 | 97 | |
| 98 | 98 | return curl_file_create($filename, $mimetype, $postname); |
| 99 | 99 | |
@@ -142,6 +142,9 @@ |
||
| 142 | 142 | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | + /** |
|
| 146 | + * @param string $storage_type |
|
| 147 | + */ |
|
| 145 | 148 | public function verify_filesystem($storage_type) |
| 146 | 149 | { |
| 147 | 150 | $method = "get_".$storage_type."_filesystem"; |
@@ -1,20 +1,14 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | use League\Flysystem\Config; |
| 3 | 3 | use League\Flysystem\Filesystem; |
| 4 | - |
|
| 5 | 4 | use League\Flysystem\Adapter\Ftp as Adapter; |
| 6 | - |
|
| 7 | 5 | use League\Flysystem\Sftp\SftpAdapter; |
| 8 | - |
|
| 9 | 6 | use League\Flysystem\Dropbox\DropboxAdapter; |
| 10 | 7 | use Dropbox\Client; |
| 11 | - |
|
| 12 | 8 | use MicrosoftAzure\Storage\Common\ServicesBuilder; |
| 13 | 9 | use League\Flysystem\Azure\AzureAdapter; |
| 14 | - |
|
| 15 | 10 | use Aws\S3\S3Client; |
| 16 | 11 | use League\Flysystem\AwsS3v3\AwsS3Adapter; |
| 17 | - |
|
| 18 | 12 | use Mhetreramesh\Flysystem\BackblazeAdapter; |
| 19 | 13 | use ChrisWhite\B2\Client as B2Client; |
| 20 | 14 | |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | $this->logger->info(sprintf("Creating the AZURE BLOB remote storage connection"), array("")); |
| 255 | 255 | |
| 256 | 256 | $endpoint = sprintf( |
| 257 | - 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', |
|
| 258 | - get_option("xcloner_azure_account_name"), |
|
| 259 | - get_option("xcloner_azure_api_key") |
|
| 257 | + 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', |
|
| 258 | + get_option("xcloner_azure_account_name"), |
|
| 259 | + get_option("xcloner_azure_api_key") |
|
| 260 | 260 | ); |
| 261 | 261 | |
| 262 | 262 | $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint); |
@@ -293,12 +293,12 @@ discard block |
||
| 293 | 293 | |
| 294 | 294 | |
| 295 | 295 | $client = new S3Client([ |
| 296 | - 'credentials' => [ |
|
| 297 | - 'key' => get_option("xcloner_aws_key"), |
|
| 298 | - 'secret' => get_option("xcloner_aws_secret") |
|
| 299 | - ], |
|
| 300 | - 'region' => get_option("xcloner_aws_region"), |
|
| 301 | - 'version' => 'latest', |
|
| 296 | + 'credentials' => [ |
|
| 297 | + 'key' => get_option("xcloner_aws_key"), |
|
| 298 | + 'secret' => get_option("xcloner_aws_secret") |
|
| 299 | + ], |
|
| 300 | + 'region' => get_option("xcloner_aws_region"), |
|
| 301 | + 'version' => 'latest', |
|
| 302 | 302 | ]); |
| 303 | 303 | |
| 304 | 304 | $adapter = new AwsS3Adapter($client, get_option("xcloner_aws_bucket_name")); |
@@ -332,16 +332,16 @@ discard block |
||
| 332 | 332 | $this->logger->info(sprintf("Creating the FTP remote storage connection"), array("")); |
| 333 | 333 | |
| 334 | 334 | $adapter = new Adapter([ |
| 335 | - 'host' => get_option("xcloner_ftp_hostname"), |
|
| 336 | - 'username' => get_option("xcloner_ftp_username"), |
|
| 337 | - 'password' => get_option("xcloner_ftp_password"), |
|
| 338 | - |
|
| 339 | - /** optional config settings */ |
|
| 340 | - 'port' => get_option("xcloner_ftp_port", 21), |
|
| 341 | - 'root' => get_option("xcloner_ftp_path"), |
|
| 342 | - 'passive' => get_option("xcloner_ftp_transfer_mode"), |
|
| 343 | - 'ssl' => get_option("xcloner_ftp_ssl_mode"), |
|
| 344 | - 'timeout' => get_option("xcloner_ftp_timeout", 30), |
|
| 335 | + 'host' => get_option("xcloner_ftp_hostname"), |
|
| 336 | + 'username' => get_option("xcloner_ftp_username"), |
|
| 337 | + 'password' => get_option("xcloner_ftp_password"), |
|
| 338 | + |
|
| 339 | + /** optional config settings */ |
|
| 340 | + 'port' => get_option("xcloner_ftp_port", 21), |
|
| 341 | + 'root' => get_option("xcloner_ftp_path"), |
|
| 342 | + 'passive' => get_option("xcloner_ftp_transfer_mode"), |
|
| 343 | + 'ssl' => get_option("xcloner_ftp_ssl_mode"), |
|
| 344 | + 'timeout' => get_option("xcloner_ftp_timeout", 30), |
|
| 345 | 345 | ]); |
| 346 | 346 | |
| 347 | 347 | $adapter->connect(); |
@@ -358,15 +358,15 @@ discard block |
||
| 358 | 358 | $this->logger->info(sprintf("Creating the SFTP remote storage connection"), array("")); |
| 359 | 359 | |
| 360 | 360 | $adapter = new SftpAdapter([ |
| 361 | - 'host' => get_option("xcloner_sftp_hostname"), |
|
| 362 | - 'username' => get_option("xcloner_sftp_username"), |
|
| 363 | - 'password' => get_option("xcloner_sftp_password"), |
|
| 364 | - |
|
| 365 | - /** optional config settings */ |
|
| 366 | - 'port' => get_option("xcloner_sftp_port", 22), |
|
| 367 | - 'root' => get_option("xcloner_sftp_path"), |
|
| 368 | - 'privateKey' => get_option("xcloner_sftp_private_key"), |
|
| 369 | - 'timeout' => get_option("xcloner_ftp_timeout", 30), |
|
| 361 | + 'host' => get_option("xcloner_sftp_hostname"), |
|
| 362 | + 'username' => get_option("xcloner_sftp_username"), |
|
| 363 | + 'password' => get_option("xcloner_sftp_password"), |
|
| 364 | + |
|
| 365 | + /** optional config settings */ |
|
| 366 | + 'port' => get_option("xcloner_sftp_port", 22), |
|
| 367 | + 'root' => get_option("xcloner_sftp_path"), |
|
| 368 | + 'privateKey' => get_option("xcloner_sftp_private_key"), |
|
| 369 | + 'timeout' => get_option("xcloner_ftp_timeout", 30), |
|
| 370 | 370 | ]); |
| 371 | 371 | |
| 372 | 372 | $adapter->connect(); |
@@ -97,8 +97,9 @@ discard block |
||
| 97 | 97 | foreach($this->storage_fields as $storage=>$data) |
| 98 | 98 | { |
| 99 | 99 | $check_field = $this->storage_fields["option_prefix"].$storage."_enable"; |
| 100 | - if(get_option($check_field)) |
|
| 101 | - $return[$storage] = $data['text']; |
|
| 100 | + if(get_option($check_field)) { |
|
| 101 | + $return[$storage] = $data['text']; |
|
| 102 | + } |
|
| 102 | 103 | } |
| 103 | 104 | |
| 104 | 105 | return $return; |
@@ -116,11 +117,13 @@ discard block |
||
| 116 | 117 | $check_field = $this->storage_fields["option_prefix"].$field; |
| 117 | 118 | $sanitize_method = "sanitize_input_as_".$validation; |
| 118 | 119 | |
| 119 | - if(!isset($_POST[$check_field])) |
|
| 120 | - $_POST[$check_field] = 0; |
|
| 120 | + if(!isset($_POST[$check_field])) { |
|
| 121 | + $_POST[$check_field] = 0; |
|
| 122 | + } |
|
| 121 | 123 | |
| 122 | - if(!method_exists($this->xcloner_sanitization, $sanitize_method)) |
|
| 123 | - $sanitize_method = "sanitize_input_as_string"; |
|
| 124 | + if(!method_exists($this->xcloner_sanitization, $sanitize_method)) { |
|
| 125 | + $sanitize_method = "sanitize_input_as_string"; |
|
| 126 | + } |
|
| 124 | 127 | |
| 125 | 128 | $sanitized_value = $this->xcloner_sanitization->$sanitize_method($_POST[$check_field]); |
| 126 | 129 | update_option($check_field, $sanitized_value); |
@@ -135,7 +138,7 @@ discard block |
||
| 135 | 138 | $this->verify_filesystem($action); |
| 136 | 139 | $this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", ucfirst($action)); |
| 137 | 140 | $this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action))); |
| 138 | - }catch(Exception $e){ |
|
| 141 | + } catch(Exception $e){ |
|
| 139 | 142 | $this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", ucfirst($action)); |
| 140 | 143 | } |
| 141 | 144 | } |
@@ -148,38 +151,44 @@ discard block |
||
| 148 | 151 | |
| 149 | 152 | $this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type))); |
| 150 | 153 | |
| 151 | - if(!method_exists($this, $method)) |
|
| 152 | - return false; |
|
| 154 | + if(!method_exists($this, $method)) { |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 153 | 157 | |
| 154 | 158 | list($adapter, $filesystem) = $this->$method(); |
| 155 | 159 | |
| 156 | 160 | $test_file = substr(".xcloner_".md5(time()), 0, 15); |
| 157 | 161 | |
| 158 | 162 | //testing write access |
| 159 | - if(!$filesystem->write($test_file, "data")) |
|
| 160 | - throw new Exception(__("Could not write data",'xcloner-backup-and-restore')); |
|
| 163 | + if(!$filesystem->write($test_file, "data")) { |
|
| 164 | + throw new Exception(__("Could not write data",'xcloner-backup-and-restore')); |
|
| 165 | + } |
|
| 161 | 166 | $this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type))); |
| 162 | 167 | |
| 163 | 168 | //testing read access |
| 164 | - if(!$filesystem->read($test_file)) |
|
| 165 | - throw new Exception(__("Could not read data",'xcloner-backup-and-restore')); |
|
| 169 | + if(!$filesystem->read($test_file)) { |
|
| 170 | + throw new Exception(__("Could not read data",'xcloner-backup-and-restore')); |
|
| 171 | + } |
|
| 166 | 172 | $this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type))); |
| 167 | 173 | |
| 168 | 174 | //delete test file |
| 169 | - if(!$filesystem->delete($test_file)) |
|
| 170 | - throw new Exception(__("Could not delete data",'xcloner-backup-and-restore')); |
|
| 175 | + if(!$filesystem->delete($test_file)) { |
|
| 176 | + throw new Exception(__("Could not delete data",'xcloner-backup-and-restore')); |
|
| 177 | + } |
|
| 171 | 178 | $this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type))); |
| 172 | 179 | } |
| 173 | 180 | |
| 174 | 181 | public function upload_backup_to_storage($file, $storage) |
| 175 | 182 | { |
| 176 | - if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
|
| 177 | - return false; |
|
| 183 | + if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) { |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 178 | 186 | |
| 179 | 187 | $method = "get_".$storage."_filesystem"; |
| 180 | 188 | |
| 181 | - if(!method_exists($this, $method)) |
|
| 182 | - return false; |
|
| 189 | + if(!method_exists($this, $method)) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 183 | 192 | |
| 184 | 193 | list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
| 185 | 194 | |
@@ -205,14 +214,16 @@ discard block |
||
| 205 | 214 | if($this->xcloner_file_system->is_multipart($file)) |
| 206 | 215 | { |
| 207 | 216 | $parts = $this->xcloner_file_system->get_multipart_files($file); |
| 208 | - if(is_array($parts)) |
|
| 209 | - foreach($parts as $part_file) |
|
| 217 | + if(is_array($parts)) { |
|
| 218 | + foreach($parts as $part_file) |
|
| 210 | 219 | { |
| 211 | 220 | $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file, strtoupper($storage)), array("")); |
| 221 | + } |
|
| 212 | 222 | |
| 213 | 223 | $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file); |
| 214 | - if(!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) |
|
| 215 | - return false; |
|
| 224 | + if(!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 216 | 227 | } |
| 217 | 228 | } |
| 218 | 229 | |
@@ -234,10 +245,11 @@ discard block |
||
| 234 | 245 | |
| 235 | 246 | $current_timestamp = strtotime("-".$expire_days." days"); |
| 236 | 247 | |
| 237 | - if(is_array($files)) |
|
| 238 | - foreach($files as $file) |
|
| 248 | + if(is_array($files)) { |
|
| 249 | + foreach($files as $file) |
|
| 239 | 250 | { |
| 240 | 251 | $file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']); |
| 252 | + } |
|
| 241 | 253 | |
| 242 | 254 | if($current_timestamp >= $file['timestamp']) |
| 243 | 255 | { |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | use Mhetreramesh\Flysystem\BackblazeAdapter; |
| 19 | 19 | use ChrisWhite\B2\Client as B2Client; |
| 20 | 20 | |
| 21 | -class Xcloner_Remote_Storage{ |
|
| 21 | +class Xcloner_Remote_Storage { |
|
| 22 | 22 | |
| 23 | 23 | private $storage_fields = array( |
| 24 | 24 | "option_prefix" => "xcloner_", |
@@ -92,17 +92,17 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | $this->xcloner_sanitization = new Xcloner_Sanitization($hash); |
| 94 | 94 | $this->xcloner_file_system = new Xcloner_File_System($hash); |
| 95 | - $this->logger = new XCloner_Logger("xcloner_remote_storage", $hash); |
|
| 96 | - $this->xcloner = new Xcloner(); |
|
| 95 | + $this->logger = new XCloner_Logger("xcloner_remote_storage", $hash); |
|
| 96 | + $this->xcloner = new Xcloner(); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function get_available_storages() |
| 100 | 100 | { |
| 101 | 101 | $return = array(); |
| 102 | - foreach($this->storage_fields as $storage=>$data) |
|
| 102 | + foreach ($this->storage_fields as $storage=>$data) |
|
| 103 | 103 | { |
| 104 | 104 | $check_field = $this->storage_fields["option_prefix"].$storage."_enable"; |
| 105 | - if(get_option($check_field)) |
|
| 105 | + if (get_option($check_field)) |
|
| 106 | 106 | $return[$storage] = $data['text']; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -114,17 +114,17 @@ discard block |
||
| 114 | 114 | $storage = $this->xcloner_sanitization->sanitize_input_as_string($action); |
| 115 | 115 | $this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action))); |
| 116 | 116 | |
| 117 | - if(is_array($this->storage_fields[$storage])) |
|
| 117 | + if (is_array($this->storage_fields[$storage])) |
|
| 118 | 118 | { |
| 119 | - foreach($this->storage_fields[$storage] as $field=>$validation) |
|
| 119 | + foreach ($this->storage_fields[$storage] as $field=>$validation) |
|
| 120 | 120 | { |
| 121 | 121 | $check_field = $this->storage_fields["option_prefix"].$field; |
| 122 | 122 | $sanitize_method = "sanitize_input_as_".$validation; |
| 123 | 123 | |
| 124 | - if(!isset($_POST[$check_field])) |
|
| 124 | + if (!isset($_POST[$check_field])) |
|
| 125 | 125 | $_POST[$check_field] = 0; |
| 126 | 126 | |
| 127 | - if(!method_exists($this->xcloner_sanitization, $sanitize_method)) |
|
| 127 | + if (!method_exists($this->xcloner_sanitization, $sanitize_method)) |
|
| 128 | 128 | $sanitize_method = "sanitize_input_as_string"; |
| 129 | 129 | |
| 130 | 130 | $sanitized_value = $this->xcloner_sanitization->$sanitize_method($_POST[$check_field]); |
@@ -134,13 +134,13 @@ discard block |
||
| 134 | 134 | $this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success", ucfirst($action)); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if(isset($_POST['connection_check']) && $_POST['connection_check']) |
|
| 137 | + if (isset($_POST['connection_check']) && $_POST['connection_check']) |
|
| 138 | 138 | { |
| 139 | - try{ |
|
| 139 | + try { |
|
| 140 | 140 | $this->verify_filesystem($action); |
| 141 | 141 | $this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", ucfirst($action)); |
| 142 | 142 | $this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action))); |
| 143 | - }catch(Exception $e){ |
|
| 143 | + }catch (Exception $e) { |
|
| 144 | 144 | $this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", ucfirst($action)); |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | $this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type))); |
| 155 | 155 | |
| 156 | - if(!method_exists($this, $method)) |
|
| 156 | + if (!method_exists($this, $method)) |
|
| 157 | 157 | return false; |
| 158 | 158 | |
| 159 | 159 | list($adapter, $filesystem) = $this->$method(); |
@@ -161,29 +161,29 @@ discard block |
||
| 161 | 161 | $test_file = substr(".xcloner_".md5(time()), 0, 15); |
| 162 | 162 | |
| 163 | 163 | //testing write access |
| 164 | - if(!$filesystem->write($test_file, "data")) |
|
| 165 | - throw new Exception(__("Could not write data",'xcloner-backup-and-restore')); |
|
| 164 | + if (!$filesystem->write($test_file, "data")) |
|
| 165 | + throw new Exception(__("Could not write data", 'xcloner-backup-and-restore')); |
|
| 166 | 166 | $this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type))); |
| 167 | 167 | |
| 168 | 168 | //testing read access |
| 169 | - if(!$filesystem->read($test_file)) |
|
| 170 | - throw new Exception(__("Could not read data",'xcloner-backup-and-restore')); |
|
| 169 | + if (!$filesystem->read($test_file)) |
|
| 170 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
| 171 | 171 | $this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type))); |
| 172 | 172 | |
| 173 | 173 | //delete test file |
| 174 | - if(!$filesystem->delete($test_file)) |
|
| 175 | - throw new Exception(__("Could not delete data",'xcloner-backup-and-restore')); |
|
| 174 | + if (!$filesystem->delete($test_file)) |
|
| 175 | + throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore')); |
|
| 176 | 176 | $this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type))); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | public function upload_backup_to_storage($file, $storage) |
| 180 | 180 | { |
| 181 | - if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
|
| 181 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
|
| 182 | 182 | return false; |
| 183 | 183 | |
| 184 | 184 | $method = "get_".$storage."_filesystem"; |
| 185 | 185 | |
| 186 | - if(!method_exists($this, $method)) |
|
| 186 | + if (!method_exists($this, $method)) |
|
| 187 | 187 | return false; |
| 188 | 188 | |
| 189 | 189 | list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)), array("")); |
| 195 | 195 | |
| 196 | - if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
|
| 196 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
|
| 197 | 197 | { |
| 198 | 198 | $this->logger->info(sprintf("File not found %s in local storage", $file)); |
| 199 | 199 | return false; |
@@ -201,22 +201,22 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($file); |
| 203 | 203 | |
| 204 | - if(!$remote_storage_filesystem->updateStream($file, $backup_file_stream)) |
|
| 204 | + if (!$remote_storage_filesystem->updateStream($file, $backup_file_stream)) |
|
| 205 | 205 | { |
| 206 | 206 | $this->logger->info(sprintf("Could not transfer file %s", $file)); |
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if($this->xcloner_file_system->is_multipart($file)) |
|
| 210 | + if ($this->xcloner_file_system->is_multipart($file)) |
|
| 211 | 211 | { |
| 212 | 212 | $parts = $this->xcloner_file_system->get_multipart_files($file); |
| 213 | - if(is_array($parts)) |
|
| 214 | - foreach($parts as $part_file) |
|
| 213 | + if (is_array($parts)) |
|
| 214 | + foreach ($parts as $part_file) |
|
| 215 | 215 | { |
| 216 | 216 | $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file, strtoupper($storage)), array("")); |
| 217 | 217 | |
| 218 | 218 | $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file); |
| 219 | - if(!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) |
|
| 219 | + if (!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) |
|
| 220 | 220 | return false; |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -232,19 +232,19 @@ discard block |
||
| 232 | 232 | public function clean_remote_storage($storage, $remote_storage_filesystem) |
| 233 | 233 | { |
| 234 | 234 | $check_field = $this->storage_fields["option_prefix"].$storage."_cleanup_days"; |
| 235 | - if($expire_days = get_option($check_field)) |
|
| 235 | + if ($expire_days = get_option($check_field)) |
|
| 236 | 236 | { |
| 237 | 237 | $this->logger->info(sprintf("Doing %s remote storage cleanup for %s days limit", strtoupper($storage), $expire_days)); |
| 238 | 238 | $files = $remote_storage_filesystem->listContents(); |
| 239 | 239 | |
| 240 | 240 | $current_timestamp = strtotime("-".$expire_days." days"); |
| 241 | 241 | |
| 242 | - if(is_array($files)) |
|
| 243 | - foreach($files as $file) |
|
| 242 | + if (is_array($files)) |
|
| 243 | + foreach ($files as $file) |
|
| 244 | 244 | { |
| 245 | 245 | $file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']); |
| 246 | 246 | |
| 247 | - if($current_timestamp >= $file['timestamp']) |
|
| 247 | + if ($current_timestamp >= $file['timestamp']) |
|
| 248 | 248 | { |
| 249 | 249 | $remote_storage_filesystem->delete($file['path']); |
| 250 | 250 | $this->logger->info("Deleting remote file ".$file['path']." matching rule", array("RETENTION LIMIT TIMESTAMP", $file['timestamp']." =< ".$expire_days)); |
@@ -26,6 +26,6 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | 28 | // If uninstall not called from WordPress, then exit. |
| 29 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
| 29 | +if (!defined('WP_UNINSTALL_PLUGIN')) { |
|
| 30 | 30 | exit; |
| 31 | 31 | } |
@@ -11,8 +11,8 @@ |
||
| 11 | 11 | |
| 12 | 12 | // add all files in the project, only include php files |
| 13 | 13 | $phar2->buildFromIterator( |
| 14 | - new RecursiveIteratorIterator( |
|
| 15 | - new RecursiveDirectoryIterator(__DIR__.'/vendor/')), |
|
| 16 | - __DIR__); |
|
| 14 | + new RecursiveIteratorIterator( |
|
| 15 | + new RecursiveDirectoryIterator(__DIR__.'/vendor/')), |
|
| 16 | + __DIR__); |
|
| 17 | 17 | |
| 18 | 18 | $phar2->setStub($phar2->createDefaultStub('vendor/autoload.php', 'vendor/autoload.php')); |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!isset($argv)) |
|
| 3 | +if (!isset($argv)) |
|
| 4 | 4 | die('Access denied from web.'); |
| 5 | 5 | |
| 6 | 6 | $file = 'restore/vendor.phar'; |
| 7 | 7 | |
| 8 | -if(file_exists($file)) |
|
| 8 | +if (file_exists($file)) |
|
| 9 | 9 | unlink($file); |
| 10 | 10 | $phar2 = new Phar($file, 0, 'vendor.phar'); |
| 11 | 11 | |
@@ -1,12 +1,14 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!isset($argv)) |
|
| 3 | +if(!isset($argv)) { |
|
| 4 | 4 | die('Access denied from web.'); |
| 5 | +} |
|
| 5 | 6 | |
| 6 | 7 | $file = 'restore/vendor.phar'; |
| 7 | 8 | |
| 8 | -if(file_exists($file)) |
|
| 9 | +if(file_exists($file)) { |
|
| 9 | 10 | unlink($file); |
| 11 | +} |
|
| 10 | 12 | $phar2 = new Phar($file, 0, 'vendor.phar'); |
| 11 | 13 | |
| 12 | 14 | // add all files in the project, only include php files |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param string $plugin_name The name of the plugin. |
| 48 | 48 | * @param string $version The version of this plugin. |
| 49 | 49 | */ |
| 50 | - public function __construct( $plugin_name, $version ) { |
|
| 50 | + public function __construct($plugin_name, $version) { |
|
| 51 | 51 | |
| 52 | 52 | $this->plugin_name = $plugin_name; |
| 53 | 53 | $this->version = $version; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * class. |
| 74 | 74 | */ |
| 75 | 75 | |
| 76 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/xcloner-public.css', array(), $this->version, 'all' ); |
|
| 76 | + wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/xcloner-public.css', array(), $this->version, 'all'); |
|
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * class. |
| 97 | 97 | */ |
| 98 | 98 | |
| 99 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/xcloner-public.js', array( 'jquery' ), $this->version, false ); |
|
| 99 | + wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/xcloner-public.js', array('jquery'), $this->version, false); |
|
| 100 | 100 | |
| 101 | 101 | } |
| 102 | 102 | |