2010-09-03 18:53:19 +00:00
< ? php
/**
* Oracle - specific updater .
*
2012-05-06 05:50:15 +00:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
* http :// www . gnu . org / copyleft / gpl . html
*
2010-09-03 18:53:19 +00:00
* @ file
* @ ingroup Deployment
*/
/**
* Class for handling updates to Oracle databases .
2010-12-19 04:31:15 +00:00
*
2010-09-03 18:53:19 +00:00
* @ ingroup Deployment
* @ since 1.17
*/
class OracleUpdater extends DatabaseUpdater {
2011-05-29 14:01:47 +00:00
/**
* Handle to the database subclass
*
* @ var DatabaseOracle
*/
protected $db ;
2010-09-03 18:53:19 +00:00
protected function getCoreUpdateList () {
2010-10-25 11:07:55 +00:00
return array (
2011-06-01 08:27:51 +00:00
// 1.17
2010-10-25 11:07:55 +00:00
array ( 'doNamespaceDefaults' ),
2010-10-27 14:52:18 +00:00
array ( 'doFKRenameDeferr' ),
array ( 'doFunctions17' ),
array ( 'doSchemaUpgrade17' ),
2011-04-26 07:17:33 +00:00
array ( 'doInsertPage0' ),
2011-06-22 14:10:55 +00:00
array ( 'doRemoveNotNullEmptyDefaults' ),
2011-09-01 13:55:14 +00:00
array ( 'addTable' , 'user_former_groups' , 'patch-user_former_groups.sql' ),
2011-07-18 23:01:08 +00:00
2011-06-01 08:27:51 +00:00
//1.18
array ( 'addIndex' , 'user' , 'i02' , 'patch-user_email_index.sql' ),
array ( 'modifyField' , 'user_properties' , 'up_property' , 'patch-up_property.sql' ),
2011-09-01 13:55:14 +00:00
array ( 'addTable' , 'uploadstash' , 'patch-uploadstash.sql' ),
2011-12-20 16:11:45 +00:00
array ( 'doRecentchangesFK2Cascade' ),
2011-06-02 22:23:05 +00:00
2011-09-01 13:55:14 +00:00
//1.19
array ( 'addIndex' , 'logging' , 'i05' , 'patch-logging_type_action_index.sql' ),
array ( 'addTable' , 'globaltemplatelinks' , 'patch-globaltemplatelinks.sql' ),
array ( 'addTable' , 'globalnamespaces' , 'patch-globalnamespaces.sql' ),
array ( 'addTable' , 'globalinterwiki' , 'patch-globalinterwiki.sql' ),
2011-11-04 07:17:13 +00:00
array ( 'addField' , 'revision' , 'rev_sha1' , 'patch-rev_sha1_field.sql' ),
array ( 'addField' , 'archive' , 'ar_sha1' , 'patch-ar_sha1_field.sql' ),
2011-11-04 11:35:10 +00:00
array ( 'doRemoveNotNullEmptyDefaults2' ),
2011-11-11 14:28:44 +00:00
array ( 'addIndex' , 'page' , 'i03' , 'patch-page_redirect_namespace_len.sql' ),
2011-11-19 17:21:55 +00:00
array ( 'modifyField' , 'user' , 'ug_group' , 'patch-ug_group-length-increase.sql' ),
2012-01-24 09:48:26 +00:00
array ( 'addField' , 'uploadstash' , 'us_chunk_inx' , 'patch-us_chunk_inx_field.sql' ),
array ( 'addField' , 'job' , 'job_timestamp' , 'patch-job_timestamp_field.sql' ),
array ( 'addIndex' , 'job' , 'i02' , 'patch-job_timestamp_index.sql' ),
2011-11-01 05:23:08 +00:00
2012-02-10 00:05:36 +00:00
//1.20
array ( 'addTable' , 'config' , 'patch-config.sql' ),
2011-12-20 16:11:45 +00:00
// KEEP THIS AT THE BOTTOM!!
2011-06-02 22:23:05 +00:00
array ( 'doRebuildDuplicateFunction' ),
2011-07-18 23:01:08 +00:00
2010-10-25 11:07:55 +00:00
);
2010-09-03 18:53:19 +00:00
}
2010-10-25 11:07:55 +00:00
/**
* MySQL uses datatype defaults for NULL inserted into NOT NULL fields
* In namespace case that results into insert of 0 which is default namespace
* Oracle inserts NULL , so namespace fields should have a default value
*/
protected function doNamespaceDefaults () {
2010-10-27 14:52:18 +00:00
$this -> output ( " Altering namespace fields with default value ... " );
2010-10-25 11:07:55 +00:00
$meta = $this -> db -> fieldInfo ( 'page' , 'page_namespace' );
if ( $meta -> defaultValue () != null ) {
2010-10-27 14:52:18 +00:00
$this -> output ( " defaults seem to present on namespace fields \n " );
2010-10-25 11:07:55 +00:00
return ;
}
$this -> applyPatch ( 'patch_namespace_defaults.sql' , false );
$this -> output ( " ok \n " );
}
2010-10-27 14:52:18 +00:00
/**
* Uniform FK names + deferrable state
*/
protected function doFKRenameDeferr () {
$this -> output ( " Altering foreign keys ... " );
$meta = $this -> db -> query ( 'SELECT COUNT(*) cnt FROM user_constraints WHERE constraint_type = \'R\' AND deferrable = \'DEFERRABLE\'' );
$row = $meta -> fetchRow ();
if ( $row && $row [ 'cnt' ] > 0 ) {
$this -> output ( " at least one FK is deferrable, considering up to date \n " );
return ;
}
$this -> applyPatch ( 'patch_fk_rename_deferred.sql' , false );
$this -> output ( " ok \n " );
}
/**
* Recreate functions to 17 schema layout
*/
protected function doFunctions17 () {
$this -> output ( " Recreating functions ... " );
$this -> applyPatch ( 'patch_create_17_functions.sql' , false );
$this -> output ( " ok \n " );
}
/**
* Schema upgrade 16 -> 17
* there are no incremental patches prior to this
*/
protected function doSchemaUpgrade17 () {
$this -> output ( " Updating schema to 17 ... " );
// check if iwlinks table exists which was added in 1.17
2011-06-22 14:10:55 +00:00
if ( $this -> db -> tableExists ( 'iwlinks' ) ) {
2010-10-27 14:52:18 +00:00
$this -> output ( " schema seem to be up to date. \n " );
return ;
}
$this -> applyPatch ( 'patch_16_17_schema_changes.sql' , false );
$this -> output ( " ok \n " );
}
2011-04-26 07:17:33 +00:00
/**
* Insert page ( page_id = 0 ) to prevent FK constraint violation
*/
protected function doInsertPage0 () {
2011-04-22 14:23:10 +00:00
$this -> output ( " Inserting page 0 if missing ... " );
$row = array (
'page_id' => 0 ,
'page_namespace' => 0 ,
2011-05-20 18:20:16 +00:00
'page_title' => ' ' ,
2011-04-22 14:23:10 +00:00
'page_counter' => 0 ,
'page_is_redirect' => 0 ,
'page_is_new' => 0 ,
'page_random' => 0 ,
'page_touched' => $this -> db -> timestamp (),
'page_latest' => 0 ,
'page_len' => 0
);
$this -> db -> insert ( 'page' , $row , 'OracleUpdater:doInserPage0' , array ( 'IGNORE' ) );
$this -> output ( " ok \n " );
}
2011-06-22 14:10:55 +00:00
/**
* Remove DEFAULT '' NOT NULL constraints from fields as '' is internally
* converted to NULL in Oracle
*/
protected function doRemoveNotNullEmptyDefaults () {
$this -> output ( " Removing not null empty constraints ... " );
$meta = $this -> db -> fieldInfo ( 'categorylinks' , 'cl_sortkey_prefix' );
if ( $meta -> isNullable () ) {
$this -> output ( " constraints seem to be removed \n " );
return ;
}
$this -> applyPatch ( 'patch_remove_not_null_empty_defs.sql' , false );
$this -> output ( " ok \n " );
}
2011-11-04 11:35:10 +00:00
protected function doRemoveNotNullEmptyDefaults2 () {
$this -> output ( " Removing not null empty constraints ... " );
$meta = $this -> db -> fieldInfo ( 'ipblocks' , 'ipb_by_text' );
if ( $meta -> isNullable () ) {
$this -> output ( " constraints seem to be removed \n " );
return ;
}
$this -> applyPatch ( 'patch_remove_not_null_empty_defs2.sql' , false );
$this -> output ( " ok \n " );
}
2011-06-02 22:23:05 +00:00
2011-12-20 16:11:45 +00:00
/**
* Removed forcing of invalid state on recentchanges_fk2 .
* cascading taken in account in the deleting function
*/
protected function doRecentchangesFK2Cascade () {
$this -> output ( " Altering RECENTCHANGES_FK2 ... " );
$meta = $this -> db -> query ( 'SELECT 1 FROM all_constraints WHERE owner = \'' . strtoupper ( $this -> db -> getDBname ()) . '\' AND constraint_name = \'' . $this -> db -> tablePrefix () . 'RECENTCHANGES_FK2\' AND delete_rule = \'CASCADE\'' );
$row = $meta -> fetchRow ();
if ( $row ) {
$this -> output ( " FK up to date \n " );
return ;
}
$this -> applyPatch ( 'patch_recentchanges_fk2_cascade.sql' , false );
$this -> output ( " ok \n " );
}
2011-06-02 22:23:05 +00:00
/**
* rebuilding of the function that duplicates tables for tests
*/
protected function doRebuildDuplicateFunction () {
$this -> output ( " Rebuilding duplicate function ... " );
$this -> applyPatch ( 'patch_rebuild_dupfunc.sql' , false );
$this -> output ( " ok \n " );
}
2010-10-25 11:07:55 +00:00
/**
* Overload : after this action field info table has to be rebuilt
2011-05-28 18:59:42 +00:00
*
* @ param $what array
2010-10-25 11:07:55 +00:00
*/
2011-09-03 10:23:47 +00:00
public function doUpdates ( $what = array ( 'core' , 'extensions' , 'purge' , 'stats' ) ) {
2011-03-30 17:32:20 +00:00
parent :: doUpdates ( $what );
2010-12-19 04:31:15 +00:00
2010-12-15 20:59:29 +00:00
$this -> db -> query ( 'BEGIN fill_wiki_info; END;' );
2010-10-25 11:07:55 +00:00
}
2011-12-20 16:11:45 +00:00
/**
* Overload : because of the DDL_MODE tablename escaping is a bit dodgy
*/
protected function purgeCache () {
# We can't guarantee that the user will be able to use TRUNCATE,
# but we know that DELETE is available to us
$this -> output ( " Purging caches... " );
$this -> db -> delete ( '/*Q*/' . $this -> db -> tableName ( 'objectcache' ), '*' , __METHOD__ );
$this -> output ( " done. \n " );
}
2010-09-03 18:53:19 +00:00
}