restore_finalisation.php
4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
* @package Joomla.Administrator
* @subpackage com_joomlaupdate
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Require the restoration environment or fail cold. Prevents direct web access.
defined('_AKEEBA_RESTORATION') or die();
// Fake a miniature Joomla environment
if (!defined('_JEXEC'))
{
define('_JEXEC', 1);
}
if (!function_exists('jimport'))
{
/**
* We don't use it but the post-update script is using it anyway, so LET'S FAKE IT!
*
* @param string $path A dot syntax path.
* @param string $base Search this directory for the class.
*
* @return boolean True on success.
*
* @since 3.5.1
*/
function jimport($path, $base = null)
{
// Do nothing
}
}
// Fake the JFile class, mapping it to Restore's post-processing class
if (!class_exists('JFile'))
{
/**
* JFile mock class proxing behaviour in the post-upgrade script to that of either native PHP or restore.php
*
* @since 3.5.1
*/
abstract class JFile
{
/**
* Proxies checking a folder exists to the native php version
*
* @param string $fileName The path to the file to be checked
*
* @return boolean
*
* @since 3.5.1
*/
public static function exists($fileName)
{
return @file_exists($fileName);
}
/**
* Proxies deleting a file to the restore.php version
*
* @param string $fileName The path to the file to be deleted
*
* @return boolean
*
* @since 3.5.1
*/
public static function delete($fileName)
{
$postproc = AKFactory::getPostProc();
$postproc->unlink($fileName);
}
}
}
// Fake the JFolder class, mapping it to Restore's post-processing class
if (!class_exists('JFolder'))
{
/**
* JFolder mock class proxing behaviour in the post-upgrade script to that of either native PHP or restore.php
*
* @since 3.5.1
*/
abstract class JFolder
{
/**
* Proxies checking a folder exists to the native php version
*
* @param string $folderName The path to the folder to be checked
*
* @return boolean
*
* @since 3.5.1
*/
public static function exists($folderName)
{
return @is_dir($folderName);
}
/**
* Proxies deleting a folder to the restore.php version
*
* @param string $folderName The path to the folder to be deleted
*
* @return void
*
* @since 3.5.1
*/
public static function delete($folderName)
{
recursive_remove_directory($folderName);
}
}
}
// Fake the JText class - we aren't going to show errors to people anyhow
if (!class_exists('JText'))
{
/**
* JText mock class proxing behaviour in the post-upgrade script to that of either native PHP or restore.php
*
* @since 3.5.1
*/
abstract class JText
{
/**
* No need for translations in a non-interactive script, so always return an empty string here
*
* @param string $text A language constant
*
* @return string
*
* @since 3.5.1
*/
public static function sprintf($text)
{
return '';
}
}
}
if (!function_exists('finalizeRestore'))
{
/**
* Run part of the Joomla! finalisation script, namely the part that cleans up unused files/folders
*
* @param string $siteRoot The root to the Joomla! site
* @param string $restorePath The base path to restore.php
*
* @return void
*
* @since 3.5.1
*/
function finalizeRestore($siteRoot, $restorePath)
{
if (!defined('JPATH_ROOT'))
{
define('JPATH_ROOT', $siteRoot);
}
$filePath = JPATH_ROOT . '/administrator/components/com_admin/script.php';
if (file_exists($filePath))
{
require_once $filePath;
}
// Make sure Joomla!'s code can figure out which files exist and need be removed
clearstatcache();
// Remove obsolete files - prevents errors occuring in some system plugins
if (class_exists('JoomlaInstallerScript'))
{
$script = new JoomlaInstallerScript;
$script->deleteUnexistingFiles();
}
// Clear OPcache
if (function_exists('opcache_reset'))
{
opcache_reset();
}
elseif (function_exists('apc_clear_cache'))
{
@apc_clear_cache();
}
}
}