You are here

function mobile_codes_update_6200 in Mobile Codes 6.2

Same name and namespace in other branches
  1. 7.2 mobile_codes.install \mobile_codes_update_6200()

Implements hook_update_N().

File

./mobile_codes.install, line 114

Code

function mobile_codes_update_6200() {
  $ret = array();

  // Remove 'mobile_codes' table.
  db_drop_table($ret, 'mobile_codes');

  // Modify 'mobile_codes_presets' table and data.
  db_drop_field($ret, 'mobile_codes_presets', 'pid');
  db_add_field($ret, 'mobile_codes_presets', 'provider', array(
    'type' => 'varchar',
    'length' => 255,
    'description' => '',
  ));
  db_change_field($ret, 'mobile_codes_presets', 'data', 'defaults', array(
    'type' => 'text',
    'size' => 'medium',
    'not null' => TRUE,
    'serialize' => TRUE,
    'description' => '',
  ));
  $results = db_query('SELECT * FROM {mobile_codes_presets} WHERE provider IS NULL');
  while ($result = db_fetch_object($results)) {
    $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'])],
    ));
    $ret[] = _mobile_codes_update_sql("UPDATE {mobile_codes_presets} SET name = '{$name}', provider = '{$provider}', defaults = '%s' WHERE name = '{$result->name}'", $defaults);
  }

  // Add 'mobile_codes_providers' table.
  db_create_table($ret, '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');
  return $ret;
}