PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.5.3
JetBackup – Backup, Restore & Migrate v1.5.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 5 years ago SGExternalRestoreWordpress.php 5 years ago
SGExternalRestore.php
163 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 getDestinationFileUrl(&$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_EXTERNAL_RESTORE_URL', true);
59
60 if (!$url) {
61 $url = $this->getDestinationUrl().SG_EXTERNAL_RESTORE_FILE.'?k='.$key;
62 SGConfig::set('SG_EXTERNAL_RESTORE_URL', $url, true);
63 }
64
65 return $url;
66 }
67
68 public static function isEnabled()
69 {
70 return SGConfig::get('SG_EXTERNAL_RESTORE_ENABLED')?true:false;
71 }
72
73 protected static function setEnabled($enabled)
74 {
75 SGConfig::set('SG_EXTERNAL_RESTORE_ENABLED', ($enabled?1:0), true);
76 }
77
78 private function getConstants($actionId)
79 {
80 $key = '';
81 $destinationUrl = $this->getDestinationFileUrl($key);
82 $isMultisite = backupGuardIsMultisite();
83
84 return array(
85 'SG_ACTION_ID' => $actionId,
86 'SG_PLUGIN_NAME' => SG_PLUGIN_NAME,
87 'SG_ENV_DB_PREFIX' => SG_ENV_DB_PREFIX,
88 'SG_SITE_URL' => SG_SITE_URL,
89 'SG_BACKUP_SITE_URL' => SG_BACKUP_SITE_URL,
90 'SG_PUBLIC_URL' => SG_PUBLIC_URL,
91 'SG_BACKUP_DIRECTORY' => SG_BACKUP_DIRECTORY,
92 'SG_PING_FILE_PATH' => SG_PING_FILE_PATH,
93 'BG_PLUGIN_URL' => SG_PUBLIC_BACKUPS_URL,
94 'BG_RESTORE_KEY' => $key,
95 'BG_RESTORE_URL' => $destinationUrl,
96 'BG_IS_MULTISITE' => $isMultisite,
97 'SG_MISC_MIGRATABLE_TABLES' => SG_MISC_MIGRATABLE_TABLES,
98 'SG_MULTISITE_TABLES_TO_MIGRATE' => SG_MULTISITE_TABLES_TO_MIGRATE,
99 'SG_DB_NAME' => SG_DB_NAME,
100 'DOMAIN_CURRENT_SITE' => defined('DOMAIN_CURRENT_SITE')?DOMAIN_CURRENT_SITE:'',
101 'PATH_CURRENT_SITE' => defined('PATH_CURRENT_SITE')?PATH_CURRENT_SITE:'',
102 'SG_SUBDOMAIN_INSTALL' => SG_SUBDOMAIN_INSTALL,
103 'WP_CONTENT_DIR' => WP_CONTENT_DIR,
104 'SG_BACKUP_DATABASE_EXCLUDE' => SG_BACKUP_DATABASE_EXCLUDE,
105 'SG_MYSQL_VERSION' => SG_MYSQL_VERSION,
106 'SG_WP_OPTIONS_MIGRATABLE_VALUES' => SG_WP_OPTIONS_MIGRATABLE_VALUES,
107 'SG_WP_USERMETA_MIGRATABLE_VALUES' => SG_WP_USERMETA_MIGRATABLE_VALUES
108 );
109 }
110
111 public function prepare($actionId)
112 {
113 $res = false;
114
115 //reset everything
116 self::setEnabled(false);
117 SGConfig::set('SG_EXTERNAL_RESTORE_URL', '', true);
118 SGConfig::set('SG_EXTERNAL_RESTORE_PATH', '', true);
119
120 if ($this->canPrepare()) {
121 $contents = @file_get_contents($this->getSourceFilePath());
122 if ($contents) {
123 $constants = $this->getConstants($actionId);
124 $customConstants = $this->getCustomConstants();
125 $allConstants = array_merge($constants, $customConstants);
126
127 $defines = '';
128 foreach ($allConstants as $key => $val) {
129 $defines .= "define('$key', '$val');\n";
130 }
131
132 //put all defines inside the file
133 $contents = str_replace('#SG_DYNAMIC_DEFINES#', $defines, $contents);
134
135 //create new copy
136 $res = (bool)@file_put_contents($this->getDestinationFilePath(), $contents);
137 }
138 }
139
140 self::setEnabled($res);
141
142 return $res;
143 }
144
145 public function cleanup()
146 {
147 if (file_exists($this->getDestinationFilePath())) {
148 $actions = SGBackup::getRunningActions();
149 if (empty($actions)) {
150 @unlink($this->getDestinationFilePath());
151 }
152 }
153 }
154
155 abstract protected function canPrepare();
156
157 abstract protected function getCustomConstants();
158
159 abstract public function getDestinationPath();
160
161 abstract public function getDestinationUrl();
162 }
163