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