1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | <?php // // Open Web Analytics - An Open Source Web Analytics Framework // // Copyright 2006 Peter Adams. All rights reserved. // // Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // $Id$ // /** * 006 Update Class * * @author Peter Adams <peter@openwebanalytics.com> * @copyright Copyright © 2006 Peter Adams <peter@openwebanalytics.com> * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 * @category owa * @package owa * @version $Revision$ * @since owa 1.4.0 */ class owa_base_006_update extends owa_update { var $schema_version = 6; var $is_cli_mode_required = true; function up() { $session = owa_coreAPI::entityFactory('base.session'); $session_columns = array( 'num_goals', 'num_goal_starts', 'goals_value', 'location_id', 'language', 'source_id', 'ad_id', 'campaign_id', 'latest_attributions', 'commerce_trans_count', 'commerce_trans_revenue', 'commerce_items_revenue', 'commerce_items_count', 'commerce_items_quantity', 'commerce_shipping_revenue', 'commerce_tax_revenue'); // create goal related columns $goals = owa_coreAPI::getSetting('base', 'numGoals'); for ($i=1; $i <= $goals; $i++ ) { $session_columns[] = 'goal_'.$i; $session_columns[] = 'goal_'.$i.'_start'; $session_columns[] = 'goal_'.$i.'_value'; } // add columns to owa_session foreach ( $session_columns as $session_col_name ) { $ret = $session->addColumn( $session_col_name ); if ( $ret === true ) { $this->e->notice( "$session_col_name added to owa_session" ); } else { $this->e->notice( "Adding $session_col_name to owa_session failed." ); return false; } } //rename col $ret = $session->renameColumn('source', 'medium'); if (!$ret) { $this->e->notice('Failed to rename source column to medium in owa_session'); return false; } $request = owa_coreAPI::entityFactory('base.request'); $request_columns = array( 'location_id', 'language'); // add columns to owa_session foreach ( $request_columns as $request_col_name ) { $ret = $request->addColumn( $request_col_name ); if ( $ret === true ) { $this->e->notice( "$request_col_name added to owa_request" ); } else { $this->e->notice( "Adding $request_col_name to owa_request failed." ); return false; } } $domstream = owa_coreAPI::entityFactory('base.domstream'); $ret = $domstream->addColumn('domstream_guid'); if ( $ret === true ) { $this->e->notice( "domstream_guid added to owa_domstream" ); } else { $this->e->notice( "Adding domstream_guid to owa_domstream failed." ); return false; } $db = owa_coreAPI::dbSingleton(); $ret = $db->query("update owa_domstream set domstream_guid = id"); $site = owa_coreAPI::entityFactory('base.site'); $ret = $site->addColumn('settings'); if ( $ret === true ) { $this->e->notice( "settings added to owa_site" ); } else { $this->e->notice( "Adding settings to owa_site failed." ); return false; } //$db->query("alter table owa_site DROP PRIMARY KEY"); $db->query("ALTER TABLE owa_site ADD id_1_3 INT"); if ( $ret === true ) { $this->e->notice( "id_1_3 column added to owa_site" ); } else { $this->e->notice( "adding id_1_3 column to owa_site failed." ); return false; } $ret = $db->query("update owa_site set id_1_3 = id"); if ( $ret === true ) { $this->e->notice( "populating id_1_3 in owa_site." ); } else { $this->e->notice( "population of id_1_3 column in owa_site failed." ); return false; } $ret = $db->query('ALTER TABLE owa_site MODIFY id BIGINT'); if ( $ret === true ) { $this->e->notice( "id column modified in owa_site" ); } else { $this->e->notice( "modify of id column in owa_site failed." ); return false; } $ret = $db->query("update owa_site set id = CRC32(site_id)"); if ( $ret === true ) { $this->e->notice( "populating id column in owa_site was successful." ); } else { $this->e->notice( "populating id column in owa_site failed." ); return false; } $click = owa_coreAPI::entityFactory('base.click'); $ret = $click->addColumn('dom_element_class'); if ( $ret === true ) { $this->e->notice( "dom_element_class added to owa_click" ); } else { $this->e->notice( "Adding dom_element_class to owa_click failed." ); return false; } $ret = $click->addColumn('dom_element_parent_id'); if ( $ret === true ) { $this->e->notice( "dom_element_parent_id added to owa_click" ); } else { $this->e->notice( "Adding dom_element_parent_id to owa_click failed." ); return false; } //create new entitiy tables $new_entities = array( 'base.ad_dim', 'base.source_dim', 'base.campaign_dim', 'base.location_dim', 'base.commerce_transaction_fact', 'base.commerce_line_item_fact', 'base.queue_item'); foreach ($new_entities as $entity_name) { $entity = owa_coreAPI::entityFactory($entity_name); $ret = $entity->createTable(); if ($ret === true) { $this->e->notice("$entity_name table created."); } else { $this->e->notice("$entity_name table failed."); return false; } } // must return true return true; } function down() { $session = owa_coreAPI::entityFactory('base.session'); // owa_session columns to drop $session_columns = array( 'num_goals', 'num_goal_starts', 'goals_value', 'location_id', 'language', 'source_id', 'ad_id', 'campaign_id', 'latest_attributions', 'commerce_trans_count', 'commerce_trans_revenue', 'commerce_items_revenue', 'commerce_items_count', 'commerce_items_quantity', 'commerce_shipping_revenue', 'commerce_tax_revenue'); // add in goal related columns $goals = owa_coreAPI::getSetting('base', 'numGoals'); for ($i=1; $i <= $goals; $i++ ) { $session_columns[] = 'goal_'.$i; $session_columns[] = 'goal_'.$i.'_start'; $session_columns[] = 'goal_'.$i.'_value'; } //drop columns from owa_session foreach ($session_columns as $session_col_name) { $session->dropColumn($session_col_name); } //rename col back to original $session->renameColumn('medium', 'source', true); //drop request columns $request = owa_coreAPI::entityFactory('base.request'); $request_columns = array( 'location_id', 'language'); // add columns to owa_session foreach ( $request_columns as $request_col_name ) { $ret = $request->dropColumn( $request_col_name ); } $domstream = owa_coreAPI::entityFactory('base.domstream'); $domstream->dropColumn('domstream_guid'); $site = owa_coreAPI::entityFactory('base.site'); $site->dropColumn('settings'); //$site->modifyColumn('id'); $db = owa_coreAPI::dbSingleton(); $db->query('ALTER TABLE owa_site MODIFY id SERIAL'); $db->query('UPDATE owa_site SET id = id_1_3'); $ret = $db->query('ALTER TABLE owa_site MODIFY id INT'); $db->query('ALTER TABLE owa_site DROP id_1_3'); $click = owa_coreAPI::entityFactory('base.click'); $click->dropColumn('dom_element_class'); $click->dropColumn('dom_element_parent_id'); //drop tables $new_entities = array( 'base.ad_dim', 'base.source_dim', 'base.campaign_dim', 'base.location_dim', 'base.commerce_transaction_fact', 'base.commerce_line_item_fact', 'base.queue_item'); foreach ($new_entities as $entity_name) { $entity = owa_coreAPI::entityFactory($entity_name); $ret = $entity->dropTable(); } return true; } } ?> |