Textpattern | PHP Cross Reference | Content Management Systems |
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 global $thisversion, $dbversion, $txp_using_svn, $dbupdatetime; 29 30 $dbupdates = array( 31 '1.0.0', 32 '4.0.2', '4.0.3', '4.0.4', '4.0.5', '4.0.6', '4.0.7', '4.0.8', 33 '4.2.0', 34 '4.3.0', 35 '4.5.0', '4.5.7', 36 '4.6.0' 37 ); 38 39 function newest_file() 40 { 41 $newest = 0; 42 $dp = opendir(txpath.'/update/'); 43 44 while (false !== ($file = readdir($dp))) { 45 if (strpos($file, "_") === 0) { 46 $newest = max($newest, filemtime(txpath."/update/$file")); 47 } 48 } 49 50 closedir($dp); 51 52 return $newest; 53 } 54 55 if (($dbversion == '') || 56 (strpos($dbversion, 'g1') === 0) || 57 (strpos($dbversion, '1.0rc') === 0)) { 58 $dbversion = '0.9.9'; 59 } 60 61 $dbversion_target = $thisversion; 62 63 if ($dbversion == $dbversion_target || 64 ($txp_using_svn && (newest_file() <= $dbupdatetime))) { 65 return; 66 } 67 68 assert_system_requirements(); 69 70 @ignore_user_abort(1); 71 @set_time_limit(0); 72 73 // Wipe out the last update check setting so the next visit to Diagnostics 74 // forces an update check, which resets the message. Without this, people who 75 // upgrade in future may still see a "new version available" message for some 76 // time after upgrading. 77 safe_delete('txp_prefs', "name = 'last_update_check'"); 78 79 set_error_handler("updateErrorHandler"); 80 81 $updates = array_fill_keys($dbupdates, true); 82 83 if (!isset($updates[$dbversion_target])) { 84 $updates[$dbversion_target] = false; 85 } 86 87 try { 88 foreach ($updates as $dbupdate => $update) { 89 if (version_compare($dbversion, $dbupdate, '<')) { 90 if ($update && (include txpath.DS.'update'.DS.'_to_'.$dbupdate.'.php') === false) { 91 trigger_error('Something bad happened. Not sure what exactly', E_USER_ERROR); 92 } 93 94 if (!($txp_using_svn && $dbversion_target == $dbupdate)) { 95 $dbversion = $dbupdate; 96 } 97 } 98 } 99 100 // Keep track of updates for SVN users. 101 safe_delete('txp_prefs', "name = 'dbupdatetime'"); 102 safe_insert('txp_prefs', "prefs_id = 1, name = 'dbupdatetime', val = '".max(newest_file(), time())."', type = '2'"); 103 } catch (Exception $e) { 104 // Nothing to do here, the goal was just to abort the update scripts 105 // Error message already communicated via updateErrorHandler 106 } 107 108 restore_error_handler(); 109 110 // Update version. 111 safe_delete('txp_prefs', "name = 'version'"); 112 safe_insert('txp_prefs', "prefs_id = 1, name = 'version', val = '$dbversion', type = '2'"); 113 114 // Invite optional third parties to the update experience 115 // Convention: Put custom code into file(s) at textpattern/update/custom/post-update-abc-foo.php 116 // where 'abc' is the third party's reserved prefix (@see http://docs.textpattern.io/development/plugin-developer-prefixes) 117 // and 'foo' is whatever. The execution order among all files is undefined. 118 $files = glob(txpath.'/update/custom/post-update*.php'); 119 120 if (is_array($files)) { 121 foreach ($files as $f) { 122 include $f; 123 } 124 } 125 126 // Updated, baby. So let's get the fresh prefs and send them to languages. 127 define('TXP_UPDATE_DONE', 1); 128 $event = 'lang'; 129 $step = 'list_languages'; 130 131 $prefs = get_prefs(); 132 133 extract($prefs);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title