function uc_product_update_4 in Ubercart 5
File
- uc_product/
uc_product.install, line 163 - Database installation, uninstallation, and updates for the product module.
Code
function uc_product_update_4() {
$ret = array();
$ret[] = update_sql("UPDATE {node} AS n, {uc_products} AS p, {uc_product_classes} AS pc SET n.type = REPLACE(LOWER(pc.name), ' ', '_') WHERE n.nid = p.nid AND p.pcid = pc.pcid");
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("DROP TABLE {uc_class_choices}");
$ret[] = update_sql("DROP TABLE {uc_class_fields}");
$ret[] = update_sql("DROP TABLE {uc_product_class_choices}");
$ret[] = update_sql("ALTER TABLE {uc_product_classes} CHANGE pcid pcid varchar(32) NOT NULL");
$ret[] = update_sql("ALTER TABLE {uc_product_classes} ADD COLUMN description text");
$ret[] = update_sql("ALTER TABLE {uc_products} DROP COLUMN pcid");
break;
case 'pgsql':
$ret[] = update_sql("DROP TABLE {uc_class_choices}");
$ret[] = update_sql("DROP TABLE {uc_class_fields}");
$ret[] = update_sql("DROP TABLE {uc_product_class_choices}");
$ret[] = update_sql("DROP INDEX {uc_product_classes}_pcid_idx");
db_change_column($ret, 'uc_product_classes', 'pcid', 'pcid', 'varchar(32)', array(
'not null' => true,
'default' => "''",
));
db_add_column($ret, 'uc_product_classes', 'description', 'text');
$ret[] = update_sql("ALTER TABLE {uc_products} DROP COLUMN pcid");
break;
}
$ret[] = update_sql("UPDATE {uc_product_classes} SET pcid = REPLACE(LOWER(name), ' ', '_')");
if ($vid = variable_get('uc_catalog_vid', 0)) {
$types = module_invoke_all('product_types');
unset($types['product']);
foreach ($types as $type) {
$placeholders[] = "(%d, '%s')";
$values[] = $vid;
$values[] = $type;
}
$result = db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES " . implode(',', $placeholders), $values);
$ret[] = array(
'success' => $result,
'query' => t('Added the following node types to the Catalog vocabulary: %list', array(
'%list' => implode(', ', $values),
)),
);
}
node_types_rebuild();
return $ret;
}