View source
<?php
include_once './' . drupal_get_path('module', 'content') . '/content.module';
function asin_install() {
content_notify('install', 'asin');
}
function asin_uninstall() {
content_notify('uninstall', 'asin');
}
function asin_enable() {
content_notify('enable', 'asin');
}
function asin_disable() {
content_notify('disable', 'asin');
}
function asin_update_6001() {
if ($abort = content_check_update('asin')) {
return $abort;
}
$ret[] = update_sql("UPDATE {" . content_instance_tablename() . "} SET widget_type = 'asin_text' WHERE widget_type = 'asin'");
content_associate_fields('asin');
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);
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);
foreach ($fields as $field) {
$new_field = $field;
$field['columns'] = array();
$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;
}
function asin_update_6002() {
module_load_install('content');
module_load_include('inc', 'content', 'includes/content.admin');
module_load_include('inc', 'content', 'includes/content.crud');
$fields = array();
foreach (content_field_instance_read() as $field) {
if ($field['type'] == 'asin') {
$fields[$field['field_name']] = $field;
}
}
if (!empty($fields)) {
$batch = array(
'title' => t('Migrating ASIN CCK field values'),
'operations' => array(
array(
'_asin_migrate_field_from_d5',
array(
$fields,
),
),
),
'finished' => '_asin_migrate_fields_finished',
'init_message' => t('Beginning ASIN migration.'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('ASIN CCK field update encountered an error.'),
'file' => drupal_get_path('module', 'asin') . '/asin.d5-migrate.inc',
);
batch_set($batch);
}
return array();
}