MediaWiki  REL1_22
OracleUpdater.php
Go to the documentation of this file.
00001 <?php
00030 class OracleUpdater extends DatabaseUpdater {
00031 
00037     protected $db;
00038 
00039     protected function getCoreUpdateList() {
00040         return array(
00041             // 1.17
00042             array( 'doNamespaceDefaults' ),
00043             array( 'doFKRenameDeferr' ),
00044             array( 'doFunctions17' ),
00045             array( 'doSchemaUpgrade17' ),
00046             array( 'doInsertPage0' ),
00047             array( 'doRemoveNotNullEmptyDefaults' ),
00048             array( 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ),
00049 
00050             //1.18
00051             array( 'addIndex', 'user', 'i02', 'patch-user_email_index.sql' ),
00052             array( 'modifyField', 'user_properties', 'up_property', 'patch-up_property.sql' ),
00053             array( 'addTable', 'uploadstash', 'patch-uploadstash.sql' ),
00054             array( 'doRecentchangesFK2Cascade' ),
00055 
00056             //1.19
00057             array( 'addIndex', 'logging', 'i05', 'patch-logging_type_action_index.sql' ),
00058             array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1_field.sql' ),
00059             array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1_field.sql' ),
00060             array( 'doRemoveNotNullEmptyDefaults2' ),
00061             array( 'addIndex', 'page', 'i03', 'patch-page_redirect_namespace_len.sql' ),
00062             array( 'addField', 'uploadstash', 'us_chunk_inx', 'patch-us_chunk_inx_field.sql' ),
00063             array( 'addField', 'job', 'job_timestamp', 'patch-job_timestamp_field.sql' ),
00064             array( 'addIndex', 'job', 'i02', 'patch-job_timestamp_index.sql' ),
00065             array( 'doPageRestrictionsPKUKFix' ),
00066 
00067             //1.20
00068             array( 'addIndex', 'ipblocks', 'i05', 'patch-ipblocks_i05_index.sql' ),
00069             array( 'addIndex', 'revision', 'i05', 'patch-revision_i05_index.sql' ),
00070             array( 'dropField', 'category', 'cat_hidden', 'patch-cat_hidden.sql' ),
00071 
00072             //1.21
00073             array( 'addField', 'revision', 'rev_content_format',
00074                 'patch-revision-rev_content_format.sql' ),
00075             array( 'addField', 'revision', 'rev_content_model',
00076                 'patch-revision-rev_content_model.sql' ),
00077             array( 'addField', 'archive', 'ar_content_format', 'patch-archive-ar_content_format.sql' ),
00078             array( 'addField', 'archive', 'ar_content_model', 'patch-archive-ar_content_model.sql' ),
00079             array( 'addField', 'archive', 'ar_id', 'patch-archive-ar_id.sql' ),
00080             array( 'addField', 'externallinks', 'el_id', 'patch-externallinks-el_id.sql' ),
00081             array( 'addField', 'page', 'page_content_model', 'patch-page-page_content_model.sql' ),
00082             array( 'dropField', 'site_stats', 'ss_admins', 'patch-ss_admins.sql' ),
00083             array( 'dropField', 'recentchanges', 'rc_moved_to_title', 'patch-rc_moved.sql' ),
00084             array( 'addTable', 'sites', 'patch-sites.sql' ),
00085             array( 'addField', 'filearchive', 'fa_sha1', 'patch-fa_sha1.sql' ),
00086             array( 'addField', 'job', 'job_token', 'patch-job_token.sql' ),
00087             array( 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ),
00088             array( 'addField', 'uploadstash', 'us_props', 'patch-uploadstash-us_props.sql' ),
00089             array( 'modifyField', 'user_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ),
00090             array( 'modifyField', 'user_former_groups', 'ufg_group',
00091                 'patch-ufg_group-length-increase-255.sql' ),
00092 
00093             // KEEP THIS AT THE BOTTOM!!
00094             array( 'doRebuildDuplicateFunction' ),
00095 
00096         );
00097     }
00098 
00104     protected function doNamespaceDefaults() {
00105         $meta = $this->db->fieldInfo( 'page', 'page_namespace' );
00106         if ( $meta->defaultValue() != null ) {
00107             return;
00108         }
00109 
00110         $this->applyPatch(
00111             'patch_namespace_defaults.sql',
00112             false,
00113             'Altering namespace fields with default value'
00114         );
00115     }
00116 
00120     protected function doFKRenameDeferr() {
00121         $meta = $this->db->query( '
00122             SELECT COUNT(*) cnt
00123             FROM user_constraints
00124             WHERE constraint_type = \'R\' AND deferrable = \'DEFERRABLE\''
00125         );
00126         $row = $meta->fetchRow();
00127         if ( $row && $row['cnt'] > 0 ) {
00128             return;
00129         }
00130 
00131         $this->applyPatch( 'patch_fk_rename_deferred.sql', false, "Altering foreign keys ... " );
00132     }
00133 
00137     protected function doFunctions17() {
00138         $this->applyPatch( 'patch_create_17_functions.sql', false, "Recreating functions" );
00139     }
00140 
00145     protected function doSchemaUpgrade17() {
00146         // check if iwlinks table exists which was added in 1.17
00147         if ( $this->db->tableExists( 'iwlinks' ) ) {
00148             return;
00149         }
00150         $this->applyPatch( 'patch_16_17_schema_changes.sql', false, "Updating schema to 17" );
00151     }
00152 
00156     protected function doInsertPage0() {
00157         $this->output( "Inserting page 0 if missing ... " );
00158         $row = array(
00159             'page_id' => 0,
00160             'page_namespace' => 0,
00161             'page_title' => ' ',
00162             'page_counter' => 0,
00163             'page_is_redirect' => 0,
00164             'page_is_new' => 0,
00165             'page_random' => 0,
00166             'page_touched' => $this->db->timestamp(),
00167             'page_latest' => 0,
00168             'page_len' => 0
00169         );
00170         $this->db->insert( 'page', $row, 'OracleUpdater:doInserPage0', array( 'IGNORE' ) );
00171         $this->output( "ok\n" );
00172     }
00173 
00178     protected function doRemoveNotNullEmptyDefaults() {
00179         $meta = $this->db->fieldInfo( 'categorylinks', 'cl_sortkey_prefix' );
00180         if ( $meta->isNullable() ) {
00181             return;
00182         }
00183         $this->applyPatch(
00184             'patch_remove_not_null_empty_defs.sql',
00185             false,
00186             'Removing not null empty constraints'
00187         );
00188     }
00189 
00190     protected function doRemoveNotNullEmptyDefaults2() {
00191         $meta = $this->db->fieldInfo( 'ipblocks', 'ipb_by_text' );
00192         if ( $meta->isNullable() ) {
00193             return;
00194         }
00195         $this->applyPatch(
00196             'patch_remove_not_null_empty_defs2.sql',
00197             false,
00198             'Removing not null empty constraints'
00199         );
00200     }
00201 
00206     protected function doRecentchangesFK2Cascade() {
00207         $meta = $this->db->query( 'SELECT 1 FROM all_constraints WHERE owner = \'' .
00208             strtoupper( $this->db->getDBname() ) .
00209             '\' AND constraint_name = \'' .
00210             $this->db->tablePrefix() .
00211             'RECENTCHANGES_FK2\' AND delete_rule = \'CASCADE\''
00212         );
00213         $row = $meta->fetchRow();
00214         if ( $row ) {
00215             return;
00216         }
00217 
00218         $this->applyPatch( 'patch_recentchanges_fk2_cascade.sql', false, "Altering RECENTCHANGES_FK2" );
00219     }
00220 
00224     protected function doPageRestrictionsPKUKFix() {
00225         $this->output( "Altering PAGE_RESTRICTIONS keys ... " );
00226 
00227         $meta = $this->db->query( 'SELECT column_name FROM all_cons_columns WHERE owner = \'' .
00228             strtoupper( $this->db->getDBname() ) .
00229             '\' AND constraint_name = \'' .
00230             $this->db->tablePrefix() .
00231             'PAGE_RESTRICTIONS_PK\' AND rownum = 1'
00232         );
00233         $row = $meta->fetchRow();
00234         if ( $row['column_name'] == 'PR_ID' ) {
00235             $this->output( "seems to be up to date.\n" );
00236 
00237             return;
00238         }
00239 
00240         $this->applyPatch( 'patch-page_restrictions_pkuk_fix.sql', false );
00241         $this->output( "ok\n" );
00242     }
00243 
00247     protected function doRebuildDuplicateFunction() {
00248         $this->applyPatch( 'patch_rebuild_dupfunc.sql', false, "Rebuilding duplicate function" );
00249     }
00250 
00256     public function doUpdates( $what = array( 'core', 'extensions', 'purge', 'stats' ) ) {
00257         parent::doUpdates( $what );
00258 
00259         $this->db->query( 'BEGIN fill_wiki_info; END;' );
00260     }
00261 
00265     public function purgeCache() {
00266         # We can't guarantee that the user will be able to use TRUNCATE,
00267         # but we know that DELETE is available to us
00268         $this->output( "Purging caches..." );
00269         $this->db->delete( '/*Q*/' . $this->db->tableName( 'objectcache' ), '*', __METHOD__ );
00270         $this->output( "done.\n" );
00271     }
00272 }