function mobile_codes_update_6200 in Mobile Codes 7.2
Same name and namespace in other branches
- 6.2 mobile_codes.install \mobile_codes_update_6200()
Implements hook_update_N().
File
- ./
mobile_codes.install, line 160
Code
function mobile_codes_update_6200() {
// Remove 'mobile_codes' table.
db_drop_table('mobile_codes');
// Modify 'mobile_codes_presets' table and data.
db_drop_field('mobile_codes_presets', 'pid');
db_add_field('mobile_codes_presets', 'provider', array(
'type' => 'varchar',
'length' => 255,
'description' => '',
));
db_change_field('mobile_codes_presets', 'data', 'defaults', array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'serialize' => TRUE,
'description' => '',
));
$results = db_select('mobile_codes_presets', 'mcp')
->fields('mcp')
->condition('provider', NULL)
->execute();
foreach ($results as $result) {
$old = unserialize($result->defaults);
$provider = "nokia_{$old['type']}";
$name = drupal_strtolower($result->name);
$size = $old['type'] = 'qr' ? array(
's' => 2,
'm' => 4,
'l' => 6,
) : array(
's' => 0.12,
'm' => 0.18,
'l' => 0.25,
);
$defaults = serialize(array(
'size' => $size[strtolower($old['size'])],
));
db_update('mobile_codes_presets')
->fields(array(
'name' => $name,
'provider' => $provider,
'defaults' => $defaults,
))
->condition('name', $name)
->execute();
}
// Add 'mobile_codes_providers' table.
db_create_table('mobile_codes_providers', array(
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 255,
'description' => '',
),
'url' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'description' => '',
),
'parameters' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'serialize' => TRUE,
'description' => '',
),
),
'primary key' => array(
'name',
),
'unique keys' => array(
'name' => array(
'name',
),
),
));
// Delete variables.
variable_del('mobile_codes_flush');
}