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