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