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