Index: branches/REL1_17/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -1087,36 +1087,6 @@ |
1088 | 1088 | return true; |
1089 | 1089 | } |
1090 | 1090 | |
1091 | | - function setup_database() { |
1092 | | - $res = $this->sourceFile( "../maintenance/oracle/tables.sql" ); |
1093 | | - if ( $res === true ) { |
1094 | | - print " done.</li>\n"; |
1095 | | - } else { |
1096 | | - print " <b>FAILED</b></li>\n"; |
1097 | | - dieout( htmlspecialchars( $res ) ); |
1098 | | - } |
1099 | | - |
1100 | | - // Avoid the non-standard "REPLACE INTO" syntax |
1101 | | - echo "<li>Populating interwiki table</li>\n"; |
1102 | | - $f = fopen( "../maintenance/interwiki.sql", 'r' ); |
1103 | | - if ( !$f ) { |
1104 | | - dieout( "Could not find the interwiki.sql file" ); |
1105 | | - } |
1106 | | - |
1107 | | - // do it like the postgres :D |
1108 | | - $SQL = "INSERT INTO " . $this->tableName( 'interwiki' ) . " (iw_prefix,iw_url,iw_local) VALUES "; |
1109 | | - while ( !feof( $f ) ) { |
1110 | | - $line = fgets( $f, 1024 ); |
1111 | | - $matches = array(); |
1112 | | - if ( !preg_match( '/^\s*(\(.+?),(\d)\)/', $line, $matches ) ) { |
1113 | | - continue; |
1114 | | - } |
1115 | | - $this->query( "$SQL $matches[1],$matches[2])" ); |
1116 | | - } |
1117 | | - |
1118 | | - echo "<li>Table interwiki successfully populated</li>\n"; |
1119 | | - } |
1120 | | - |
1121 | 1091 | function selectDB( $db ) { |
1122 | 1092 | if ( $db == null || $db == $this->mUser ) { return true; } |
1123 | 1093 | $sql = 'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper($db); |
Index: branches/REL1_17/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -224,328 +224,6 @@ |
225 | 225 | return $s; |
226 | 226 | } |
227 | 227 | |
228 | | - |
229 | | - function initial_setup( $superuser, $password, $dbName ) { |
230 | | - // If this is the initial connection, setup the schema stuff and possibly create the user |
231 | | - global $wgDBname, $wgDBuser, $wgDBpassword, $wgDBmwschema, $wgDBts2schema; |
232 | | - |
233 | | - print '<li>Checking the version of Postgres...'; |
234 | | - $version = $this->getServerVersion(); |
235 | | - $PGMINVER = '8.1'; |
236 | | - if ( $version < $PGMINVER ) { |
237 | | - print "<b>FAILED</b>. Required version is $PGMINVER. You have " . htmlspecialchars( $version ) . "</li>\n"; |
238 | | - dieout( ); |
239 | | - } |
240 | | - print 'version ' . htmlspecialchars( $this->numeric_version ) . " is OK.</li>\n"; |
241 | | - |
242 | | - $safeuser = $this->addIdentifierQuotes( $wgDBuser ); |
243 | | - // Are we connecting as a superuser for the first time? |
244 | | - if ( $superuser ) { |
245 | | - // Are we really a superuser? Check out our rights |
246 | | - $SQL = "SELECT |
247 | | - CASE WHEN usesuper IS TRUE THEN |
248 | | - CASE WHEN usecreatedb IS TRUE THEN 3 ELSE 1 END |
249 | | - ELSE CASE WHEN usecreatedb IS TRUE THEN 2 ELSE 0 END |
250 | | - END AS rights |
251 | | - FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes( $superuser ); |
252 | | - $rows = $this->numRows( $res = $this->doQuery( $SQL ) ); |
253 | | - if ( !$rows ) { |
254 | | - print '<li>ERROR: Could not read permissions for user "' . htmlspecialchars( $superuser ) . "\"</li>\n"; |
255 | | - dieout( ); |
256 | | - } |
257 | | - $perms = pg_fetch_result( $res, 0, 0 ); |
258 | | - |
259 | | - $SQL = "SELECT 1 FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes( $wgDBuser ); |
260 | | - $rows = $this->numRows( $this->doQuery( $SQL ) ); |
261 | | - if ( $rows ) { |
262 | | - print '<li>User "' . htmlspecialchars( $wgDBuser ) . '" already exists, skipping account creation.</li>'; |
263 | | - } else { |
264 | | - if ( $perms != 1 && $perms != 3 ) { |
265 | | - print '<li>ERROR: the user "' . htmlspecialchars( $superuser ) . '" cannot create other users. '; |
266 | | - print 'Please use a different Postgres user.</li>'; |
267 | | - dieout( ); |
268 | | - } |
269 | | - print '<li>Creating user <b>' . htmlspecialchars( $wgDBuser ) . '</b>...'; |
270 | | - $safepass = $this->addQuotes( $wgDBpassword ); |
271 | | - $SQL = "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass"; |
272 | | - $this->doQuery( $SQL ); |
273 | | - print "OK</li>\n"; |
274 | | - } |
275 | | - // User now exists, check out the database |
276 | | - if ( $dbName != $wgDBname ) { |
277 | | - $SQL = "SELECT 1 FROM pg_catalog.pg_database WHERE datname = " . $this->addQuotes( $wgDBname ); |
278 | | - $rows = $this->numRows( $this->doQuery( $SQL ) ); |
279 | | - if ( $rows ) { |
280 | | - print '<li>Database "' . htmlspecialchars( $wgDBname ) . '" already exists, skipping database creation.</li>'; |
281 | | - } else { |
282 | | - if ( $perms < 1 ) { |
283 | | - print '<li>ERROR: the user "' . htmlspecialchars( $superuser ) . '" cannot create databases. '; |
284 | | - print 'Please use a different Postgres user.</li>'; |
285 | | - dieout( ); |
286 | | - } |
287 | | - print '<li>Creating database <b>' . htmlspecialchars( $wgDBname ) . '</b>...'; |
288 | | - $safename = $this->addIdentifierQuotes( $wgDBname ); |
289 | | - $SQL = "CREATE DATABASE $safename OWNER $safeuser "; |
290 | | - $this->doQuery( $SQL ); |
291 | | - print "OK</li>\n"; |
292 | | - // Hopefully tsearch2 and plpgsql are in template1... |
293 | | - } |
294 | | - |
295 | | - // Reconnect to check out tsearch2 rights for this user |
296 | | - print '<li>Connecting to "' . htmlspecialchars( $wgDBname ) . '" as superuser "' . |
297 | | - htmlspecialchars( $superuser ) . '" to check rights...'; |
298 | | - |
299 | | - $connectVars = array(); |
300 | | - if ( $this->mServer != false && $this->mServer != '' ) { |
301 | | - $connectVars['host'] = $this->mServer; |
302 | | - } |
303 | | - if ( $this->mPort != false && $this->mPort != '' ) { |
304 | | - $connectVars['port'] = $this->mPort; |
305 | | - } |
306 | | - $connectVars['dbname'] = $wgDBname; |
307 | | - $connectVars['user'] = $superuser; |
308 | | - $connectVars['password'] = $password; |
309 | | - |
310 | | - @$this->mConn = pg_connect( $this->makeConnectionString( $connectVars ) ); |
311 | | - if ( !$this->mConn ) { |
312 | | - print "<b>FAILED TO CONNECT!</b></li>"; |
313 | | - dieout( ); |
314 | | - } |
315 | | - print "OK</li>\n"; |
316 | | - } |
317 | | - |
318 | | - if ( $this->numeric_version < 8.3 ) { |
319 | | - // Tsearch2 checks |
320 | | - print '<li>Checking that tsearch2 is installed in the database "' . |
321 | | - htmlspecialchars( $wgDBname ) . '"...'; |
322 | | - if ( !$this->tableExists( 'pg_ts_cfg', $wgDBts2schema ) ) { |
323 | | - print '<b>FAILED</b>. tsearch2 must be installed in the database "' . |
324 | | - htmlspecialchars( $wgDBname ) . '".'; |
325 | | - print 'Please see <a href="http://www.devx.com/opensource/Article/21674/0/page/2">this article</a>'; |
326 | | - print " for instructions or ask on #postgresql on irc.freenode.net</li>\n"; |
327 | | - dieout( ); |
328 | | - } |
329 | | - print "OK</li>\n"; |
330 | | - print '<li>Ensuring that user "' . htmlspecialchars( $wgDBuser ) . |
331 | | - '" has select rights on the tsearch2 tables...'; |
332 | | - foreach ( array( 'cfg', 'cfgmap', 'dict', 'parser' ) as $table ) { |
333 | | - $SQL = "GRANT SELECT ON pg_ts_$table TO $safeuser"; |
334 | | - $this->doQuery( $SQL ); |
335 | | - } |
336 | | - print "OK</li>\n"; |
337 | | - } |
338 | | - |
339 | | - // Setup the schema for this user if needed |
340 | | - $result = $this->schemaExists( $wgDBmwschema ); |
341 | | - $safeschema = $this->addIdentifierQuotes( $wgDBmwschema ); |
342 | | - if ( !$result ) { |
343 | | - print '<li>Creating schema <b>' . htmlspecialchars( $wgDBmwschema ) . '</b> ...'; |
344 | | - $result = $this->doQuery( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" ); |
345 | | - if ( !$result ) { |
346 | | - print "<b>FAILED</b>.</li>\n"; |
347 | | - dieout( ); |
348 | | - } |
349 | | - print "OK</li>\n"; |
350 | | - } else { |
351 | | - print "<li>Schema already exists, explicitly granting rights...\n"; |
352 | | - $safeschema2 = $this->addQuotes( $wgDBmwschema ); |
353 | | - $SQL = "SELECT 'GRANT ALL ON '||pg_catalog.quote_ident(relname)||' TO $safeuser;'\n". |
354 | | - "FROM pg_catalog.pg_class p, pg_catalog.pg_namespace n\n". |
355 | | - "WHERE relnamespace = n.oid AND n.nspname = $safeschema2\n". |
356 | | - "AND p.relkind IN ('r','S','v')\n"; |
357 | | - $SQL .= "UNION\n"; |
358 | | - $SQL .= "SELECT 'GRANT ALL ON FUNCTION '||pg_catalog.quote_ident(proname)||'('||\n". |
359 | | - "pg_catalog.oidvectortypes(p.proargtypes)||') TO $safeuser;'\n". |
360 | | - "FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n\n". |
361 | | - "WHERE p.pronamespace = n.oid AND n.nspname = $safeschema2"; |
362 | | - $res = $this->doQuery( $SQL ); |
363 | | - if ( !$res ) { |
364 | | - print "<b>FAILED</b>. Could not set rights for the user.</li>\n"; |
365 | | - dieout( ); |
366 | | - } |
367 | | - $this->doQuery( "SET search_path = $safeschema" ); |
368 | | - $rows = $this->numRows( $res ); |
369 | | - while ( $rows ) { |
370 | | - $rows--; |
371 | | - $this->doQuery( pg_fetch_result( $res, $rows, 0 ) ); |
372 | | - } |
373 | | - print "OK</li>"; |
374 | | - } |
375 | | - |
376 | | - // Install plpgsql if needed |
377 | | - $this->setup_plpgsql(); |
378 | | - |
379 | | - return true; // Reconnect as regular user |
380 | | - |
381 | | - } // end superuser |
382 | | - |
383 | | - if ( !defined( 'POSTGRES_SEARCHPATH' ) ) { |
384 | | - |
385 | | - if ( $this->numeric_version < 8.3 ) { |
386 | | - // Do we have the basic tsearch2 table? |
387 | | - print '<li>Checking for tsearch2 in the schema "' . htmlspecialchars( $wgDBts2schema ) . '"...'; |
388 | | - if ( !$this->tableExists( 'pg_ts_dict', $wgDBts2schema ) ) { |
389 | | - print '<b>FAILED</b>. Make sure tsearch2 is installed. See <a href="'; |
390 | | - print 'http://www.devx.com/opensource/Article/21674/0/page/2">this article</a>'; |
391 | | - print " for instructions.</li>\n"; |
392 | | - dieout( ); |
393 | | - } |
394 | | - print "OK</li>\n"; |
395 | | - |
396 | | - // Does this user have the rights to the tsearch2 tables? |
397 | | - $ctype = pg_fetch_result( $this->doQuery( 'SHOW lc_ctype' ), 0, 0 ); |
398 | | - print '<li>Checking tsearch2 permissions...'; |
399 | | - // Let's check all four, just to be safe |
400 | | - error_reporting( 0 ); |
401 | | - $ts2tables = array( 'cfg', 'cfgmap', 'dict', 'parser' ); |
402 | | - $safetsschema = $this->addIdentifierQuotes( $wgDBts2schema ); |
403 | | - foreach ( $ts2tables as $tname ) { |
404 | | - $SQL = "SELECT count(*) FROM $safetsschema.pg_ts_$tname"; |
405 | | - $res = $this->doQuery( $SQL ); |
406 | | - if ( !$res ) { |
407 | | - print "<b>FAILED</b> to access " . htmlspecialchars( "pg_ts_$tname" ) . |
408 | | - ". Make sure that the user \"". htmlspecialchars( $wgDBuser ) . |
409 | | - "\" has SELECT access to all four tsearch2 tables</li>\n"; |
410 | | - dieout( ); |
411 | | - } |
412 | | - } |
413 | | - $SQL = "SELECT ts_name FROM $safetsschema.pg_ts_cfg WHERE locale = " . $this->addQuotes( $ctype ) ; |
414 | | - $SQL .= " ORDER BY CASE WHEN ts_name <> 'default' THEN 1 ELSE 0 END"; |
415 | | - $res = $this->doQuery( $SQL ); |
416 | | - error_reporting( E_ALL ); |
417 | | - if ( !$res ) { |
418 | | - print "<b>FAILED</b>. Could not determine the tsearch2 locale information</li>\n"; |
419 | | - dieout("</ul>"); |
420 | | - } |
421 | | - print 'OK</li>'; |
422 | | - |
423 | | - // Will the current locale work? Can we force it to? |
424 | | - print '<li>Verifying tsearch2 locale with ' . htmlspecialchars( $ctype ) . '...'; |
425 | | - $rows = $this->numRows( $res ); |
426 | | - $resetlocale = 0; |
427 | | - if ( !$rows ) { |
428 | | - print "<b>not found</b></li>\n"; |
429 | | - print '<li>Attempting to set default tsearch2 locale to "' . htmlspecialchars( $ctype ) . '"...'; |
430 | | - $resetlocale = 1; |
431 | | - } else { |
432 | | - $tsname = pg_fetch_result( $res, 0, 0 ); |
433 | | - if ( $tsname != 'default' ) { |
434 | | - print "<b>not set to default (" . htmlspecialchars( $tsname ) . ")</b>"; |
435 | | - print "<li>Attempting to change tsearch2 default locale to \"" . |
436 | | - htmlspecialchars( $ctype ) . "\"..."; |
437 | | - $resetlocale = 1; |
438 | | - } |
439 | | - } |
440 | | - if ( $resetlocale ) { |
441 | | - $SQL = "UPDATE $safetsschema.pg_ts_cfg SET locale = " . $this->addQuotes( $ctype ) . " WHERE ts_name = 'default'"; |
442 | | - $res = $this->doQuery( $SQL ); |
443 | | - if ( !$res ) { |
444 | | - print '<b>FAILED</b>. '; |
445 | | - print 'Please make sure that the locale in pg_ts_cfg for "default" is set to "' . |
446 | | - htmlspecialchars( $ctype ) . "\"</li>\n"; |
447 | | - dieout( ); |
448 | | - } |
449 | | - print 'OK</li>'; |
450 | | - } |
451 | | - |
452 | | - // Final test: try out a simple tsearch2 query |
453 | | - $SQL = "SELECT $safetsschema.to_tsvector('default','MediaWiki tsearch2 testing')"; |
454 | | - $res = $this->doQuery( $SQL ); |
455 | | - if ( !$res ) { |
456 | | - print '<b>FAILED</b>. Specifically, "' . htmlspecialchars( $SQL ) . '" did not work.</li>'; |
457 | | - dieout( ); |
458 | | - } |
459 | | - print 'OK</li>'; |
460 | | - } |
461 | | - |
462 | | - // Install plpgsql if needed |
463 | | - $this->setup_plpgsql(); |
464 | | - |
465 | | - // Does the schema already exist? Who owns it? |
466 | | - $result = $this->schemaExists( $wgDBmwschema ); |
467 | | - if ( !$result ) { |
468 | | - print '<li>Creating schema <b>' . htmlspecialchars( $wgDBmwschema ) . '</b> ...'; |
469 | | - error_reporting( 0 ); |
470 | | - $safeschema = $this->addIdentifierQuotes( $wgDBmwschema ); |
471 | | - $result = $this->doQuery( "CREATE SCHEMA $safeschema" ); |
472 | | - error_reporting( E_ALL ); |
473 | | - if ( !$result ) { |
474 | | - print '<b>FAILED</b>. The user "' . htmlspecialchars( $wgDBuser ) . |
475 | | - '" must be able to access the schema. '. |
476 | | - 'You can try making them the owner of the database, or try creating the schema with a '. |
477 | | - 'different user, and then grant access to the "' . |
478 | | - htmlspecialchars( $wgDBuser ) . "\" user.</li>\n"; |
479 | | - dieout( ); |
480 | | - } |
481 | | - print "OK</li>\n"; |
482 | | - } elseif ( $result != $wgDBuser ) { |
483 | | - print '<li>Schema "' . htmlspecialchars( $wgDBmwschema ) . '" exists but is not owned by "' . |
484 | | - htmlspecialchars( $wgDBuser ) . "\". Not ideal.</li>\n"; |
485 | | - } else { |
486 | | - print '<li>Schema "' . htmlspecialchars( $wgDBmwschema ) . '" exists and is owned by "' . |
487 | | - htmlspecialchars( $wgDBuser ) . "\". Excellent.</li>\n"; |
488 | | - } |
489 | | - |
490 | | - // Always return GMT time to accomodate the existing integer-based timestamp assumption |
491 | | - print "<li>Setting the timezone to GMT for user \"" . htmlspecialchars( $wgDBuser ) . '" ...'; |
492 | | - $SQL = "ALTER USER $safeuser SET timezone = 'GMT'"; |
493 | | - $result = pg_query( $this->mConn, $SQL ); |
494 | | - if ( !$result ) { |
495 | | - print "<b>FAILED</b>.</li>\n"; |
496 | | - dieout( ); |
497 | | - } |
498 | | - print "OK</li>\n"; |
499 | | - // Set for the rest of this session |
500 | | - $SQL = "SET timezone = 'GMT'"; |
501 | | - $result = pg_query( $this->mConn, $SQL ); |
502 | | - if ( !$result ) { |
503 | | - print "<li>Failed to set timezone</li>\n"; |
504 | | - dieout( ); |
505 | | - } |
506 | | - |
507 | | - print '<li>Setting the datestyle to ISO, YMD for user "' . htmlspecialchars( $wgDBuser ) . '" ...'; |
508 | | - $SQL = "ALTER USER $safeuser SET datestyle = 'ISO, YMD'"; |
509 | | - $result = pg_query( $this->mConn, $SQL ); |
510 | | - if ( !$result ) { |
511 | | - print "<b>FAILED</b>.</li>\n"; |
512 | | - dieout( ); |
513 | | - } |
514 | | - print "OK</li>\n"; |
515 | | - // Set for the rest of this session |
516 | | - $SQL = "SET datestyle = 'ISO, YMD'"; |
517 | | - $result = pg_query( $this->mConn, $SQL ); |
518 | | - if ( !$result ) { |
519 | | - print "<li>Failed to set datestyle</li>\n"; |
520 | | - dieout( ); |
521 | | - } |
522 | | - |
523 | | - // Fix up the search paths if needed |
524 | | - print '<li>Setting the search path for user "' . htmlspecialchars( $wgDBuser ) . '" ...'; |
525 | | - $path = $this->addIdentifierQuotes( $wgDBmwschema ); |
526 | | - if ( $wgDBts2schema !== $wgDBmwschema ) { |
527 | | - $path .= ', '. $this->addIdentifierQuotes( $wgDBts2schema ); |
528 | | - } |
529 | | - if ( $wgDBmwschema !== 'public' && $wgDBts2schema !== 'public' ) { |
530 | | - $path .= ', public'; |
531 | | - } |
532 | | - $SQL = "ALTER USER $safeuser SET search_path = $path"; |
533 | | - $result = pg_query( $this->mConn, $SQL ); |
534 | | - if ( !$result ) { |
535 | | - print "<b>FAILED</b>.</li>\n"; |
536 | | - dieout( ); |
537 | | - } |
538 | | - print "OK</li>\n"; |
539 | | - // Set for the rest of this session |
540 | | - $SQL = "SET search_path = $path"; |
541 | | - $result = pg_query( $this->mConn, $SQL ); |
542 | | - if ( !$result ) { |
543 | | - print "<li>Failed to set search_path</li>\n"; |
544 | | - dieout( ); |
545 | | - } |
546 | | - define( 'POSTGRES_SEARCHPATH', $path ); |
547 | | - } |
548 | | - } |
549 | | - |
550 | 228 | /** |
551 | 229 | * Closes a database connection, if it is open |
552 | 230 | * Returns success, true if already closed |