You are here

function uc_product_kit_update_6003 in Ubercart 6.2

File

uc_product_kit/uc_product_kit.install, line 171
Install, update and uninstall functions for the uc_product_kit module.

Code

function uc_product_kit_update_6003() {
  $ret = array();
  if (!db_column_exists('uc_product_kits', 'synchronized')) {
    db_add_field($ret, 'uc_product_kits', 'synchronized', array(
      'type' => 'int',
      'size',
      'tiny',
      'not null' => TRUE,
      'default' => 0,
    ));
    $ret[] = update_sql("UPDATE {uc_product_kits} SET synchronized = 1 WHERE discount < 0");
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $ret[] = update_sql("UPDATE {uc_product_kits} AS pk JOIN {uc_products} AS p ON pk.product_id = p.nid SET pk.discount = pk.discount - p.sell_price WHERE pk.discount >= 0;");
        break;
      case 'pgsql':
        $ret[] = update_sql("UPDATE {uc_product_kits} SET discount = discount - (SELECT p.sell_price FROM {uc_products} p JOIN {uc_product_kits} pk ON pk.product_id = p.nid WHERE pk.discount >= 0);");
        break;
    }
  }
  return $ret;
}