Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/update/_to_4.7.0.php - 192 lines - 6117 bytes - 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  // Remove a few licence files. De-clutters the root directory a tad.
  29  Txp::get('\Textpattern\Admin\Tools')->removeFiles(txpath.DS.'..', array('LICENSE-BSD-3.txt', 'LICENSE-LESSER.txt'));
  30  Txp::get('\Textpattern\Admin\Tools')->removeFiles(txpath.DS.'vendors', 'dropbox');
  31  Txp::get('\Textpattern\Admin\Tools')->removeFiles(txpath.DS.'lang', 'en-gb.txt');
  32  
  33  // Drop the ip column in txp_discuss
  34  $cols = getThings("DESCRIBE `".PFX."txp_discuss`");
  35  
  36  if (in_array('ip', $cols)) {
  37      safe_alter('txp_discuss', "DROP ip");
  38  }
  39  
  40  // Drop the ip and host column in txp_log
  41  $cols = getThings("DESCRIBE `".PFX."txp_log`");
  42  
  43  if (in_array('ip', $cols)) {
  44      safe_drop_index('txp_log', 'ip');
  45      safe_alter('txp_log', "DROP ip");
  46  }
  47  
  48  if (in_array('host', $cols)) {
  49      safe_alter('txp_log', "DROP host");
  50  }
  51  
  52  safe_delete('txp_prefs', "name='use_dns'");
  53  
  54  // Drop the prefs_id column in txp_prefs
  55  $cols = getThings("DESCRIBE `".PFX."txp_prefs`");
  56  
  57  if (in_array('prefs_id', $cols)) {
  58      safe_drop_index('txp_prefs', 'prefs_idx');
  59      safe_alter('txp_prefs', "ADD UNIQUE prefs_idx (name(185), user_name)");
  60      safe_alter('txp_prefs', "DROP prefs_id");
  61  }
  62  
  63  // Correct the language designators to become less opinionated.
  64  $available_lang = Txp::get('\Textpattern\L10n\Lang')->available();
  65  $available_keys = array_keys($available_lang);
  66  $installed_lang = Txp::get('\Textpattern\L10n\Lang')->available(TEXTPATTERN_LANG_ACTIVE | TEXTPATTERN_LANG_INSTALLED);
  67  $installed_keys = array_keys($installed_lang);
  68  
  69  foreach ($installed_keys as $key) {
  70      if (!in_array($key, $available_keys)) {
  71          $newKey = Txp::get('\Textpattern\L10n\Locale')->validLocale($key);
  72          safe_update('txp_lang', "lang='".doSlash($newKey)."'", "lang='".doSlash($key)."'");
  73  
  74          if (get_pref('language') === $key) {
  75              update_pref('language', $newKey);
  76          }
  77      }
  78  }
  79  
  80  // New fields in the plugin table.
  81  $colInfo = getRows("DESCRIBE `".PFX."txp_plugin`");
  82  $cols = array_map(function ($el) {
  83      return $el['Field'];
  84  }, $colInfo);
  85  
  86  if (!in_array('data', $cols)) {
  87      safe_alter('txp_plugin', "ADD data MEDIUMTEXT NOT NULL AFTER code_md5");
  88  }
  89  
  90  if (!in_array('textpack', $cols)) {
  91      safe_alter('txp_plugin', "ADD textpack MEDIUMTEXT NOT NULL AFTER code_md5");
  92  }
  93  
  94  // Bigger plugin help text.
  95  $helpCol = array_search('help', $cols);
  96  
  97  if (strtolower($colInfo[$helpCol]['Type']) !== 'mediumtext') {
  98      safe_alter('txp_plugin', "MODIFY help MEDIUMTEXT NOT NULL");
  99  }
 100  
 101  // Add theme (skin) support. Note that even though outwardly they're
 102  // referred to as Themes, internally they're known as skins because
 103  // "theme" has already been hijacked by admin-side themes. This
 104  // convention avoids potential name clashes.
 105  safe_create('txp_skin', "
 106      name        VARCHAR(63)    NOT NULL DEFAULT 'default',
 107      title       VARCHAR(255)   NOT NULL DEFAULT 'Default',
 108      version     VARCHAR(255)       NULL DEFAULT '1.0',
 109      description VARCHAR(10240)     NULL DEFAULT '',
 110      author      VARCHAR(255)       NULL DEFAULT '',
 111      author_uri  VARCHAR(255)       NULL DEFAULT '',
 112      lastmod     DATETIME           NULL DEFAULT NULL,
 113  
 114      PRIMARY KEY (`name`(63))
 115  ");
 116  
 117  // Add theme support to Pages...
 118  $cols = getThings('describe `'.PFX.'txp_page`');
 119  
 120  if (!in_array('lastmod', $cols)) {
 121      safe_alter('txp_page',
 122          "ADD lastmod DATETIME DEFAULT NULL AFTER user_html");
 123  }
 124  
 125  if (!in_array('skin', $cols)) {
 126      safe_alter('txp_page',
 127          "ADD skin VARCHAR(63) NOT NULL DEFAULT 'default' AFTER user_html");
 128  }
 129  
 130  safe_drop_index('txp_page', 'primary');
 131  safe_create_index('txp_page', 'name(63), skin(63)', 'name_skin', 'unique');
 132  
 133  // ... Forms...
 134  $cols = getThings('describe `'.PFX.'txp_form`');
 135  
 136  if (!in_array('lastmod', $cols)) {
 137      safe_alter('txp_form',
 138          "ADD lastmod DATETIME DEFAULT NULL AFTER Form");
 139  }
 140  
 141  if (!in_array('skin', $cols)) {
 142      safe_alter('txp_form',
 143          "ADD skin VARCHAR(63) NOT NULL DEFAULT 'default' AFTER Form");
 144  }
 145  
 146  safe_drop_index('txp_form', 'primary');
 147  safe_create_index('txp_form', 'name(63), skin(63)', 'name_skin', 'unique');
 148  
 149  // ... Stylesheets...
 150  $cols = getThings('describe `'.PFX.'txp_css`');
 151  
 152  if (!in_array('lastmod', $cols)) {
 153      safe_alter('txp_css',
 154          "ADD lastmod DATETIME DEFAULT NULL AFTER css");
 155  }
 156  
 157  if (!in_array('skin', $cols)) {
 158      safe_alter('txp_css',
 159          "ADD skin VARCHAR(63) NOT NULL DEFAULT 'default' AFTER css");
 160  }
 161  
 162  safe_drop_index('txp_css', 'name');
 163  safe_create_index('txp_css', 'name(63), skin(63)', 'name_skin', 'unique');
 164  
 165  // ... and Sections...
 166  $cols = getThings('describe `'.PFX.'txp_section`');
 167  
 168  if (!in_array('skin', $cols)) {
 169      safe_alter('txp_section',
 170          "ADD skin VARCHAR(63) NOT NULL DEFAULT 'default' AFTER name");
 171  }
 172  
 173  safe_drop_index('txp_section', 'primary');
 174  safe_create_index('txp_section', 'page(50), skin(63)', 'page_skin');
 175  safe_create_index('txp_section', 'css(50), skin(63)', 'css_skin');
 176  
 177  $exists = safe_row('name', 'txp_skin', "1=1");
 178  
 179  if (!$exists) {
 180      safe_insert('txp_skin',
 181          "name = 'default',
 182          title = 'Default',
 183          version = '".txp_version."',
 184          author = 'Team Textpattern',
 185          author_uri = 'https://textpattern.com/'"
 186      );
 187  }
 188  
 189  // Add theme path pref.
 190  if (!get_pref('skin_dir')) {
 191      set_pref('skin_dir', 'themes', 'admin', PREF_CORE, 'text_input', 70);
 192  }

title

Description

title

Description

title

Description

title

title

Body