| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
function uc_store_schema() {
|
| 5 |
$schema = array();
|
| 6 |
|
| 7 |
$schema['uc_countries'] = array(
|
| 8 |
'fields' => array(
|
| 9 |
'country_id' => array(
|
| 10 |
'type' => 'serial',
|
| 11 |
'unsigned' => TRUE,
|
| 12 |
'not null' => TRUE,
|
| 13 |
),
|
| 14 |
'country_name' => array(
|
| 15 |
'type' => 'varchar',
|
| 16 |
'length' => 255,
|
| 17 |
'not null' => TRUE,
|
| 18 |
'default' => '',
|
| 19 |
),
|
| 20 |
'country_iso_code_2' => array(
|
| 21 |
'description' => t('Two-character ISO country code.'),
|
| 22 |
'type' => 'char',
|
| 23 |
'length' => 2,
|
| 24 |
'not null' => TRUE,
|
| 25 |
'default' => '',
|
| 26 |
),
|
| 27 |
'country_iso_code_3' => array(
|
| 28 |
'description' => t('Three-character ISO country code.'),
|
| 29 |
'type' => 'char',
|
| 30 |
'length' => 3,
|
| 31 |
'not null' => TRUE,
|
| 32 |
'default' => '',
|
| 33 |
),
|
| 34 |
'version' => array(
|
| 35 |
'description' => t('The version of the CIF that loaded the country information.'),
|
| 36 |
'type' => 'int',
|
| 37 |
'size' => 'small',
|
| 38 |
'not null' => TRUE,
|
| 39 |
'default' => 0,
|
| 40 |
),
|
| 41 |
),
|
| 42 |
'indexes' => array(
|
| 43 |
'uc_countries_country_name' => array('country_name'),
|
| 44 |
),
|
| 45 |
'primary key' => array('country_id'),
|
| 46 |
);
|
| 47 |
$schema['uc_zones'] = array(
|
| 48 |
'fields' => array(
|
| 49 |
'zone_id' => array(
|
| 50 |
'type' => 'serial',
|
| 51 |
'unsigned' => TRUE,
|
| 52 |
'not null' => TRUE,
|
| 53 |
),
|
| 54 |
'zone_country_id' => array(
|
| 55 |
'type' => 'int',
|
| 56 |
'unsigned' => TRUE,
|
| 57 |
'not null' => TRUE,
|
| 58 |
'default' => 0,
|
| 59 |
),
|
| 60 |
'zone_code' => array(
|
| 61 |
'description' => t('Standard abbreviation of the zone name.'),
|
| 62 |
'type' => 'varchar',
|
| 63 |
'length' => 32,
|
| 64 |
'not null' => TRUE,
|
| 65 |
'default' => '',
|
| 66 |
),
|
| 67 |
'zone_name' => array(
|
| 68 |
'type' => 'varchar',
|
| 69 |
'length' => 255,
|
| 70 |
'not null' => TRUE,
|
| 71 |
'default' => '',
|
| 72 |
),
|
| 73 |
),
|
| 74 |
'indexes' => array(
|
| 75 |
'uc_zones_zone_code' => array('zone_code'),
|
| 76 |
'uc_zones_zone_country_id' => array('zone_country_id'),
|
| 77 |
),
|
| 78 |
'primary key' => array('zone_id'),
|
| 79 |
);
|
| 80 |
$schema['uc_store_footers'] = array(
|
| 81 |
'fields' => array(
|
| 82 |
'path_hash' => array(
|
| 83 |
'type' => 'varchar',
|
| 84 |
'length' => 32,
|
| 85 |
'not null' => TRUE,
|
| 86 |
'default' => '',
|
| 87 |
),
|
| 88 |
'message' => array(
|
| 89 |
'type' => 'text',
|
| 90 |
),
|
| 91 |
),
|
| 92 |
'primary key' => array('path_hash'),
|
| 93 |
);
|
| 94 |
|
| 95 |
return $schema;
|
| 96 |
}
|
| 97 |
|
| 98 |
function uc_store_install() {
|
| 99 |
drupal_install_schema('uc_store');
|
| 100 |
// Install United States and Canada by default.
|
| 101 |
$path = drupal_get_path('module', 'uc_store');
|
| 102 |
require_once($path .'/countries/united_states_840_1.cif');
|
| 103 |
require_once($path .'/countries/canada_124_1.cif');
|
| 104 |
united_states_install();
|
| 105 |
canada_install();
|
| 106 |
}
|
| 107 |
|
| 108 |
function uc_store_uninstall() {
|
| 109 |
drupal_uninstall_schema('uc_store');
|
| 110 |
|
| 111 |
db_query("DELETE FROM {variable} WHERE name LIKE 'user_initials_%%'");
|
| 112 |
db_query("DELETE FROM {variable} WHERE name LIKE 'uc_address_format_%%'");
|
| 113 |
|
| 114 |
variable_del('uc_store_prev_time');
|
| 115 |
variable_del('uc_store_site_id');
|
| 116 |
variable_del('uc_store_name');
|
| 117 |
variable_del('uc_store_owner');
|
| 118 |
variable_del('uc_store_email');
|
| 119 |
variable_del('uc_store_phone');
|
| 120 |
variable_del('uc_store_fax');
|
| 121 |
variable_del('uc_store_street1');
|
| 122 |
variable_del('uc_store_street2');
|
| 123 |
variable_del('uc_store_city');
|
| 124 |
variable_del('uc_store_zone');
|
| 125 |
variable_del('uc_store_postal_code');
|
| 126 |
variable_del('uc_store_country');
|
| 127 |
variable_del('uc_store_admin_page_display');
|
| 128 |
variable_del('uc_customer_list_address');
|
| 129 |
variable_del('uc_currency_sign');
|
| 130 |
variable_del('uc_sign_after_amount');
|
| 131 |
variable_del('uc_currency_thou');
|
| 132 |
variable_del('uc_currency_dec');
|
| 133 |
variable_del('uc_currency_prec');
|
| 134 |
variable_del('uc_weight_unit');
|
| 135 |
variable_del('uc_weight_format');
|
| 136 |
variable_del('uc_weight_format_lb');
|
| 137 |
variable_del('uc_weight_format_kg');
|
| 138 |
variable_del('uc_weight_format_oz');
|
| 139 |
variable_del('uc_weight_format_g');
|
| 140 |
variable_del('uc_length_unit');
|
| 141 |
variable_del('uc_length_format_in');
|
| 142 |
variable_del('uc_length_format_cm');
|
| 143 |
variable_del('uc_date_format_default');
|
| 144 |
variable_del('uc_field_first_name');
|
| 145 |
variable_del('uc_field_last_name');
|
| 146 |
variable_del('uc_field_email');
|
| 147 |
variable_del('uc_field_phone');
|
| 148 |
variable_del('uc_field_company');
|
| 149 |
variable_del('uc_field_address');
|
| 150 |
variable_del('uc_field_street');
|
| 151 |
variable_del('uc_field_street1');
|
| 152 |
variable_del('uc_field_street2');
|
| 153 |
variable_del('uc_field_city');
|
| 154 |
variable_del('uc_field_zone');
|
| 155 |
variable_del('uc_field_country');
|
| 156 |
variable_del('uc_field_postal_code');
|
| 157 |
variable_del('uc_address_fields');
|
| 158 |
variable_del('uc_address_fields_required');
|
| 159 |
}
|
| 160 |
|
| 161 |
function uc_store_update_1() {
|
| 162 |
$ret = array();
|
| 163 |
switch ($GLOBALS['db_type']) {
|
| 164 |
case 'mysql':
|
| 165 |
case 'mysqli':
|
| 166 |
$ret[] = update_sql("DROP TABLE IF EXISTS {uc_address_formats}");
|
| 167 |
$ret[] = update_sql("ALTER TABLE {uc_countries} CHANGE address_format_id version SMALLINT(11) NOT NULL DEFAULT '0'");
|
| 168 |
$ret[] = update_sql("ALTER TABLE {uc_zones} CHANGE zone_name zone_name VARCHAR(32) CHARACTER SET utf8 NOT NULL");
|
| 169 |
break;
|
| 170 |
case 'pgsql':
|
| 171 |
$ret[] = update_sql("DROP TABLE IF EXISTS {uc_address_formats}");
|
| 172 |
$ret[] = update_sql("ALTER TABLE {uc_countries} CHANGE address_format_id version SMALLINT(11) NOT NULL DEFAULT '0'");
|
| 173 |
$ret[] = update_sql("ALTER TABLE {uc_zones} CHANGE zone_name zone_name VARCHAR(32) CHARACTER SET utf8 NOT NULL default ''");
|
| 174 |
break;
|
| 175 |
}
|
| 176 |
return $ret;
|
| 177 |
}
|
| 178 |
|
| 179 |
function uc_store_update_2() {
|
| 180 |
$ret = array();
|
| 181 |
// Get rid of the auto_increment.
|
| 182 |
switch ($GLOBALS['db_type']) {
|
| 183 |
case 'mysql':
|
| 184 |
case 'mysqli':
|
| 185 |
$ret[] = update_sql("ALTER TABLE {uc_zones} CHANGE zone_id zone_id MEDIUMINT(11) NOT NULL");
|
| 186 |
$ret[] = update_sql("ALTER TABLE {uc_zones} CHANGE zone_name zone_name VARCHAR(255) CHARACTER SET utf8 NOT NULL");
|
| 187 |
$ret[] = update_sql("ALTER TABLE {uc_countries} CHANGE country_id country_id MEDIUMINT(11) NOT NULL");
|
| 188 |
break;
|
| 189 |
case 'pgsql':
|
| 190 |
db_change_column($ret, 'uc_zones', 'zone_id', 'zone_id', 'integer', array('not null' => true, 'default' => 0));
|
| 191 |
db_change_column($ret, 'uc_zones', 'zone_name', 'zone_name', 'varchar(255) CHARACTER SET utf8', array('not null' => true, 'default' => ''));
|
| 192 |
db_change_column($ret, 'uc_countries', 'country_id', 'country_id', 'integer', array('not null' => true, 'default' => 0));
|
| 193 |
break;
|
| 194 |
}
|
| 195 |
|
| 196 |
// Make the fixes for U.S.
|
| 197 |
$ret[] = update_sql("UPDATE {uc_countries} SET country_id = 840 WHERE country_id = 223");
|
| 198 |
$ret[] = update_sql("UPDATE {uc_zones} SET zone_country_id = 840 WHERE zone_country_id = 223");
|
| 199 |
$ret[] = update_sql("UPDATE {uc_orders} SET delivery_country = 840 WHERE delivery_country = 223");
|
| 200 |
$ret[] = update_sql("UPDATE {uc_orders} SET billing_country = 840 WHERE billing_country = 223");
|
| 201 |
if (variable_get('uc_store_country', 223) == 223) {
|
| 202 |
variable_set('uc_store_country', 840);
|
| 203 |
}
|
| 204 |
|
| 205 |
// Make the fixes for Canada.
|
| 206 |
$ret[] = update_sql("UPDATE {uc_countries} SET country_id = 124 WHERE country_id = 38");
|
| 207 |
$ret[] = update_sql("UPDATE {uc_zones} SET zone_country_id = 124 WHERE zone_country_id = 38");
|
| 208 |
if (variable_get('uc_store_country', 223) == 38) {
|
| 209 |
variable_set('uc_store_country', 124);
|
| 210 |
}
|
| 211 |
|
| 212 |
$result = db_query("SELECT zone_id FROM {uc_zones} ORDER BY zone_id DESC LIMIT 1");
|
| 213 |
if ($row = db_fetch_object($result)) {
|
| 214 |
$max_id = $row->zone_id;
|
| 215 |
}
|
| 216 |
else {
|
| 217 |
$max_id = 1;
|
| 218 |
}
|
| 219 |
$ret[] = update_sql("INSERT INTO {sequences} VALUES ('{uc_zones}_zone_id', $max_id)");
|
| 220 |
return $ret;
|
| 221 |
}
|
| 222 |
|
| 223 |
function uc_store_update_3() {
|
| 224 |
$ret = array();
|
| 225 |
switch ($GLOBALS['db_type']) {
|
| 226 |
case 'mysql':
|
| 227 |
case 'mysqli':
|
| 228 |
$ret[] = update_sql("CREATE TABLE {uc_store_footers} (
|
| 229 |
`path_hash` varchar(32) NOT NULL default '',
|
| 230 |
`message` text NOT NULL,
|
| 231 |
PRIMARY KEY (path_hash)
|
| 232 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 233 |
break;
|
| 234 |
case 'pgsql':
|
| 235 |
$ret[] = update_sql("CREATE TABLE {uc_store_footers} (
|
| 236 |
path_hash varchar(32) NOT NULL default '',
|
| 237 |
message text NOT NULL default '',
|
| 238 |
PRIMARY KEY (path_hash)
|
| 239 |
)");
|
| 240 |
break;
|
| 241 |
}
|
| 242 |
return $ret;
|
| 243 |
}
|
| 244 |
|
| 245 |
function uc_store_update_4() {
|
| 246 |
db_query("DELETE FROM {variable} WHERE name LIKE 'uc_store_opt_in%%'");
|
| 247 |
variable_del('uc_store_prev_time');
|
| 248 |
|
| 249 |
return array();
|
| 250 |
}
|