installer/updater
[lhc/web/wiklou.git] / includes / installer / OracleUpdater.php
1 <?php
2 /**
3 * Oracle-specific updater.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * Class for handling updates to Oracle databases.
11 *
12 * @ingroup Deployment
13 * @since 1.17
14 */
15 class OracleUpdater extends DatabaseUpdater {
16
17 /**
18 * Handle to the database subclass
19 *
20 * @var DatabaseOracle
21 */
22 protected $db;
23
24 protected function getCoreUpdateList() {
25 return array(
26 // 1.17
27 array( 'doNamespaceDefaults' ),
28 array( 'doFKRenameDeferr' ),
29 array( 'doFunctions17' ),
30 array( 'doSchemaUpgrade17' ),
31 array( 'doInsertPage0' ),
32 array( 'doRemoveNotNullEmptyDefaults' ),
33 array( 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ),
34
35 //1.18
36 array( 'addIndex', 'user', 'i02', 'patch-user_email_index.sql' ),
37 array( 'modifyField', 'user_properties', 'up_property', 'patch-up_property.sql' ),
38 array( 'addTable', 'uploadstash', 'patch-uploadstash.sql' ),
39 array( 'doRecentchangesFK2Cascade' ),
40
41 //1.19
42 array( 'addTable', 'config', 'patch-config.sql' ),
43 array( 'addIndex', 'logging', 'i05', 'patch-logging_type_action_index.sql'),
44 array( 'addTable', 'globaltemplatelinks', 'patch-globaltemplatelinks.sql' ),
45 array( 'addTable', 'globalnamespaces', 'patch-globalnamespaces.sql' ),
46 array( 'addTable', 'globalinterwiki', 'patch-globalinterwiki.sql' ),
47 array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1_field.sql' ),
48 array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1_field.sql' ),
49 array( 'doRemoveNotNullEmptyDefaults2' ),
50 array( 'addIndex', 'page', 'i03', 'patch-page_redirect_namespace_len.sql' ),
51 array( 'modifyField', 'user', 'ug_group', 'patch-ug_group-length-increase.sql' ),
52 array( 'addField', 'uploadstash', 'us_chunk_inx', 'patch-us_chunk_inx_field.sql' ),
53 array( 'addField', 'job', 'job_timestamp', 'patch-job_timestamp_field.sql' ),
54 array( 'addIndex', 'job', 'i02', 'patch-job_timestamp_index.sql' ),
55
56 // 1.20
57 // content model stuff for WikiData
58 array( 'addField', 'revision', 'rev_content_format', 'patch-revision-rev_content_format.sql' ),
59 array( 'addField', 'revision', 'rev_content_model', 'patch-revision-rev_content_model.sql' ),
60 array( 'addField', 'archive', 'ar_content_format', 'patch-archive-ar_content_format.sql' ),
61 array( 'addField', 'archive', 'ar_content_model', 'patch-archive-ar_content_model.sql' ),
62 array( 'addField', 'page', 'page_content_model', 'patch-page-page_content_model.sql' ),
63
64 // KEEP THIS AT THE BOTTOM!!
65 array( 'doRebuildDuplicateFunction' ),
66
67 );
68 }
69
70 /**
71 * MySQL uses datatype defaults for NULL inserted into NOT NULL fields
72 * In namespace case that results into insert of 0 which is default namespace
73 * Oracle inserts NULL, so namespace fields should have a default value
74 */
75 protected function doNamespaceDefaults() {
76 $this->output( "Altering namespace fields with default value ... " );
77 $meta = $this->db->fieldInfo( 'page', 'page_namespace' );
78 if ( $meta->defaultValue() != null ) {
79 $this->output( "defaults seem to present on namespace fields\n" );
80 return;
81 }
82
83 $this->applyPatch( 'patch_namespace_defaults.sql', false );
84 $this->output( "ok\n" );
85 }
86
87 /**
88 * Uniform FK names + deferrable state
89 */
90 protected function doFKRenameDeferr() {
91 $this->output( "Altering foreign keys ... " );
92 $meta = $this->db->query( 'SELECT COUNT(*) cnt FROM user_constraints WHERE constraint_type = \'R\' AND deferrable = \'DEFERRABLE\'' );
93 $row = $meta->fetchRow();
94 if ( $row && $row['cnt'] > 0 ) {
95 $this->output( "at least one FK is deferrable, considering up to date\n" );
96 return;
97 }
98
99 $this->applyPatch( 'patch_fk_rename_deferred.sql', false );
100 $this->output( "ok\n" );
101 }
102
103 /**
104 * Recreate functions to 17 schema layout
105 */
106 protected function doFunctions17() {
107 $this->output( "Recreating functions ... " );
108 $this->applyPatch( 'patch_create_17_functions.sql', false );
109 $this->output( "ok\n" );
110 }
111
112 /**
113 * Schema upgrade 16->17
114 * there are no incremental patches prior to this
115 */
116 protected function doSchemaUpgrade17() {
117 $this->output( "Updating schema to 17 ... " );
118 // check if iwlinks table exists which was added in 1.17
119 if ( $this->db->tableExists( 'iwlinks' ) ) {
120 $this->output( "schema seem to be up to date.\n" );
121 return;
122 }
123 $this->applyPatch( 'patch_16_17_schema_changes.sql', false );
124 $this->output( "ok\n" );
125 }
126
127 /**
128 * Insert page (page_id = 0) to prevent FK constraint violation
129 */
130 protected function doInsertPage0() {
131 $this->output( "Inserting page 0 if missing ... " );
132 $row = array(
133 'page_id' => 0,
134 'page_namespace' => 0,
135 'page_title' => ' ',
136 'page_counter' => 0,
137 'page_is_redirect' => 0,
138 'page_is_new' => 0,
139 'page_random' => 0,
140 'page_touched' => $this->db->timestamp(),
141 'page_latest' => 0,
142 'page_len' => 0
143 );
144 $this->db->insert( 'page', $row, 'OracleUpdater:doInserPage0', array( 'IGNORE' ) );
145 $this->output( "ok\n" );
146 }
147
148 /**
149 * Remove DEFAULT '' NOT NULL constraints from fields as '' is internally
150 * converted to NULL in Oracle
151 */
152 protected function doRemoveNotNullEmptyDefaults() {
153 $this->output( "Removing not null empty constraints ... " );
154 $meta = $this->db->fieldInfo( 'categorylinks' , 'cl_sortkey_prefix' );
155 if ( $meta->isNullable() ) {
156 $this->output( "constraints seem to be removed\n" );
157 return;
158 }
159 $this->applyPatch( 'patch_remove_not_null_empty_defs.sql', false );
160 $this->output( "ok\n" );
161 }
162 protected function doRemoveNotNullEmptyDefaults2() {
163 $this->output( "Removing not null empty constraints ... " );
164 $meta = $this->db->fieldInfo( 'ipblocks' , 'ipb_by_text' );
165 if ( $meta->isNullable() ) {
166 $this->output( "constraints seem to be removed\n" );
167 return;
168 }
169 $this->applyPatch( 'patch_remove_not_null_empty_defs2.sql', false );
170 $this->output( "ok\n" );
171 }
172
173 /**
174 * Removed forcing of invalid state on recentchanges_fk2.
175 * cascading taken in account in the deleting function
176 */
177 protected function doRecentchangesFK2Cascade() {
178 $this->output( "Altering RECENTCHANGES_FK2 ... " );
179
180 $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\'' );
181 $row = $meta->fetchRow();
182 if ( $row ) {
183 $this->output( "FK up to date\n" );
184 return;
185 }
186
187 $this->applyPatch( 'patch_recentchanges_fk2_cascade.sql', false );
188 $this->output( "ok\n" );
189 }
190
191 /**
192 * rebuilding of the function that duplicates tables for tests
193 */
194 protected function doRebuildDuplicateFunction() {
195 $this->output( "Rebuilding duplicate function ... " );
196 $this->applyPatch( 'patch_rebuild_dupfunc.sql', false );
197 $this->output( "ok\n" );
198 }
199
200 /**
201 * Overload: after this action field info table has to be rebuilt
202 *
203 * @param $what array
204 */
205 public function doUpdates( $what = array( 'core', 'extensions', 'purge', 'stats' ) ) {
206 parent::doUpdates( $what );
207
208 $this->db->query( 'BEGIN fill_wiki_info; END;' );
209 }
210
211 /**
212 * Overload: because of the DDL_MODE tablename escaping is a bit dodgy
213 */
214 protected function purgeCache() {
215 # We can't guarantee that the user will be able to use TRUNCATE,
216 # but we know that DELETE is available to us
217 $this->output( "Purging caches..." );
218 $this->db->delete( '/*Q*/'.$this->db->tableName( 'objectcache' ), '*', __METHOD__ );
219 $this->output( "done.\n" );
220 }
221
222 }