Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../methods
File: openstack-base.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.');
[2] Fix | Delete
[3] Fix | Delete
if (!class_exists('UpdraftPlus_BackupModule')) require_once(UPDRAFTPLUS_DIR.'/methods/backup-module.php');
[4] Fix | Delete
[5] Fix | Delete
class UpdraftPlus_BackupModule_openstack_base extends UpdraftPlus_BackupModule {
[6] Fix | Delete
[7] Fix | Delete
protected $chunk_size;
[8] Fix | Delete
[9] Fix | Delete
protected $client;
[10] Fix | Delete
[11] Fix | Delete
protected $method;
[12] Fix | Delete
[13] Fix | Delete
protected $desc;
[14] Fix | Delete
[15] Fix | Delete
protected $long_desc;
[16] Fix | Delete
[17] Fix | Delete
protected $img_url;
[18] Fix | Delete
[19] Fix | Delete
public function __construct($method, $desc, $long_desc = null, $img_url = '') {
[20] Fix | Delete
$this->method = $method;
[21] Fix | Delete
$this->desc = $desc;
[22] Fix | Delete
$this->long_desc = (is_string($long_desc)) ? $long_desc : $desc;
[23] Fix | Delete
$this->img_url = $img_url;
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
public function backup($backup_array) {
[27] Fix | Delete
[28] Fix | Delete
global $updraftplus;
[29] Fix | Delete
[30] Fix | Delete
$default_chunk_size = (defined('UPDRAFTPLUS_UPLOAD_CHUNKSIZE') && UPDRAFTPLUS_UPLOAD_CHUNKSIZE > 0) ? max(UPDRAFTPLUS_UPLOAD_CHUNKSIZE, 1048576) : 5242880;
[31] Fix | Delete
[32] Fix | Delete
$this->chunk_size = $updraftplus->jobdata_get('openstack_chunk_size', $default_chunk_size);
[33] Fix | Delete
[34] Fix | Delete
$opts = $this->get_options();
[35] Fix | Delete
[36] Fix | Delete
$this->container = $opts['path'];
[37] Fix | Delete
[38] Fix | Delete
try {
[39] Fix | Delete
$storage = $this->get_openstack_service($opts, UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'), UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'));
[40] Fix | Delete
} catch (AuthenticationError $e) {
[41] Fix | Delete
$updraftplus->log($this->desc.' authentication failed ('.$e->getMessage().')');
[42] Fix | Delete
$updraftplus->log(sprintf(__('%s authentication failed', 'updraftplus'), $this->desc).' ('.$e->getMessage().')', 'error');
[43] Fix | Delete
return false;
[44] Fix | Delete
} catch (Exception $e) {
[45] Fix | Delete
$updraftplus->log($this->desc.' error - failed to access the container ('.$e->getMessage().') (line: '.$e->getLine().', file: '.$e->getFile().')');
[46] Fix | Delete
$updraftplus->log(sprintf(__('%s error - failed to access the container', 'updraftplus'), $this->desc).' ('.$e->getMessage().')', 'error');
[47] Fix | Delete
return false;
[48] Fix | Delete
}
[49] Fix | Delete
// Get the container
[50] Fix | Delete
try {
[51] Fix | Delete
$this->container_object = $storage->getContainer($this->container);
[52] Fix | Delete
} catch (Exception $e) {
[53] Fix | Delete
$updraftplus->log('Could not access '.$this->desc.' container ('.get_class($e).', '.$e->getMessage().') (line: '.$e->getLine().', file: '.$e->getFile().')');
[54] Fix | Delete
$updraftplus->log(sprintf(__('Could not access %s container', 'updraftplus'), $this->desc).' ('.get_class($e).', '.$e->getMessage().')', 'error');
[55] Fix | Delete
return false;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
foreach ($backup_array as $file) {
[59] Fix | Delete
[60] Fix | Delete
$file_key = 'status_'.md5($file);
[61] Fix | Delete
$file_status = $this->jobdata_get($file_key, null, 'openstack_'.$file_key);
[62] Fix | Delete
if (is_array($file_status) && !empty($file_status['chunks']) && !empty($file_status['chunks'][1]['size'])) $this->chunk_size = $file_status['chunks'][1]['size'];
[63] Fix | Delete
[64] Fix | Delete
// First, see the object's existing size (if any)
[65] Fix | Delete
$uploaded_size = $this->get_remote_size($file);
[66] Fix | Delete
[67] Fix | Delete
try {
[68] Fix | Delete
if (1 === $updraftplus->chunked_upload($this, $file, $this->method."://".$this->container."/$file", $this->desc, $this->chunk_size, $uploaded_size)) {
[69] Fix | Delete
try {
[70] Fix | Delete
if (false !== ($data = fopen($updraftplus->backups_dir_location().'/'.$file, 'r+'))) {
[71] Fix | Delete
$this->container_object->uploadObject($file, $data);
[72] Fix | Delete
$updraftplus->log($this->desc." regular upload: success");
[73] Fix | Delete
$updraftplus->uploaded_file($file);
[74] Fix | Delete
} else {
[75] Fix | Delete
throw new Exception('uploadObject failed: fopen failed');
[76] Fix | Delete
}
[77] Fix | Delete
} catch (Exception $e) {
[78] Fix | Delete
$this->log("regular upload: failed ($file) (".$e->getMessage().")");
[79] Fix | Delete
$this->log("$file: ".sprintf(__('Error: Failed to upload', 'updraftplus')), 'error');
[80] Fix | Delete
}
[81] Fix | Delete
}
[82] Fix | Delete
} catch (Exception $e) {
[83] Fix | Delete
$updraftplus->log($this->desc.' error - failed to upload file'.' ('.$e->getMessage().') (line: '.$e->getLine().', file: '.$e->getFile().')');
[84] Fix | Delete
$updraftplus->log(sprintf(__('%s error - failed to upload file', 'updraftplus'), $this->desc).' ('.$e->getMessage().')', 'error');
[85] Fix | Delete
return false;
[86] Fix | Delete
}
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
return array('object' => $this->container_object, 'orig_path' => $opts['path'], 'container' => $this->container);
[90] Fix | Delete
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
private function get_remote_size($file) {
[94] Fix | Delete
try {
[95] Fix | Delete
$response = $this->container_object->getClient()->head($this->container_object->getUrl($file))->send();
[96] Fix | Delete
$response_object = $this->container_object->dataObject()->populateFromResponse($response)->setName($file);
[97] Fix | Delete
return $response_object->getContentLength();
[98] Fix | Delete
} catch (Exception $e) {
[99] Fix | Delete
// Allow caller to distinguish between zero-sized and not-found
[100] Fix | Delete
return false;
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* This function lists the files found in the configured storage location
[106] Fix | Delete
*
[107] Fix | Delete
* @param String $match a substring to require (tested via strpos() !== false)
[108] Fix | Delete
*
[109] Fix | Delete
* @return Array - each file is represented by an array with entries 'name' and (optional) 'size'
[110] Fix | Delete
*/
[111] Fix | Delete
public function listfiles($match = 'backup_') {
[112] Fix | Delete
$opts = $this->get_options();
[113] Fix | Delete
$container = $opts['path'];
[114] Fix | Delete
[115] Fix | Delete
if (empty($opts['user']) || (empty($opts['apikey']) && empty($opts['password']))) return new WP_Error('no_settings', __('No settings were found', 'updraftplus'));
[116] Fix | Delete
[117] Fix | Delete
try {
[118] Fix | Delete
$storage = $this->get_openstack_service($opts, UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'), UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'));
[119] Fix | Delete
} catch (Exception $e) {
[120] Fix | Delete
return new WP_Error('no_access', sprintf(__('%s error - failed to access the container', 'updraftplus'), $this->desc).' ('.$e->getMessage().')');
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
// Get the container
[124] Fix | Delete
try {
[125] Fix | Delete
$this->container_object = $storage->getContainer($container);
[126] Fix | Delete
} catch (Exception $e) {
[127] Fix | Delete
return new WP_Error('no_access', sprintf(__('%s error - failed to access the container', 'updraftplus'), $this->desc).' ('.$e->getMessage().')');
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
$results = array();
[131] Fix | Delete
$marker = '';
[132] Fix | Delete
$page_size = 1000;
[133] Fix | Delete
try {
[134] Fix | Delete
// http://php-opencloud.readthedocs.io/en/latest/services/object-store/objects.html#list-objects-in-a-container
[135] Fix | Delete
while (null !== $marker) {
[136] Fix | Delete
[137] Fix | Delete
$params = array(
[138] Fix | Delete
'prefix' => $match,
[139] Fix | Delete
'limit' => $page_size,
[140] Fix | Delete
'marker' => $marker
[141] Fix | Delete
);
[142] Fix | Delete
[143] Fix | Delete
$objects = $this->container_object->objectList($params);
[144] Fix | Delete
[145] Fix | Delete
$total = $objects->count();
[146] Fix | Delete
[147] Fix | Delete
if (0 == $total) break;
[148] Fix | Delete
[149] Fix | Delete
$index = 0;
[150] Fix | Delete
[151] Fix | Delete
while (false !== ($file = $objects->offsetGet($index)) && !empty($file)) {
[152] Fix | Delete
$index++;
[153] Fix | Delete
try {
[154] Fix | Delete
if ((is_object($file) && !empty($file->name))) {
[155] Fix | Delete
$result = array('name' => $file->name);
[156] Fix | Delete
// Rackspace returns the size of a manifested file properly; other OpenStack implementations may not
[157] Fix | Delete
if (!empty($file->bytes)) {
[158] Fix | Delete
$result['size'] = $file->bytes;
[159] Fix | Delete
} else {
[160] Fix | Delete
$size = $this->get_remote_size($file->name);
[161] Fix | Delete
if (false !== $size && $size > 0) $result['size'] = $size;
[162] Fix | Delete
}
[163] Fix | Delete
$results[] = $result;
[164] Fix | Delete
}
[165] Fix | Delete
} catch (Exception $e) {
[166] Fix | Delete
// Catch
[167] Fix | Delete
}
[168] Fix | Delete
$marker = (!empty($file->name) && $total >= $page_size) ? $file->name : null;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
}
[172] Fix | Delete
} catch (Exception $e) {
[173] Fix | Delete
// Catch
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
return $results;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Called when all chunks have been uploaded, to allow any required finishing actions to be carried out
[181] Fix | Delete
*
[182] Fix | Delete
* @param String $file - the basename of the file being uploaded
[183] Fix | Delete
*
[184] Fix | Delete
* @return Boolean - success or failure state of any finishing actions
[185] Fix | Delete
*/
[186] Fix | Delete
public function chunked_upload_finish($file) {
[187] Fix | Delete
[188] Fix | Delete
$chunk_path = 'chunk-do-not-delete-'.$file;
[189] Fix | Delete
try {
[190] Fix | Delete
[191] Fix | Delete
$headers = array(
[192] Fix | Delete
'Content-Length' => 0,
[193] Fix | Delete
'X-Object-Manifest' => sprintf('%s/%s', $this->container, $chunk_path.'_')
[194] Fix | Delete
);
[195] Fix | Delete
[196] Fix | Delete
$url = $this->container_object->getUrl($file);
[197] Fix | Delete
$this->container_object->getClient()->put($url, $headers)->send();
[198] Fix | Delete
return true;
[199] Fix | Delete
[200] Fix | Delete
} catch (Exception $e) {
[201] Fix | Delete
global $updraftplus;
[202] Fix | Delete
$updraftplus->log("Error when sending manifest (".get_class($e)."): ".$e->getMessage());
[203] Fix | Delete
return false;
[204] Fix | Delete
}
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* N.B. Since we use varying-size chunks, we must be careful as to what we do with $chunk_index
[209] Fix | Delete
*
[210] Fix | Delete
* @param String $file Full path for the file being uploaded
[211] Fix | Delete
* @param Resource $fp File handle to read upload data from
[212] Fix | Delete
* @param Integer $chunk_index Index of chunked upload
[213] Fix | Delete
* @param Integer $upload_size Size of the upload, in bytes
[214] Fix | Delete
* @param Integer $upload_start How many bytes into the file the upload process has got
[215] Fix | Delete
* @param Integer $upload_end How many bytes into the file we will be after this chunk is uploaded
[216] Fix | Delete
* @param Integer $total_file_size Total file size
[217] Fix | Delete
*
[218] Fix | Delete
* @return Boolean
[219] Fix | Delete
*/
[220] Fix | Delete
public function chunked_upload($file, $fp, $chunk_index, $upload_size, $upload_start, $upload_end, $total_file_size) {
[221] Fix | Delete
[222] Fix | Delete
global $updraftplus;
[223] Fix | Delete
[224] Fix | Delete
$file_key = 'status_'.md5($file);
[225] Fix | Delete
$file_status = $this->jobdata_get($file_key, null, 'openstack_'.$file_key);
[226] Fix | Delete
[227] Fix | Delete
$next_chunk_size = $upload_size;
[228] Fix | Delete
[229] Fix | Delete
$bytes_already_uploaded = 0;
[230] Fix | Delete
[231] Fix | Delete
$last_uploaded_chunk_index = 0;
[232] Fix | Delete
[233] Fix | Delete
// Once a chunk is uploaded, its status is set, allowing the sequence to be reconstructed
[234] Fix | Delete
if (is_array($file_status) && isset($file_status['chunks']) && !empty($file_status['chunks'])) {
[235] Fix | Delete
foreach ($file_status['chunks'] as $c_id => $c_status) {
[236] Fix | Delete
if ($c_id > $last_uploaded_chunk_index) $last_uploaded_chunk_index = $c_id;
[237] Fix | Delete
if ($chunk_index + 1 == $c_id) {
[238] Fix | Delete
$next_chunk_size = $c_status['size'];
[239] Fix | Delete
}
[240] Fix | Delete
$bytes_already_uploaded += $c_status['size'];
[241] Fix | Delete
}
[242] Fix | Delete
} else {
[243] Fix | Delete
$file_status = array('chunks' => array());
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$this->jobdata_set($file_key, $file_status);
[247] Fix | Delete
[248] Fix | Delete
if ($upload_start < $bytes_already_uploaded) {
[249] Fix | Delete
if ($next_chunk_size != $upload_size) {
[250] Fix | Delete
$response = new stdClass;
[251] Fix | Delete
$response->new_chunk_size = $upload_size;
[252] Fix | Delete
$response->log = false;
[253] Fix | Delete
return $response;
[254] Fix | Delete
} else {
[255] Fix | Delete
return 1;
[256] Fix | Delete
}
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
// Shouldn't be able to happen
[260] Fix | Delete
if ($chunk_index <= $last_uploaded_chunk_index) {
[261] Fix | Delete
$updraftplus->log($this->desc.": Chunk sequence error; chunk_index=$chunk_index, last_uploaded_chunk_index=$last_uploaded_chunk_index, upload_start=$upload_start, upload_end=$upload_end, file_status=".json_encode($file_status));
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
// Used to use $chunk_index here, before switching to variable chunk sizes
[265] Fix | Delete
$upload_remotepath = 'chunk-do-not-delete-'.$file.'_'.sprintf("%016d", $chunk_index);
[266] Fix | Delete
[267] Fix | Delete
$remote_size = $this->get_remote_size($upload_remotepath);
[268] Fix | Delete
[269] Fix | Delete
// Without this, some versions of Curl add Expect: 100-continue, which results in Curl then giving this back: curl error: 55) select/poll returned error
[270] Fix | Delete
// Didn't make the difference - instead we just check below for actual success even when Curl reports an error
[271] Fix | Delete
// $chunk_object->headers = array('Expect' => '');
[272] Fix | Delete
[273] Fix | Delete
if ($remote_size >= $upload_size) {
[274] Fix | Delete
$updraftplus->log($this->desc.": Chunk ($upload_start - $upload_end, $chunk_index): already uploaded");
[275] Fix | Delete
} else {
[276] Fix | Delete
$updraftplus->log($this->desc.": Chunk ($upload_start - $upload_end, $chunk_index): begin upload");
[277] Fix | Delete
// Upload the chunk
[278] Fix | Delete
try {
[279] Fix | Delete
$data = fread($fp, $upload_size);
[280] Fix | Delete
$time_start = microtime(true);
[281] Fix | Delete
$this->container_object->uploadObject($upload_remotepath, $data);
[282] Fix | Delete
$time_now = microtime(true);
[283] Fix | Delete
$time_taken = $time_now - $time_start;
[284] Fix | Delete
if ($next_chunk_size < 52428800 && $total_file_size > 0 && $upload_end + 1 < $total_file_size) {
[285] Fix | Delete
$job_run_time = $time_now - $updraftplus->job_time_ms;
[286] Fix | Delete
if ($time_taken < 10) {
[287] Fix | Delete
$upload_rate = $upload_size / max($time_taken, 0.0001);
[288] Fix | Delete
$upload_secs = min(floor($job_run_time), 10);
[289] Fix | Delete
if ($job_run_time < 15) $upload_secs = max(6, $job_run_time*0.6);
[290] Fix | Delete
[291] Fix | Delete
// In megabytes
[292] Fix | Delete
$memory_limit_mb = $updraftplus->memory_check_current();
[293] Fix | Delete
$bytes_used = memory_get_usage();
[294] Fix | Delete
$bytes_free = $memory_limit_mb * 1048576 - $bytes_used;
[295] Fix | Delete
[296] Fix | Delete
$new_chunk = max(min($upload_secs * $upload_rate * 0.9, 52428800, $bytes_free), 5242880);
[297] Fix | Delete
$new_chunk = $new_chunk - ($new_chunk % 5242880);
[298] Fix | Delete
$next_chunk_size = (int) $new_chunk;
[299] Fix | Delete
$updraftplus->jobdata_set('openstack_chunk_size', $next_chunk_size);
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
} catch (Exception $e) {
[304] Fix | Delete
$updraftplus->log($this->desc." chunk upload: error: ($file / $chunk_index) (".$e->getMessage().") (line: ".$e->getLine().', file: '.$e->getFile().')');
[305] Fix | Delete
// Experience shows that Curl sometimes returns a select/poll error (curl error 55) even when everything succeeded. Google seems to indicate that this is a known bug.
[306] Fix | Delete
[307] Fix | Delete
$remote_size = $this->get_remote_size($upload_remotepath);
[308] Fix | Delete
[309] Fix | Delete
if ($remote_size >= $upload_size) {
[310] Fix | Delete
$updraftplus->log("$file: Chunk now exists; ignoring error (presuming it was an apparently known curl bug)");
[311] Fix | Delete
} else {
[312] Fix | Delete
$updraftplus->log("$file: ".sprintf(__('%s Error: Failed to upload', 'updraftplus'), $this->desc), 'error');
[313] Fix | Delete
return false;
[314] Fix | Delete
}
[315] Fix | Delete
}
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
$file_status['chunks'][$chunk_index]['size'] = $upload_size;
[319] Fix | Delete
[320] Fix | Delete
$this->jobdata_set($file_key, $file_status);
[321] Fix | Delete
[322] Fix | Delete
if ($next_chunk_size != $upload_size) {
[323] Fix | Delete
$response = new stdClass;
[324] Fix | Delete
$response->new_chunk_size = $next_chunk_size;
[325] Fix | Delete
$response->log = true;
[326] Fix | Delete
return $response;
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
return true;
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* Delete a single file from the service using OpenStack API
[334] Fix | Delete
*
[335] Fix | Delete
* @param Array|String $files - array of file names to delete
[336] Fix | Delete
* @param Array $data - service object and container details
[337] Fix | Delete
* @param Array $sizeinfo - unused here
[338] Fix | Delete
* @return Boolean|String - either a boolean true or an error code string
[339] Fix | Delete
*/
[340] Fix | Delete
public function delete($files, $data = false, $sizeinfo = array()) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- $sizeinfo unused
[341] Fix | Delete
[342] Fix | Delete
global $updraftplus;
[343] Fix | Delete
if (is_string($files)) $files = array($files);
[344] Fix | Delete
[345] Fix | Delete
if (is_array($data)) {
[346] Fix | Delete
$container_object = $data['object'];
[347] Fix | Delete
$container = $data['container'];
[348] Fix | Delete
} else {
[349] Fix | Delete
$opts = $this->get_options();
[350] Fix | Delete
$container = $opts['path'];
[351] Fix | Delete
try {
[352] Fix | Delete
$storage = $this->get_openstack_service($opts, UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'), UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'));
[353] Fix | Delete
} catch (AuthenticationError $e) {
[354] Fix | Delete
$updraftplus->log($this->desc.' authentication failed ('.$e->getMessage().')');
[355] Fix | Delete
$updraftplus->log(sprintf(__('%s authentication failed', 'updraftplus'), $this->desc).' ('.$e->getMessage().')', 'error');
[356] Fix | Delete
return 'authentication_fail';
[357] Fix | Delete
} catch (Exception $e) {
[358] Fix | Delete
$updraftplus->log($this->desc.' error - failed to access the container ('.$e->getMessage().')');
[359] Fix | Delete
$updraftplus->log(sprintf(__('%s error - failed to access the container', 'updraftplus'), $this->desc).' ('.$e->getMessage().')', 'error');
[360] Fix | Delete
return 'service_unavailable';
[361] Fix | Delete
}
[362] Fix | Delete
// Get the container
[363] Fix | Delete
try {
[364] Fix | Delete
$container_object = $storage->getContainer($container);
[365] Fix | Delete
} catch (Exception $e) {
[366] Fix | Delete
$updraftplus->log('Could not access '.$this->desc.' container ('.get_class($e).', '.$e->getMessage().')');
[367] Fix | Delete
$updraftplus->log(sprintf(__('Could not access %s container', 'updraftplus'), $this->desc).' ('.get_class($e).', '.$e->getMessage().')', 'error');
[368] Fix | Delete
return 'container_access_error';
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
$ret = true;
[374] Fix | Delete
foreach ($files as $file) {
[375] Fix | Delete
[376] Fix | Delete
$updraftplus->log($this->desc.": Delete remote: container=$container, path=$file");
[377] Fix | Delete
[378] Fix | Delete
// We need to search for chunks
[379] Fix | Delete
$chunk_path = "chunk-do-not-delete-".$file;
[380] Fix | Delete
[381] Fix | Delete
try {
[382] Fix | Delete
$objects = $container_object->objectList(array('prefix' => $chunk_path));
[383] Fix | Delete
$index = 0;
[384] Fix | Delete
while (false !== ($chunk = $objects->offsetGet($index)) && !empty($chunk)) {
[385] Fix | Delete
try {
[386] Fix | Delete
$name = $chunk->name;
[387] Fix | Delete
$container_object->dataObject()->setName($name)->delete();
[388] Fix | Delete
$updraftplus->log($this->desc.': Chunk deleted: '.$name);
[389] Fix | Delete
} catch (Exception $e) {
[390] Fix | Delete
$updraftplus->log($this->desc." chunk delete failed: $name: ".$e->getMessage());
[391] Fix | Delete
}
[392] Fix | Delete
$index++;
[393] Fix | Delete
}
[394] Fix | Delete
} catch (Exception $e) {
[395] Fix | Delete
$updraftplus->log($this->desc.' chunk delete failed: '.$e->getMessage());
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
// Finally, delete the object itself
[399] Fix | Delete
try {
[400] Fix | Delete
$container_object->dataObject()->setName($file)->delete();
[401] Fix | Delete
$updraftplus->log($this->desc.': Deleted: '.$file);
[402] Fix | Delete
} catch (Exception $e) {
[403] Fix | Delete
$updraftplus->log($this->desc.' delete failed: '.$e->getMessage());
[404] Fix | Delete
$ret = 'file_delete_error';
[405] Fix | Delete
}
[406] Fix | Delete
}
[407] Fix | Delete
return $ret;
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
public function download($file) {
[411] Fix | Delete
[412] Fix | Delete
global $updraftplus;
[413] Fix | Delete
[414] Fix | Delete
$opts = $this->get_options();
[415] Fix | Delete
[416] Fix | Delete
try {
[417] Fix | Delete
$storage = $this->get_openstack_service($opts, UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'), UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'));
[418] Fix | Delete
} catch (AuthenticationError $e) {
[419] Fix | Delete
$updraftplus->log($this->desc.' authentication failed ('.$e->getMessage().')');
[420] Fix | Delete
$updraftplus->log(sprintf(__('%s authentication failed', 'updraftplus'), $this->desc).' ('.$e->getMessage().')', 'error');
[421] Fix | Delete
return false;
[422] Fix | Delete
} catch (Exception $e) {
[423] Fix | Delete
$updraftplus->log($this->desc.' error - failed to access the container ('.$e->getMessage().')');
[424] Fix | Delete
$updraftplus->log(sprintf(__('%s error - failed to access the container', 'updraftplus'), $this->desc).' ('.$e->getMessage().')', 'error');
[425] Fix | Delete
return false;
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
$container = untrailingslashit($opts['path']);
[429] Fix | Delete
$updraftplus->log($this->desc." download: ".$this->method."://$container/$file");
[430] Fix | Delete
[431] Fix | Delete
// Get the container
[432] Fix | Delete
try {
[433] Fix | Delete
$this->container_object = $storage->getContainer($container);
[434] Fix | Delete
} catch (Exception $e) {
[435] Fix | Delete
$updraftplus->log('Could not access '.$this->desc.' container ('.get_class($e).', '.$e->getMessage().')');
[436] Fix | Delete
$updraftplus->log(sprintf(__('Could not access %s container', 'updraftplus'), $this->desc).' ('.get_class($e).', '.$e->getMessage().')', 'error');
[437] Fix | Delete
return false;
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
// Get information about the object within the container
[441] Fix | Delete
$remote_size = $this->get_remote_size($file);
[442] Fix | Delete
if (false === $remote_size) {
[443] Fix | Delete
$updraftplus->log('Could not access '.$this->desc.' object');
[444] Fix | Delete
$updraftplus->log(sprintf(__('The %s object was not found', 'updraftplus'), $this->desc), 'error');
[445] Fix | Delete
return false;
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
return (!is_bool($remote_size)) ? $updraftplus->chunked_download($file, $this, $remote_size, true, $this->container_object) : false;
[449] Fix | Delete
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
public function chunked_download($file, $headers, $container_object) {
[453] Fix | Delete
try {
[454] Fix | Delete
$dl = $container_object->getObject($file, $headers);
[455] Fix | Delete
} catch (Exception $e) {
[456] Fix | Delete
global $updraftplus;
[457] Fix | Delete
$updraftplus->log("$file: Failed to download (".$e->getMessage().")");
[458] Fix | Delete
$updraftplus->log("$file: ".sprintf(__("%s Error", 'updraftplus'), $this->desc).": ".__('Error downloading remote file: Failed to download', 'updraftplus').' ('.$e->getMessage().")", 'error');
[459] Fix | Delete
return false;
[460] Fix | Delete
}
[461] Fix | Delete
return $dl->getContent();
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
public function credentials_test_go($opts, $path, $useservercerts, $disableverify) {
[465] Fix | Delete
[466] Fix | Delete
if (preg_match("#^([^/]+)/(.*)$#", $path, $bmatches)) {
[467] Fix | Delete
$container = $bmatches[1];
[468] Fix | Delete
$path = $bmatches[2];
[469] Fix | Delete
} else {
[470] Fix | Delete
$container = $path;
[471] Fix | Delete
$path = '';
[472] Fix | Delete
}
[473] Fix | Delete
[474] Fix | Delete
if (empty($container)) {
[475] Fix | Delete
_e('Failure: No container details were given.', 'updraftplus');
[476] Fix | Delete
return;
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
try {
[480] Fix | Delete
$storage = $this->get_openstack_service($opts, $useservercerts, $disableverify);
[481] Fix | Delete
// @codingStandardsIgnoreLine
[482] Fix | Delete
} catch (Guzzle\Http\Exception\ClientErrorResponseException $e) {
[483] Fix | Delete
$response = $e->getResponse();
[484] Fix | Delete
$code = $response->getStatusCode();
[485] Fix | Delete
$reason = $response->getReasonPhrase();
[486] Fix | Delete
if (401 == $code && 'Unauthorized' == $reason) {
[487] Fix | Delete
echo __('Authorisation failed (check your credentials)', 'updraftplus');
[488] Fix | Delete
} else {
[489] Fix | Delete
echo __('Authorisation failed (check your credentials)', 'updraftplus')." ($code:$reason)";
[490] Fix | Delete
}
[491] Fix | Delete
return;
[492] Fix | Delete
} catch (AuthenticationError $e) {
[493] Fix | Delete
echo sprintf(__('%s authentication failed', 'updraftplus'), $this->desc).' ('.$e->getMessage().')';
[494] Fix | Delete
return;
[495] Fix | Delete
} catch (Exception $e) {
[496] Fix | Delete
echo sprintf(__('%s authentication failed', 'updraftplus'), $this->desc).' ('.get_class($e).', '.$e->getMessage().')';
[497] Fix | Delete
return;
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function