Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/update/_update.php - 188 lines - 5863 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * https://textpattern.com/
   6   *
   7   * Copyright (C) 2020 The Textpattern Development Team
   8   *
   9   * This file is part of Textpattern.
  10   *
  11   * Textpattern is free software; you can redistribute it and/or
  12   * modify it under the terms of the GNU General Public License
  13   * as published by the Free Software Foundation, version 2.
  14   *
  15   * Textpattern is distributed in the hope that it will be useful,
  16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18   * GNU General Public License for more details.
  19   *
  20   * You should have received a copy of the GNU General Public License
  21   * along with Textpattern. If not, see <https://www.gnu.org/licenses/>.
  22   */
  23  
  24  if (!defined('TXP_UPDATE')) {
  25      exit("Nothing here. You can't access this file directly.");
  26  }
  27  
  28  global $thisversion, $dbversion, $txp_is_dev, $dbupdatetime, $app_mode, $event;
  29  
  30  $dbupdates = array(
  31      '4.0.3', '4.0.4', '4.0.5', '4.0.6', '4.0.7', '4.0.8',
  32      '4.2.0',
  33      '4.3.0',
  34      '4.5.0', '4.5.7',
  35      '4.6.0',
  36      '4.7.0', '4.7.2',
  37      '4.8.0', '4.8.4',
  38  );
  39  
  40  function newest_file()
  41  {
  42      $newest = 0;
  43      $dp = opendir(txpath.'/update/');
  44  
  45      while (false !== ($file = readdir($dp))) {
  46          if (strpos($file, "_") === 0) {
  47              $newest = max($newest, filemtime(txpath."/update/$file"));
  48          }
  49      }
  50  
  51      closedir($dp);
  52  
  53      return $newest;
  54  }
  55  
  56  if (($dbversion == '') ||
  57      (strpos($dbversion, 'g1') === 0) ||
  58      (strpos($dbversion, '1.0rc') === 0)) {
  59      $dbversion = '0.9.9';
  60  }
  61  
  62  if ($dbversion == $thisversion ||
  63      ($txp_is_dev && (newest_file() <= $dbupdatetime))) {
  64      return;
  65  }
  66  
  67  assert_system_requirements();
  68  
  69  @ignore_user_abort(1);
  70  @set_time_limit(0);
  71  
  72  // Wipe out the last update check setting so the next visit to Diagnostics
  73  // forces an update check, which resets the message. Without this, people who
  74  // upgrade in future may still see a "new version available" message for a
  75  // short time after upgrading.
  76  safe_delete('txp_prefs', "name = 'last_update_check'");
  77  
  78  set_error_handler("updateErrorHandler");
  79  
  80  $updates = array_fill_keys($dbupdates, true);
  81  
  82  if (!isset($updates[$thisversion])) {
  83      $updates[$thisversion] = false;
  84  }
  85  
  86  try {
  87      $versionparts = explode('-', $thisversion);
  88      $baseversion = $versionparts[0];
  89  
  90      // Disable no zero dates mode
  91      if (version_compare($dbversion, '4.6', '<') && $sql_mode = getThing('SELECT @@SESSION.sql_mode')) {
  92          $tmp_mode = implode(',', array_diff(
  93              do_list_unique($sql_mode),
  94              array('NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'TRADITIONAL')
  95          ));
  96          safe_query("SET SESSION sql_mode = '".doSlash($tmp_mode)."'");
  97      }
  98  
  99      foreach ($updates as $dbupdate => $update) {
 100          if (version_compare($dbversion, $dbupdate, '<') && version_compare($dbupdate, $baseversion, '<=')) {
 101              if ($update && (include txpath.DS.'update'.DS.'_to_'.$dbupdate.'.php') === false) {
 102                  trigger_error('Something bad happened. Not sure what exactly', E_USER_ERROR);
 103              }
 104  
 105              if (!($txp_is_dev && $thisversion == $dbupdate)) {
 106                  $dbversion = $dbupdate;
 107              }
 108          }
 109      }
 110  
 111      // Keep track of updates for SVN users.
 112      safe_delete('txp_prefs', "name = 'dbupdatetime'");
 113      safe_insert('txp_prefs', "name = 'dbupdatetime', val = '".max(newest_file(), time())."', type = '2'");
 114  
 115      // Restore sql_mode
 116      if (!empty($sql_mode)) {
 117          safe_query("SET SESSION sql_mode = '".doSlash($sql_mode)."'");
 118      }
 119  } catch (Exception $e) {
 120      // Nothing to do here, the goal was just to abort the update scripts
 121      // Error message already communicated via updateErrorHandler
 122  }
 123  
 124  // Update any out-of-date installed languages.
 125  // Have to refresh the cache first by reloading everything.
 126  $txpLang = Txp::get('\Textpattern\L10n\Lang');
 127  $installed_langs = $txpLang->available(
 128      TEXTPATTERN_LANG_INSTALLED | TEXTPATTERN_LANG_ACTIVE,
 129      TEXTPATTERN_LANG_INSTALLED | TEXTPATTERN_LANG_ACTIVE | TEXTPATTERN_LANG_AVAILABLE
 130  );
 131  
 132  foreach ($installed_langs as $lang_code => $info) {
 133      // Reinstall all languages and update the DB stamps in the cache,
 134      // just in case we're on the Languages panel so it doesn't report
 135      // the languages as being stale.
 136      $txpLang->installFile($lang_code);
 137      $txpLang->available(TEXTPATTERN_LANG_AVAILABLE, TEXTPATTERN_LANG_INSTALLED | TEXTPATTERN_LANG_AVAILABLE);
 138  
 139      if (get_pref('language_ui') === $lang_code) {
 140          load_lang($lang_code, $event);
 141      }
 142  }
 143  
 144  restore_error_handler();
 145  
 146  // Update version if not dev.
 147  if (!$txp_is_dev) {
 148      remove_pref('version', 'publish');
 149      create_pref('version', $dbversion, 'publish', PREF_HIDDEN);
 150  
 151      if (isset($txpcfg['multisite_root_path'])) {
 152          Txp::get('\Textpattern\Admin\Tools')->removeFiles($txpcfg['multisite_root_path'].DS.'admin', 'setup');
 153      } else {
 154          Txp::get('\Textpattern\Admin\Tools')->removeFiles(txpath, 'setup');
 155      }
 156  }
 157  
 158  // Invite optional third parties to the update experience
 159  // Convention: Put custom code into file(s) at textpattern/update/custom/post-update-abc-foo.php
 160  // where 'abc' is the third party's reserved prefix (@see https://docs.textpattern.com/development/plugin-developer-prefixes)
 161  // and 'foo' is whatever. The execution order among all files is undefined.
 162  $files = glob(txpath.'/update/custom/post-update*.php');
 163  
 164  if (is_array($files)) {
 165      foreach ($files as $f) {
 166          include $f;
 167      }
 168  }
 169  
 170  $js = <<<EOS
 171      textpattern.Console.addMessage(["A new Textpattern version ($thisversion) has been installed.", 0])
 172  EOS;
 173  
 174  if ($app_mode == 'async') {
 175      send_script_response($js);
 176  } else {
 177      script_js($js, false);
 178  }
 179  
 180  // Updated, baby. So let's get the fresh prefs and send them to Diagnostics.
 181  define('TXP_UPDATE_DONE', 1);
 182  
 183  $prefs = get_prefs();
 184  extract($prefs);
 185  /*
 186  $event = 'diag';
 187  $step = 'update';
 188  */

title

Description

title

Description

title

Description

title

title

Body