Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/update/_to_4.6.0.php - 297 lines - 13544 bytes - Text - Print

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * http://textpattern.com
   6   *
   7   * Copyright (C) 2016 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 <http://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  // 3) Consolidate existing prefs into better groups.
  43  safe_update('txp_prefs', "event = 'site'", "name IN ('sitename', 'siteurl', 'site_slogan', 'production_status', 'gmtoffset', 'auto_dst', 'is_dst', 'dateformat', 'archive_dateformat', 'permlink_mode', 'doctype', 'logging', 'use_comments', 'expire_logs_after')");
  44  
  45  // 4) Reorder existing prefs into a more logical progression.
  46  safe_update('txp_prefs', "position = '110'", "name = 'gmtoffset'");
  47  safe_update('txp_prefs', "position = '230'", "name = 'expire_logs_after'");
  48  safe_update('txp_prefs', "position = '340'", "name = 'max_url_len'");
  49  safe_update('txp_prefs', "position = '160'", "name = 'comments_sendmail'");
  50  safe_update('txp_prefs', "position = '180'", "name = 'comments_are_ol'");
  51  safe_update('txp_prefs', "position = '200'", "name = 'comment_means_site_updated'");
  52  safe_update('txp_prefs', "position = '220'", "name = 'comments_require_name'");
  53  safe_update('txp_prefs', "position = '240'", "name = 'comments_require_email'");
  54  safe_update('txp_prefs', "position = '260'", "name = 'never_display_email'");
  55  safe_update('txp_prefs', "position = '280'", "name = 'comment_nofollow'");
  56  safe_update('txp_prefs', "position = '300'", "name = 'comments_disallow_images'");
  57  safe_update('txp_prefs', "position = '320'", "name = 'comments_use_fat_textile'");
  58  safe_update('txp_prefs', "position = '340'", "name = 'spam_blacklists'");
  59  safe_update('txp_prefs', "name = 'permlink_format', html = 'permlink_format'", "name = 'permalink_title_format'");
  60  
  61  // Support for l10n string owners.
  62  $cols = getThings("DESCRIBE `".PFX."txp_lang`");
  63  
  64  if (!in_array('owner', $cols)) {
  65      safe_alter('txp_lang', "ADD owner VARCHAR(64) NOT NULL DEFAULT '' AFTER event");
  66      safe_create_index('txp_lang', 'owner', 'owner');
  67  }
  68  
  69  // Keep all comment-related forms together. The loss of 'preview' ability on the
  70  // comments_display Form is of little consequence compared with the benefit of
  71  // tucking them away neatly when not required.
  72  safe_update('txp_form', "type = 'comment'", "name = 'comments_display'");
  73  
  74  // Add protocol to logged HTTP referrers.
  75  safe_update(
  76      'txp_log',
  77      "refer = CONCAT('http://', refer)",
  78      "refer != '' AND refer NOT LIKE 'http://%' AND refer NOT LIKE 'https://%'"
  79  );
  80  
  81  // Usernames can be 64 characters long at most.
  82  safe_alter('txp_file',  "MODIFY author VARCHAR(64) NOT NULL DEFAULT ''");
  83  safe_alter('txp_link',  "MODIFY author VARCHAR(64) NOT NULL DEFAULT ''");
  84  safe_alter('txp_image', "MODIFY author VARCHAR(64) NOT NULL DEFAULT ''");
  85  
  86  // Consistent name length limitations for presentation items.
  87  safe_alter('txp_form',    "MODIFY name VARCHAR(255) NOT NULL DEFAULT ''");
  88  safe_alter('txp_page',    "MODIFY name VARCHAR(255) NOT NULL DEFAULT ''");
  89  safe_alter('txp_section', "MODIFY page VARCHAR(255) NOT NULL DEFAULT ''");
  90  safe_alter('txp_section', "MODIFY css  VARCHAR(255) NOT NULL DEFAULT ''");
  91  
  92  // Save sections correctly in articles.
  93  safe_alter('textpattern', "MODIFY Section VARCHAR(255) NOT NULL DEFAULT ''");
  94  safe_alter('txp_section', "MODIFY name    VARCHAR(255) NOT NULL DEFAULT ''");
  95  
  96  // Plugins can have longer version numbers.
  97  safe_alter('txp_plugin', "MODIFY version VARCHAR(255) NOT NULL DEFAULT '1.0'");
  98  
  99  // Translation strings should allow more than 255 characters.
 100  safe_alter('txp_lang', "MODIFY data TEXT");
 101  
 102  // Add meta description to articles.
 103  $cols = getThings("DESCRIBE `".PFX."textpattern`");
 104  
 105  if (!in_array('description', $cols)) {
 106      safe_alter('textpattern', "ADD description VARCHAR(255) NOT NULL DEFAULT '' AFTER Keywords");
 107  }
 108  
 109  // Add meta description to categories.
 110  $cols = getThings("DESCRIBE `".PFX."txp_category`");
 111  
 112  if (!in_array('description', $cols)) {
 113      safe_alter('txp_category', "ADD description VARCHAR(255) NOT NULL DEFAULT '' AFTER title");
 114  }
 115  
 116  // Add meta description to sections.
 117  $cols = getThings("DESCRIBE `".PFX."txp_section`");
 118  
 119  if (!in_array('description', $cols)) {
 120      safe_alter('txp_section', "ADD description VARCHAR(255) NOT NULL DEFAULT '' AFTER css");
 121  }
 122  
 123  // Remove textpattern.com ping and lastmod_keepalive prefs.
 124  safe_delete('txp_prefs', "name = 'ping_textpattern_com'");
 125  safe_delete('txp_prefs', "name = 'lastmod_keepalive'");
 126  
 127  // Add default publishing status pref.
 128  if (!get_pref('default_publish_status')) {
 129      set_pref('default_publish_status', STATUS_LIVE, 'publish', PREF_CORE, 'defaultPublishStatus', 15, PREF_PRIVATE);
 130  }
 131  
 132  // Add prefs to allow query caching when now() is used.
 133  if (!get_pref('sql_now_posted')) {
 134      set_pref('sql_now_posted', time(), 'publish', PREF_HIDDEN);
 135      set_pref('sql_now_expires', time(), 'publish', PREF_HIDDEN);
 136      set_pref('sql_now_created', time(), 'publish', PREF_HIDDEN);
 137  }
 138  
 139  // Remove broken import functionality.
 140  if (is_writable(txpath.DS.'include') && file_exists(txpath.DS.'include'.DS.'txp_import.php')) {
 141      $import_files = array(
 142          'BloggerImportTemplate.txt',
 143          'import_blogger.php',
 144          'import_mt.php',
 145          'import_b2.php',
 146          'import_mtdb.php',
 147          'import_wp.php'
 148      );
 149  
 150      if (is_writable(txpath.DS.'include'.DS.'import')) {
 151          foreach ($import_files as $file) {
 152              if (file_exists(txpath.DS.'include'.DS.'import'.DS.$file)) {
 153                  unlink(txpath.DS.'include'.DS.'import'.DS.$file);
 154              }
 155          }
 156          rmdir(txpath.DS.'include'.DS.'import');
 157      }
 158  
 159      unlink(txpath.DS.'include'.DS.'txp_import.php');
 160  }
 161  
 162  // Remove unused ipban table or recreate its index (for future utf8mb4 conversion).
 163  if (getThing("SHOW TABLES LIKE '".PFX."txp_discuss_ipban'")) {
 164      if (!safe_count('txp_discuss_ipban', "1 = 1")) {
 165          safe_drop('txp_discuss_ipban');
 166      } else {
 167          safe_drop_index('txp_discuss_ipban', "PRIMARY");
 168          safe_alter('txp_discuss_ipban', "ADD PRIMARY KEY (ip(250))");
 169      }
 170  }
 171  
 172  // Recreate indexes with smaller key sizes to allow future conversion to charset utf8mb4.
 173  safe_drop_index('txp_css',     "name");
 174  safe_drop_index('txp_file',    "filename");
 175  safe_drop_index('txp_form',    "PRIMARY");
 176  safe_drop_index('txp_page',    "PRIMARY");
 177  safe_drop_index('txp_section', "PRIMARY");
 178  safe_drop_index('txp_prefs',   "prefs_idx");
 179  safe_drop_index('txp_prefs',   "name");
 180  safe_drop_index('textpattern', "section_status_idx");
 181  safe_drop_index('textpattern', "url_title_idx");
 182  // Not using safe_create_index here, because we just dropped the index.
 183  safe_alter('txp_css',     "ADD UNIQUE name (name(250))");
 184  safe_alter('txp_file',    "ADD UNIQUE filename (filename(250))");
 185  safe_alter('txp_form',    "ADD PRIMARY KEY (name(250))");
 186  safe_alter('txp_page',    "ADD PRIMARY KEY (name(250))");
 187  safe_alter('txp_section', "ADD PRIMARY KEY (name(250))");
 188  safe_alter('txp_prefs',   "ADD UNIQUE prefs_idx (prefs_id, name(185), user_name)");
 189  safe_alter('txp_prefs',   "ADD INDEX name (name(250))");
 190  safe_alter('textpattern', "ADD INDEX section_status_idx (Section(249), Status)");
 191  safe_alter('textpattern', "ADD INDEX url_title_idx (url_title(250))");
 192  // Specifically, txp_discuss_nonce didn't have a primary key in 4.0.3
 193  // so it has to be done in two separate steps.
 194  safe_drop_index('txp_discuss_nonce', "PRIMARY");
 195  safe_alter('txp_discuss_nonce', "ADD PRIMARY KEY (nonce(250))");
 196  
 197  // Fix typo: textinput should be text_input.
 198  safe_update('txp_prefs', "html = 'text_input'", "name = 'timezone_key'");
 199  
 200  // Fix typo: position 40 should be 0 (because it's a hidden pref).
 201  safe_update('txp_prefs', "position = 0", "name = 'language'");
 202  
 203  // Fix typo: position should be 60 instead of 30 (so it appears just below the site name).
 204  safe_update('txp_prefs', "position = 60", "name = 'site_slogan'");
 205  
 206  // Enforce some table changes that happened after 4.0.3 but weren't part of
 207  // update scripts until now.
 208  safe_alter('txp_css',  "MODIFY name  VARCHAR(255) NOT NULL");
 209  safe_alter('txp_lang', "MODIFY lang  VARCHAR(16)  NOT NULL");
 210  safe_alter('txp_lang', "MODIFY name  VARCHAR(64)  NOT NULL");
 211  safe_alter('txp_lang', "MODIFY event VARCHAR(64)  NOT NULL");
 212  safe_drop_index('txp_form', "name");
 213  safe_drop_index('txp_page', "name");
 214  safe_drop_index('txp_plugin', "name_2");
 215  safe_drop_index('txp_section', "name");
 216  
 217  // The txp_priv table was created for version 1.0, but never used nor created in
 218  // later versions.
 219  safe_drop('txp_priv');
 220  
 221  // Remove empty update files.
 222  if (is_writable(txpath.DS.'update')) {
 223      foreach (array('4.4.0', '4.4.1') as $v) {
 224          $file = txpath.DS.'update'.DS.'_to_'.$v.'.php';
 225  
 226          if (file_exists($file)) {
 227              unlink($file);
 228          }
 229      }
 230  }
 231  
 232  // Remove unnecessary licence files that have been moved to root.
 233  if (is_writable(txpath)) {
 234      foreach (array('license', 'lgpl-2.1') as $v) {
 235          $file = txpath.DS.$v.'.txt';
 236  
 237          if (file_exists($file)) {
 238              unlink($file);
 239          }
 240      }
 241  }
 242  
 243  // Add generic token table (dropping first, because of changes to the table setup).
 244  safe_drop('txp_token');
 245  safe_create('txp_token', "
 246      id           INT          NOT NULL AUTO_INCREMENT,
 247      reference_id INT          NOT NULL,
 248      type         VARCHAR(255) NOT NULL,
 249      selector     VARCHAR(12)  NOT NULL DEFAULT '',
 250      token        VARCHAR(255) NOT NULL,
 251      expires      DATETIME         NULL DEFAULT NULL,
 252  
 253      PRIMARY KEY (id),
 254      UNIQUE INDEX ref_type (reference_id, type(50))
 255  ");
 256  
 257  // Remove default zero dates to make MySQL 5.7 happy.
 258  safe_alter('textpattern',       "MODIFY Posted      DATETIME NOT NULL");
 259  safe_alter('textpattern',       "MODIFY Expires     DATETIME     NULL DEFAULT NULL");
 260  safe_alter('textpattern',       "MODIFY LastMod     DATETIME NOT NULL");
 261  safe_alter('textpattern',       "MODIFY feed_time   DATE     NOT NULL"); //0000-00-00
 262  safe_alter('txp_discuss',       "MODIFY posted      DATETIME NOT NULL");
 263  safe_alter('txp_discuss_nonce', "MODIFY issue_time  DATETIME NOT NULL");
 264  safe_alter('txp_file',          "MODIFY created     DATETIME NOT NULL");
 265  safe_alter('txp_file',          "MODIFY modified    DATETIME NOT NULL");
 266  safe_alter('txp_image',         "MODIFY date        DATETIME NOT NULL");
 267  safe_alter('txp_link',          "MODIFY date        DATETIME NOT NULL");
 268  safe_alter('txp_log',           "MODIFY time        DATETIME NOT NULL");
 269  safe_alter('txp_users',         "MODIFY last_access DATETIME     NULL DEFAULT NULL");
 270  // Remove logs and nonces with zero dates.
 271  safe_delete('txp_discuss_nonce', "DATE(issue_time) = '0000-00-00'");
 272  safe_delete('txp_log',           "DATE(time)       = '0000-00-00'");
 273  // Replace zero dates (which shouldn't exist, really) with somewhat sensible values.
 274  safe_update('textpattern', "Posted      = NOW()",   "DATE(Posted)      = '0000-00-00'");
 275  safe_update('textpattern', "Expires     = NULL",    "DATE(Expires)     = '0000-00-00'");
 276  safe_update('textpattern', "LastMod     = Posted",  "DATE(LastMod)     = '0000-00-00'");
 277  safe_update('txp_discuss', "posted      = NOW()",   "DATE(posted)      = '0000-00-00'");
 278  safe_update('txp_file',    "created     = NOW()",   "DATE(created)     = '0000-00-00'");
 279  safe_update('txp_file',    "modified    = created", "DATE(modified)    = '0000-00-00'");
 280  safe_update('txp_image',   "date        = NOW()",   "DATE(date)        = '0000-00-00'");
 281  safe_update('txp_link',    "date        = NOW()",   "DATE(date)        = '0000-00-00'");
 282  safe_update('txp_users',   "last_access = NULL",    "DATE(last_access) = '0000-00-00'");
 283  safe_update('textpattern', "feed_time   = DATE(Posted)", "feed_time    = '0000-00-00'");
 284  
 285  // Category names are max 64 characters when created/edited, so don't pretend
 286  // they can be longer.
 287  safe_alter('textpattern', "MODIFY Category1 VARCHAR(64) NOT NULL DEFAULT ''");
 288  safe_alter('textpattern', "MODIFY Category2 VARCHAR(64) NOT NULL DEFAULT ''");
 289  safe_alter('txp_file',    "MODIFY category  VARCHAR(64) NOT NULL DEFAULT ''");
 290  safe_alter('txp_image',   "MODIFY category  VARCHAR(64) NOT NULL DEFAULT ''");
 291  
 292  // Farewell Classic and Remora themes.
 293  $availableThemes = \Textpattern\Admin\Theme::names();
 294  
 295  if (!in_array(get_pref('theme_name'), $availableThemes)) {
 296      set_pref('theme_name', 'hive');
 297  }

title

Description

title

Description

title

Description

title

title

Body