function asin_update_6001 in Amazon Product Advertisement API 6
Database schema update from the ugly, borked D5 version.
File
- asin/
asin.install, line 43
Code
function asin_update_6001() {
if ($abort = content_check_update('asin')) {
return $abort;
}
// The name of the widget type has changed from asin to asin_text.
$ret[] = update_sql("UPDATE {" . content_instance_tablename() . "} SET widget_type = 'asin_text' WHERE widget_type = 'asin'");
// All CCK fields are disabled by Content module during the D6 upgrade.
// Re-enable the 'asin' field.
content_associate_fields('asin');
// Build a list of fields that need data updating.
module_load_install('content');
module_load_include('inc', 'content', 'includes/content.admin');
module_load_include('inc', 'content', 'includes/content.crud');
$ret = array();
$fields = array();
content_clear_type_cache(TRUE);
// Grab the list of fields to update.
foreach (content_field_instance_read(NULL, TRUE) as $field) {
if ($field['type'] == 'asin' && $field['widget']['type'] == 'asin_text') {
$fields[] = $field;
}
}
content_clear_type_cache(TRUE);
// Update database storage (add data column, since the D5 version assumed all control).
foreach ($fields as $field) {
$new_field = $field;
// Setup the previous definition.
$field['columns'] = array();
// Setup the new.
$new_field['columns']['asin'] = array(
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
);
$field['widget']['type'] = 'asin_text';
content_alter_db($field, $new_field);
content_field_instance_update($field);
$ret[] = array(
'success' => TRUE,
'query' => 'Updated database schema and widget settings for ' . $field['field_name'],
);
}
content_clear_type_cache(TRUE);
return $ret;
}