| @@ -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; | 
| @@ -33,39 +33,39 @@ discard block | ||
| 33 | 33 |  		$this->logger = new XCloner_Logger('xcloner_file_system', $hash); | 
| 34 | 34 | $this->xcloner_requirements = new Xcloner_Requirements(); | 
| 35 | 35 | |
| 36 | - $this->xcloner_settings = new Xcloner_Settings($hash); | |
| 36 | + $this->xcloner_settings = new Xcloner_Settings($hash); | |
| 37 | 37 | |
| 38 | -		try{ | |
| 38 | +		try { | |
| 39 | 39 | |
| 40 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS'); | |
| 40 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); | |
| 41 | 41 | $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ | 
| 42 | 42 | 'disable_asserts' => true, | 
| 43 | 43 | ])); | 
| 44 | 44 | |
| 45 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS'); | |
| 45 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); | |
| 46 | 46 | $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ | 
| 47 | 47 | 'disable_asserts' => true, | 
| 48 | 48 | ])); | 
| 49 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); | |
| 49 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); | |
| 50 | 50 | $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ | 
| 51 | 51 | 'disable_asserts' => true, | 
| 52 | 52 | ])); | 
| 53 | 53 | |
| 54 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS'); | |
| 54 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); | |
| 55 | 55 | $this->storage_filesystem = new Filesystem($adapter, new Config([ | 
| 56 | 56 | 'disable_asserts' => true, | 
| 57 | 57 | ])); | 
| 58 | 58 | |
| 59 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS'); | |
| 59 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS'); | |
| 60 | 60 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ | 
| 61 | 61 | 'disable_asserts' => true, | 
| 62 | 62 | ])); | 
| 63 | -		}catch(Exception $e){ | |
| 63 | +		}catch (Exception $e) { | |
| 64 | 64 | return false; | 
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | |
| 68 | -		if($value = get_option('xcloner_directories_to_scan_per_request')) | |
| 68 | +		if ($value = get_option('xcloner_directories_to_scan_per_request')) | |
| 69 | 69 | $this->folders_to_process_per_session = $value; | 
| 70 | 70 | |
| 71 | 71 | } | 
| @@ -126,10 +126,10 @@ discard block | ||
| 126 | 126 |  		return $this->getMetadataFull('storage_adapter', $file); | 
| 127 | 127 | } | 
| 128 | 128 | |
| 129 | - public function get_included_files_handler($metadata = 0) | |
| 129 | + public function get_included_files_handler($metadata = 0) | |
| 130 | 130 |  	{ | 
| 131 | 131 | $path = $this->included_files_handler; | 
| 132 | - if(!$metadata) | |
| 132 | + if (!$metadata) | |
| 133 | 133 | return $path; | 
| 134 | 134 | |
| 135 | 135 |  		$spl_info = $this->getMetadataFull('tmp_adapter', $path); | 
| @@ -146,16 +146,16 @@ discard block | ||
| 146 | 146 |  	{ | 
| 147 | 147 | $files = $this->get_backup_archives_list(); | 
| 148 | 148 | |
| 149 | - if(is_array($files)) | |
| 150 | - $this->sort_by($files, "timestamp","desc"); | |
| 149 | + if (is_array($files)) | |
| 150 | + $this->sort_by($files, "timestamp", "desc"); | |
| 151 | 151 | |
| 152 | 152 | $new_list = array(); | 
| 153 | 153 | |
| 154 | - foreach($files as $key=>$file) | |
| 155 | - if(!isset($file['parent'])) | |
| 154 | + foreach ($files as $key=>$file) | |
| 155 | + if (!isset($file['parent'])) | |
| 156 | 156 | $new_list[] = ($files[$key]); | 
| 157 | 157 | |
| 158 | - if(isset($new_list[0])) | |
| 158 | + if (isset($new_list[0])) | |
| 159 | 159 | return $new_list[0]; | 
| 160 | 160 | } | 
| 161 | 161 | |
| @@ -163,13 +163,13 @@ discard block | ||
| 163 | 163 |  	{ | 
| 164 | 164 | $files = $this->get_backup_archives_list(); | 
| 165 | 165 | |
| 166 | - if(is_array($files)) | |
| 167 | - $this->sort_by($files, "timestamp","desc"); | |
| 166 | + if (is_array($files)) | |
| 167 | + $this->sort_by($files, "timestamp", "desc"); | |
| 168 | 168 | |
| 169 | 169 | $new_list = array(); | 
| 170 | 170 | |
| 171 | - foreach($files as $key=>$file) | |
| 172 | - if(!isset($file['parent'])) | |
| 171 | + foreach ($files as $key=>$file) | |
| 172 | + if (!isset($file['parent'])) | |
| 173 | 173 | $new_list[] = ($files[$key]); | 
| 174 | 174 | |
| 175 | 175 | return $new_list; | 
| @@ -180,8 +180,8 @@ discard block | ||
| 180 | 180 | $files = $this->get_backup_archives_list(); | 
| 181 | 181 | $total = 0; | 
| 182 | 182 | |
| 183 | - if(is_array($files)) | |
| 184 | - foreach($files as $file) | |
| 183 | + if (is_array($files)) | |
| 184 | + foreach ($files as $file) | |
| 185 | 185 | $total += $file['size']; | 
| 186 | 186 | |
| 187 | 187 | return $total; | 
| @@ -189,7 +189,7 @@ discard block | ||
| 189 | 189 | |
| 190 | 190 | public function is_part($backup_name) | 
| 191 | 191 |  	{ | 
| 192 | - if(stristr($backup_name, "-part")) | |
| 192 | + if (stristr($backup_name, "-part")) | |
| 193 | 193 | return true; | 
| 194 | 194 | |
| 195 | 195 | return false; | 
| @@ -197,7 +197,7 @@ discard block | ||
| 197 | 197 | |
| 198 | 198 | public function is_multipart($backup_name) | 
| 199 | 199 |  	{ | 
| 200 | - if(stristr($backup_name, "-multipart")) | |
| 200 | + if (stristr($backup_name, "-multipart")) | |
| 201 | 201 | return true; | 
| 202 | 202 | |
| 203 | 203 | return false; | 
| @@ -206,10 +206,10 @@ discard block | ||
| 206 | 206 | public function get_backup_size($backup_name) | 
| 207 | 207 |  	{ | 
| 208 | 208 | $backup_size = $this->get_storage_filesystem()->getSize($backup_name); | 
| 209 | - if($this->is_multipart($backup_name)) | |
| 209 | + if ($this->is_multipart($backup_name)) | |
| 210 | 210 |  		{ | 
| 211 | 211 | $backup_parts = $this->get_multipart_files($backup_name); | 
| 212 | - foreach($backup_parts as $part_file) | |
| 212 | + foreach ($backup_parts as $part_file) | |
| 213 | 213 | $backup_size += $this->get_storage_filesystem()->getSize($part_file); | 
| 214 | 214 | } | 
| 215 | 215 | |
| @@ -220,12 +220,12 @@ discard block | ||
| 220 | 220 |  	{ | 
| 221 | 221 | $files = array(); | 
| 222 | 222 | |
| 223 | - if($this->is_multipart($backup_name)) | |
| 223 | + if ($this->is_multipart($backup_name)) | |
| 224 | 224 |  		{ | 
| 225 | 225 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); | 
| 226 | - foreach($lines as $line) | |
| 226 | + foreach ($lines as $line) | |
| 227 | 227 |  			{ | 
| 228 | - if($line) | |
| 228 | + if ($line) | |
| 229 | 229 |  				{ | 
| 230 | 230 | $data = str_getcsv($line); | 
| 231 | 231 | $files[] = $data[0]; | 
| @@ -238,12 +238,12 @@ discard block | ||
| 238 | 238 | |
| 239 | 239 | public function delete_backup_by_name($backup_name) | 
| 240 | 240 |  	{ | 
| 241 | - if($this->is_multipart($backup_name)) | |
| 241 | + if ($this->is_multipart($backup_name)) | |
| 242 | 242 |  		{ | 
| 243 | 243 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); | 
| 244 | - foreach($lines as $line) | |
| 244 | + foreach ($lines as $line) | |
| 245 | 245 |  			{ | 
| 246 | - if($line) | |
| 246 | + if ($line) | |
| 247 | 247 |  				{ | 
| 248 | 248 | $data = str_getcsv($line); | 
| 249 | 249 | $this->get_storage_filesystem()->delete($data[0]); | 
| @@ -251,7 +251,7 @@ discard block | ||
| 251 | 251 | } | 
| 252 | 252 | } | 
| 253 | 253 | |
| 254 | - if($this->get_storage_filesystem()->delete($backup_name)) | |
| 254 | + if ($this->get_storage_filesystem()->delete($backup_name)) | |
| 255 | 255 | $return = true; | 
| 256 | 256 | else | 
| 257 | 257 | $return = false; | 
| @@ -259,7 +259,7 @@ discard block | ||
| 259 | 259 | return $return; | 
| 260 | 260 | } | 
| 261 | 261 | |
| 262 | - public function getMetadataFull($adapter = "storage_adapter" , $path) | |
| 262 | + public function getMetadataFull($adapter = "storage_adapter", $path) | |
| 263 | 263 |      { | 
| 264 | 264 | $location = $this->$adapter->applyPathPrefix($path); | 
| 265 | 265 | $spl_info = new SplFileInfo($location); | 
| @@ -272,25 +272,25 @@ discard block | ||
| 272 | 272 |  	{ | 
| 273 | 273 | $list = array(); | 
| 274 | 274 | |
| 275 | - if(method_exists($this->get_storage_filesystem(), "listContents")) | |
| 275 | + if (method_exists($this->get_storage_filesystem(), "listContents")) | |
| 276 | 276 | $list = $this->get_storage_filesystem()->listContents(); | 
| 277 | 277 | |
| 278 | 278 | |
| 279 | 279 | $backup_files = array(); | 
| 280 | 280 | $parents = array(); | 
| 281 | 281 | |
| 282 | - foreach($list as $file_info) | |
| 282 | + foreach ($list as $file_info) | |
| 283 | 283 |  		{ | 
| 284 | 284 | $data = array(); | 
| 285 | 285 | |
| 286 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") | |
| 286 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") | |
| 287 | 287 |  			{ | 
| 288 | 288 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); | 
| 289 | - foreach($lines as $line) | |
| 290 | - if($line) | |
| 289 | + foreach ($lines as $line) | |
| 290 | + if ($line) | |
| 291 | 291 |  					{ | 
| 292 | 292 | $data = str_getcsv($line); | 
| 293 | -						if(is_array($data)){ | |
| 293 | +						if (is_array($data)) { | |
| 294 | 294 | $parents[$data[0]] = $file_info['path']; | 
| 295 | 295 | $file_info['childs'][] = $data; | 
| 296 | 296 | $file_info['size'] += $data[2]; | 
| @@ -299,13 +299,13 @@ discard block | ||
| 299 | 299 | |
| 300 | 300 | } | 
| 301 | 301 | |
| 302 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) | |
| 302 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) | |
| 303 | 303 | $backup_files[$file_info['path']] = $file_info; | 
| 304 | 304 | } | 
| 305 | 305 | |
| 306 | - foreach($backup_files as $key=>$file_info) | |
| 306 | + foreach ($backup_files as $key=>$file_info) | |
| 307 | 307 |  		{ | 
| 308 | - if(isset($parents[$file_info['path']])) | |
| 308 | + if (isset($parents[$file_info['path']])) | |
| 309 | 309 | $backup_files[$key]['parent'] = $parents[$file_info['path']]; | 
| 310 | 310 | } | 
| 311 | 311 | |
| @@ -314,40 +314,40 @@ discard block | ||
| 314 | 314 | |
| 315 | 315 | public function start_file_recursion($init = 0) | 
| 316 | 316 |  	{ | 
| 317 | - if($init) | |
| 317 | + if ($init) | |
| 318 | 318 |  		{ | 
| 319 | 319 |  			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path())); | 
| 320 | 320 | $this->do_system_init(); | 
| 321 | 321 | } | 
| 322 | 322 | |
| 323 | -		if($this->tmp_filesystem->has($this->get_temp_dir_handler())){ | |
| 323 | +		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { | |
| 324 | 324 | //.dir exists, we presume we have files to iterate | 
| 325 | 325 | $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); | 
| 326 | 326 |  			$files = array_filter(explode("\n", $content)); | 
| 327 | 327 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); | 
| 328 | 328 | |
| 329 | 329 | $counter = 0; | 
| 330 | - foreach($files as $file) | |
| 330 | + foreach ($files as $file) | |
| 331 | 331 |  			{ | 
| 332 | -				if($counter < $this->folders_to_process_per_session){ | |
| 332 | +				if ($counter < $this->folders_to_process_per_session) { | |
| 333 | 333 | $this->build_files_list($file); | 
| 334 | 334 | $counter++; | 
| 335 | -				}else{ | |
| 335 | +				} else { | |
| 336 | 336 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); | 
| 337 | 337 | } | 
| 338 | 338 | } | 
| 339 | -		}else{ | |
| 339 | +		} else { | |
| 340 | 340 | $this->build_files_list(); | 
| 341 | 341 | } | 
| 342 | 342 | |
| 343 | - if($this->scan_finished()) | |
| 343 | + if ($this->scan_finished()) | |
| 344 | 344 |  		{ | 
| 345 | 345 |  			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); | 
| 346 | 346 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); | 
| 347 | 347 | $this->files_counter++; | 
| 348 | 348 | |
| 349 | 349 | //adding included dump file to the included files list | 
| 350 | - if($this->get_tmp_filesystem()->has($this->get_included_files_handler())) | |
| 350 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) | |
| 351 | 351 |  			{ | 
| 352 | 352 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); | 
| 353 | 353 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); | 
| @@ -355,13 +355,13 @@ discard block | ||
| 355 | 355 | } | 
| 356 | 356 | |
| 357 | 357 | //adding a default index.html to the temp xcloner folder | 
| 358 | -			if(!$this->get_tmp_filesystem()->has("index.html")) | |
| 358 | +			if (!$this->get_tmp_filesystem()->has("index.html")) | |
| 359 | 359 |  			{ | 
| 360 | -				$this->get_tmp_filesystem()->write("index.html",""); | |
| 360 | +				$this->get_tmp_filesystem()->write("index.html", ""); | |
| 361 | 361 | } | 
| 362 | 362 | |
| 363 | 363 | //adding the default log file | 
| 364 | - if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) | |
| 364 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) | |
| 365 | 365 |  			{ | 
| 366 | 366 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); | 
| 367 | 367 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); | 
| @@ -378,7 +378,7 @@ discard block | ||
| 378 | 378 |  	{ | 
| 379 | 379 | $return = array(); | 
| 380 | 380 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); | 
| 381 | -		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) | |
| 381 | +		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) | |
| 382 | 382 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); | 
| 383 | 383 | |
| 384 | 384 | return $return; | 
| @@ -391,8 +391,8 @@ discard block | ||
| 391 | 391 | |
| 392 | 392 | $contents = $this->get_tmp_filesystem()->listContents(); | 
| 393 | 393 | |
| 394 | - if(is_array($contents)) | |
| 395 | - foreach($contents as $file_info) | |
| 394 | + if (is_array($contents)) | |
| 395 | + foreach ($contents as $file_info) | |
| 396 | 396 | $this->get_tmp_filesystem()->delete($file_info['path']); | 
| 397 | 397 | |
| 398 | 398 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); | 
| @@ -404,16 +404,16 @@ discard block | ||
| 404 | 404 |  	{ | 
| 405 | 405 | $this->files_counter = 0; | 
| 406 | 406 | |
| 407 | -		if(!$this->storage_filesystem->has("index.html"))	 | |
| 408 | -			$this->storage_filesystem->write("index.html",""); | |
| 407 | +		if (!$this->storage_filesystem->has("index.html"))	 | |
| 408 | +			$this->storage_filesystem->write("index.html", ""); | |
| 409 | 409 | |
| 410 | -		if(!$this->tmp_filesystem->has("index.html"))	 | |
| 411 | -			$this->tmp_filesystem->write("index.html",""); | |
| 410 | +		if (!$this->tmp_filesystem->has("index.html"))	 | |
| 411 | +			$this->tmp_filesystem->write("index.html", ""); | |
| 412 | 412 | |
| 413 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) | |
| 413 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) | |
| 414 | 414 | $this->tmp_filesystem->delete($this->get_included_files_handler()); | 
| 415 | 415 | |
| 416 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) | |
| 416 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) | |
| 417 | 417 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); | 
| 418 | 418 | } | 
| 419 | 419 | |
| @@ -434,7 +434,7 @@ discard block | ||
| 434 | 434 | |
| 435 | 435 | public function set_excluded_files($excluded_files = array()) | 
| 436 | 436 |  	{ | 
| 437 | - if(!is_array($excluded_files)) | |
| 437 | + if (!is_array($excluded_files)) | |
| 438 | 438 | $excluded_files = array(); | 
| 439 | 439 | |
| 440 | 440 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); | 
| @@ -457,33 +457,33 @@ discard block | ||
| 457 | 457 |  		$this->logger->debug(sprintf(("Building the files system list"))); | 
| 458 | 458 | |
| 459 | 459 | //if we start with the root folder(empty value), we initializa the file system | 
| 460 | -		if(!$folder){ | |
| 460 | +		if (!$folder) { | |
| 461 | 461 | |
| 462 | 462 | } | 
| 463 | 463 | |
| 464 | -		try{ | |
| 464 | +		try { | |
| 465 | 465 | |
| 466 | 466 | $files = $this->start_filesystem->listContents($folder); | 
| 467 | - foreach($files as $file) | |
| 467 | + foreach ($files as $file) | |
| 468 | 468 |  			{ | 
| 469 | - if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) | |
| 469 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) | |
| 470 | 470 |  				{ | 
| 471 | -					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); | |
| 471 | +					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE")); | |
| 472 | 472 | } | 
| 473 | -				elseif(!$matching_pattern = $this->is_excluded($file) ){ | |
| 474 | -					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); | |
| 473 | +				elseif (!$matching_pattern = $this->is_excluded($file)) { | |
| 474 | +					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE")); | |
| 475 | 475 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); | 
| 476 | 476 | $this->store_file($file); | 
| 477 | 477 | $this->files_counter++; | 
| 478 | - if(isset($file['size'])) | |
| 478 | + if (isset($file['size'])) | |
| 479 | 479 | $this->files_size += $file['size']; | 
| 480 | 480 | |
| 481 | -				}else{ | |
| 482 | -					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); | |
| 481 | +				} else { | |
| 482 | +					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE")); | |
| 483 | 483 | } | 
| 484 | 484 | } | 
| 485 | 485 | |
| 486 | -		}catch(Exception $e){ | |
| 486 | +		}catch (Exception $e) { | |
| 487 | 487 | |
| 488 | 488 | $this->logger->error($e->getMessage()); | 
| 489 | 489 | |
| @@ -497,9 +497,9 @@ discard block | ||
| 497 | 497 | |
| 498 | 498 | $start_time = microtime(); | 
| 499 | 499 | |
| 500 | - $data = str_repeat(rand(0,9), 1024*1024); //write 1MB data | |
| 500 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data | |
| 501 | 501 | |
| 502 | -		try{ | |
| 502 | +		try { | |
| 503 | 503 | $this->tmp_filesystem->write($tmp_file, $data); | 
| 504 | 504 | |
| 505 | 505 | $end_time = microtime() - $start_time; | 
| @@ -510,7 +510,7 @@ discard block | ||
| 510 | 510 | |
| 511 | 511 | $this->tmp_filesystem->delete($tmp_file); | 
| 512 | 512 | |
| 513 | -		}catch(Exception $e){ | |
| 513 | +		}catch (Exception $e) { | |
| 514 | 514 | |
| 515 | 515 | $this->logger->error($e->getMessage()); | 
| 516 | 516 | |
| @@ -531,10 +531,10 @@ discard block | ||
| 531 | 531 | |
| 532 | 532 | $files = $this->storage_filesystem->listContents(); | 
| 533 | 533 | |
| 534 | - if(is_array($files)) | |
| 535 | - foreach($files as $file) | |
| 534 | + if (is_array($files)) | |
| 535 | + foreach ($files as $file) | |
| 536 | 536 |  			{ | 
| 537 | - if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) | |
| 537 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) | |
| 538 | 538 |  				{ | 
| 539 | 539 | $_storage_size += $file['size']; //bytes | 
| 540 | 540 | $_backup_files_list[] = $file; | 
| @@ -542,15 +542,15 @@ discard block | ||
| 542 | 542 | } | 
| 543 | 543 | |
| 544 | 544 | |
| 545 | - $this->sort_by($_backup_files_list, "timestamp","asc"); | |
| 545 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); | |
| 546 | 546 | |
| 547 | 547 | $_backups_counter = sizeof($_backup_files_list); | 
| 548 | 548 | |
| 549 | - foreach($_backup_files_list as $file) | |
| 549 | + foreach ($_backup_files_list as $file) | |
| 550 | 550 |  		{ | 
| 551 | 551 | //processing rule folder capacity | 
| 552 | -			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && | |
| 553 | -			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	 | |
| 552 | +			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && | |
| 553 | +			$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	 | |
| 554 | 554 |  			{ | 
| 555 | 555 | $this->storage_filesystem->delete($file['path']); | 
| 556 | 556 | $_storage_size -= $file['size']; | 
| @@ -558,14 +558,14 @@ discard block | ||
| 558 | 558 | } | 
| 559 | 559 | |
| 560 | 560 | //processing rule days limit | 
| 561 | -			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) | |
| 561 | +			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) | |
| 562 | 562 |  			{ | 
| 563 | 563 | $this->storage_filesystem->delete($file['path']); | 
| 564 | 564 |  				$this->logger->info("Deleting backup ".$file['path']." matching rule", array("RETENTION LIMIT TIMESTAMP", $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days'))); | 
| 565 | 565 | } | 
| 566 | 566 | |
| 567 | 567 | //processing backup countert limit | 
| 568 | -			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) | |
| 568 | +			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) | |
| 569 | 569 |  			{ | 
| 570 | 570 | $this->storage_filesystem->delete($file['path']); | 
| 571 | 571 | $_backups_counter--; | 
| @@ -591,33 +591,33 @@ discard block | ||
| 591 | 591 | |
| 592 | 592 | } | 
| 593 | 593 | |
| 594 | - public function process_backup_name($name = "", $max_length=100) | |
| 594 | + public function process_backup_name($name = "", $max_length = 100) | |
| 595 | 595 |  	{ | 
| 596 | - if(!$name) | |
| 596 | + if (!$name) | |
| 597 | 597 | $name = $this->xcloner_settings->get_default_backup_name(); | 
| 598 | 598 | |
| 599 | - foreach($this->backup_name_tags as $tag) | |
| 599 | + foreach ($this->backup_name_tags as $tag) | |
| 600 | 600 |  		{ | 
| 601 | - if($tag == '[time]') | |
| 602 | -				$name = str_replace($tag, date("Y-m-d_H-i"),$name); | |
| 603 | - elseif($tag == '[hostname]') | |
| 604 | - $name = str_replace($tag, gethostname() ,$name); | |
| 605 | - elseif($tag == '[domain]') | |
| 601 | + if ($tag == '[time]') | |
| 602 | +				$name = str_replace($tag, date("Y-m-d_H-i"), $name); | |
| 603 | + elseif ($tag == '[hostname]') | |
| 604 | + $name = str_replace($tag, gethostname(), $name); | |
| 605 | + elseif ($tag == '[domain]') | |
| 606 | 606 |  			{ | 
| 607 | 607 | $domain = parse_url(admin_url(), PHP_URL_HOST); | 
| 608 | - $name = str_replace($tag, $domain ,$name); | |
| 608 | + $name = str_replace($tag, $domain, $name); | |
| 609 | 609 | } | 
| 610 | 610 | } | 
| 611 | 611 | |
| 612 | - if($max_length) | |
| 612 | + if ($max_length) | |
| 613 | 613 | $name = substr($name, 0, $max_length); | 
| 614 | 614 | |
| 615 | 615 | return $name; | 
| 616 | 616 | } | 
| 617 | 617 | |
| 618 | - public function sort_by( &$array, $field, $direction = 'asc') | |
| 618 | + public function sort_by(&$array, $field, $direction = 'asc') | |
| 619 | 619 |  	{ | 
| 620 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) | |
| 620 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) | |
| 621 | 621 | $direction = SORT_DESC; | 
| 622 | 622 | else | 
| 623 | 623 | $direction = SORT_ASC; | 
| @@ -637,7 +637,7 @@ discard block | ||
| 637 | 637 | $tmp = array(); | 
| 638 | 638 | foreach ($data as $key => $row) | 
| 639 | 639 |  	            { | 
| 640 | - if(is_array($row)) | |
| 640 | + if (is_array($row)) | |
| 641 | 641 | $tmp[$key] = $row[$field]; | 
| 642 | 642 | else | 
| 643 | 643 | $tmp[$key] = $row->$field; | 
| @@ -656,29 +656,29 @@ discard block | ||
| 656 | 656 |  	{ | 
| 657 | 657 |  		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); | 
| 658 | 658 | |
| 659 | -		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) | |
| 659 | +		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) | |
| 660 | 660 |  		{ | 
| 661 | - if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) | |
| 661 | + if (isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) | |
| 662 | 662 | return "> ".$xcloner_exclude_files_larger_than_mb."MB"; | 
| 663 | 663 | } | 
| 664 | 664 | |
| 665 | - if(!sizeof($this->excluded_files)) | |
| 665 | + if (!sizeof($this->excluded_files)) | |
| 666 | 666 | $this->set_excluded_files(); | 
| 667 | 667 | |
| 668 | - if(is_array($this->excluded_files)) | |
| 669 | - foreach($this->excluded_files as $excluded_file_pattern) | |
| 668 | + if (is_array($this->excluded_files)) | |
| 669 | + foreach ($this->excluded_files as $excluded_file_pattern) | |
| 670 | 670 |  		{ | 
| 671 | - if($excluded_file_pattern == "/") | |
| 671 | + if ($excluded_file_pattern == "/") | |
| 672 | 672 | $needle = "$"; | 
| 673 | 673 | else | 
| 674 | 674 | $needle = "$".$excluded_file_pattern; | 
| 675 | 675 | |
| 676 | -			if(strstr("$".$file['path'], $needle)){ | |
| 676 | +			if (strstr("$".$file['path'], $needle)) { | |
| 677 | 677 | return $excluded_file_pattern; | 
| 678 | 678 | } | 
| 679 | 679 | } | 
| 680 | 680 | |
| 681 | - if( $regex = $this->is_excluded_regex($file)) | |
| 681 | + if ($regex = $this->is_excluded_regex($file)) | |
| 682 | 682 | return $regex; | 
| 683 | 683 | |
| 684 | 684 | return false; | 
| @@ -724,25 +724,25 @@ discard block | ||
| 724 | 724 | |
| 725 | 725 | //print_r($regex_patterns);exit; | 
| 726 | 726 | |
| 727 | - if(is_array($regex_patterns)) | |
| 727 | + if (is_array($regex_patterns)) | |
| 728 | 728 |  		{ | 
| 729 | 729 | //$this->excluded_files = array(); | 
| 730 | 730 | //$this->excluded_files[] ="(.*)\.(git)(.*)$"; | 
| 731 | 731 | //$this->excluded_files[] ="wp-content\/backups(.*)$"; | 
| 732 | 732 | |
| 733 | - foreach($regex_patterns as $excluded_file_pattern) | |
| 733 | + foreach ($regex_patterns as $excluded_file_pattern) | |
| 734 | 734 |  			{ | 
| 735 | 735 | |
| 736 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") | |
| 737 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); | |
| 736 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r") | |
| 737 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); | |
| 738 | 738 | |
| 739 | - if($file['path'] == "/") | |
| 739 | + if ($file['path'] == "/") | |
| 740 | 740 | $needle = "/"; | 
| 741 | 741 | else | 
| 742 | 742 | $needle = "/".$file['path']; | 
| 743 | 743 | //echo $needle."---".$excluded_file_pattern."---\n"; | 
| 744 | 744 | |
| 745 | -				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ | |
| 745 | +				if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { | |
| 746 | 746 | return $excluded_file_pattern; | 
| 747 | 747 | } | 
| 748 | 748 | } | 
| @@ -755,27 +755,27 @@ discard block | ||
| 755 | 755 |  	{ | 
| 756 | 756 |  		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); | 
| 757 | 757 | |
| 758 | - if(!isset($file['size'])) | |
| 758 | + if (!isset($file['size'])) | |
| 759 | 759 | $file['size'] = 0; | 
| 760 | - if(!isset($file['visibility'])) | |
| 760 | + if (!isset($file['visibility'])) | |
| 761 | 761 | $file['visibility'] = "private"; | 
| 762 | 762 | |
| 763 | 763 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; | 
| 764 | 764 | |
| 765 | 765 | $this->last_logged_file = $file['path']; | 
| 766 | 766 | |
| 767 | -		try{ | |
| 767 | +		try { | |
| 768 | 768 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); | 
| 769 | 769 | |
| 770 | -		}catch(Exception $e){ | |
| 770 | +		}catch (Exception $e) { | |
| 771 | 771 | |
| 772 | 772 | $this->logger->error($e->getMessage()); | 
| 773 | 773 | } | 
| 774 | 774 | |
| 775 | -		if($file['type'] == "dir"){ | |
| 776 | -			try{ | |
| 775 | +		if ($file['type'] == "dir") { | |
| 776 | +			try { | |
| 777 | 777 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); | 
| 778 | -			}catch(Exception $e){ | |
| 778 | +			}catch (Exception $e) { | |
| 779 | 779 | $this->logger->error($e->getMessage()); | 
| 780 | 780 | } | 
| 781 | 781 | } | 
| @@ -788,13 +788,13 @@ discard block | ||
| 788 | 788 | |
| 789 | 789 | public function get_filesystem($system = "") | 
| 790 | 790 |  	{ | 
| 791 | - if($system == "storage_filesystem_append") | |
| 791 | + if ($system == "storage_filesystem_append") | |
| 792 | 792 | return $this->storage_filesystem_append; | 
| 793 | - elseif($system == "tmp_filesystem_append") | |
| 793 | + elseif ($system == "tmp_filesystem_append") | |
| 794 | 794 | return $this->tmp_filesystem_append; | 
| 795 | - elseif($system == "tmp_filesystem") | |
| 795 | + elseif ($system == "tmp_filesystem") | |
| 796 | 796 | return $this->tmp_filesystem; | 
| 797 | - elseif($system == "storage_filesystem") | |
| 797 | + elseif ($system == "storage_filesystem") | |
| 798 | 798 | return $this->storage_filesystem; | 
| 799 | 799 | else | 
| 800 | 800 | return $this->start_filesystem; | 
| @@ -802,9 +802,9 @@ discard block | ||
| 802 | 802 | |
| 803 | 803 | public function get_adapter($system) | 
| 804 | 804 |  	{ | 
| 805 | - if($system == "tmp_filesystem") | |
| 805 | + if ($system == "tmp_filesystem") | |
| 806 | 806 | return $this->tmp_adapter; | 
| 807 | - elseif($system == "storage_filesystem") | |
| 807 | + elseif ($system == "storage_filesystem") | |
| 808 | 808 | return $this->storage_adapter; | 
| 809 | 809 | else | 
| 810 | 810 | return $this->start_adapter; | 
| @@ -812,10 +812,10 @@ discard block | ||
| 812 | 812 | |
| 813 | 813 | private function scan_finished() | 
| 814 | 814 |  	{ | 
| 815 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) | |
| 815 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) | |
| 816 | 816 | return false; | 
| 817 | 817 | |
| 818 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) | |
| 818 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) | |
| 819 | 819 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); | 
| 820 | 820 | |
| 821 | 821 |  		$this->logger->debug(sprintf(("File scan finished"))); | 
| @@ -825,7 +825,7 @@ discard block | ||
| 825 | 825 | |
| 826 | 826 | private function calc_to_bytes($mb_size) | 
| 827 | 827 |  	{ | 
| 828 | - return $mb_size*(1024*1024); | |
| 828 | + return $mb_size * (1024 * 1024); | |
| 829 | 829 | } | 
| 830 | 830 | |
| 831 | 831 | } | 
| @@ -60,13 +60,14 @@ discard block | ||
| 60 | 60 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ | 
| 61 | 61 | 'disable_asserts' => true, | 
| 62 | 62 | ])); | 
| 63 | -		}catch(Exception $e){ | |
| 63 | +		} catch(Exception $e){ | |
| 64 | 64 | return false; | 
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | |
| 68 | -		if($value = get_option('xcloner_directories_to_scan_per_request')) | |
| 69 | - $this->folders_to_process_per_session = $value; | |
| 68 | +		if($value = get_option('xcloner_directories_to_scan_per_request')) { | |
| 69 | + $this->folders_to_process_per_session = $value; | |
| 70 | + } | |
| 70 | 71 | |
| 71 | 72 | } | 
| 72 | 73 | |
| @@ -129,8 +130,9 @@ discard block | ||
| 129 | 130 | public function get_included_files_handler($metadata = 0) | 
| 130 | 131 |  	{ | 
| 131 | 132 | $path = $this->included_files_handler; | 
| 132 | - if(!$metadata) | |
| 133 | - return $path; | |
| 133 | +		if(!$metadata) { | |
| 134 | + return $path; | |
| 135 | + } | |
| 134 | 136 | |
| 135 | 137 |  		$spl_info = $this->getMetadataFull('tmp_adapter', $path); | 
| 136 | 138 | return $spl_info; | 
| @@ -146,31 +148,36 @@ discard block | ||
| 146 | 148 |  	{ | 
| 147 | 149 | $files = $this->get_backup_archives_list(); | 
| 148 | 150 | |
| 149 | - if(is_array($files)) | |
| 150 | - $this->sort_by($files, "timestamp","desc"); | |
| 151 | +		if(is_array($files)) { | |
| 152 | + $this->sort_by($files, "timestamp","desc"); | |
| 153 | + } | |
| 151 | 154 | |
| 152 | 155 | $new_list = array(); | 
| 153 | 156 | |
| 154 | - foreach($files as $key=>$file) | |
| 155 | - if(!isset($file['parent'])) | |
| 157 | +		foreach($files as $key=>$file) { | |
| 158 | + if(!isset($file['parent'])) | |
| 156 | 159 | $new_list[] = ($files[$key]); | 
| 160 | + } | |
| 157 | 161 | |
| 158 | - if(isset($new_list[0])) | |
| 159 | - return $new_list[0]; | |
| 162 | +		if(isset($new_list[0])) { | |
| 163 | + return $new_list[0]; | |
| 164 | + } | |
| 160 | 165 | } | 
| 161 | 166 | |
| 162 | 167 | public function get_latest_backups() | 
| 163 | 168 |  	{ | 
| 164 | 169 | $files = $this->get_backup_archives_list(); | 
| 165 | 170 | |
| 166 | - if(is_array($files)) | |
| 167 | - $this->sort_by($files, "timestamp","desc"); | |
| 171 | +		if(is_array($files)) { | |
| 172 | + $this->sort_by($files, "timestamp","desc"); | |
| 173 | + } | |
| 168 | 174 | |
| 169 | 175 | $new_list = array(); | 
| 170 | 176 | |
| 171 | - foreach($files as $key=>$file) | |
| 172 | - if(!isset($file['parent'])) | |
| 177 | +		foreach($files as $key=>$file) { | |
| 178 | + if(!isset($file['parent'])) | |
| 173 | 179 | $new_list[] = ($files[$key]); | 
| 180 | + } | |
| 174 | 181 | |
| 175 | 182 | return $new_list; | 
| 176 | 183 | } | 
| @@ -180,25 +187,28 @@ discard block | ||
| 180 | 187 | $files = $this->get_backup_archives_list(); | 
| 181 | 188 | $total = 0; | 
| 182 | 189 | |
| 183 | - if(is_array($files)) | |
| 184 | - foreach($files as $file) | |
| 190 | +		if(is_array($files)) { | |
| 191 | + foreach($files as $file) | |
| 185 | 192 | $total += $file['size']; | 
| 193 | + } | |
| 186 | 194 | |
| 187 | 195 | return $total; | 
| 188 | 196 | } | 
| 189 | 197 | |
| 190 | 198 | public function is_part($backup_name) | 
| 191 | 199 |  	{ | 
| 192 | - if(stristr($backup_name, "-part")) | |
| 193 | - return true; | |
| 200 | +		if(stristr($backup_name, "-part")) { | |
| 201 | + return true; | |
| 202 | + } | |
| 194 | 203 | |
| 195 | 204 | return false; | 
| 196 | 205 | } | 
| 197 | 206 | |
| 198 | 207 | public function is_multipart($backup_name) | 
| 199 | 208 |  	{ | 
| 200 | - if(stristr($backup_name, "-multipart")) | |
| 201 | - return true; | |
| 209 | +		if(stristr($backup_name, "-multipart")) { | |
| 210 | + return true; | |
| 211 | + } | |
| 202 | 212 | |
| 203 | 213 | return false; | 
| 204 | 214 | } | 
| @@ -209,8 +219,9 @@ discard block | ||
| 209 | 219 | if($this->is_multipart($backup_name)) | 
| 210 | 220 |  		{ | 
| 211 | 221 | $backup_parts = $this->get_multipart_files($backup_name); | 
| 212 | - foreach($backup_parts as $part_file) | |
| 213 | - $backup_size += $this->get_storage_filesystem()->getSize($part_file); | |
| 222 | +			foreach($backup_parts as $part_file) { | |
| 223 | + $backup_size += $this->get_storage_filesystem()->getSize($part_file); | |
| 224 | + } | |
| 214 | 225 | } | 
| 215 | 226 | |
| 216 | 227 | return $backup_size; | 
| @@ -251,10 +262,11 @@ discard block | ||
| 251 | 262 | } | 
| 252 | 263 | } | 
| 253 | 264 | |
| 254 | - if($this->get_storage_filesystem()->delete($backup_name)) | |
| 255 | - $return = true; | |
| 256 | - else | |
| 257 | - $return = false; | |
| 265 | +		if($this->get_storage_filesystem()->delete($backup_name)) { | |
| 266 | + $return = true; | |
| 267 | +		} else { | |
| 268 | + $return = false; | |
| 269 | + } | |
| 258 | 270 | |
| 259 | 271 | return $return; | 
| 260 | 272 | } | 
| @@ -272,8 +284,9 @@ discard block | ||
| 272 | 284 |  	{ | 
| 273 | 285 | $list = array(); | 
| 274 | 286 | |
| 275 | - if(method_exists($this->get_storage_filesystem(), "listContents")) | |
| 276 | - $list = $this->get_storage_filesystem()->listContents(); | |
| 287 | +		if(method_exists($this->get_storage_filesystem(), "listContents")) { | |
| 288 | + $list = $this->get_storage_filesystem()->listContents(); | |
| 289 | + } | |
| 277 | 290 | |
| 278 | 291 | |
| 279 | 292 | $backup_files = array(); | 
| @@ -286,10 +299,11 @@ discard block | ||
| 286 | 299 | if(isset($file_info['extension']) and $file_info['extension'] == "csv") | 
| 287 | 300 |  			{ | 
| 288 | 301 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); | 
| 289 | - foreach($lines as $line) | |
| 290 | - if($line) | |
| 302 | +				foreach($lines as $line) { | |
| 303 | + if($line) | |
| 291 | 304 |  					{ | 
| 292 | 305 | $data = str_getcsv($line); | 
| 306 | + } | |
| 293 | 307 |  						if(is_array($data)){ | 
| 294 | 308 | $parents[$data[0]] = $file_info['path']; | 
| 295 | 309 | $file_info['childs'][] = $data; | 
| @@ -299,14 +313,16 @@ discard block | ||
| 299 | 313 | |
| 300 | 314 | } | 
| 301 | 315 | |
| 302 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) | |
| 303 | - $backup_files[$file_info['path']] = $file_info; | |
| 316 | +			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { | |
| 317 | + $backup_files[$file_info['path']] = $file_info; | |
| 318 | + } | |
| 304 | 319 | } | 
| 305 | 320 | |
| 306 | 321 | foreach($backup_files as $key=>$file_info) | 
| 307 | 322 |  		{ | 
| 308 | - if(isset($parents[$file_info['path']])) | |
| 309 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; | |
| 323 | +			if(isset($parents[$file_info['path']])) { | |
| 324 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; | |
| 325 | + } | |
| 310 | 326 | } | 
| 311 | 327 | |
| 312 | 328 | return $backup_files; | 
| @@ -332,11 +348,11 @@ discard block | ||
| 332 | 348 |  				if($counter < $this->folders_to_process_per_session){ | 
| 333 | 349 | $this->build_files_list($file); | 
| 334 | 350 | $counter++; | 
| 335 | -				}else{ | |
| 351 | +				} else{ | |
| 336 | 352 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); | 
| 337 | 353 | } | 
| 338 | 354 | } | 
| 339 | -		}else{ | |
| 355 | +		} else{ | |
| 340 | 356 | $this->build_files_list(); | 
| 341 | 357 | } | 
| 342 | 358 | |
| @@ -378,8 +394,9 @@ discard block | ||
| 378 | 394 |  	{ | 
| 379 | 395 | $return = array(); | 
| 380 | 396 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); | 
| 381 | -		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) | |
| 382 | - $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); | |
| 397 | +		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { | |
| 398 | + $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); | |
| 399 | + } | |
| 383 | 400 | |
| 384 | 401 | return $return; | 
| 385 | 402 | } | 
| @@ -391,9 +408,10 @@ discard block | ||
| 391 | 408 | |
| 392 | 409 | $contents = $this->get_tmp_filesystem()->listContents(); | 
| 393 | 410 | |
| 394 | - if(is_array($contents)) | |
| 395 | - foreach($contents as $file_info) | |
| 411 | +		if(is_array($contents)) { | |
| 412 | + foreach($contents as $file_info) | |
| 396 | 413 | $this->get_tmp_filesystem()->delete($file_info['path']); | 
| 414 | + } | |
| 397 | 415 | |
| 398 | 416 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); | 
| 399 | 417 | |
| @@ -404,17 +422,21 @@ discard block | ||
| 404 | 422 |  	{ | 
| 405 | 423 | $this->files_counter = 0; | 
| 406 | 424 | |
| 407 | -		if(!$this->storage_filesystem->has("index.html"))	 | |
| 408 | -			$this->storage_filesystem->write("index.html",""); | |
| 425 | +		if(!$this->storage_filesystem->has("index.html")) { | |
| 426 | +					$this->storage_filesystem->write("index.html",""); | |
| 427 | + } | |
| 409 | 428 | |
| 410 | -		if(!$this->tmp_filesystem->has("index.html"))	 | |
| 411 | -			$this->tmp_filesystem->write("index.html",""); | |
| 429 | +		if(!$this->tmp_filesystem->has("index.html")) { | |
| 430 | +					$this->tmp_filesystem->write("index.html",""); | |
| 431 | + } | |
| 412 | 432 | |
| 413 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) | |
| 414 | - $this->tmp_filesystem->delete($this->get_included_files_handler()); | |
| 433 | +		if($this->tmp_filesystem->has($this->get_included_files_handler())) { | |
| 434 | + $this->tmp_filesystem->delete($this->get_included_files_handler()); | |
| 435 | + } | |
| 415 | 436 | |
| 416 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) | |
| 417 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); | |
| 437 | +		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { | |
| 438 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); | |
| 439 | + } | |
| 418 | 440 | } | 
| 419 | 441 | |
| 420 | 442 | public function get_scanned_files_num() | 
| @@ -434,8 +456,9 @@ discard block | ||
| 434 | 456 | |
| 435 | 457 | public function set_excluded_files($excluded_files = array()) | 
| 436 | 458 |  	{ | 
| 437 | - if(!is_array($excluded_files)) | |
| 438 | - $excluded_files = array(); | |
| 459 | +		if(!is_array($excluded_files)) { | |
| 460 | + $excluded_files = array(); | |
| 461 | + } | |
| 439 | 462 | |
| 440 | 463 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); | 
| 441 | 464 | |
| @@ -469,21 +492,21 @@ discard block | ||
| 469 | 492 | if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) | 
| 470 | 493 |  				{ | 
| 471 | 494 |  					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); | 
| 472 | - } | |
| 473 | -				elseif(!$matching_pattern = $this->is_excluded($file) ){ | |
| 495 | +				} elseif(!$matching_pattern = $this->is_excluded($file) ){ | |
| 474 | 496 |  					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); | 
| 475 | 497 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); | 
| 476 | 498 | $this->store_file($file); | 
| 477 | 499 | $this->files_counter++; | 
| 478 | - if(isset($file['size'])) | |
| 479 | - $this->files_size += $file['size']; | |
| 500 | +					if(isset($file['size'])) { | |
| 501 | + $this->files_size += $file['size']; | |
| 502 | + } | |
| 480 | 503 | |
| 481 | -				}else{ | |
| 504 | +				} else{ | |
| 482 | 505 |  					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); | 
| 483 | 506 | } | 
| 484 | 507 | } | 
| 485 | 508 | |
| 486 | -		}catch(Exception $e){ | |
| 509 | +		} catch(Exception $e){ | |
| 487 | 510 | |
| 488 | 511 | $this->logger->error($e->getMessage()); | 
| 489 | 512 | |
| @@ -510,7 +533,7 @@ discard block | ||
| 510 | 533 | |
| 511 | 534 | $this->tmp_filesystem->delete($tmp_file); | 
| 512 | 535 | |
| 513 | -		}catch(Exception $e){ | |
| 536 | +		} catch(Exception $e){ | |
| 514 | 537 | |
| 515 | 538 | $this->logger->error($e->getMessage()); | 
| 516 | 539 | |
| @@ -531,12 +554,14 @@ discard block | ||
| 531 | 554 | |
| 532 | 555 | $files = $this->storage_filesystem->listContents(); | 
| 533 | 556 | |
| 534 | - if(is_array($files)) | |
| 535 | - foreach($files as $file) | |
| 557 | +		if(is_array($files)) { | |
| 558 | + foreach($files as $file) | |
| 536 | 559 |  			{ | 
| 537 | 560 | if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) | 
| 538 | 561 |  				{ | 
| 539 | - $_storage_size += $file['size']; //bytes | |
| 562 | + $_storage_size += $file['size']; | |
| 563 | + } | |
| 564 | + //bytes | |
| 540 | 565 | $_backup_files_list[] = $file; | 
| 541 | 566 | } | 
| 542 | 567 | } | 
| @@ -550,9 +575,11 @@ discard block | ||
| 550 | 575 |  		{ | 
| 551 | 576 | //processing rule folder capacity | 
| 552 | 577 |  			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && | 
| 553 | -			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	 | |
| 578 | +			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) { | |
| 579 | + //bytes | |
| 554 | 580 |  			{ | 
| 555 | 581 | $this->storage_filesystem->delete($file['path']); | 
| 582 | + } | |
| 556 | 583 | $_storage_size -= $file['size']; | 
| 557 | 584 |  				$this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit)); | 
| 558 | 585 | } | 
| @@ -593,34 +620,37 @@ discard block | ||
| 593 | 620 | |
| 594 | 621 | public function process_backup_name($name = "", $max_length=100) | 
| 595 | 622 |  	{ | 
| 596 | - if(!$name) | |
| 597 | - $name = $this->xcloner_settings->get_default_backup_name(); | |
| 623 | +		if(!$name) { | |
| 624 | + $name = $this->xcloner_settings->get_default_backup_name(); | |
| 625 | + } | |
| 598 | 626 | |
| 599 | 627 | foreach($this->backup_name_tags as $tag) | 
| 600 | 628 |  		{ | 
| 601 | - if($tag == '[time]') | |
| 602 | -				$name = str_replace($tag, date("Y-m-d_H-i"),$name); | |
| 603 | - elseif($tag == '[hostname]') | |
| 604 | - $name = str_replace($tag, gethostname() ,$name); | |
| 605 | - elseif($tag == '[domain]') | |
| 629 | +			if($tag == '[time]') { | |
| 630 | +							$name = str_replace($tag, date("Y-m-d_H-i"),$name); | |
| 631 | +			} elseif($tag == '[hostname]') { | |
| 632 | + $name = str_replace($tag, gethostname() ,$name); | |
| 633 | + } elseif($tag == '[domain]') | |
| 606 | 634 |  			{ | 
| 607 | 635 | $domain = parse_url(admin_url(), PHP_URL_HOST); | 
| 608 | 636 | $name = str_replace($tag, $domain ,$name); | 
| 609 | 637 | } | 
| 610 | 638 | } | 
| 611 | 639 | |
| 612 | - if($max_length) | |
| 613 | - $name = substr($name, 0, $max_length); | |
| 640 | +		if($max_length) { | |
| 641 | + $name = substr($name, 0, $max_length); | |
| 642 | + } | |
| 614 | 643 | |
| 615 | 644 | return $name; | 
| 616 | 645 | } | 
| 617 | 646 | |
| 618 | 647 | public function sort_by( &$array, $field, $direction = 'asc') | 
| 619 | 648 |  	{ | 
| 620 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) | |
| 621 | - $direction = SORT_DESC; | |
| 622 | - else | |
| 623 | - $direction = SORT_ASC; | |
| 649 | +		if(strtolower($direction) == "desc" || $direction == SORT_DESC) { | |
| 650 | + $direction = SORT_DESC; | |
| 651 | +		} else { | |
| 652 | + $direction = SORT_ASC; | |
| 653 | + } | |
| 624 | 654 | |
| 625 | 655 | $array = $this->array_orderby($array, $field, $direction); | 
| 626 | 656 | |
| @@ -637,10 +667,11 @@ discard block | ||
| 637 | 667 | $tmp = array(); | 
| 638 | 668 | foreach ($data as $key => $row) | 
| 639 | 669 |  	            { | 
| 640 | - if(is_array($row)) | |
| 641 | - $tmp[$key] = $row[$field]; | |
| 642 | - else | |
| 643 | - $tmp[$key] = $row->$field; | |
| 670 | +					if(is_array($row)) { | |
| 671 | + $tmp[$key] = $row[$field]; | |
| 672 | +					} else { | |
| 673 | + $tmp[$key] = $row->$field; | |
| 674 | + } | |
| 644 | 675 | } | 
| 645 | 676 | $args[$n] = $tmp; | 
| 646 | 677 | } | 
| @@ -658,28 +689,32 @@ discard block | ||
| 658 | 689 | |
| 659 | 690 |  		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) | 
| 660 | 691 |  		{ | 
| 661 | - if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) | |
| 662 | - return "> ".$xcloner_exclude_files_larger_than_mb."MB"; | |
| 692 | +			if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { | |
| 693 | + return "> ".$xcloner_exclude_files_larger_than_mb."MB"; | |
| 694 | + } | |
| 663 | 695 | } | 
| 664 | 696 | |
| 665 | - if(!sizeof($this->excluded_files)) | |
| 666 | - $this->set_excluded_files(); | |
| 697 | +		if(!sizeof($this->excluded_files)) { | |
| 698 | + $this->set_excluded_files(); | |
| 699 | + } | |
| 667 | 700 | |
| 668 | - if(is_array($this->excluded_files)) | |
| 669 | - foreach($this->excluded_files as $excluded_file_pattern) | |
| 701 | +		if(is_array($this->excluded_files)) { | |
| 702 | + foreach($this->excluded_files as $excluded_file_pattern) | |
| 670 | 703 |  		{ | 
| 671 | 704 | if($excluded_file_pattern == "/") | 
| 672 | 705 | $needle = "$"; | 
| 673 | - else | |
| 674 | - $needle = "$".$excluded_file_pattern; | |
| 706 | +		} else { | |
| 707 | + $needle = "$".$excluded_file_pattern; | |
| 708 | + } | |
| 675 | 709 | |
| 676 | 710 |  			if(strstr("$".$file['path'], $needle)){ | 
| 677 | 711 | return $excluded_file_pattern; | 
| 678 | 712 | } | 
| 679 | 713 | } | 
| 680 | 714 | |
| 681 | - if( $regex = $this->is_excluded_regex($file)) | |
| 682 | - return $regex; | |
| 715 | +		if( $regex = $this->is_excluded_regex($file)) { | |
| 716 | + return $regex; | |
| 717 | + } | |
| 683 | 718 | |
| 684 | 719 | return false; | 
| 685 | 720 | } | 
| @@ -733,13 +768,15 @@ discard block | ||
| 733 | 768 | foreach($regex_patterns as $excluded_file_pattern) | 
| 734 | 769 |  			{ | 
| 735 | 770 | |
| 736 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") | |
| 737 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); | |
| 771 | +				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") { | |
| 772 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); | |
| 773 | + } | |
| 738 | 774 | |
| 739 | - if($file['path'] == "/") | |
| 740 | - $needle = "/"; | |
| 741 | - else | |
| 742 | - $needle = "/".$file['path']; | |
| 775 | +				if($file['path'] == "/") { | |
| 776 | + $needle = "/"; | |
| 777 | +				} else { | |
| 778 | + $needle = "/".$file['path']; | |
| 779 | + } | |
| 743 | 780 | //echo $needle."---".$excluded_file_pattern."---\n"; | 
| 744 | 781 | |
| 745 | 782 |  				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ | 
| @@ -755,10 +792,12 @@ discard block | ||
| 755 | 792 |  	{ | 
| 756 | 793 |  		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); | 
| 757 | 794 | |
| 758 | - if(!isset($file['size'])) | |
| 759 | - $file['size'] = 0; | |
| 760 | - if(!isset($file['visibility'])) | |
| 761 | - $file['visibility'] = "private"; | |
| 795 | +		if(!isset($file['size'])) { | |
| 796 | + $file['size'] = 0; | |
| 797 | + } | |
| 798 | +		if(!isset($file['visibility'])) { | |
| 799 | + $file['visibility'] = "private"; | |
| 800 | + } | |
| 762 | 801 | |
| 763 | 802 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; | 
| 764 | 803 | |
| @@ -767,7 +806,7 @@ discard block | ||
| 767 | 806 |  		try{ | 
| 768 | 807 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); | 
| 769 | 808 | |
| 770 | -		}catch(Exception $e){ | |
| 809 | +		} catch(Exception $e){ | |
| 771 | 810 | |
| 772 | 811 | $this->logger->error($e->getMessage()); | 
| 773 | 812 | } | 
| @@ -775,7 +814,7 @@ discard block | ||
| 775 | 814 |  		if($file['type'] == "dir"){ | 
| 776 | 815 |  			try{ | 
| 777 | 816 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); | 
| 778 | -			}catch(Exception $e){ | |
| 817 | +			} catch(Exception $e){ | |
| 779 | 818 | $this->logger->error($e->getMessage()); | 
| 780 | 819 | } | 
| 781 | 820 | } | 
| @@ -788,35 +827,39 @@ discard block | ||
| 788 | 827 | |
| 789 | 828 | public function get_filesystem($system = "") | 
| 790 | 829 |  	{ | 
| 791 | - if($system == "storage_filesystem_append") | |
| 792 | - return $this->storage_filesystem_append; | |
| 793 | - elseif($system == "tmp_filesystem_append") | |
| 794 | - return $this->tmp_filesystem_append; | |
| 795 | - elseif($system == "tmp_filesystem") | |
| 796 | - return $this->tmp_filesystem; | |
| 797 | - elseif($system == "storage_filesystem") | |
| 798 | - return $this->storage_filesystem; | |
| 799 | - else | |
| 800 | - return $this->start_filesystem; | |
| 830 | +		if($system == "storage_filesystem_append") { | |
| 831 | + return $this->storage_filesystem_append; | |
| 832 | +		} elseif($system == "tmp_filesystem_append") { | |
| 833 | + return $this->tmp_filesystem_append; | |
| 834 | +		} elseif($system == "tmp_filesystem") { | |
| 835 | + return $this->tmp_filesystem; | |
| 836 | +		} elseif($system == "storage_filesystem") { | |
| 837 | + return $this->storage_filesystem; | |
| 838 | +		} else { | |
| 839 | + return $this->start_filesystem; | |
| 840 | + } | |
| 801 | 841 | } | 
| 802 | 842 | |
| 803 | 843 | public function get_adapter($system) | 
| 804 | 844 |  	{ | 
| 805 | - if($system == "tmp_filesystem") | |
| 806 | - return $this->tmp_adapter; | |
| 807 | - elseif($system == "storage_filesystem") | |
| 808 | - return $this->storage_adapter; | |
| 809 | - else | |
| 810 | - return $this->start_adapter; | |
| 845 | +		if($system == "tmp_filesystem") { | |
| 846 | + return $this->tmp_adapter; | |
| 847 | +		} elseif($system == "storage_filesystem") { | |
| 848 | + return $this->storage_adapter; | |
| 849 | +		} else { | |
| 850 | + return $this->start_adapter; | |
| 851 | + } | |
| 811 | 852 | } | 
| 812 | 853 | |
| 813 | 854 | private function scan_finished() | 
| 814 | 855 |  	{ | 
| 815 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) | |
| 816 | - return false; | |
| 856 | +		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { | |
| 857 | + return false; | |
| 858 | + } | |
| 817 | 859 | |
| 818 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) | |
| 819 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); | |
| 860 | +		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { | |
| 861 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); | |
| 862 | + } | |
| 820 | 863 | |
| 821 | 864 |  		$this->logger->debug(sprintf(("File scan finished"))); | 
| 822 | 865 | |
| @@ -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(); | 
| @@ -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_", | 
| @@ -87,17 +87,17 @@ discard block | ||
| 87 | 87 |  	{ | 
| 88 | 88 | $this->xcloner_sanitization = new Xcloner_Sanitization($hash); | 
| 89 | 89 | $this->xcloner_file_system = new Xcloner_File_System($hash); | 
| 90 | -		$this->logger 					= new XCloner_Logger("xcloner_remote_storage", $hash); | |
| 90 | +		$this->logger = new XCloner_Logger("xcloner_remote_storage", $hash); | |
| 91 | 91 | $this->xcloner = new Xcloner(); | 
| 92 | 92 | } | 
| 93 | 93 | |
| 94 | 94 | public function get_available_storages() | 
| 95 | 95 |  	{ | 
| 96 | 96 | $return = array(); | 
| 97 | - foreach($this->storage_fields as $storage=>$data) | |
| 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)) | |
| 100 | + if (get_option($check_field)) | |
| 101 | 101 | $return[$storage] = $data['text']; | 
| 102 | 102 | } | 
| 103 | 103 | |
| @@ -109,17 +109,17 @@ discard block | ||
| 109 | 109 | $storage = $this->xcloner_sanitization->sanitize_input_as_string($action); | 
| 110 | 110 |  		$this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action)));	 | 
| 111 | 111 | |
| 112 | - if(is_array($this->storage_fields[$storage])) | |
| 112 | + if (is_array($this->storage_fields[$storage])) | |
| 113 | 113 |  		{ | 
| 114 | - foreach($this->storage_fields[$storage] as $field=>$validation) | |
| 114 | + foreach ($this->storage_fields[$storage] as $field=>$validation) | |
| 115 | 115 |  			{ | 
| 116 | 116 | $check_field = $this->storage_fields["option_prefix"].$field; | 
| 117 | 117 | $sanitize_method = "sanitize_input_as_".$validation; | 
| 118 | 118 | |
| 119 | - if(!isset($_POST[$check_field])) | |
| 119 | + if (!isset($_POST[$check_field])) | |
| 120 | 120 | $_POST[$check_field] = 0; | 
| 121 | 121 | |
| 122 | - if(!method_exists($this->xcloner_sanitization, $sanitize_method)) | |
| 122 | + if (!method_exists($this->xcloner_sanitization, $sanitize_method)) | |
| 123 | 123 | $sanitize_method = "sanitize_input_as_string"; | 
| 124 | 124 | |
| 125 | 125 | $sanitized_value = $this->xcloner_sanitization->$sanitize_method($_POST[$check_field]); | 
| @@ -129,13 +129,13 @@ discard block | ||
| 129 | 129 |  			$this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success", ucfirst($action)); | 
| 130 | 130 | } | 
| 131 | 131 | |
| 132 | - if(isset($_POST['connection_check']) && $_POST['connection_check']) | |
| 132 | + if (isset($_POST['connection_check']) && $_POST['connection_check']) | |
| 133 | 133 |  		{ | 
| 134 | -			try{ | |
| 134 | +			try { | |
| 135 | 135 | $this->verify_filesystem($action); | 
| 136 | 136 |  				$this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", ucfirst($action)); | 
| 137 | 137 |  				$this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action)));	 | 
| 138 | -			}catch(Exception $e){ | |
| 138 | +			}catch (Exception $e) { | |
| 139 | 139 |  				$this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", ucfirst($action)); | 
| 140 | 140 | } | 
| 141 | 141 | } | 
| @@ -148,7 +148,7 @@ discard block | ||
| 148 | 148 | |
| 149 | 149 |  		$this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type)));	 | 
| 150 | 150 | |
| 151 | - if(!method_exists($this, $method)) | |
| 151 | + if (!method_exists($this, $method)) | |
| 152 | 152 | return false; | 
| 153 | 153 | |
| 154 | 154 | list($adapter, $filesystem) = $this->$method(); | 
| @@ -156,29 +156,29 @@ discard block | ||
| 156 | 156 |  		$test_file = substr(".xcloner_".md5(time()), 0, 15); | 
| 157 | 157 | |
| 158 | 158 | //testing write access | 
| 159 | - if(!$filesystem->write($test_file, "data")) | |
| 160 | -			throw new Exception(__("Could not write data",'xcloner-backup-and-restore')); | |
| 159 | + if (!$filesystem->write($test_file, "data")) | |
| 160 | +			throw new Exception(__("Could not write data", 'xcloner-backup-and-restore')); | |
| 161 | 161 |  		$this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type)));	 | 
| 162 | 162 | |
| 163 | 163 | //testing read access | 
| 164 | - if(!$filesystem->read($test_file)) | |
| 165 | -			throw new Exception(__("Could not read data",'xcloner-backup-and-restore')); | |
| 164 | + if (!$filesystem->read($test_file)) | |
| 165 | +			throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); | |
| 166 | 166 |  		$this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type)));		 | 
| 167 | 167 | |
| 168 | 168 | //delete test file | 
| 169 | - if(!$filesystem->delete($test_file)) | |
| 170 | -			throw new Exception(__("Could not delete data",'xcloner-backup-and-restore')); | |
| 169 | + if (!$filesystem->delete($test_file)) | |
| 170 | +			throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore')); | |
| 171 | 171 |  		$this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type)));		 | 
| 172 | 172 | } | 
| 173 | 173 | |
| 174 | 174 | public function upload_backup_to_storage($file, $storage) | 
| 175 | 175 |  	{ | 
| 176 | - if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) | |
| 176 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) | |
| 177 | 177 | return false; | 
| 178 | 178 | |
| 179 | 179 | $method = "get_".$storage."_filesystem"; | 
| 180 | 180 | |
| 181 | - if(!method_exists($this, $method)) | |
| 181 | + if (!method_exists($this, $method)) | |
| 182 | 182 | return false; | 
| 183 | 183 | |
| 184 | 184 | list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); | 
| @@ -188,7 +188,7 @@ discard block | ||
| 188 | 188 | |
| 189 | 189 |  		$this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)), array("")); | 
| 190 | 190 | |
| 191 | - if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) | |
| 191 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) | |
| 192 | 192 |  		{ | 
| 193 | 193 |  			$this->logger->info(sprintf("File not found %s in local storage", $file)); | 
| 194 | 194 | return false; | 
| @@ -196,22 +196,22 @@ discard block | ||
| 196 | 196 | |
| 197 | 197 | $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($file); | 
| 198 | 198 | |
| 199 | - if(!$remote_storage_filesystem->updateStream($file, $backup_file_stream)) | |
| 199 | + if (!$remote_storage_filesystem->updateStream($file, $backup_file_stream)) | |
| 200 | 200 |  		{ | 
| 201 | 201 |  			$this->logger->info(sprintf("Could not transfer file %s", $file)); | 
| 202 | 202 | return false; | 
| 203 | 203 | } | 
| 204 | 204 | |
| 205 | - if($this->xcloner_file_system->is_multipart($file)) | |
| 205 | + if ($this->xcloner_file_system->is_multipart($file)) | |
| 206 | 206 |  		{ | 
| 207 | 207 | $parts = $this->xcloner_file_system->get_multipart_files($file); | 
| 208 | - if(is_array($parts)) | |
| 209 | - foreach($parts as $part_file) | |
| 208 | + if (is_array($parts)) | |
| 209 | + foreach ($parts as $part_file) | |
| 210 | 210 |  				{ | 
| 211 | 211 |  					$this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file, strtoupper($storage)), array("")); | 
| 212 | 212 | |
| 213 | 213 | $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file); | 
| 214 | - if(!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) | |
| 214 | + if (!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) | |
| 215 | 215 | return false; | 
| 216 | 216 | } | 
| 217 | 217 | } | 
| @@ -227,19 +227,19 @@ discard block | ||
| 227 | 227 | public function clean_remote_storage($storage, $remote_storage_filesystem) | 
| 228 | 228 |  	{ | 
| 229 | 229 | $check_field = $this->storage_fields["option_prefix"].$storage."_cleanup_days"; | 
| 230 | - if($expire_days = get_option($check_field)) | |
| 230 | + if ($expire_days = get_option($check_field)) | |
| 231 | 231 |  		{ | 
| 232 | 232 |  			$this->logger->info(sprintf("Doing %s remote storage cleanup for %s days limit", strtoupper($storage), $expire_days)); | 
| 233 | 233 | $files = $remote_storage_filesystem->listContents(); | 
| 234 | 234 | |
| 235 | 235 |  			$current_timestamp = strtotime("-".$expire_days." days"); | 
| 236 | 236 | |
| 237 | - if(is_array($files)) | |
| 238 | - foreach($files as $file) | |
| 237 | + if (is_array($files)) | |
| 238 | + foreach ($files as $file) | |
| 239 | 239 |  			{ | 
| 240 | 240 | $file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']); | 
| 241 | 241 | |
| 242 | - if($current_timestamp >= $file['timestamp']) | |
| 242 | + if ($current_timestamp >= $file['timestamp']) | |
| 243 | 243 |  				{ | 
| 244 | 244 | $remote_storage_filesystem->delete($file['path']); | 
| 245 | 245 |  					$this->logger->info("Deleting remote file ".$file['path']." matching rule", array("RETENTION LIMIT TIMESTAMP", $file['timestamp']." =< ".$expire_days)); | 
| @@ -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 |  				{ | 
| @@ -115,6 +115,9 @@ | ||
| 115 | 115 | |
| 116 | 116 | } | 
| 117 | 117 | |
| 118 | + /** | |
| 119 | + * @param string $message | |
| 120 | + */ | |
| 118 | 121 | public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "") | 
| 119 | 122 |  	{ | 
| 120 | 123 | $message = sprintf(__($message), $message_param1, $message_param2, $message_param3); | 
| @@ -247,7 +247,7 @@ discard block | ||
| 247 | 247 | $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); | 
| 248 | 248 | |
| 249 | 249 | //wp_localize_script( 'ajax-script', 'my_ajax_object', | 
| 250 | - // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); | |
| 250 | + // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); | |
| 251 | 251 | |
| 252 | 252 | } | 
| 253 | 253 | |
| @@ -281,8 +281,8 @@ discard block | ||
| 281 | 281 | |
| 282 | 282 |  	private function define_plugin_settings(){ | 
| 283 | 283 | /** | 
| 284 | - * register wporg_settings_init to the admin_init action hook | |
| 285 | - */ | |
| 284 | + * register wporg_settings_init to the admin_init action hook | |
| 285 | + */ | |
| 286 | 286 | $settings = new Xcloner_Settings(); | 
| 287 | 287 |  		add_action('admin_init', array($settings, 'settings_init')); | 
| 288 | 288 | } | 
| @@ -316,15 +316,15 @@ discard block | ||
| 316 | 316 | } | 
| 317 | 317 | |
| 318 | 318 |  	function friendly_error_type($type) { | 
| 319 | - static $levels=null; | |
| 320 | -	    if ($levels===null) { | |
| 321 | - $levels=[]; | |
| 322 | -	        foreach (get_defined_constants() as $key=>$value) { | |
| 323 | -	            if (strpos($key,'E_')!==0) {continue;} | |
| 319 | + static $levels=null; | |
| 320 | +		if ($levels===null) { | |
| 321 | + $levels=[]; | |
| 322 | +			foreach (get_defined_constants() as $key=>$value) { | |
| 323 | +				if (strpos($key,'E_')!==0) {continue;} | |
| 324 | 324 | $levels[$value]= $key; //substr($key,2); | 
| 325 | - } | |
| 326 | - } | |
| 327 | -	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); | |
| 325 | + } | |
| 326 | + } | |
| 327 | +		return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); | |
| 328 | 328 | } | 
| 329 | 329 | |
| 330 | 330 | private function define_ajax_hooks() | 
| @@ -355,20 +355,20 @@ discard block | ||
| 355 | 355 | add_action( 'admin_notices', array($this, 'xcloner_error_admin_notices' )); | 
| 356 | 356 | |
| 357 | 357 |  		//if (is_admin()) { | 
| 358 | -            add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2); | |
| 359 | - } | |
| 358 | +			add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2); | |
| 359 | + } | |
| 360 | 360 | |
| 361 | 361 | } | 
| 362 | 362 | |
| 363 | 363 |  	function add_plugin_action_links($links, $file) { | 
| 364 | - if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) | |
| 364 | + if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) | |
| 365 | 365 |  		{	 | 
| 366 | 366 |  			$links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; | 
| 367 | 367 |  			$links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; | 
| 368 | 368 | } | 
| 369 | 369 | |
| 370 | - return $links; | |
| 371 | - } | |
| 370 | + return $links; | |
| 371 | + } | |
| 372 | 372 | |
| 373 | 373 |  	public function xcloner_error_admin_notices() { | 
| 374 | 374 | settings_errors( 'xcloner_error_message' ); | 
| @@ -88,15 +88,15 @@ discard block | ||
| 88 | 88 | |
| 89 | 89 | } | 
| 90 | 90 | |
| 91 | -	public function check_dependencies(){ | |
| 91 | +	public function check_dependencies() { | |
| 92 | 92 | |
| 93 | 93 | $backup_storage_path = realpath(__DIR__.DS."..".DS."..".DS."..").DS."backups".DS; | 
| 94 | 94 | |
| 95 | 95 |  		define("XCLONER_STORAGE_PATH", realpath($backup_storage_path)); | 
| 96 | 96 | |
| 97 | - if(!is_dir($backup_storage_path)) | |
| 97 | + if (!is_dir($backup_storage_path)) | |
| 98 | 98 |  		{ | 
| 99 | - if(!@mkdir($backup_storage_path)) | |
| 99 | + if (!@mkdir($backup_storage_path)) | |
| 100 | 100 |  			{ | 
| 101 | 101 | $status = "error"; | 
| 102 | 102 |  				$message = sprintf(__("Unable to create the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); | 
| @@ -104,7 +104,7 @@ discard block | ||
| 104 | 104 | return; | 
| 105 | 105 | } | 
| 106 | 106 | } | 
| 107 | - if(!is_writable($backup_storage_path)) | |
| 107 | + if (!is_writable($backup_storage_path)) | |
| 108 | 108 |  		{ | 
| 109 | 109 | $status = "error"; | 
| 110 | 110 |  			$message = sprintf(__("Unable to write to the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); | 
| @@ -118,15 +118,15 @@ discard block | ||
| 118 | 118 | public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "") | 
| 119 | 119 |  	{ | 
| 120 | 120 | $message = sprintf(__($message), $message_param1, $message_param2, $message_param3); | 
| 121 | - add_action( 'xcloner_admin_notices', array($this,"trigger_message_notice"), 10, 2); | |
| 122 | - do_action( 'xcloner_admin_notices', $message, $status); | |
| 121 | +			add_action('xcloner_admin_notices', array($this, "trigger_message_notice"), 10, 2); | |
| 122 | +			do_action('xcloner_admin_notices', $message, $status); | |
| 123 | 123 | } | 
| 124 | 124 | |
| 125 | 125 | public function trigger_message_notice($message, $status = "success") | 
| 126 | 126 |  	{ | 
| 127 | 127 | ?> | 
| 128 | 128 | <div class="notice notice-<?php echo $status?> is-dismissible"> | 
| 129 | - <p><?php _e( $message, 'xcloner-backup-and-restore' ); ?></p> | |
| 129 | + <p><?php _e($message, 'xcloner-backup-and-restore'); ?></p> | |
| 130 | 130 | </div> | 
| 131 | 131 | <?php | 
| 132 | 132 | } | 
| @@ -153,79 +153,79 @@ discard block | ||
| 153 | 153 | * The class responsible for orchestrating the actions and filters of the | 
| 154 | 154 | * core plugin. | 
| 155 | 155 | */ | 
| 156 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-loader.php'; | |
| 156 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-loader.php'; | |
| 157 | 157 | |
| 158 | 158 | /** | 
| 159 | 159 | * The class responsible for defining internationalization functionality | 
| 160 | 160 | * of the plugin. | 
| 161 | 161 | */ | 
| 162 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-i18n.php'; | |
| 162 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-i18n.php'; | |
| 163 | 163 | |
| 164 | 164 | /** | 
| 165 | 165 | * The class responsible for defining all actions that occur in the admin area. | 
| 166 | 166 | */ | 
| 167 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-xcloner-admin.php'; | |
| 167 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-xcloner-admin.php'; | |
| 168 | 168 | |
| 169 | 169 | /** | 
| 170 | 170 | * The class responsible for debugging XCloner. | 
| 171 | 171 | */ | 
| 172 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-logger.php'; | |
| 172 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-logger.php'; | |
| 173 | 173 | |
| 174 | 174 | /** | 
| 175 | 175 | * The class responsible for defining the admin settings area. | 
| 176 | 176 | */ | 
| 177 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-settings.php'; | |
| 177 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-settings.php'; | |
| 178 | 178 | |
| 179 | 179 | /** | 
| 180 | 180 | * The class responsible for defining the Remote Storage settings area. | 
| 181 | 181 | */ | 
| 182 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-remote-storage.php'; | |
| 182 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-remote-storage.php'; | |
| 183 | 183 | |
| 184 | 184 | /** | 
| 185 | 185 | * The class responsible for implementing the database backup methods. | 
| 186 | 186 | */ | 
| 187 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-database.php'; | |
| 187 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-database.php'; | |
| 188 | 188 | |
| 189 | 189 | /** | 
| 190 | 190 | * The class responsible for sanitization of users input. | 
| 191 | 191 | */ | 
| 192 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-sanitization.php'; | |
| 192 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-sanitization.php'; | |
| 193 | 193 | |
| 194 | 194 | /** | 
| 195 | 195 | * The class responsible for XCloner system requirements validation. | 
| 196 | 196 | */ | 
| 197 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-requirements.php'; | |
| 197 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-requirements.php'; | |
| 198 | 198 | |
| 199 | 199 | /** | 
| 200 | 200 | * The class responsible for XCloner backup archive creation. | 
| 201 | 201 | */ | 
| 202 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-archive.php'; | |
| 202 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-archive.php'; | |
| 203 | 203 | |
| 204 | 204 | /** | 
| 205 | 205 | * The class responsible for XCloner API requests. | 
| 206 | 206 | */ | 
| 207 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-api.php'; | |
| 207 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-api.php'; | |
| 208 | 208 | |
| 209 | 209 | /** | 
| 210 | 210 | * The class responsible for the XCloner File System methods. | 
| 211 | 211 | */ | 
| 212 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-system.php'; | |
| 212 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-system.php'; | |
| 213 | 213 | |
| 214 | 214 | /** | 
| 215 | 215 | * The class responsible for the XCloner File Transfer methods. | 
| 216 | 216 | */ | 
| 217 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-transfer.php'; | |
| 217 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-transfer.php'; | |
| 218 | 218 | |
| 219 | 219 | /** | 
| 220 | 220 | * The class responsible for the XCloner Scheduler methods. | 
| 221 | 221 | */ | 
| 222 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php'; | |
| 222 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-scheduler.php'; | |
| 223 | 223 | |
| 224 | 224 | /** | 
| 225 | 225 | * The class responsible for defining all actions that occur in the public-facing | 
| 226 | 226 | * side of the site. | 
| 227 | 227 | */ | 
| 228 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-xcloner-public.php'; | |
| 228 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-xcloner-public.php'; | |
| 229 | 229 | |
| 230 | 230 | $this->loader = new Xcloner_Loader(); | 
| 231 | 231 | |
| @@ -244,7 +244,7 @@ discard block | ||
| 244 | 244 | |
| 245 | 245 | $plugin_i18n = new Xcloner_i18n(); | 
| 246 | 246 | |
| 247 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); | |
| 247 | +		$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); | |
| 248 | 248 | |
| 249 | 249 | //wp_localize_script( 'ajax-script', 'my_ajax_object', | 
| 250 | 250 | // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); | 
| @@ -260,11 +260,11 @@ discard block | ||
| 260 | 260 | */ | 
| 261 | 261 |  	private function define_admin_hooks() { | 
| 262 | 262 | |
| 263 | - $plugin_admin = new Xcloner_Admin( $this->get_plugin_name(), $this->get_version() ); | |
| 263 | + $plugin_admin = new Xcloner_Admin($this->get_plugin_name(), $this->get_version()); | |
| 264 | 264 | $this->plugin_admin = $plugin_admin; | 
| 265 | 265 | |
| 266 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); | |
| 267 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); | |
| 266 | +		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); | |
| 267 | +		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); | |
| 268 | 268 | |
| 269 | 269 | } | 
| 270 | 270 | |
| @@ -273,13 +273,13 @@ discard block | ||
| 273 | 273 | * | 
| 274 | 274 | * @access private | 
| 275 | 275 | */ | 
| 276 | -	private function define_admin_menu(){ | |
| 276 | +	private function define_admin_menu() { | |
| 277 | 277 | |
| 278 | 278 |  		add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu')); | 
| 279 | 279 | |
| 280 | 280 | } | 
| 281 | 281 | |
| 282 | -	private function define_plugin_settings(){ | |
| 282 | +	private function define_plugin_settings() { | |
| 283 | 283 | /** | 
| 284 | 284 | * register wporg_settings_init to the admin_init action hook | 
| 285 | 285 | */ | 
| @@ -296,10 +296,10 @@ discard block | ||
| 296 | 296 | */ | 
| 297 | 297 |  	private function define_public_hooks() { | 
| 298 | 298 | |
| 299 | - $plugin_public = new Xcloner_Public( $this->get_plugin_name(), $this->get_version() ); | |
| 299 | + $plugin_public = new Xcloner_Public($this->get_plugin_name(), $this->get_version()); | |
| 300 | 300 | |
| 301 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); | |
| 302 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); | |
| 301 | +		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); | |
| 302 | +		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); | |
| 303 | 303 | |
| 304 | 304 | } | 
| 305 | 305 | |
| @@ -308,20 +308,20 @@ discard block | ||
| 308 | 308 |  		$logger = new XCloner_Logger("php_system"); | 
| 309 | 309 | $error = error_get_last(); | 
| 310 | 310 | |
| 311 | - if($error['type'] and $logger) | |
| 311 | + if ($error['type'] and $logger) | |
| 312 | 312 |  		{ | 
| 313 | - $logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true)); | |
| 313 | + $logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true)); | |
| 314 | 314 | } | 
| 315 | 315 | |
| 316 | 316 | } | 
| 317 | 317 | |
| 318 | 318 |  	function friendly_error_type($type) { | 
| 319 | - static $levels=null; | |
| 320 | -	    if ($levels===null) { | |
| 321 | - $levels=[]; | |
| 319 | + static $levels = null; | |
| 320 | +	    if ($levels === null) { | |
| 321 | + $levels = []; | |
| 322 | 322 |  	        foreach (get_defined_constants() as $key=>$value) { | 
| 323 | -	            if (strpos($key,'E_')!==0) {continue;} | |
| 324 | - $levels[$value]= $key; //substr($key,2); | |
| 323 | +	            if (strpos($key, 'E_') !== 0) {continue; } | |
| 324 | + $levels[$value] = $key; //substr($key,2); | |
| 325 | 325 | } | 
| 326 | 326 | } | 
| 327 | 327 |  	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); | 
| @@ -329,30 +329,30 @@ discard block | ||
| 329 | 329 | |
| 330 | 330 | private function define_ajax_hooks() | 
| 331 | 331 |  	{ | 
| 332 | - $plugin_public = new Xcloner_Public( $this->get_plugin_name(), $this->get_version() ); | |
| 332 | + $plugin_public = new Xcloner_Public($this->get_plugin_name(), $this->get_version()); | |
| 333 | 333 |  		//$this->loader->add_action( 'wp_ajax_get_database_tables_action', $plugin_public, array('Xcloner_Api','get_database_tables_action') ); | 
| 334 | 334 | |
| 335 | - if(is_admin()) | |
| 335 | + if (is_admin()) | |
| 336 | 336 |  		{ | 
| 337 | 337 | $xcloner_api = new Xcloner_Api(); | 
| 338 | 338 | |
| 339 | - add_action( 'wp_ajax_get_database_tables_action' , array($xcloner_api,'get_database_tables_action') ); | |
| 340 | - add_action( 'wp_ajax_get_file_system_action' , array($xcloner_api,'get_file_system_action') ); | |
| 341 | - add_action( 'wp_ajax_scan_filesystem' , array($xcloner_api,'scan_filesystem') ); | |
| 342 | - add_action( 'wp_ajax_backup_database' , array($xcloner_api,'backup_database') ); | |
| 343 | - add_action( 'wp_ajax_backup_files' , array($xcloner_api,'backup_files') ); | |
| 344 | - add_action( 'wp_ajax_save_schedule' , array($xcloner_api,'save_schedule') ); | |
| 345 | - add_action( 'wp_ajax_get_schedule_by_id' , array($xcloner_api,'get_schedule_by_id') ); | |
| 346 | - add_action( 'wp_ajax_get_scheduler_list' , array($xcloner_api,'get_scheduler_list') ); | |
| 347 | - add_action( 'wp_ajax_delete_schedule_by_id' , array($xcloner_api,'delete_schedule_by_id') ); | |
| 348 | - add_action( 'wp_ajax_delete_backup_by_name' , array($xcloner_api,'delete_backup_by_name') ); | |
| 349 | - add_action( 'wp_ajax_download_backup_by_name' , array($xcloner_api,'download_backup_by_name') ); | |
| 350 | - add_action( 'wp_ajax_remote_storage_save_status' , array($xcloner_api,'remote_storage_save_status') ); | |
| 351 | - add_action( 'wp_ajax_upload_backup_to_remote' , array($xcloner_api,'upload_backup_to_remote') ); | |
| 352 | - add_action( 'wp_ajax_list_backup_files' , array($xcloner_api,'list_backup_files') ); | |
| 353 | - add_action( 'wp_ajax_restore_upload_backup' , array($xcloner_api,'restore_upload_backup') ); | |
| 354 | - add_action( 'wp_ajax_download_restore_script' , array($xcloner_api,'download_restore_script') ); | |
| 355 | - add_action( 'admin_notices', array($this, 'xcloner_error_admin_notices' )); | |
| 339 | +			add_action('wp_ajax_get_database_tables_action', array($xcloner_api, 'get_database_tables_action')); | |
| 340 | +			add_action('wp_ajax_get_file_system_action', array($xcloner_api, 'get_file_system_action')); | |
| 341 | +			add_action('wp_ajax_scan_filesystem', array($xcloner_api, 'scan_filesystem')); | |
| 342 | +			add_action('wp_ajax_backup_database', array($xcloner_api, 'backup_database')); | |
| 343 | +			add_action('wp_ajax_backup_files', array($xcloner_api, 'backup_files')); | |
| 344 | +			add_action('wp_ajax_save_schedule', array($xcloner_api, 'save_schedule')); | |
| 345 | +			add_action('wp_ajax_get_schedule_by_id', array($xcloner_api, 'get_schedule_by_id')); | |
| 346 | +			add_action('wp_ajax_get_scheduler_list', array($xcloner_api, 'get_scheduler_list')); | |
| 347 | +			add_action('wp_ajax_delete_schedule_by_id', array($xcloner_api, 'delete_schedule_by_id')); | |
| 348 | +			add_action('wp_ajax_delete_backup_by_name', array($xcloner_api, 'delete_backup_by_name')); | |
| 349 | +			add_action('wp_ajax_download_backup_by_name', array($xcloner_api, 'download_backup_by_name')); | |
| 350 | +			add_action('wp_ajax_remote_storage_save_status', array($xcloner_api, 'remote_storage_save_status')); | |
| 351 | +			add_action('wp_ajax_upload_backup_to_remote', array($xcloner_api, 'upload_backup_to_remote')); | |
| 352 | +			add_action('wp_ajax_list_backup_files', array($xcloner_api, 'list_backup_files')); | |
| 353 | +			add_action('wp_ajax_restore_upload_backup', array($xcloner_api, 'restore_upload_backup')); | |
| 354 | +			add_action('wp_ajax_download_restore_script', array($xcloner_api, 'download_restore_script')); | |
| 355 | +			add_action('admin_notices', array($this, 'xcloner_error_admin_notices')); | |
| 356 | 356 | |
| 357 | 357 |  		//if (is_admin()) { | 
| 358 | 358 |              add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2); | 
| @@ -361,7 +361,7 @@ discard block | ||
| 361 | 361 | } | 
| 362 | 362 | |
| 363 | 363 |  	function add_plugin_action_links($links, $file) { | 
| 364 | - if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) | |
| 364 | + if ($file == plugin_basename(dirname(dirname(__FILE__)).'/xcloner.php')) | |
| 365 | 365 |  		{	 | 
| 366 | 366 |  			$links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; | 
| 367 | 367 |  			$links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; | 
| @@ -371,13 +371,13 @@ discard block | ||
| 371 | 371 | } | 
| 372 | 372 | |
| 373 | 373 |  	public function xcloner_error_admin_notices() { | 
| 374 | - settings_errors( 'xcloner_error_message' ); | |
| 374 | +			settings_errors('xcloner_error_message'); | |
| 375 | 375 | } | 
| 376 | 376 | |
| 377 | 377 | public function define_cron_hooks() | 
| 378 | 378 |  	{ | 
| 379 | 379 | //registering new schedule intervals | 
| 380 | - add_filter( 'cron_schedules', array($this, 'add_new_intervals')); | |
| 380 | +		add_filter('cron_schedules', array($this, 'add_new_intervals')); | |
| 381 | 381 | |
| 382 | 382 | |
| 383 | 383 | $xcloner_scheduler = new Xcloner_Scheduler(); | 
| @@ -451,7 +451,7 @@ discard block | ||
| 451 | 451 | |
| 452 | 452 | public function display($page) | 
| 453 | 453 |  	{ | 
| 454 | - $plugin_admin = new Xcloner_Admin( $this->get_plugin_name(), $this->get_version() ); | |
| 454 | + $plugin_admin = new Xcloner_Admin($this->get_plugin_name(), $this->get_version()); | |
| 455 | 455 | $this->plugin_admin = $plugin_admin; | 
| 456 | 456 | |
| 457 | 457 | $view = call_user_func_array(array($this->plugin_admin, $page), array()); | 
| @@ -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 |