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