PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 2.0.3
JetBackup – Backup, Restore & Migrate v2.0.3
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / core / restore / SGExternalRestore.php
backup / com / core / restore Last commit date
SGExternalRestore.php 3 years ago SGExternalRestoreWordpress.php 3 years ago
SGExternalRestore.php
186 lines
1 <?php
2
3 abstract class SGExternalRestore
4 {
5 private static $instance = null;
6
7 public static function getInstance()
8 {
9 if (!self::$instance) {
10 self::$instance = self::createChildInstance();
11 }
12
13 return self::$instance;
14 }
15
16 private static function createChildInstance()
17 {
18 $className = 'SGExternalRestore'.SG_ENV_ADAPTER;
19 require_once(dirname(__FILE__).'/'.$className.'.php');
20 $child = new $className();
21 return $child;
22 }
23
24 protected function __construct()
25 {
26
27 }
28
29 private function __clone()
30 {
31
32 }
33
34 public function getSourceFilePath()
35 {
36 return SG_PUBLIC_PATH.'restore_'.strtolower(SG_ENV_ADAPTER).'.php';
37 }
38
39 public function getDestinationFilePath()
40 {
41 //get already saved restore path
42 $path = SGConfig::get('SG_EXTERNAL_RESTORE_PATH', true);
43
44 if (!$path) {
45 $path = $this->getDestinationPath().SG_EXTERNAL_RESTORE_FILE;
46 SGConfig::set('SG_EXTERNAL_RESTORE_PATH', $path, true);
47 }
48
49 return $path;
50 }
51
52 public function getDestinationFileUrlArray(&$key = '')
53 {
54 //we use this key to deny direct access to the file
55 $key = SGConfig::get('SG_BACKUP_CURRENT_KEY', true);
56
57 //get already saved restore url
58 $url = SGConfig::get('SG_SITE_URL', true);
59
60 if (!$url) $url = $this->getDestinationUrl();
61
62 $array['key'] = $key;
63 $array['url'] = $url;
64 $array['restore_file'] = SG_EXTERNAL_RESTORE_FILE;
65
66 return $array;
67 }
68
69 public function getDestinationFileUrl(&$key = '')
70 {
71 //we use this key to deny direct access to the file
72 $key = SGConfig::get('SG_BACKUP_CURRENT_KEY', true);
73
74 //get already saved restore url
75 $url = SGConfig::get('SG_EXTERNAL_RESTORE_URL', true);
76
77 if (!$url) {
78 $url = $this->getDestinationUrl().SG_EXTERNAL_RESTORE_FILE.'?k='.$key;
79 SGConfig::set('SG_EXTERNAL_RESTORE_URL', $url, true);
80 }
81
82 return $url;
83 }
84
85 public static function isEnabled()
86 {
87 return SGConfig::get('SG_EXTERNAL_RESTORE_ENABLED')?true:false;
88 }
89
90 protected static function setEnabled($enabled)
91 {
92 SGConfig::set('SG_EXTERNAL_RESTORE_ENABLED', ($enabled?1:0), true);
93 }
94 private function getConstants($actionId)
95 {
96 $key = '';
97 $destinationUrl = $this->getDestinationFileUrl($key);
98 $isMultisite = backupGuardIsMultisite();
99 return array(
100 'SG_ACTION_ID' => $actionId,
101 'SG_PLUGIN_NAME' => SG_PLUGIN_NAME,
102 'SG_ENV_DB_PREFIX' => SG_ENV_DB_PREFIX,
103 'SG_SITE_URL' => SG_SITE_URL,
104 'SG_BACKUP_SITE_URL' => SG_BACKUP_SITE_URL,
105 'SG_PUBLIC_URL' => SG_PUBLIC_URL,
106 'SG_BACKUP_DIRECTORY' => SG_BACKUP_DIRECTORY,
107 'SG_BACKUP_OLD_DIRECTORY' => SG_BACKUP_OLD_DIRECTORY,
108 'SG_BACKUP_GUARD_VERSION' => SG_BACKUP_GUARD_VERSION,
109 'SG_HOME_URL' => SG_HOME_URL,
110 'SG_UPLOAD_PATH' => SG_UPLOAD_PATH,
111 'SG_SITE_TYPE' => SG_SITE_TYPE,
112 'SG_ENV_VERSION' => SG_ENV_VERSION,
113 'SG_PING_FILE_PATH' => SG_PING_FILE_PATH,
114 'BG_PLUGIN_URL' => SG_PUBLIC_BACKUPS_URL,
115 'BG_RESTORE_KEY' => $key,
116 'BG_RESTORE_URL' => $destinationUrl,
117 'BG_AWAKE_URL' => get_admin_url() . "admin-ajax.php?action=backup_guard_awake",
118 'BG_IS_MULTISITE' => $isMultisite,
119 'SG_MISC_MIGRATABLE_TABLES' => SG_MISC_MIGRATABLE_TABLES,
120 'SG_MULTISITE_TABLES_TO_MIGRATE' => SG_MULTISITE_TABLES_TO_MIGRATE,
121 'SG_DB_NAME' => SG_DB_NAME,
122 'DOMAIN_CURRENT_SITE' => defined('DOMAIN_CURRENT_SITE')?DOMAIN_CURRENT_SITE:'',
123 'PATH_CURRENT_SITE' => defined('PATH_CURRENT_SITE')?PATH_CURRENT_SITE:'',
124 'SG_SUBDOMAIN_INSTALL' => SG_SUBDOMAIN_INSTALL,
125 'WP_CONTENT_DIR' => WP_CONTENT_DIR,
126 'SG_BACKUP_DATABASE_EXCLUDE' => SG_BACKUP_DATABASE_EXCLUDE,
127 'SG_MYSQL_VERSION' => SG_MYSQL_VERSION,
128 'SG_WP_OPTIONS_MIGRATABLE_VALUES' => SG_WP_OPTIONS_MIGRATABLE_VALUES,
129 'SG_WP_USERMETA_MIGRATABLE_VALUES' => SG_WP_USERMETA_MIGRATABLE_VALUES,
130 'SG_BACKUP_OLD_DIRECTORY' => SG_BACKUP_OLD_DIRECTORY
131 );
132 }
133
134 public function prepare($actionId)
135 {
136 $res = false;
137
138 //reset everything
139 self::setEnabled(false);
140 SGConfig::set('SG_EXTERNAL_RESTORE_URL', '', true);
141 SGConfig::set('SG_EXTERNAL_RESTORE_PATH', '', true);
142
143 if ($this->canPrepare()) {
144 $contents = @file_get_contents($this->getSourceFilePath());
145 if ($contents) {
146 $constants = $this->getConstants($actionId);
147 $customConstants = $this->getCustomConstants();
148 $allConstants = array_merge($constants, $customConstants);
149
150 $defines = '';
151 foreach ($allConstants as $key => $val) {
152 $defines .= "define('$key', '$val');\n";
153 }
154
155 //put all defines inside the file
156 $contents = str_replace('#SG_DYNAMIC_DEFINES#', $defines, $contents);
157
158 //create new copy
159 $res = (bool)@file_put_contents($this->getDestinationFilePath(), $contents);
160 }
161 }
162
163 self::setEnabled($res);
164
165 return $res;
166 }
167
168 public function cleanup()
169 {
170 if (file_exists($this->getDestinationFilePath())) {
171 $actions = SGBackup::getRunningActions();
172 if (empty($actions)) {
173 @unlink($this->getDestinationFilePath());
174 }
175 }
176 }
177
178 abstract protected function canPrepare();
179
180 abstract protected function getCustomConstants();
181
182 abstract public function getDestinationPath();
183
184 abstract public function getDestinationUrl();
185 }
186