[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_joomlaupdate/ -> finalisation.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_joomlaupdate
   6   *
   7   * @copyright   (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   *
  10   * Important Notes:
  11   * - Unlike other files, this file requires multiple namespace declarations in order to overload core classes during the update process
  12   * - Also unlike other files, the normal constant defined checks must be within the global namespace declaration and can't be outside of it
  13   */
  14  
  15  namespace
  16  {
  17      // Require the restoration environment or fail cold. Prevents direct web access.
  18      \defined('_JOOMLA_UPDATE') or die();
  19  
  20      // Fake a miniature Joomla environment
  21      if (!\defined('_JEXEC')) {
  22          \define('_JEXEC', 1);
  23      }
  24  
  25      if (!function_exists('jimport')) {
  26          /**
  27           * This is deprecated but it may still be used in the update finalisation script.
  28           *
  29           * @param   string  $path  Ignored.
  30           * @param   string  $base  Ignored.
  31           *
  32           * @return  boolean  Always true.
  33           *
  34           * @since   1.7.0
  35           */
  36          function jimport(string $path, ?string $base = null): bool
  37          {
  38              // Do nothing
  39              return true;
  40          }
  41      }
  42  
  43      if (!function_exists('finalizeUpdate')) {
  44          /**
  45           * Run part of the Joomla! finalisation script, namely the part that cleans up unused files/folders
  46           *
  47           * @param   string  $siteRoot     The root to the Joomla! site
  48           * @param   string  $restorePath  The base path to extract.php
  49           *
  50           * @return  void
  51           *
  52           * @since   3.5.1
  53           */
  54          function finalizeUpdate(string $siteRoot, string $restorePath): void
  55          {
  56              if (!\defined('JPATH_ROOT')) {
  57                  \define('JPATH_ROOT', $siteRoot);
  58              }
  59  
  60              $filePath = JPATH_ROOT . '/administrator/components/com_admin/script.php';
  61  
  62              if (file_exists($filePath)) {
  63                  require_once $filePath;
  64              }
  65  
  66              // Make sure Joomla!'s code can figure out which files exist and need be removed
  67              clearstatcache();
  68  
  69              // Remove obsolete files - prevents errors occurring in some system plugins
  70              if (class_exists('JoomlaInstallerScript')) {
  71                  (new JoomlaInstallerScript())->deleteUnexistingFiles();
  72              }
  73  
  74              /**
  75               * Remove autoload_psr4.php so that namespace map is re-generated on the next request. This is needed
  76               * when there are new classes added to extensions on new Joomla! release.
  77               */
  78              $namespaceMapFile = JPATH_ROOT . '/administrator/cache/autoload_psr4.php';
  79  
  80              if (\Joomla\CMS\Filesystem\File::exists($namespaceMapFile)) {
  81                  \Joomla\CMS\Filesystem\File::delete($namespaceMapFile);
  82              }
  83          }
  84      }
  85  }
  86  
  87  namespace Joomla\CMS\Filesystem
  88  {
  89      // Fake the File class
  90      if (!class_exists('\Joomla\CMS\Filesystem\File')) {
  91          /**
  92           * File mock class
  93           *
  94           * @since  3.5.1
  95           */
  96          abstract class File
  97          {
  98              /**
  99               * Proxies checking a file exists to the native php version
 100               *
 101               * @param   string  $fileName  The path to the file to be checked
 102               *
 103               * @return  boolean
 104               *
 105               * @since   3.5.1
 106               */
 107              public static function exists(string $fileName): bool
 108              {
 109                  return @file_exists($fileName);
 110              }
 111  
 112              /**
 113               * Delete a file and invalidate the PHP OPcache
 114               *
 115               * @param   string  $fileName  The path to the file to be deleted
 116               *
 117               * @return  boolean
 118               *
 119               * @since   3.5.1
 120               */
 121              public static function delete(string $fileName): bool
 122              {
 123                  self::invalidateFileCache($fileName);
 124  
 125                  return @unlink($fileName);
 126              }
 127  
 128              /**
 129               * Rename a file and invalidate the PHP OPcache
 130               *
 131               * @param   string  $src   The path to the source file
 132               * @param   string  $dest  The path to the destination file
 133               *
 134               * @return  boolean  True on success
 135               *
 136               * @since   4.0.1
 137               */
 138              public static function move(string $src, string $dest): bool
 139              {
 140                  self::invalidateFileCache($src);
 141  
 142                  $result = @rename($src, $dest);
 143  
 144                  if ($result) {
 145                      self::invalidateFileCache($dest);
 146                  }
 147  
 148                  return $result;
 149              }
 150  
 151              /**
 152               * Invalidate opcache for a newly written/deleted file immediately, if opcache* functions exist and if this was a PHP file.
 153               *
 154               * @param   string  $filepath   The path to the file just written to, to flush from opcache
 155               * @param   boolean $force      If set to true, the script will be invalidated regardless of whether invalidation is necessary
 156               *
 157               * @return  boolean TRUE if the opcode cache for script was invalidated/nothing to invalidate,
 158               *                  or FALSE if the opcode cache is disabled or other conditions returning
 159               *                  FALSE from opcache_invalidate (like file not found).
 160               *
 161               * @since  4.0.2
 162               */
 163              public static function invalidateFileCache($filepath, $force = true)
 164              {
 165                  return \clearFileInOPCache($filepath);
 166              }
 167          }
 168      }
 169  
 170      // Fake the Folder class, mapping it to Restore's post-processing class
 171      if (!class_exists('\Joomla\CMS\Filesystem\Folder')) {
 172          /**
 173           * Folder mock class
 174           *
 175           * @since  3.5.1
 176           */
 177          abstract class Folder
 178          {
 179              /**
 180               * Proxies checking a folder exists to the native php version
 181               *
 182               * @param   string  $folderName  The path to the folder to be checked
 183               *
 184               * @return  boolean
 185               *
 186               * @since   3.5.1
 187               */
 188              public static function exists(string $folderName): bool
 189              {
 190                  return @is_dir($folderName);
 191              }
 192  
 193              /**
 194               * Delete a folder recursively and invalidate the PHP OPcache
 195               *
 196               * @param   string  $folderName  The path to the folder to be deleted
 197               *
 198               * @return  boolean
 199               *
 200               * @since   3.5.1
 201               */
 202              public static function delete(string $folderName): bool
 203              {
 204                  if (substr($folderName, -1) == '/') {
 205                      $folderName = substr($folderName, 0, -1);
 206                  }
 207  
 208                  if (!@file_exists($folderName) || !@is_dir($folderName) || !is_readable($folderName)) {
 209                      return false;
 210                  }
 211  
 212                  $di = new \DirectoryIterator($folderName);
 213  
 214                  /** @var \DirectoryIterator $item */
 215                  foreach ($di as $item) {
 216                      if ($item->isDot()) {
 217                          continue;
 218                      }
 219  
 220                      if ($item->isDir()) {
 221                          $status = self::delete($item->getPathname());
 222  
 223                          if (!$status) {
 224                              return false;
 225                          }
 226  
 227                          continue;
 228                      }
 229  
 230                      \clearFileInOPCache($item->getPathname());
 231  
 232                      @unlink($item->getPathname());
 233                  }
 234  
 235                  return @rmdir($folderName);
 236              }
 237          }
 238      }
 239  }
 240  
 241  namespace Joomla\CMS\Language
 242  {
 243      // Fake the Text class - we aren't going to show errors to people anyhow
 244      if (!class_exists('\Joomla\CMS\Language\Text')) {
 245          /**
 246           * Text mock class
 247           *
 248           * @since  3.5.1
 249           */
 250          abstract class Text
 251          {
 252              /**
 253               * No need for translations in a non-interactive script, so always return an empty string here
 254               *
 255               * @param   string  $text  A language constant
 256               *
 257               * @return  string
 258               *
 259               * @since   3.5.1
 260               */
 261              public static function sprintf(string $text): string
 262              {
 263                  return '';
 264              }
 265          }
 266      }
 267  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer