Commit graph

76 commits

Author SHA1 Message Date
Alexandre Emsenhuber
09bb6975c5 Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: I1615bf268515ed7169e33173cea6ec30402451dc
2012-05-06 07:50:15 +02:00
saper
f752cf8042 Fix PostgreSQL updater to produce 1.19 schema
* PostgresField now reports column default value
* DatabasePostgres::indexAttributes reports index
  details
* Perform schema update in one transaction

With this change we can sucessfully update
MediaWiki 1.7.3 schema to trunk^Wmaster

Patch set 2: Rebased against master. PLEASE check carefully
to make sure I got those conflicted files right.

Conflicts:

	includes/db/DatabasePostgres.php
	includes/installer/PostgresUpdater.php

Change-Id: Iebb6855e8f6f44470bbb1dc5ab9ac1abb513adfe
2012-04-10 12:59:21 -04:00
Marcin Cieślak
cfb8e9a251 Handle PostgreSQL transaction errors and improve schema detection
* Introduce $wgDebugDBTransactions facility to help
  figure out what's going on with transactions.
  Currently PostgreSQL only.

  PostgresTransactionState can be easily be made more general 
  to trace all sorts of state machinery.

* Improve r113408: we don't need to full reconnect on error,
  rollback is enough. 
  
  Rolling back breaks search_path, as PostgreSQL
  can manage sessions settings under transaction therefore
  we need to improve schema sniffing introduced in r82674

* Introduce few schema handling functions. This could
  probably be generalized for other databases like DB2 and Oracle.

* Fix bug 15816 - Add a switch for SETting the search_path

  We try to avoid touching search_path at all unless
  really necessary. Even in this case we append MediaWiki
  core schema to the front of the list.

* No longer add $wgDBmwschema to PostgreSQL role search_path
  in the installer. This is no longer necessary as 
  setting schema on connect should ReallyWorkNow(tm).

* Get rid as much as possible of $wgDBmwschema and
  bring us one step closer to fix bug 16794 (wgSharedDB
  support). 
  
  All references to core MediaWiki schema in PostgreSQL
  specific code should now use Database::getCoreSchema() 
  unless we know what we are doing. 

Followup-To: r113408 r82674
2012-03-09 17:24:57 +00:00
Sam Reed
c47f83a4d4 More __METHOD__ in our madness 2012-02-24 18:45:24 +00:00
Sam Reed
2ec09c5165 More return documentation 2012-02-09 21:35:05 +00:00
Sam Reed
85bbb0b080 Fixing some of the "@return true" or "@return false", need to be "@return bool" and then the metadata can say true if foo, false if bar
Other documentation improvements
2012-02-09 18:01:10 +00:00
OverlordQ
9191b2f8e6 Bug 28172 - wfGetDB called when it shouldn't be 2011-11-03 21:00:14 +00:00
Sam Reed
9d41b95053 Kill various unused variables
Comment some out also

Add some bits of documentation
2011-10-29 01:17:26 +00:00
Sam Reed
856faea6d6 Add documentation
Fix some unused variables, commented some others out
2011-10-18 17:26:09 +00:00
Mark A. Hershberger
a67094c6c1 Remove hardcoded commit statements for pg installer. 2011-10-11 21:54:10 +00:00
Mark A. Hershberger
d8db86a4a6 Fix cli install so that db user is created if needed. 2011-10-11 21:24:00 +00:00
Sam Reed
6bc9679307 Update calls to deprecated User::isValidEmailAddr
Fix trailing whitespace

Some minor documentation fixes
2011-06-26 19:16:04 +00:00
Tim Starling
88e8af820c Fix for r72150: rename getSchema() to getSchemaPath(). This terminology creates an unfortunate and potentially confusing conflict with the PostgreSQL usage of the term. At some point in the future I'd like to have a getSchema() that gives you the PostgreSQL schema name ($wgDBmwschema). Strictly speaking, tables.sql is not a schema, it's an SQL file that creates a schema. 2011-06-20 07:16:09 +00:00
Tim Starling
7a6c42e9bc Fix for r89821, r89839: we can skip certain tests if the web user is the same as the install user. 2011-06-10 22:33:16 +00:00
Mark A. Hershberger
1866fa1381 Make Pg installer work in the “common” case: follow up r89821 so that $exists can be set true if same user is the same for install and web. 2011-06-10 18:48:16 +00:00
Tim Starling
b37cde66c1 PostgreSQL install fixes:
* Made PG throw a DBQueryError when it gets a query error, instead of DBUnexpectedError. Apparently this mistake goes back to r14625, when exceptions were first introduced. Did it by removing reportQueryError(), the DatabaseBase version works fine.
* Fixed several places where there was an attempt to check for a query error by checking if the result of query() was false. This never worked. Used try/catch instead.
* Made the DBConnectionError messages go on one line so that they don't mess up the formatting in the installer.
* In DatabasePostgres::selectDB(), only disconnect and reconnect if the DB name is actually changing.
* Made DatabasePostgres::schemaExists() less weird and scary.
* Added DatabasePostgres::roleExists() for use by the installer.
* Removed the PostgreSQL-specific hack to make _InstallUser have a default other than "root". Made _InstallUser into a proper DBMS-specific internal variable instead, since every DBMS we support so far needs a different default.
* Removed the $dbName parameters from openConnection/getConnection, and got rid of $this->useAdmin. Implemented a more sophisticated caching scheme instead. Partial revert of r89389 and r81440.
* When connecting as the install user before DB creation, and when testing the web user's credentials, try a few different database names and use whichever one works. 
* Instead of connecting as the web user to create tables, I used SET ROLE. It seems cleaner and more like what the other DBMSes do during installation. "SET ROLE wikiuser" requires the same privileges as "CREATE SCHEMA ... AUTHORIZATION wikiuser", so it's unlikely to break anything.
* In the area of web account creation, fixed various minor logic errors and introduced more informative error messages at the submit stage, pre-install. Show a helpful error message if the web user exists already and the install user can't do the relevant SET ROLE.
* Split schema creation out to a separate install step.
* When creating an account as a non-superuser, add the administrative account to the new account's group. This is necessary to avoid a fatal error during installation (bug 28845).
* Removed code which alters an existing web user to have appropriate search paths and permissions. This may break other apps and is not necessary. As in other DBMSes, If the web user exists, it is the responsibility of the sysadmin to ensure that it has appropriate permissions.
* Rewrote setupPLpgSQL() to use the query builder functions.
2011-06-10 11:32:57 +00:00
Mark A. Hershberger
9be60e5725 forward port r88929 2011-06-03 03:41:11 +00:00
Mark A. Hershberger
44f9460caf w/s cleanup 2011-05-20 18:20:16 +00:00
Greg Sabino Mullane
d7f7a69d6a When switching from admin to non-admin account, make sure to set $this->db to null, otherwise MW will happily return the old handle, which means we end up in the old admin database, and thus create our 'mediawiki' schema in the postgres or template1 database (whoops!). There may be other similar cases in the code in which we are not clearing this->db before toggling the useAdmin attribute. Fixes bug 28171. 2011-03-21 22:09:49 +00:00
Greg Sabino Mullane
e19a2ac3e1 template1 is a poor choice: use the standard 'postgres' database instead.
Especially as the installer currently is modifying this database! (a separate bug...)
2011-03-21 21:59:04 +00:00
Greg Sabino Mullane
cfb993f5b9 $safedb needs to be set *outside* the if/else block, not just inside the if
Fixes bug 28170
2011-03-21 21:36:21 +00:00
Greg Sabino Mullane
b694d74c80 Change the default user from 'root' to 'postgres' if using a PostgreSQL backend.
There may be a better way to do this, so comments welcome.
2011-03-21 14:59:14 +00:00
Greg Sabino Mullane
ed8e58314e Don't need an Oracle flag here... 2011-03-21 03:01:36 +00:00
Chad Horohoe
62679f963e Various Postgres fixes (bug 26612 stuff)
* Remove last of $wgDBuser-specific settings like timezone, datestyle and search_path. This is all handled by open() :D
* Only set search_path if the schema exists (rather than just set to some random string), fall back to 'public' otherwise
* Only call setupUser() if we need to _CreateDBAccount, otherwise it returns immediately and confuses you (no functional change)
* Implement selectDB() for Postgres, basically call open() with a new DB name
* Try to fix setupDatabase() for this "user must be owner of relation" error I'm getting when the $wgDBuser exists (have tried with roles granted && no roles granted). I get no errors at all when
2011-02-23 16:01:22 +00:00
Chad Horohoe
3b23b4291b Fix backwards canCreateAccounts() check, remove setting search_path for $wgDBuser, since this is set per-session on open() 2011-02-23 14:26:45 +00:00
Sam Reed
64be8c7b26 Ununsed variables
Documentation and explicit definitions
2011-02-23 12:35:41 +00:00
Sam Reed
2c6e16e5e5 Remove unused variables 2011-02-18 01:10:38 +00:00
Mark A. Hershberger
4625f338ca Make schema selection really work for PostgreSQL installation 2011-02-06 03:06:45 +00:00
Chad Horohoe
78101f2bdd More uppercase trues 2011-02-04 21:00:17 +00:00
Chad Horohoe
198574cb45 lowercase a few more t/f 2011-02-04 20:54:43 +00:00
Chad Horohoe
39e7d019d8 Rm selectDB from Postgres, doesn't do anything 2011-02-04 20:52:55 +00:00
Mark A. Hershberger
ee3e5163c4 re r81495 — you know, I've completely forgotten why I wanted to return a status object. Fix that and not the busted status message. 2011-02-04 00:21:59 +00:00
Mark A. Hershberger
5e1e89c63f * make canCreateAccounts() return Status Objects instead of boolean
* re-use openConnection to test the ability of the user to connect.
2011-02-04 00:15:44 +00:00
Sam Reed
0c3f623d71 Fixup spaces to tabs 2011-02-03 20:47:54 +00:00
Chad Horohoe
6e35fc91a1 2011-02-03 20:40:20 +00:00
OverlordQ
113639eb02 Follow-up to r81439, works up to installing the admin user then dies with:
Creating administrator user account...

Mediawiki tried to access the database via wfGetDB(). This is not allowed.

Backtrace:

#0 /var/www/testsite.com/w/includes/GlobalFunctions.php(3020): LBFactory_Fake->getMainLB(false)
#1 /var/www/testsite.com/w/includes/GlobalFunctions.php(3010): wfGetLB(false)
#2 /var/www/testsite.com/w/includes/User.php(2558): wfGetDB(-1)
#3 /var/www/testsite.com/w/includes/installer/Installer.php(1383): User->idForName()
#4 [internal function]: Installer->createSysop(Object(PostgresInstaller))
#5 /var/www/testsite.com/w/includes/installer/Installer.php(1293): call_user_func(Array, Object(PostgresInstaller))
#6 /var/www/testsite.com/w/includes/installer/WebInstallerPage.php(1022): Installer->performInstallation(Array, Array)
#7 /var/www/testsite.com/w/includes/installer/WebInstaller.php(243): WebInstaller_Install->execute()
#8 /var/www/testsite.com/w/config/index.php(46): WebInstaller->execute(Array)
#9 /var/www/testsite.com/w/config/index.php(14): wfInstallerMain()
#10 {main}
2011-02-03 05:17:18 +00:00
Mark A. Hershberger
1eb2307caa Results of my work on new-installer and Pg.
* NOTE: this commit removes any semblence of tsearch compatibility with pre-8.3 PostgreSQL
* Make new-installer work against PostgreSQL
* Remove SearchPostgres.php's call to pg_fetch_result.  I think this is the only one outside of the vestigtial old installer code.
2011-02-03 04:06:11 +00:00
Chad Horohoe
69d2ee1095 Followup r81132, missed some more ts2 removal 2011-01-28 15:25:15 +00:00
Chad Horohoe
bf3e2be8d5 Per comment on bug 26612, we should drop the pre-Postgres 8.3 support with the TSearch2 schema.
This removes a bunch of back-compat code in the installer and search code.
Minimum postgres version is now 8.3
2011-01-28 14:12:26 +00:00
Tim Starling
e1c8e80297 * Fixed Oracle new installer support, broken by r80957. This is a minimal patch and doesn't address the architectural issues.
** Moved the responsibility for calling setupSchemaVars() on install to the DatabaseInstaller subclass. This allows it to be called after setupDatabase() has completed, as required by Oracle and PostgreSQL.
** Fixed OracleInstaller::getConnection() so that it respects $this->useSysDBA correctly.
** In OracleInstaller, added some more variables to the list of schema vars, which are needed by user.sql and tables.sql
** In SearchOracle, specify the database name when calling ctx_ddl.sync_index(). This fixes a fatal error in the createMainpage step, caused by the schema name not being equal to the current user. 

* In oracle/tables.sql, fixed a couple of indexes with missing table prefixes.
* Improved debugging output in DatabaseInstaller::getConnection() and Installer::createMainpage().
* In DatabaseBase::selectDB(), set $this->mDBname correctly, as in DatabaseMysql.
2011-01-27 08:25:48 +00:00
Tim Starling
0c86b1611a * Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database.
* Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade.
* Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. 
* Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used.
* Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes.
* Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database.
* In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary.
* On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added.
* Fixed several instances of inappropriate call-by-reference. 
* Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler.	
* Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892.
* In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). 
* Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging.
* MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
Chad Horohoe
a5053d4c5a * Cleanup massive duplication across Database constructors. Default implementation fairly sane. Now they all share the same if( $server ) logic to allow constructing the class without forcing open a connection (MySQL has done this since at least r15094)
* Get rid of intermediate installTables() callback
* Actually cache the result of DbInstaller::getConnection() like the documentation says
2011-01-24 18:36:09 +00:00
Sam Reed
6111daf9ef Spaces to tabs 2011-01-12 23:01:47 +00:00
Chad Horohoe
19bde21182 Fix undefined variable from r79828 2011-01-12 21:28:59 +00:00
Chad Horohoe
49ee8fede4 Fix a few doQuery() -> query() 2011-01-11 16:02:56 +00:00
Chad Horohoe
587c077aad Fix callbacks for the final time so it actually works per documentation.
Other minor postgres fixes
2011-01-11 15:02:59 +00:00
Chad Horohoe
b8e4029eab Fix copy+paste mistake from r79989 2011-01-11 14:00:47 +00:00
Chad Horohoe
958ed916db Fix callback issue noted in r79989 (broken in r78774).
$this makes a difference.
I'm an idiot.
2011-01-11 13:54:05 +00:00
OverlordQ
e17d76f631 I have no clue how the callbacks work, this at least sets up a database, everything after that is fubar 2011-01-11 03:07:45 +00:00
Chad Horohoe
a36ff08975 More postgres
* Add user creation form like MySQL
* Fix canCreateAccounts() check
* Fix ts2 setup callback
* Still needs schema creation and other misc. stuff from lines ~370-530 of DatabasePostgres
2011-01-10 19:18:28 +00:00