You are here

function uc_recurring_update_6012 in UC Recurring Payments and Subscriptions 6.2

Same name and namespace in other branches
  1. 7.2 uc_recurring.install \uc_recurring_update_6012()

Add another table to track order relationships.

File

./uc_recurring.install, line 510
Installs the Recurring Fee module.

Code

function uc_recurring_update_6012() {
  $ret = array();
  $recurring_order_table = array(
    'fields' => array(
      'original_order_id' => array(
        'description' => t('The original order ID.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'renewal_order_id' => array(
        'description' => t('The recurring order ID.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
  );
  db_create_table($ret, 'uc_recurring_orders', $recurring_order_table);

  // Load all the recurring fees and build the uc_recurring_orders table from data found.
  $result = db_query("SELECT * from {uc_recurring_users}");
  while ($row = db_fetch_object($result)) {
    $row->data = unserialize($row->data);
    if (!empty($row->data['recurring orders'])) {
      foreach ($row->data['recurring orders'] as $order_id => $order) {
        db_query("INSERT INTO {uc_recurring_orders} (original_order_id, renewal_order_id) VALUES (%d, %d)", $row->order_id, $order_id);
      }
    }
  }
  return $ret;
}