Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/update/_to_4.6.0.php - 251 lines - 10845 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  safe_alter('textpattern', "MODIFY textile_body    VARCHAR(32) NOT NULL DEFAULT '1'");
  29  safe_alter('textpattern', "MODIFY textile_excerpt VARCHAR(32) NOT NULL DEFAULT '1'");
  30  safe_update('txp_prefs', "name = 'pane_article_textfilter_help_visible'", "name = 'pane_article_textile_help_visible'");
  31  
  32  // Rejig preferences panel.
  33  $core_ev = join(',', quote_list(array('site', 'admin', 'publish', 'feeds', 'custom', 'comments')));
  34  
  35  // 1) Increase event column size.
  36  safe_alter('txp_prefs', "MODIFY event VARCHAR(255) NOT NULL DEFAULT 'publish'");
  37  safe_alter('txp_prefs', "MODIFY html  VARCHAR(255) NOT NULL DEFAULT 'text_input'");
  38  
  39  // 2) Remove basic/advanced distinction.
  40  safe_update('txp_prefs', "type = '".PREF_CORE."'", "type = '".PREF_PLUGIN."' AND event IN ($core_ev)");
  41  
  42  // Support for l10n string owners.
  43  $cols = getThings("DESCRIBE `".PFX."txp_lang`");
  44  
  45  if (!in_array('owner', $cols)) {
  46      safe_alter('txp_lang', "ADD owner VARCHAR(64) NOT NULL DEFAULT '' AFTER event");
  47      safe_create_index('txp_lang', 'owner', 'owner');
  48  }
  49  
  50  // Keep all comment-related forms together. The loss of 'preview' ability on the
  51  // comments_display Form is of little consequence compared with the benefit of
  52  // tucking them away neatly when not required.
  53  safe_update('txp_form', "type = 'comment'", "name = 'comments_display'");
  54  
  55  // Add protocol to logged HTTP referrers.
  56  safe_update(
  57      'txp_log',
  58      "refer = CONCAT('http://', refer)",
  59      "refer != '' AND refer NOT LIKE 'http://%' AND refer NOT LIKE 'https://%'"
  60  );
  61  
  62  // Usernames can be 64 characters long at most.
  63  safe_alter('txp_file',  "MODIFY author VARCHAR(64) NOT NULL DEFAULT ''");
  64  safe_alter('txp_link',  "MODIFY author VARCHAR(64) NOT NULL DEFAULT ''");
  65  safe_alter('txp_image', "MODIFY author VARCHAR(64) NOT NULL DEFAULT ''");
  66  
  67  // Consistent name length limitations for presentation items.
  68  safe_alter('txp_form',    "MODIFY name VARCHAR(255) NOT NULL DEFAULT ''");
  69  safe_alter('txp_page',    "MODIFY name VARCHAR(255) NOT NULL DEFAULT ''");
  70  safe_alter('txp_section', "MODIFY page VARCHAR(255) NOT NULL DEFAULT ''");
  71  safe_alter('txp_section', "MODIFY css  VARCHAR(255) NOT NULL DEFAULT ''");
  72  
  73  // Save sections correctly in articles.
  74  safe_alter('textpattern', "MODIFY Section VARCHAR(255) NOT NULL DEFAULT ''");
  75  safe_alter('txp_section', "MODIFY name    VARCHAR(255) NOT NULL DEFAULT ''");
  76  
  77  // Plugins can have longer version numbers.
  78  safe_alter('txp_plugin', "MODIFY version VARCHAR(255) NOT NULL DEFAULT '1.0'");
  79  
  80  // Translation strings should allow more than 255 characters.
  81  safe_alter('txp_lang', "MODIFY data TEXT");
  82  
  83  // Add meta description to articles.
  84  $cols = getThings("DESCRIBE `".PFX."textpattern`");
  85  
  86  if (!in_array('description', $cols)) {
  87      safe_alter('textpattern', "ADD description VARCHAR(255) NOT NULL DEFAULT '' AFTER Keywords");
  88  }
  89  
  90  // Add meta description to categories.
  91  $cols = getThings("DESCRIBE `".PFX."txp_category`");
  92  
  93  if (!in_array('description', $cols)) {
  94      safe_alter('txp_category', "ADD description VARCHAR(255) NOT NULL DEFAULT '' AFTER title");
  95  }
  96  
  97  // Add meta description to sections.
  98  $cols = getThings("DESCRIBE `".PFX."txp_section`");
  99  
 100  if (!in_array('description', $cols)) {
 101      safe_alter('txp_section', "ADD description VARCHAR(255) NOT NULL DEFAULT '' AFTER css");
 102  }
 103  
 104  // Remove broken import functionality.
 105  if (is_writable(txpath.DS.'include') && file_exists(txpath.DS.'include'.DS.'txp_import.php')) {
 106      $import_files = array(
 107          'BloggerImportTemplate.txt',
 108          'import_blogger.php',
 109          'import_mt.php',
 110          'import_b2.php',
 111          'import_mtdb.php',
 112          'import_wp.php'
 113      );
 114  
 115      if (is_writable(txpath.DS.'include'.DS.'import')) {
 116          foreach ($import_files as $file) {
 117              if (file_exists(txpath.DS.'include'.DS.'import'.DS.$file)) {
 118                  unlink(txpath.DS.'include'.DS.'import'.DS.$file);
 119              }
 120          }
 121          rmdir(txpath.DS.'include'.DS.'import');
 122      }
 123  
 124      unlink(txpath.DS.'include'.DS.'txp_import.php');
 125  }
 126  
 127  // Remove unused ipban table or recreate its index (for future utf8mb4 conversion).
 128  if (getThing("SHOW TABLES LIKE '".PFX."txp_discuss_ipban'")) {
 129      if (!safe_count('txp_discuss_ipban', "1 = 1")) {
 130          safe_drop('txp_discuss_ipban');
 131      } else {
 132          safe_drop_index('txp_discuss_ipban', "PRIMARY");
 133          safe_alter('txp_discuss_ipban', "ADD PRIMARY KEY (ip(250))");
 134      }
 135  }
 136  
 137  // Recreate indexes with smaller key sizes to allow future conversion to charset utf8mb4.
 138  safe_drop_index('txp_css',     "name");
 139  safe_drop_index('txp_file',    "filename");
 140  safe_drop_index('txp_form',    "PRIMARY");
 141  safe_drop_index('txp_page',    "PRIMARY");
 142  safe_drop_index('txp_section', "PRIMARY");
 143  safe_drop_index('txp_prefs',   "name");
 144  safe_drop_index('textpattern', "section_status_idx");
 145  safe_drop_index('textpattern', "url_title_idx");
 146  // Not using safe_create_index here, because we just dropped the index.
 147  safe_alter('txp_css',     "ADD UNIQUE name (name(250))");
 148  safe_alter('txp_file',    "ADD UNIQUE filename (filename(250))");
 149  safe_alter('txp_form',    "ADD PRIMARY KEY (name(250))");
 150  safe_alter('txp_page',    "ADD PRIMARY KEY (name(250))");
 151  safe_alter('txp_section', "ADD PRIMARY KEY (name(250))");
 152  safe_alter('txp_prefs',   "ADD INDEX name (name(250))");
 153  safe_alter('textpattern', "ADD INDEX section_status_idx (Section(249), Status)");
 154  safe_alter('textpattern', "ADD INDEX url_title_idx (url_title(250))");
 155  // Specifically, txp_discuss_nonce didn't have a primary key in 4.0.3
 156  // so it has to be done in two separate steps.
 157  safe_drop_index('txp_discuss_nonce', "PRIMARY");
 158  safe_alter('txp_discuss_nonce', "ADD PRIMARY KEY (nonce(250))");
 159  
 160  // Enforce some table changes that happened after 4.0.3 but weren't part of
 161  // update scripts until now.
 162  safe_alter('txp_css',  "MODIFY name  VARCHAR(255) NOT NULL");
 163  safe_alter('txp_lang', "MODIFY lang  VARCHAR(16)  NOT NULL");
 164  safe_alter('txp_lang', "MODIFY name  VARCHAR(64)  NOT NULL");
 165  safe_alter('txp_lang', "MODIFY event VARCHAR(64)  NOT NULL");
 166  safe_drop_index('txp_form', "name");
 167  safe_drop_index('txp_page', "name");
 168  safe_drop_index('txp_plugin', "name_2");
 169  safe_drop_index('txp_section', "name");
 170  
 171  // The txp_priv table was created for version 1.0, but never used nor created in
 172  // later versions.
 173  safe_drop('txp_priv');
 174  
 175  // Remove empty update files.
 176  if (is_writable(txpath.DS.'update')) {
 177      foreach (array('4.4.0', '4.4.1') as $v) {
 178          $file = txpath.DS.'update'.DS.'_to_'.$v.'.php';
 179  
 180          if (file_exists($file)) {
 181              unlink($file);
 182          }
 183      }
 184  }
 185  
 186  // Remove unnecessary licence files that have been moved to root.
 187  if (is_writable(txpath)) {
 188      foreach (array('license', 'lgpl-2.1') as $v) {
 189          $file = txpath.DS.$v.'.txt';
 190  
 191          if (file_exists($file)) {
 192              unlink($file);
 193          }
 194      }
 195  }
 196  
 197  // Add generic token table (dropping first, because of changes to the table setup).
 198  safe_drop('txp_token');
 199  safe_create('txp_token', "
 200      id           INT          NOT NULL AUTO_INCREMENT,
 201      reference_id INT          NOT NULL,
 202      type         VARCHAR(255) NOT NULL,
 203      selector     VARCHAR(12)  NOT NULL DEFAULT '',
 204      token        VARCHAR(255) NOT NULL,
 205      expires      DATETIME         NULL DEFAULT NULL,
 206  
 207      PRIMARY KEY (id),
 208      UNIQUE INDEX ref_type (reference_id, type(50))
 209  ");
 210  
 211  // Remove default zero dates to make MySQL 5.7 happy.
 212  safe_alter('textpattern',       "MODIFY Posted      DATETIME NOT NULL");
 213  safe_alter('textpattern',       "MODIFY Expires     DATETIME     NULL DEFAULT NULL");
 214  safe_alter('textpattern',       "MODIFY LastMod     DATETIME NOT NULL");
 215  safe_alter('textpattern',       "MODIFY feed_time   DATE     NOT NULL"); //0000-00-00
 216  safe_alter('txp_discuss',       "MODIFY posted      DATETIME NOT NULL");
 217  safe_alter('txp_discuss_nonce', "MODIFY issue_time  DATETIME NOT NULL");
 218  safe_alter('txp_file',          "MODIFY created     DATETIME NOT NULL");
 219  safe_alter('txp_file',          "MODIFY modified    DATETIME NOT NULL");
 220  safe_alter('txp_image',         "MODIFY date        DATETIME NOT NULL");
 221  safe_alter('txp_link',          "MODIFY date        DATETIME NOT NULL");
 222  safe_alter('txp_log',           "MODIFY time        DATETIME NOT NULL");
 223  safe_alter('txp_users',         "MODIFY last_access DATETIME     NULL DEFAULT NULL");
 224  // Remove logs and nonces with zero dates.
 225  safe_delete('txp_discuss_nonce', "DATE(issue_time) = '0000-00-00'");
 226  safe_delete('txp_log',           "DATE(time)       = '0000-00-00'");
 227  // Replace zero dates (which shouldn't exist, really) with somewhat sensible values.
 228  safe_update('textpattern', "Posted      = NOW()",   "DATE(Posted)      = '0000-00-00'");
 229  safe_update('textpattern', "Expires     = NULL",    "DATE(Expires)     = '0000-00-00'");
 230  safe_update('textpattern', "LastMod     = Posted",  "DATE(LastMod)     = '0000-00-00'");
 231  safe_update('txp_discuss', "posted      = NOW()",   "DATE(posted)      = '0000-00-00'");
 232  safe_update('txp_file',    "created     = NOW()",   "DATE(created)     = '0000-00-00'");
 233  safe_update('txp_file',    "modified    = created", "DATE(modified)    = '0000-00-00'");
 234  safe_update('txp_image',   "date        = NOW()",   "DATE(date)        = '0000-00-00'");
 235  safe_update('txp_link',    "date        = NOW()",   "DATE(date)        = '0000-00-00'");
 236  safe_update('txp_users',   "last_access = NULL",    "DATE(last_access) = '0000-00-00'");
 237  safe_update('textpattern', "feed_time   = DATE(Posted)", "feed_time    = '0000-00-00'");
 238  
 239  // Category names are max 64 characters when created/edited, so don't pretend
 240  // they can be longer.
 241  safe_alter('textpattern', "MODIFY Category1 VARCHAR(64) NOT NULL DEFAULT ''");
 242  safe_alter('textpattern', "MODIFY Category2 VARCHAR(64) NOT NULL DEFAULT ''");
 243  safe_alter('txp_file',    "MODIFY category  VARCHAR(64) NOT NULL DEFAULT ''");
 244  safe_alter('txp_image',   "MODIFY category  VARCHAR(64) NOT NULL DEFAULT ''");
 245  
 246  // Farewell Classic and Remora themes.
 247  $availableThemes = \Textpattern\Admin\Theme::names();
 248  
 249  if (!in_array(get_pref('theme_name'), $availableThemes)) {
 250      set_pref('theme_name', 'hive');
 251  }

title

Description

title

Description

title

Description

title

title

Body