4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008-2011 StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
23 $shortoptions = 'x::';
24 $longoptions = array('extensions=');
26 $helptext = <<<END_OF_UPGRADE_HELP
27 php upgrade.php [options]
28 Upgrade database schema and data to latest software
32 require_once INSTALLDIR.'/scripts/commandline.inc';
37 updateSchemaPlugins();
39 // These replace old "fixup_*" scripts
41 fixupNoticeRendered();
42 fixupNoticeConversation();
49 require INSTALLDIR.'/db/core.php';
53 function updateSchemaCore()
55 printfnq("Upgrading core schema...");
57 $schema = Schema::get();
58 $schemaUpdater = new SchemaUpdater($schema);
59 foreach (tableDefs() as $table => $def) {
60 $schemaUpdater->register($table, $def);
62 $schemaUpdater->checkSchema();
67 function updateSchemaPlugins()
69 printfnq("Upgrading plugin schema...");
71 Event::handle('CheckSchema');
76 function fixupNoticeRendered()
78 printfnq("Ensuring all notices have rendered HTML...");
80 $notice = new Notice();
82 $notice->whereAdd('rendered IS NULL');
85 while ($notice->fetch()) {
86 $original = clone($notice);
87 $notice->rendered = common_render_content($notice->content, $notice);
88 $notice->update($original);
94 function fixupNoticeConversation()
96 printfnq("Ensuring all notices have a conversation ID...");
98 $notice = new Notice();
99 $notice->whereAdd('conversation is null');
100 $notice->orderBy('id'); // try to get originals before replies
103 while ($notice->fetch()) {
107 $orig = clone($notice);
109 if (empty($notice->reply_to)) {
110 $notice->conversation = $notice->id;
112 $reply = Notice::staticGet('id', $notice->reply_to);
115 $notice->conversation = $notice->id;
116 } else if (empty($reply->conversation)) {
117 $notice->conversation = $notice->id;
119 $notice->conversation = $reply->conversation;
126 $result = $notice->update($orig);
130 } catch (Exception $e) {
131 printv("Error setting conversation: " . $e->getMessage());
138 function fixupGroupURI()
140 printfnq("Ensuring all groups have an URI...");
142 $group = new User_group();
143 $group->whereAdd('uri IS NULL');
145 if ($group->find()) {
146 while ($group->fetch()) {
147 $orig = User_group::staticGet('id', $group->id);
148 $group->uri = $group->getUri();
149 $group->update($orig);