Index: trunk/phase3/maintenance/postgres/tables.sql |
— | — | @@ -9,6 +9,21 @@ |
10 | 10 | BEGIN; |
11 | 11 | SET client_min_messages = 'ERROR'; |
12 | 12 | |
| 13 | +DROP SEQUENCE IF EXISTS user_user_id_seq; |
| 14 | +DROP SEQUENCE IF EXISTS page_page_id_seq; |
| 15 | +DROP SEQUENCE IF EXISTS revision_rev_id_seq; |
| 16 | +DROP SEQUENCE IF EXISTS page_restrictions_id_seq; |
| 17 | +DROP SEQUENCE IF EXISTS ipblocks_ipb_id_seq; |
| 18 | +DROP SEQUENCE IF EXISTS recentchanges_rc_id_seq; |
| 19 | +DROP SEQUENCE IF EXISTS logging_log_id_seq; |
| 20 | +DROP SEQUENCE IF EXISTS trackbacks_tb_id_seq; |
| 21 | +DROP SEQUENCE IF EXISTS job_job_id_seq; |
| 22 | +DROP SEQUENCE IF EXISTS category_cat_id_seq; |
| 23 | +DROP FUNCTION IF EXISTS page_deleted(); |
| 24 | +DROP FUNCTION IF EXISTS ts2_page_title(); |
| 25 | +DROP FUNCTION IF EXISTS ts2_page_text(); |
| 26 | +DROP FUNCTION IF EXISTS add_interwiki(TEXT,INT,SMALLINT); |
| 27 | + |
13 | 28 | CREATE SEQUENCE user_user_id_seq MINVALUE 0 START WITH 0; |
14 | 29 | CREATE TABLE mwuser ( -- replace reserved word 'user' |
15 | 30 | user_id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('user_user_id_seq'), |
— | — | @@ -495,7 +510,7 @@ |
496 | 511 | CREATE INDEX job_cmd_namespace_title ON job (job_cmd, job_namespace, job_title); |
497 | 512 | |
498 | 513 | -- Tsearch2 2 stuff. Will fail if we don't have proper access to the tsearch2 tables |
| 514 | +-- Version 8.3 or higher only. Previous versions would need another parmeter for to_tsvector. |
499 | 515 | -- Make sure you also change patch-tsearch2funcs.sql if the funcs below change. |
500 | 516 | |
501 | 517 | ALTER TABLE page ADD titlevector tsvector; |
— | — | @@ -503,9 +518,9 @@ |
504 | 519 | $mw$ |
505 | 520 | BEGIN |
506 | 521 | IF TG_OP = 'INSERT' THEN |
507 | | - NEW.titlevector = to_tsvector('default',REPLACE(NEW.page_title,'/',' ')); |
| 522 | + NEW.titlevector = to_tsvector(REPLACE(NEW.page_title,'/',' ')); |
508 | 523 | ELSIF NEW.page_title != OLD.page_title THEN |
509 | | - NEW.titlevector := to_tsvector('default',REPLACE(NEW.page_title,'/',' ')); |
| 524 | + NEW.titlevector := to_tsvector(REPLACE(NEW.page_title,'/',' ')); |
510 | 525 | END IF; |
511 | 526 | RETURN NEW; |
512 | 527 | END; |
— | — | @@ -520,9 +535,9 @@ |
521 | 536 | $mw$ |
522 | 537 | BEGIN |
523 | 538 | IF TG_OP = 'INSERT' THEN |
524 | | - NEW.textvector = to_tsvector('default',NEW.old_text); |
| 539 | + NEW.textvector = to_tsvector(NEW.old_text); |
525 | 540 | ELSIF NEW.old_text != OLD.old_text THEN |
526 | | - NEW.textvector := to_tsvector('default',NEW.old_text); |
| 541 | + NEW.textvector := to_tsvector(NEW.old_text); |
527 | 542 | END IF; |
528 | 543 | RETURN NEW; |
529 | 544 | END; |
Index: trunk/phase3/includes/search/SearchPostgres.php |
— | — | @@ -151,7 +151,8 @@ |
152 | 152 | ## TODO: Better output (example to catch: one 'two) |
153 | 153 | die ("Sorry, that was not a valid search string. Please go back and try again"); |
154 | 154 | } |
155 | | - $top = pg_fetch_result($res,0,0); |
| 155 | + $top = $res->fetchRow(); |
| 156 | + $top = $top[0]; |
156 | 157 | |
157 | 158 | if ($top === "") { ## e.g. if only stopwords are used XXX return something better |
158 | 159 | $query = "SELECT page_id, page_namespace, page_title, 0 AS score ". |
Index: trunk/phase3/includes/installer/PostgresInstaller.php |
— | — | @@ -70,7 +70,7 @@ |
71 | 71 | } |
72 | 72 | |
73 | 73 | // Try to connect |
74 | | - $status->merge( $this->getConnection() ); |
| 74 | + $status->merge( $this->getConnection( 'template1' ) ); |
75 | 75 | if ( !$status->isOK() ) { |
76 | 76 | return $status; |
77 | 77 | } |
— | — | @@ -107,8 +107,32 @@ |
108 | 108 | return $status; |
109 | 109 | } |
110 | 110 | |
| 111 | + function getConnection($database = null) { |
| 112 | + $status = Status::newGood(); |
| 113 | + |
| 114 | + if( is_null( $database ) ) { |
| 115 | + $dbname = $this->getVar( 'wgDBname' ); |
| 116 | + $dbuser = $this->getVar( 'wgDBuser' ); |
| 117 | + $dbpass = $this->getVar( 'wgDBpassword' ); |
| 118 | + } else { |
| 119 | + $dbname = $database; |
| 120 | + $dbuser = $this->getVar( '_InstallUser' ); |
| 121 | + $dbpass = $this->getVar( '_InstallPassword' ); |
| 122 | + } |
| 123 | + |
| 124 | + try { |
| 125 | + $this->db = new DatabasePostgres( |
| 126 | + $this->getVar( 'wgDBserver' ), |
| 127 | + $dbuser, $dbpass, $dbname ); |
| 128 | + $status->value = $this->db; |
| 129 | + } catch ( DBConnectionError $e ) { |
| 130 | + $status->fatal( 'config-connection-error', $e->getMessage() ); |
| 131 | + } |
| 132 | + return $status; |
| 133 | + } |
| 134 | + |
111 | 135 | protected function canCreateAccounts() { |
112 | | - $status = $this->getConnection(); |
| 136 | + $status = $this->getConnection( 'template1' ); |
113 | 137 | if ( !$status->isOK() ) { |
114 | 138 | return false; |
115 | 139 | } |
— | — | @@ -200,7 +224,7 @@ |
201 | 225 | } |
202 | 226 | |
203 | 227 | function setupDatabase() { |
204 | | - $status = $this->getConnection(); |
| 228 | + $status = $this->getConnection( 'template1' ); |
205 | 229 | if ( !$status->isOK() ) { |
206 | 230 | return $status; |
207 | 231 | } |
— | — | @@ -265,7 +289,7 @@ |
266 | 290 | return Status::newGood(); |
267 | 291 | } |
268 | 292 | |
269 | | - $status = $this->getConnection(); |
| 293 | + $status = $this->getConnection( 'template1' ); |
270 | 294 | if ( !$status->isOK() ) { |
271 | 295 | return $status; |
272 | 296 | } |
— | — | @@ -273,13 +297,19 @@ |
274 | 298 | $db = $this->getVar( 'wgDBname' ); |
275 | 299 | $this->db->selectDB( $db ); |
276 | 300 | $safeuser = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) ); |
| 301 | + $safeusercheck = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) ); |
277 | 302 | $safepass = $this->db->addQuotes( $this->getVar( 'wgDBpassword' ) ); |
| 303 | + |
| 304 | + $rows = $this->db->numRows( |
| 305 | + $this->db->query( "SELECT 1 FROM pg_catalog.pg_shadow WHERE usename = $safeusercheck" ) |
| 306 | + ); |
| 307 | + if ( $rows < 1 ) { |
278 | 308 | $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ ); |
279 | | - return $status; |
280 | 309 | |
281 | | - if ( $res !== true ) { |
282 | | - $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ) ); |
| 310 | + if ( $res !== true && !( $res instanceOf ResultWrapper ) ) { |
| 311 | + $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $res ); |
283 | 312 | } |
| 313 | + } |
284 | 314 | |
285 | 315 | return $status; |
286 | 316 | } |