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