View source
<?php
function panels_mini_install() {
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_query(<<<EOT
CREATE TABLE {panels_mini} (
pid integer NOT NULL DEFAULT 0,
name varchar(255) UNIQUE,
category varchar(64),
did integer,
title varchar(128),
requiredcontexts text,
contexts text,
relationships text,
PRIMARY KEY (pid)
);
EOT
);
db_query("CREATE SEQUENCE {panels_mini}_pid_seq;");
db_query("CREATE INDEX {panels_mini}_name_idx ON {panels_mini} (name);");
break;
case 'mysql':
case 'mysqli':
db_query(<<<EOT
CREATE TABLE {panels_mini} (
pid int(10) NOT NULL DEFAULT 0 PRIMARY KEY,
name varchar(255) UNIQUE,
category varchar(64),
did int(10),
title varchar(128),
contexts longtext,
requiredcontexts longtext,
relationships longtext,
KEY (name)
) /*!40100 DEFAULT CHARACTER SET utf8 */
EOT
);
break;
}
}
function panels_mini_uninstall() {
$result = db_query("SELECT * FROM {panels_mini} ORDER BY title");
$panels_exists = db_table_exists('panels_display');
while ($panel_mini = db_fetch_object($result)) {
if (!function_exists('panels_delete_display')) {
require_once drupal_get_path('module', 'panels') . '/panels.module';
}
if ($panels_exists) {
panels_delete_display($panel_mini->did);
}
db_query("DELETE FROM {blocks} WHERE module = 'panels_mini' AND delta = %d", $panel_mini->pid);
}
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_query("DROP TABLE {panels_mini}");
db_query("DROP SEQUENCE {panels_mini}_pid_seq");
break;
case 'mysql':
case 'mysqli':
db_query("DROP TABLE IF EXISTS {panels_mini}");
break;
}
}
function panels_mini_update_5000() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_add_column($ret, 'panels_mini', 'relationships', 'text', array());
db_add_column($ret, 'panels_mini', 'contexts', 'text', array());
db_add_column($ret, 'panels_mini', 'name', 'varchar(255) UNIQUE', array());
break;
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {panels_mini} ADD COLUMN relationships longtext");
$ret[] = update_sql("ALTER TABLE {panels_mini} ADD COLUMN contexts longtext");
$ret[] = update_sql("ALTER TABLE {panels_mini} ADD COLUMN name varchar(255) UNIQUE AFTER pid");
break;
}
$ret[] = update_sql("CREATE INDEX {panels_mini}_name_idx ON {panels_mini} (name)");
$ret[] = update_sql("UPDATE {panels_mini} SET name = CONCAT('mini_', pid)");
$ret[] = update_sql("UPDATE {blocks} b INNER JOIN {panels_mini} pm on pm.pid = b.delta SET b.delta = pm.name WHERE b.module = 'panels_mini'");
$pids = array();
$result = db_query("SELECT pid, name FROM {panels_mini}");
while ($mini = db_fetch_object($result)) {
$pids[$mini->pid] = $mini->name;
}
$result = db_query("SELECT * FROM {panels_pane} WHERE configuration LIKE '%panels_mini%' AND type = 'block'");
while ($pane = db_fetch_object($result)) {
$conf = unserialize($pane->configuration);
if (empty($conf['module']) || $conf['module'] != 'panels_mini') {
continue;
}
unset($conf['module']);
$conf['name'] = $pids[$conf['delta']];
unset($conf['delta']);
db_query("UPDATE {panels_pane} SET type = 'panels_mini', configuration = '%s', subtype = '%s' WHERE pid = %d", serialize($conf), $conf['name'], $pane->pid);
}
return $ret;
}
function panels_mini_update_5001() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_add_column($ret, 'panels_mini', 'requiredcontexts', 'text', array());
break;
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {panels_mini} ADD COLUMN requiredcontexts longtext");
}
return $ret;
}
function panels_mini_update_5002() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = array(
'success' => TRUE,
'query' => t('It does NOT matter if the following query fails. If it fails, it means you did not have a duplicate \'name_2\' index, and trying to remove a non-existent index does not harm, alter, or otherwise affect your database in any way. If it succeeds, then the duplicate index is gone, and your table is as it should be.'),
);
$ret[] = update_sql("ALTER TABLE {panels_mini} DROP INDEX name_2");
}
return $ret;
}
function panels_mini_update_5003() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_add_column($ret, 'panels_mini', 'category', 'varchar(64)', array());
break;
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {panels_mini} ADD COLUMN category varchar(64) AFTER name");
}
return $ret;
}