context_prefix.install in Context 5
File
context_prefix/context_prefix.install
View source
<?php
function context_prefix_install() {
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
db_query("CREATE TABLE {context_prefix} (\n provider VARCHAR(255) NOT NULL,\n prefix VARCHAR(255) NOT NULL,\n id INT(10) NOT NULL,\n PRIMARY KEY (prefix)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
db_query("UPDATE {system} SET weight = -20 WHERE name = 'context_prefix'");
break;
}
}
function context_prefix_update_1() {
$items = array();
$items[] = update_sql("UPDATE {system} SET weight = -20 WHERE name = 'context_prefix'");
return $items;
}
function context_prefix_update_2() {
$items = array();
$items[] = update_sql("CREATE TABLE {context_prefix} (space VARCHAR(255) NOT NULL, path VARCHAR(255) NOT NULL, id INT(10) NOT NULL, PRIMARY KEY (path)) /*!40100 DEFAULT CHARACTER SET UTF8 */");
$paths = variable_get('context_paths', array());
if ($paths) {
foreach ($paths as $space => $p) {
foreach ($p as $path => $nid) {
db_query("REPLACE INTO {context_prefix} (space, path, id) VALUES('%s', '%s', %d)", $space, $path, $nid);
}
}
variable_del('context_paths');
}
return $items;
}
function context_prefix_update_3() {
$items = array();
$items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN space space VARCHAR(255) NOT NULL;");
$items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN path path VARCHAR(255) NOT NULL;");
$items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN id id VARCHAR(255) NOT NULL;");
return $items;
}
function context_prefix_update_4() {
$items = array();
$items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN space module VARCHAR(255) NOT NULL;");
$items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN path prefix VARCHAR(255) NOT NULL;");
return $items;
}
function context_prefix_update_5() {
$items = array();
$items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN module provider VARCHAR(255) NOT NULL;");
return $items;
}
function context_prefix_uninstall() {
db_query('DROP TABLE {context_prefix}');
}