View source
<?php
function context_ui_install() {
}
function context_ui_uninstall() {
drupal_uninstall_schema('context_ui');
}
function context_ui_schema() {
$schema['context_ui'] = array(
'description' => t('context_ui.'),
'fields' => array(
'cid' => array(
'description' => t('The primary identifier for a context.'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'namespace' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'attribute' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
),
'unique keys' => array(
'key1' => array(
'namespace',
'attribute',
'value',
),
),
'primary key' => array(
'cid',
),
);
$schema['context_ui_setter'] = array(
'description' => t('context_ui_setter.'),
'fields' => array(
'type' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'id' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'cid' => array(
'description' => t('?'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'key1' => array(
'type',
'id',
'cid',
),
),
);
$schema['context_ui_getter'] = array(
'description' => t('context_ui_getter.'),
'fields' => array(
'type' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'data' => array(
'description' => t('?'),
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
'default' => '',
),
'cid' => array(
'description' => t('?'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'key1' => array(
'type',
'cid',
),
),
);
$schema['context_ui_block'] = array(
'description' => t('context_ui_block.'),
'fields' => array(
'module' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'delta' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'region' => array(
'description' => t('?'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'weight' => array(
'description' => t('?'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'cid' => array(
'description' => t('?'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'key1' => array(
'module',
'delta',
'region',
'cid',
),
),
);
return $schema;
}
function context_ui_update_1() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {context_ui} CHANGE COLUMN space namespace VARCHAR(64) NOT NULL");
$ret[] = update_sql("ALTER TABLE {context_ui} CHANGE COLUMN ckey attribute VARCHAR(64) NOT NULL");
break;
}
return $ret;
}
function context_ui_update_6001() {
$ret = array();
if (!db_table_exists('context_ui_getter')) {
$schema = context_ui_schema();
db_create_table($ret, 'context_ui_getter', $schema['context_ui_getter']);
$result = db_query("SELECT * FROM {context_ui_item} WHERE type IN ('menu', 'css_injector')");
while ($row = db_fetch_object($result)) {
$row->data = $row->id;
unset($row->id);
drupal_write_record('context_ui_getter', $row);
}
$ret[] = update_sql("DELETE FROM {context_ui_item} WHERE type IN ('menu', 'css_injector')");
db_rename_table($ret, 'context_ui_item', 'context_ui_setter');
db_drop_unique_key($ret, 'context_ui_setter', 'key1');
_db_create_keys_sql(array(
'unique keys' => $schema['context_ui_setter']['unique keys'],
));
db_drop_primary_key($ret, 'context_ui');
db_change_field($ret, 'context_ui', 'cid', 'cid', $schema['context_ui']['fields']['cid'], array(
'primary key' => $schema['context_ui']['primary key'],
));
db_drop_unique_key($ret, 'context_ui', 'key1');
db_change_field($ret, 'context_ui', 'status', 'status', $schema['context_ui']['fields']['status'], array(
'unique keys' => $schema['context_ui']['unique keys'],
));
}
return $ret;
}
function context_ui_update_6002() {
$ret = array();
$result = db_query("SELECT cid FROM {context_ui} WHERE system = 1");
$cids = array();
while ($row = db_fetch_object($result)) {
$cids[] = $row->cid;
}
$cids = implode(',', $cids);
if ($cids != '') {
$ret[] = update_sql("DELETE FROM {context_ui} WHERE cid IN ({$cids})");
$ret[] = update_sql("DELETE FROM {context_ui_setter} WHERE cid IN ({$cids})");
$ret[] = update_sql("DELETE FROM {context_ui_getter} WHERE cid IN ({$cids})");
$ret[] = update_sql("DELETE FROM {context_ui_block} WHERE cid IN ({$cids})");
}
db_drop_field($ret, 'context_ui', 'system');
db_drop_field($ret, 'context_ui', 'status');
$schema = context_ui_schema();
db_drop_unique_key($ret, 'context_ui', 'key1');
db_add_unique_key($ret, 'context_ui', 'key1', $schema['context_ui']['unique keys']['key1']);
return $ret;
}
function context_ui_update_6003() {
$statuses = variable_get('context_status', array());
$new_statuses = array();
foreach ($statuses as $key => $status) {
$new_statuses[str_replace(':', '-', $key)] = $status;
}
variable_set('context_status', $new_statuses);
context_ui_invalidate_cache();
return array();
}