| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.'); |
| 4 |
|
| 5 |
require_once(UPDRAFTPLUS_DIR.'/methods/s3.php'); |
| 6 |
|
| 7 |
/** |
| 8 |
* Converted to multi-options (Feb 2017-) and previous options conversion removed: Yes |
| 9 |
*/ |
| 10 |
class UpdraftPlus_BackupModule_dreamobjects extends UpdraftPlus_BackupModule_s3 { |
| 11 |
|
| 12 |
// This gets populated in the constructor |
| 13 |
private $dreamobjects_endpoints = array(); |
| 14 |
|
| 15 |
protected $provider_can_use_aws_sdk = false; |
| 16 |
|
| 17 |
protected $provider_has_regions = true; |
| 18 |
|
| 19 |
/** |
| 20 |
* Class constructor |
| 21 |
*/ |
| 22 |
public function __construct() { |
| 23 |
// When new endpoint introduced in future, Please add it here and also add it as hard coded option for endpoint dropdown in self::get_partial_configuration_template_for_endpoint() |
| 24 |
// Put the default first |
| 25 |
$this->dreamobjects_endpoints = array( |
| 26 |
// Endpoint, then the label |
| 27 |
'objects-us-east-1.dream.io' => 'objects-us-east-1.dream.io', |
| 28 |
'objects-us-west-1.dream.io' => 'objects-us-west-1.dream.io ('.__('Closing 1st October 2018', 'updraftplus').')', |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
protected $use_v4 = false; |
| 33 |
|
| 34 |
/** |
| 35 |
* Given an S3 object, possibly set the region on it |
| 36 |
* |
| 37 |
* @param Object $obj - like UpdraftPlus_S3 |
| 38 |
* @param String $region - or empty to fetch one from saved configuration |
| 39 |
* @param String $bucket_name |
| 40 |
*/ |
| 41 |
protected function set_region($obj, $region = '', $bucket_name = '') {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- $bucket_name |
| 42 |
|
| 43 |
$config = $this->get_config(); |
| 44 |
$endpoint = ('' != $region && 'n/a' != $region) ? $region : $config['endpoint']; |
| 45 |
global $updraftplus; |
| 46 |
if ($updraftplus->backup_time) { |
| 47 |
$updraftplus->log("Set endpoint (".get_class($obj)."): $endpoint"); |
| 48 |
|
| 49 |
// Warning for objects-us-west-1 shutdown in Oct 2018 |
| 50 |
if ('objects-us-west-1.dream.io' == $endpoint) { |
| 51 |
$updraftplus->log("The objects-us-west-1.dream.io endpoint shut down on the 1st October 2018. The upload is expected to fail. Please see the following article for more information https://help.dreamhost.com/hc/en-us/articles/360002135871-Cluster-migration-procedure", 'warning', 'dreamobjects_west_shutdown'); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
$obj->setEndpoint($endpoint); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* This method overrides the parent method and lists the supported features of this remote storage option. |
| 60 |
* |
| 61 |
* @return Array - an array of supported features (any features not mentioned are asuumed to not be supported) |
| 62 |
*/ |
| 63 |
public function get_supported_features() { |
| 64 |
// This options format is handled via only accessing options via $this->get_options() |
| 65 |
return array('multi_options', 'config_templates', 'multi_storage', 'conditional_logic'); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Retrieve default options for this remote storage module. |
| 70 |
* |
| 71 |
* @return Array - an array of options |
| 72 |
*/ |
| 73 |
public function get_default_options() { |
| 74 |
return array( |
| 75 |
'accesskey' => '', |
| 76 |
'secretkey' => '', |
| 77 |
'path' => '', |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Retrieve specific options for this remote storage module |
| 83 |
* |
| 84 |
* @param Boolean $force_refresh - if set, and if relevant, don't use cached credentials, but get them afresh |
| 85 |
* |
| 86 |
* @return Array - an array of options |
| 87 |
*/ |
| 88 |
protected function get_config($force_refresh = false) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- $force_refresh unused |
| 89 |
$opts = $this->get_options(); |
| 90 |
$opts['whoweare'] = 'DreamObjects'; |
| 91 |
$opts['whoweare_long'] = 'DreamObjects'; |
| 92 |
$opts['key'] = 'dreamobjects'; |
| 93 |
if (empty($opts['endpoint'])) { |
| 94 |
$endpoints = array_keys($this->dreamobjects_endpoints); |
| 95 |
$opts['endpoint'] = $endpoints[0]; |
| 96 |
} |
| 97 |
return $opts; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Get the pre configuration template |
| 102 |
* |
| 103 |
* @return String - the template |
| 104 |
*/ |
| 105 |
public function get_pre_configuration_template() { |
| 106 |
$this->get_pre_configuration_template_engine('dreamobjects', 'DreamObjects', 'DreamObjects', 'DreamObjects', 'https://panel.dreamhost.com/index.cgi?tree=storage.dreamhostobjects', '<a href="https://dreamhost.com/cloud/dreamobjects/" target="_blank"><img alt="DreamObjects" src="'.UPDRAFTPLUS_URL.'/images/dreamobjects_logo-horiz-2013.png"></a>'); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Get the configuration template |
| 111 |
* |
| 112 |
* @return String - the template, ready for substitutions to be carried out |
| 113 |
*/ |
| 114 |
public function get_configuration_template() { |
| 115 |
return $this->get_configuration_template_engine('dreamobjects', 'DreamObjects', 'DreamObjects', 'DreamObjects', 'https://panel.dreamhost.com/index.cgi?tree=storage.dreamhostobjects', '<a href="https://dreamhost.com/cloud/dreamobjects/" target="_blank"><img alt="DreamObjects" src="'.UPDRAFTPLUS_URL.'/images/dreamobjects_logo-horiz-2013.png"></a>'); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Get handlebar partial template string for endpoint of s3 compatible remote storage method. Other child class can extend it. |
| 120 |
* |
| 121 |
* @return String the partial template string |
| 122 |
*/ |
| 123 |
protected function get_partial_configuration_template_for_endpoint() { |
| 124 |
// When new endpoint introduced in future, Please add it as hard coded option for below endpoint dropdown and also add as array value in private $dreamobjects_endpoints variable |
| 125 |
return '<tr class="'.$this->get_css_classes().'"> |
| 126 |
<th>'.sprintf(__('%s end-point', 'updraftplus'), 'DreamObjects').'</th> |
| 127 |
<td> |
| 128 |
<select data-updraft_settings_test="endpoint" '.$this->output_settings_field_name_and_id('endpoint', true).' style="width: 360px"> |
| 129 |
{{#each dreamobjects_endpoints as |description endpoint|}} |
| 130 |
<option value="{{endpoint}}" {{#ifeq ../endpoint endpoint}}selected="selected"{{/ifeq}}>{{description}}</option> |
| 131 |
{{/each}} |
| 132 |
</select> |
| 133 |
</td> |
| 134 |
</tr>'; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Modifies handerbar template options |
| 139 |
* |
| 140 |
* @param array $opts |
| 141 |
* @return Array - Modified handerbar template options |
| 142 |
*/ |
| 143 |
public function transform_options_for_template($opts) { |
| 144 |
$opts['endpoint'] = empty($opts['endpoint']) ? '' : $opts['endpoint']; |
| 145 |
$opts['dreamobjects_endpoints'] = $this->dreamobjects_endpoints; |
| 146 |
return $opts; |
| 147 |
} |
| 148 |
} |
| 149 |
|