Install fixes for group table
[lhc/web/wiklou.git] / maintenance / updaters.inc
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 */
6
7 /** */
8
9 require_once 'convertLinks.inc';
10 require_once 'InitialiseMessages.inc';
11 require_once 'archives/moveCustomMessages.inc';
12
13 $wgNewTables = array(
14 # table patch file (in maintenance/archives)
15 array( 'linkscc', 'patch-linkscc.sql' ),
16 array( 'hitcounter', 'patch-hitcounter.sql' ),
17 array( 'querycache', 'patch-querycache.sql' ),
18 array( 'objectcache', 'patch-objectcache.sql' ),
19 array( 'categorylinks', 'patch-categorylinks.sql' ),
20 array( 'logging', 'patch-logging.sql' ),
21 array( 'user_rights', 'patch-user_rights.sql' ),
22 array( 'user_groups', 'patch-userlevels.sql' ),
23 );
24
25 $wgNewFields = array(
26 # table field patch file (in maintenance/archives)
27 array( 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ),
28 array( 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ),
29 array( 'recentchanges', 'rc_type', 'patch-rc_type.sql' ),
30 array( 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ),
31 array( 'recentchanges', 'rc_id', 'patch-rc_id.sql' ),
32 array( 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
33 array( 'user', 'user_real_name', 'patch-user-realname.sql' ),
34 array( 'user', 'user_token', 'patch-user_token.sql' ),
35 array( 'user_rights', 'ur_user', 'patch-rename-user_groups-and_rights.sql' ),
36 );
37
38 function add_table( $name, $patch ) {
39 global $wgDatabase;
40 if ( $wgDatabase->tableExists( $name ) ) {
41 echo "...$name table already exists.\n";
42 } else {
43 echo "Creating $name table...";
44 dbsource( "maintenance/archives/$patch", $wgDatabase );
45 echo "ok\n";
46 }
47 }
48
49 function add_field( $table, $field, $patch ) {
50 global $wgDatabase;
51 if ( $wgDatabase->fieldExists( $table, $field ) ) {
52 echo "...have $field field in $table table.\n";
53 } else {
54 echo "Adding $field field to table $table...";
55 dbsource( "maintenance/archives/$patch" , $wgDatabase );
56 echo "ok\n";
57 }
58 }
59
60 function do_revision_updates() {
61 global $wgSoftwareRevision;
62 if ( $wgSoftwareRevision < 1001 ) {
63 update_passwords();
64 }
65 }
66
67 function update_passwords() {
68 global $wgDatabase;
69 $fname = "Update script: update_passwords()";
70 print "\nIt appears that you need to update the user passwords in your\n" .
71 "database. If you have already done this (if you've run this update\n" .
72 "script once before, for example), doing so again will make all your\n" .
73 "user accounts inaccessible, so be sure you only do this once.\n" .
74 "Update user passwords? (yes/no)";
75
76 $resp = readconsole();
77 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
78
79 $sql = "SELECT user_id,user_password FROM user";
80 $source = $wgDatabase->query( $sql, $fname );
81
82 while ( $row = $wgDatabase->fetchObject( $source ) ) {
83 $id = $row->user_id;
84 $oldpass = $row->user_password;
85 $newpass = md5( "{$id}-{$oldpass}" );
86
87 $sql = "UPDATE user SET user_password='{$newpass}' " .
88 "WHERE user_id={$id}";
89 $wgDatabase->query( $sql, $fname );
90 }
91 }
92
93 function do_interwiki_update() {
94 # Check that interwiki table exists; if it doesn't source it
95 global $wgDatabase;
96 if( $wgDatabase->tableExists( "interwiki" ) ) {
97 echo "...already have interwiki table\n";
98 return true;
99 }
100 echo "Creating interwiki table: ";
101 dbsource( "maintenance/archives/patch-interwiki.sql" );
102 echo "ok\n";
103 echo "Adding default interwiki definitions: ";
104 dbsource( "maintenance/interwiki.sql" );
105 echo "ok\n";
106 }
107
108 function do_index_update() {
109 # Check that proper indexes are in place
110 global $wgDatabase;
111 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
112 if( $meta->multiple_key == 0 ) {
113 echo "Updating indexes to 20031107: ";
114 dbsource( "maintenance/archives/patch-indexes.sql" );
115 echo "ok\n";
116 return true;
117 }
118 echo "...indexes seem up to 20031107 standards\n";
119 return false;
120 }
121
122 function do_linkscc_1_3_update() {
123 // Update linkscc table to 1.3 schema if necessary
124 global $wgDatabase, $wgVersion;
125 if( ( strpos( "1.3", $wgVersion ) === 0 ) && $wgDatabase->tableExists( "linkscc" )
126 && $wgDatabase->fieldExists( "linkscc", "lcc_title" ) ) {
127 echo "Altering lcc_title field from linkscc table... ";
128 dbsource( "maintenance/archives/patch-linkscc-1.3.sql", $wgDatabase );
129 echo "ok\n";
130 } else {
131 echo "...linkscc is up to date, or does not exist. Good.\n";
132 }
133 }
134
135 function do_image_name_unique_update() {
136 global $wgDatabase;
137 if( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
138 echo "...image primary key already set.\n";
139 } else {
140 echo "Making img_name the primary key... ";
141 dbsource( "maintenance/archives/patch-image_name_primary.sql", $wgDatabase );
142 echo "ok\n";
143 }
144 }
145
146 # Assumes that the group table has been added.
147 function do_group_update() {
148 global $wgDatabase;
149 $res = $wgDatabase->safeQuery( 'SELECT COUNT(*) AS c FROM !',
150 $wgDatabase->tableName( 'group' ) );
151 $row = $wgDatabase->fetchObject( $res );
152 $wgDatabase->freeResult( $res );
153 if( $row->c == 0 ) {
154 echo "Adding default group definitions... ";
155 dbsource( "maintenance/archives/patch-userlevels-defaultgroups.sql", $wgDatabase );
156 echo "ok\n";
157 } else {
158 echo "...group definitions already in place.\n";
159 }
160 }
161
162 function do_all_updates() {
163 global $wgNewTables, $wgNewFields;
164
165 # Add missing tables
166 foreach ( $wgNewTables as $tableRecord ) {
167 add_table( $tableRecord[0], $tableRecord[1] );
168 flush();
169 }
170
171 # Add missing fields
172 foreach ( $wgNewFields as $fieldRecord ) {
173 add_table( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2] );
174 flush();
175 }
176
177 # Add default group data
178 do_group_update(); flush();
179
180 # Do schema updates which require special handling
181 do_interwiki_update(); flush();
182 do_index_update(); flush();
183 do_linkscc_1_3_update(); flush();
184 convertLinks(); flush();
185 do_image_name_unique_update(); flush();
186
187 if ( isTemplateInitialised() ) {
188 print "Template namespace already initialised\n";
189 } else {
190 moveCustomMessages( 1 ); flush();
191 moveCustomMessages( 2 ); flush();
192 moveCustomMessages( 3 ); flush();
193 }
194
195 initialiseMessages(); flush();
196 }
197
198 ?>