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