| 1 |
<?php
|
| 2 |
// $Id: uc_addresses.install,v 1.3 2008/05/29 15:52:50 freixas Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_schema().
|
| 6 |
*/
|
| 7 |
function uc_addresses_schema() {
|
| 8 |
$schema['uc_addresses'] = array(
|
| 9 |
'description' => t('Ubercart customer addresses'),
|
| 10 |
'fields' => array(
|
| 11 |
'aid' => array(
|
| 12 |
'description' => t('The address ID'),
|
| 13 |
'type' => 'serial',
|
| 14 |
'unsigned' => TRUE,
|
| 15 |
'not null' => TRUE,
|
| 16 |
),
|
| 17 |
'uid' => array(
|
| 18 |
'description' => t('The ID of the user who owns this address'),
|
| 19 |
'type' => 'int',
|
| 20 |
'unsigned' => TRUE,
|
| 21 |
'not null' => TRUE,
|
| 22 |
'default' => 0,
|
| 23 |
),
|
| 24 |
'first_name' => array(
|
| 25 |
'description' => t('The addressee\'s first name'),
|
| 26 |
'type' => 'varchar',
|
| 27 |
'length' => 255,
|
| 28 |
'not null' => TRUE,
|
| 29 |
'default' => '',
|
| 30 |
),
|
| 31 |
'last_name' => array(
|
| 32 |
'description' => t('The addressee\'s last name'),
|
| 33 |
'type' => 'varchar',
|
| 34 |
'length' => 255,
|
| 35 |
'not null' => TRUE,
|
| 36 |
'default' => '',
|
| 37 |
),
|
| 38 |
'phone' => array(
|
| 39 |
'description' => t('The addressee\'s phone number'),
|
| 40 |
'type' => 'varchar',
|
| 41 |
'length' => 255,
|
| 42 |
'not null' => TRUE,
|
| 43 |
'default' => '',
|
| 44 |
),
|
| 45 |
'company' => array(
|
| 46 |
'description' => t('The addressee\'s company name'),
|
| 47 |
'type' => 'varchar',
|
| 48 |
'length' => 255,
|
| 49 |
'not null' => TRUE,
|
| 50 |
'default' => '',
|
| 51 |
),
|
| 52 |
'street1' => array(
|
| 53 |
'description' => t('The addressee\'s residence number and street'),
|
| 54 |
'type' => 'varchar',
|
| 55 |
'length' => 255,
|
| 56 |
'not null' => TRUE,
|
| 57 |
'default' => '',
|
| 58 |
),
|
| 59 |
'street2' => array(
|
| 60 |
'description' => t('The addressee\'s residence number and street (continued)'),
|
| 61 |
'type' => 'varchar',
|
| 62 |
'length' => 255,
|
| 63 |
'not null' => TRUE,
|
| 64 |
'default' => '',
|
| 65 |
),
|
| 66 |
'city' => array(
|
| 67 |
'description' => t('The addressee\'s city of residence'),
|
| 68 |
'type' => 'varchar',
|
| 69 |
'length' => 255,
|
| 70 |
'not null' => TRUE,
|
| 71 |
'default' => '',
|
| 72 |
),
|
| 73 |
'zone' => array(
|
| 74 |
'description' => t('The addressee\'s zone of residence'),
|
| 75 |
'type' => 'int',
|
| 76 |
'size' => 'medium',
|
| 77 |
'not null' => TRUE,
|
| 78 |
'default' => 0,
|
| 79 |
),
|
| 80 |
'postal_code' => array(
|
| 81 |
'description' => t('The addressee\'s postal code'),
|
| 82 |
'type' => 'varchar',
|
| 83 |
'length' => 255,
|
| 84 |
'not null' => TRUE,
|
| 85 |
'default' => '',
|
| 86 |
),
|
| 87 |
'country' => array(
|
| 88 |
'description' => t('The addressee\'s country of residence'),
|
| 89 |
'type' => 'int',
|
| 90 |
'size' => 'medium',
|
| 91 |
'unsigned' => TRUE,
|
| 92 |
'not null' => TRUE,
|
| 93 |
'default' => 0,
|
| 94 |
),
|
| 95 |
'address_name' => array(
|
| 96 |
'description' => t('The name used to access this address'),
|
| 97 |
'type' => 'varchar',
|
| 98 |
'length' => 20,
|
| 99 |
'not null' => FALSE,
|
| 100 |
),
|
| 101 |
'created' => array(
|
| 102 |
'description' => t('The date this address was created'),
|
| 103 |
'type' => 'int',
|
| 104 |
'not null' => TRUE,
|
| 105 |
'default' => 0,
|
| 106 |
),
|
| 107 |
'modified' => array(
|
| 108 |
'description' => t('The date this address was last modified'),
|
| 109 |
'type' => 'int',
|
| 110 |
'not null' => TRUE,
|
| 111 |
'default' => 0,
|
| 112 |
),
|
| 113 |
),
|
| 114 |
'indexes' => array(
|
| 115 |
'aid_uid_idx' => array('aid', 'uid'),
|
| 116 |
),
|
| 117 |
'primary key' => array('aid'),
|
| 118 |
);
|
| 119 |
|
| 120 |
$schema['uc_addresses_defaults'] = array(
|
| 121 |
'description' => t('Associates a user with an address: the default address'),
|
| 122 |
'fields' => array(
|
| 123 |
'aid' => array(
|
| 124 |
'description' => t('The ID of the address in the uc_adresses table'),
|
| 125 |
'type' => 'int',
|
| 126 |
'unsigned' => 1,
|
| 127 |
'not null' => TRUE,
|
| 128 |
),
|
| 129 |
'uid' => array(
|
| 130 |
'description' => t('The ID of the user'),
|
| 131 |
'type' => 'int',
|
| 132 |
'unsigned' => 1,
|
| 133 |
'not null' => TRUE,
|
| 134 |
),
|
| 135 |
),
|
| 136 |
'primary key' => array('aid', 'uid'),
|
| 137 |
);
|
| 138 |
|
| 139 |
return $schema;
|
| 140 |
}
|
| 141 |
|
| 142 |
/**
|
| 143 |
* Implementation of hook_install().
|
| 144 |
*/
|
| 145 |
function uc_addresses_install() {
|
| 146 |
drupal_install_schema('uc_addresses');
|
| 147 |
}
|
| 148 |
|
| 149 |
/**
|
| 150 |
* First update: remove the old incorrect sequence number name and add
|
| 151 |
* the correct new one. Copy over the sequence number.
|
| 152 |
*/
|
| 153 |
function uc_addresses_update_1() {
|
| 154 |
$items = array();
|
| 155 |
$seq = db_query("SELECT * FROM {sequences} WHERE name = 'uc_addresses'");
|
| 156 |
if (db_num_rows($seq) == 1) {
|
| 157 |
$obj = db_fetch_object($seq);
|
| 158 |
$items[] = update_sql("DELETE FROM {sequences} WHERE name = 'uc_addresses'");
|
| 159 |
$items[] = update_sql("INSERT INTO {sequences} (name, id) VALUES('{uc_addresses}_aid'," . $obj->id . ")");
|
| 160 |
}
|
| 161 |
return $items;
|
| 162 |
}
|
| 163 |
|
| 164 |
/**
|
| 165 |
* Second update: add nickname field.
|
| 166 |
*/
|
| 167 |
function uc_addresses_update_2() {
|
| 168 |
$items = array();
|
| 169 |
$items[] = update_sql("ALTER TABLE {uc_addresses} ADD COLUMN address_name VARCHAR(20) DEFAULT NULL AFTER country");
|
| 170 |
return $items;
|
| 171 |
}
|
| 172 |
|
| 173 |
/**
|
| 174 |
* First Drupal 6 update: standardize database definitions as per uc_orders
|
| 175 |
*/
|
| 176 |
function uc_addresses_update_6000() {
|
| 177 |
db_drop_primary_key($ret, 'uc_addresses');
|
| 178 |
db_drop_index($ret, 'uc_addresses', 'aid_uid_idx');
|
| 179 |
db_change_field($ret, 'uc_addresses', 'aid', 'aid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('aid')));
|
| 180 |
db_change_field($ret, 'uc_addresses', 'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 181 |
db_change_field($ret, 'uc_addresses', 'first_name', 'delivery_first_name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 182 |
db_change_field($ret, 'uc_addresses', 'last_name', 'delivery_last_name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 183 |
db_change_field($ret, 'uc_addresses', 'phone', 'delivery_phone', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 184 |
db_change_field($ret, 'uc_addresses', 'company', 'delivery_company', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 185 |
db_change_field($ret, 'uc_addresses', 'street1', 'delivery_street1', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 186 |
db_change_field($ret, 'uc_addresses', 'street2', 'delivery_street2', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 187 |
db_change_field($ret, 'uc_addresses', 'city', 'delivery_city', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 188 |
db_change_field($ret, 'uc_addresses', 'zone', 'delivery_zone', array('type' => 'int', 'unsigned' => TRUE, 'size' => 'medium', 'not null' => TRUE, 'default' => 0));
|
| 189 |
db_change_field($ret, 'uc_addresses', 'postal_code', 'delivery_postal_code', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 190 |
db_change_field($ret, 'uc_addresses', 'country', 'delivery_country', array('type' => 'int', 'unsigned' => TRUE, 'size' => 'medium', 'not null' => TRUE, 'default' => 0));
|
| 191 |
db_add_index($ret, 'uc_addresses', 'aid_uid_idx', array('aid', 'uid'));
|
| 192 |
|
| 193 |
db_drop_primary_key($ret, 'uc_addresses_defaults');
|
| 194 |
db_change_field($ret, 'uc_addresses_defaults', 'aid', 'aid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE));
|
| 195 |
db_change_field($ret, 'uc_addresses_defaults', 'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 196 |
db_add_primary_key($ret, 'uc_addresses_defaults', array('aid', 'uid'));
|
| 197 |
|
| 198 |
return $ret;
|
| 199 |
}
|
| 200 |
|
| 201 |
/**
|
| 202 |
* Implementation of hook_uninstall().
|
| 203 |
*/
|
| 204 |
function uc_addresses_uninstall() {
|
| 205 |
drupal_uninstall_schema('uc_addresses');
|
| 206 |
|
| 207 |
db_query("DELETE FROM {variable} WHERE name LIKE 'uc_addresses%'");
|
| 208 |
}
|