Index: store.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/store/store.install,v retrieving revision 1.20.2.1 diff -U3 -r1.20.2.1 store.install --- store.install 27 Sep 2006 07:06:54 -0000 1.20.2.1 +++ store.install 30 Oct 2006 10:18:58 -0000 @@ -405,100 +405,52 @@ } function store_update_21() { - // Init - $address_fields = array( - 'firstname', - 'lastname', - 'street1', - 'street2', - 'zip', - 'city', - 'state', - 'country', - ); - if (!isset($_SESSION['store_update_18_txnid'])) { - // Create New Table - switch($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("CREATE TABLE {ec_transaction_address} ( - txnid int(10) unsigned NOT NULL default '0', - type varchar(16) NOT NULL default '', - firstname varchar(32) NOT NULL default '', - lastname varchar(32) NOT NULL default '', - street1 varchar(64) NOT NULL default '', - street2 varchar(64) NOT NULL default '', - zip varchar(10) NOT NULL default '', - city varchar(32) NOT NULL default '', - state varchar(32) NOT NULL default '', - country varchar(2) NOT NULL default '', - PRIMARY KEY (txnid,type) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - break; - case 'pgsql': - break; - } - - $_SESSION['store_update_18_txnid'] = 0; - $_SESSION['store_update_18_max'] = db_query('SELECT MAX(txnid) FROM {ec_transaction}'); - // Return query info - $ret['#finished'] = 0; - return $ret; - } - - // Do work - $result = db_query_range('SELECT * FROM {ec_transaction} ORDER BY txnid ASC', $_SESSION['store_update_18_txnid'], 20); - while ($txn = db_fetch_object($result)) { - // Merge in billing and shipping addresses - foreach (array('billing', 'shipping') as $address_type) { - $k[] = 'txnid'; - $v[] = $txn->txnid; - $s[] = '%d'; - $k[] = 'type'; - $v[] = $address_type; - $s[] = "'%s'"; - foreach ($address_fields as $key) { - $key2 = $address_type . '_' . $key; - if(isset($txn->$key2)) { - $k[] = db_escape_string($key); - $v[] = $txn->$key2; - $s[] = "'%s'"; - } - } - db_query('INSERT INTO {ec_transaction_address} ('. implode(', ', $k) .') VALUES('. implode(', ', $s) .')', $v); - $k = $v = $s = array(); - $_SESSION['store_update_18_txnid'] = $txn->txnid; - } - } - - // See if we are done. - if ($_SESSION['store_update_18_txnid'] < $_SESSION['store_update_18_max']) { - // Not done yet. Return the progress. - return array('#finished' => $_SESSION['store_update_18_txnid'] / $_SESSION['store_update_18_max']); - } - else { - // Done. Clean up and indicate we're finished. - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_firstname"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_lastname"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_street1"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_street2"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_city"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_state"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_zip"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_country"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_firstname"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_lastname"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_street1"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_street2"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_city"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_state"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_zip"); - $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_country"); - $ret['#finished'] = 1; - unset($_SESSION['store_update_18_txnid']); - unset($_SESSION['store_update_18_max']); - return $ret; + // Create New Table and move billing shipping addresses there. + switch($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("CREATE TABLE {ec_transaction_address} ( + txnid int(10) unsigned NOT NULL default '0', + type varchar(16) NOT NULL default '', + firstname varchar(32) NOT NULL default '', + lastname varchar(32) NOT NULL default '', + street1 varchar(64) NOT NULL default '', + street2 varchar(64) NOT NULL default '', + zip varchar(10) NOT NULL default '', + city varchar(32) NOT NULL default '', + state varchar(32) NOT NULL default '', + country varchar(2) NOT NULL default '', + PRIMARY KEY (txnid,type) + ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); + $ret[] = update_sql("INSERT INTO ec_transaction_address + (`txnid`, `type`, `firstname`, `lastname`, `street1`, `street2`, `zip`, `city`, `state`, `country`) + SELECT `txnid`,'shipping' AS `type`, `shipping_firstname`, `shipping_lastname`,`shipping_street1`,`shipping_street2`,`shipping_zip`,`shipping_city`,`shipping_state`,`shipping_country` + FROM ec_transaction"); + $ret[] = update_sql("INSERT INTO ec_transaction_address + (`txnid`, `type`, `firstname`, `lastname`, `street1`, `street2`, `zip`, `city`, `state`, `country`) + SELECT `txnid`,'billing' AS `type`, `billing_firstname`, `billing_lastname`,`billing_street1`,`billing_street2`,`billing_zip`,`billing_city`,`billing_state`,`billing_country` + FROM ec_transaction"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_firstname"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_lastname"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_street1"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_street2"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_city"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_state"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_zip"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP shipping_country"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_firstname"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_lastname"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_street1"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_street2"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_city"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_state"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_zip"); + $ret[] = update_sql("ALTER TABLE {ec_transaction} DROP billing_country"); + break; + case 'pgsql': + break; } + return $ret; } function store_update_22() {