revert r103691 that makes update.php output garbage
[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
40 //1.19
41 array( 'addTable', 'config', 'patch-config.sql' ),
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
52 // till 2.0 i guess
53 array( 'doRebuildDuplicateFunction' ),
54
55 );
56 }
57
58 /**
59 * MySQL uses datatype defaults for NULL inserted into NOT NULL fields
60 * In namespace case that results into insert of 0 which is default namespace
61 * Oracle inserts NULL, so namespace fields should have a default value
62 */
63 protected function doNamespaceDefaults() {
64 $this->output( "Altering namespace fields with default value ... " );
65 $meta = $this->db->fieldInfo( 'page', 'page_namespace' );
66 if ( $meta->defaultValue() != null ) {
67 $this->output( "defaults seem to present on namespace fields\n" );
68 return;
69 }
70
71 $this->applyPatch( 'patch_namespace_defaults.sql', false );
72 $this->output( "ok\n" );
73 }
74
75 /**
76 * Uniform FK names + deferrable state
77 */
78 protected function doFKRenameDeferr() {
79 $this->output( "Altering foreign keys ... " );
80 $meta = $this->db->query( 'SELECT COUNT(*) cnt FROM user_constraints WHERE constraint_type = \'R\' AND deferrable = \'DEFERRABLE\'' );
81 $row = $meta->fetchRow();
82 if ( $row && $row['cnt'] > 0 ) {
83 $this->output( "at least one FK is deferrable, considering up to date\n" );
84 return;
85 }
86
87 $this->applyPatch( 'patch_fk_rename_deferred.sql', false );
88 $this->output( "ok\n" );
89 }
90
91 /**
92 * Recreate functions to 17 schema layout
93 */
94 protected function doFunctions17() {
95 $this->output( "Recreating functions ... " );
96 $this->applyPatch( 'patch_create_17_functions.sql', false );
97 $this->output( "ok\n" );
98 }
99
100 /**
101 * Schema upgrade 16->17
102 * there are no incremental patches prior to this
103 */
104 protected function doSchemaUpgrade17() {
105 $this->output( "Updating schema to 17 ... " );
106 // check if iwlinks table exists which was added in 1.17
107 if ( $this->db->tableExists( 'iwlinks' ) ) {
108 $this->output( "schema seem to be up to date.\n" );
109 return;
110 }
111 $this->applyPatch( 'patch_16_17_schema_changes.sql', false );
112 $this->output( "ok\n" );
113 }
114
115 /**
116 * Insert page (page_id = 0) to prevent FK constraint violation
117 */
118 protected function doInsertPage0() {
119 $this->output( "Inserting page 0 if missing ... " );
120 $row = array(
121 'page_id' => 0,
122 'page_namespace' => 0,
123 'page_title' => ' ',
124 'page_counter' => 0,
125 'page_is_redirect' => 0,
126 'page_is_new' => 0,
127 'page_random' => 0,
128 'page_touched' => $this->db->timestamp(),
129 'page_latest' => 0,
130 'page_len' => 0
131 );
132 $this->db->insert( 'page', $row, 'OracleUpdater:doInserPage0', array( 'IGNORE' ) );
133 $this->output( "ok\n" );
134 }
135
136 /**
137 * Remove DEFAULT '' NOT NULL constraints from fields as '' is internally
138 * converted to NULL in Oracle
139 */
140 protected function doRemoveNotNullEmptyDefaults() {
141 $this->output( "Removing not null empty constraints ... " );
142 $meta = $this->db->fieldInfo( 'categorylinks' , 'cl_sortkey_prefix' );
143 if ( $meta->isNullable() ) {
144 $this->output( "constraints seem to be removed\n" );
145 return;
146 }
147 $this->applyPatch( 'patch_remove_not_null_empty_defs.sql', false );
148 $this->output( "ok\n" );
149 }
150 protected function doRemoveNotNullEmptyDefaults2() {
151 $this->output( "Removing not null empty constraints ... " );
152 $meta = $this->db->fieldInfo( 'ipblocks' , 'ipb_by_text' );
153 if ( $meta->isNullable() ) {
154 $this->output( "constraints seem to be removed\n" );
155 return;
156 }
157 $this->applyPatch( 'patch_remove_not_null_empty_defs2.sql', false );
158 $this->output( "ok\n" );
159 }
160
161 /**
162 * rebuilding of the function that duplicates tables for tests
163 */
164 protected function doRebuildDuplicateFunction() {
165 $this->output( "Rebuilding duplicate function ... " );
166 $this->applyPatch( 'patch_rebuild_dupfunc.sql', false );
167 $this->output( "ok\n" );
168 }
169
170 /**
171 * Overload: after this action field info table has to be rebuilt
172 *
173 * @param $what array
174 */
175 public function doUpdates( $what = array( 'core', 'extensions', 'purge', 'stats' ) ) {
176 parent::doUpdates( $what );
177
178 $this->db->query( 'BEGIN fill_wiki_info; END;' );
179 }
180
181 }