View source
<?php
function mobile_codes_schema() {
$schema['mobile_codes_presets'] = array(
'export' => array(
'key' => 'name',
'key name' => 'Name',
'primary key' => 'name',
'identifier' => 'preset',
'default hook' => 'default_mobile_codes_preset',
'api' => array(
'owner' => 'mobile_codes',
'api' => 'default_mobile_codes_presets',
'minimum_version' => 2,
'current_version' => 2,
),
),
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => '',
),
'provider' => array(
'type' => 'varchar',
'length' => 255,
'description' => '',
),
'defaults' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'serialize' => TRUE,
'description' => '',
),
),
'unique keys' => array(
'name' => array(
'name',
),
),
'primary key' => array(
'name',
),
);
$schema['mobile_codes_providers'] = array(
'export' => array(
'key' => 'name',
'key name' => 'Name',
'primary key' => 'name',
'identifier' => 'provider',
'default hook' => 'default_mobile_codes_provider',
'api' => array(
'owner' => 'mobile_codes',
'api' => 'default_mobile_codes_providers',
'minimum_version' => 2,
'current_version' => 2,
),
),
'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',
),
),
);
return $schema;
}
function mobile_codes_install() {
drupal_install_schema('mobile_codes');
}
function mobile_codes_uninstall() {
drupal_uninstall_schema('mobile_codes');
variable_del('mobile_codes_block_node_url_preset');
variable_del('mobile_codes_block_user_vcard_preset');
variable_del('mobile_codes_settings');
}
function mobile_codes_update_6200() {
$ret = array();
db_drop_table($ret, 'mobile_codes');
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);
}
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',
),
),
));
variable_del('mobile_codes_flush');
return $ret;
}
function _mobile_codes_update_sql($sql) {
$args = func_get_args();
array_shift($args);
$result = db_query($sql, $args);
$sql = _mobile_codes_return_query_string($sql, $args);
return array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
'rows' => db_affected_rows(),
);
}
function _mobile_codes_return_query_string($query) {
$args = func_get_args();
array_shift($args);
$query = db_prefix_tables($query);
if (isset($args[0]) and is_array($args[0])) {
$args = $args[0];
}
_db_query_callback($args, TRUE);
$query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
return $query;
}