View source
<?php
function panels_install() {
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_query(<<<EOT
CREATE TABLE {panels_page} (
pid integer NOT NULL DEFAULT 0,
name varchar(255) UNIQUE,
did integer,
title varchar(128),
access varchar(128),
path varchar(128),
css_id varchar(128),
css text,
arguments text,
displays text,
contexts text,
relationships text,
no_blocks smallint DEFAULT 0,
switcher_type varchar(128),
switcher_name varchar(128),
switcher_options text,
-- menu fields
menu smallint DEFAULT 0,
menu_tab smallint,
menu_tab_weight smallint,
menu_title varchar(255),
menu_tab_default smallint,
menu_tab_default_parent_type varchar(10),
menu_parent_title varchar(255),
menu_parent_tab_weight smallint,
PRIMARY KEY (pid)
);
EOT
);
db_query("CREATE SEQUENCE {panels_page}_pid_seq;");
db_query("CREATE INDEX {panels_page}_path_idx ON {panels_page} (path);");
db_query("CREATE INDEX {panels_page}_name_idx ON {panels_page} (name);");
db_query(<<<EOT
CREATE TABLE {panels_display} (
did integer NOT NULL DEFAULT 0,
layout varchar(32),
layout_settings text,
panel_settings text,
cache text,
title varchar(128),
hide_title smallint DEFAULT 0,
PRIMARY KEY (did)
);
EOT
);
db_query("CREATE SEQUENCE {panels_display}_did_seq;");
db_query("CREATE INDEX {panels_display}_name_idx ON {panels_page} (name);");
db_query(<<<EOT
CREATE TABLE {panels_pane} (
pid integer NOT NULL DEFAULT 0,
did integer NOT NULL DEFAULT 0,
panel varchar(32),
type varchar(32),
subtype varchar(64),
shown smallint DEFAULT 1,
access varchar(128),
visibility text,
configuration text,
cache text,
position smallint,
PRIMARY KEY (pid)
);
EOT
);
db_query("CREATE SEQUENCE {panels_pane}_pid_seq;");
db_query("CREATE INDEX {panels_pane}_did_idx ON {panels_pane} (did);");
db_query(<<<EOT
CREATE TABLE {panels_object_cache} (
sid varchar(64),
did integer,
obj varchar(255),
timestamp integer,
data text
);
EOT
);
db_query("CREATE INDEX {panels_object_cache}_idx ON {panels_object_cache} (sid, obj, did);");
db_query("CREATE INDEX {panels_object_cache}_time_idx ON {panels_object_cache} (timestamp);");
break;
case 'mysql':
case 'mysqli':
db_query(<<<EOT
CREATE TABLE {panels_page} (
pid int(10) NOT NULL DEFAULT 0 PRIMARY KEY,
name varchar(255) UNIQUE,
did int(10),
title varchar(128),
access varchar(128),
path varchar(128),
css_id varchar(128),
css longtext,
arguments longtext,
displays longtext,
contexts longtext,
relationships longtext,
no_blocks int(1) DEFAULT 0,
switcher_type varchar(128),
switcher_name varchar(128),
switcher_options longtext,
-- menu fields
menu int(1) DEFAULT 0,
menu_tab int(1),
menu_tab_weight int(4),
menu_title varchar(255),
menu_tab_default int(1),
menu_tab_default_parent_type varchar(10),
menu_parent_title varchar(255),
menu_parent_tab_weight int(4),
KEY path (path)
)/*!40100 DEFAULT CHARACTER SET utf8 */
EOT
);
db_query(<<<EOT
CREATE TABLE {panels_display} (
did INT(10) NOT NULL DEFAULT 0 PRIMARY KEY,
layout varchar(32),
layout_settings longtext,
panel_settings longtext,
cache text,
title varchar(128),
hide_title int(1) DEFAULT 0
) /*!40100 DEFAULT CHARACTER SET utf8 */
EOT
);
db_query(<<<EOT
CREATE TABLE {panels_pane} (
pid int(10) NOT NULL DEFAULT 0 PRIMARY KEY,
did int(10) NOT NULL DEFAULT 0,
panel varchar(32),
type varchar(32),
subtype varchar(64),
shown int(1) DEFAULT 1,
access varchar(128),
visibility text,
configuration longtext,
cache longtext,
position int(5),
KEY (did)
) /*!40100 DEFAULT CHARACTER SET utf8 */
EOT
);
db_query(<<<EOT
CREATE TABLE {panels_object_cache} (
sid varchar(64),
did integer,
obj varchar(255),
data longtext,
timestamp integer,
KEY (sid, obj, did),
KEY (timestamp)
) /*!40100 DEFAULT CHARACTER SET utf8 */
EOT
);
}
db_query("UPDATE {system} SET weight = 10 WHERE name = 'panels'");
if (!module_exists('panels_page')) {
$panels_path = base_path() . drupal_get_path('module', 'panels');
drupal_set_message(t('If you have not already enabled the Panel pages module, you are encouraged to do so.'));
}
}
function panels_uninstall() {
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_query("DROP SEQUENCE {panels_page}_pid_seq");
db_query("DROP SEQUENCE {panels_pane}_pid_seq");
db_query("DROP SEQUENCE {panels_display}_did_seq");
db_query("DROP TABLE {panels_display}");
db_query("DROP TABLE {panels_pane}");
db_query("DROP TABLE {panels_page}");
db_query("DROP TABLE {panels_object_cache}");
break;
case 'mysql':
case 'mysqli':
db_query("DROP TABLE IF EXISTS {panels_display}");
db_query("DROP TABLE IF EXISTS {panels_pane}");
db_query("DROP TABLE IF EXISTS {panels_page}");
db_query("DROP TABLE IF EXISTS {panels_object_cache}");
break;
}
}
function panels_update_1() {
return _system_update_utf8(array(
'panels_info',
'panels_area',
));
}
function panels_update_1000() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_info} RENAME {panels_page}");
$ret[] = update_sql("ALTER TABLE {panels_page} CHANGE COLUMN did pid int(10) NOT NULL DEFAULT 0;");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN did int(10) NOT NULL DEFAULT 0 AFTER pid");
$ret[] = update_sql("UPDATE {panels_page} SET did = pid");
$max_pid = db_result(db_query("SELECT MAX(pid) FROM {panels_page}"));
if ($max_pid) {
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_page}_pid', {$max_pid})");
}
$ret[] = update_sql("ALTER TABLE {panels_area} RENAME {panels_pane}");
$ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN pid int(10) NOT NULL DEFAULT 0 FIRST");
$ret[] = update_sql("ALTER TABLE {panels_pane} CHANGE area panel varchar(32)");
$result = db_query("SELECT * FROM {panels_pane}");
while ($pane = db_fetch_object($result)) {
$count++;
$ret[] = update_sql("UPDATE {panels_pane} SET pid = {$count} WHERE did = {$pane->did} AND panel = '{$pane->panel}' AND position = {$pane->position}");
}
if ($count) {
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_pane}_pid', {$count})");
}
$ret[] = update_sql(<<<EOT
CREATE TABLE {panels_display} (
did INT(10) NOT NULL DEFAULT 0 PRIMARY KEY,
layout VARCHAR(32)
) /*!40100 DEFAULT CHARACTER SET utf8 */
EOT
);
$result = db_query("SELECT did, layout FROM {panels_page}");
$max_did = 0;
while ($display = db_fetch_object($result)) {
$ret[] = update_sql("INSERT INTO {panels_display} VALUES ({$display->did}, '{$display->layout}')");
if ($display->did > $max_did) {
$max_did = $display->did;
}
}
$ret[] = update_sql("ALTER TABLE {panels_page} DROP COLUMN layout");
if ($max_did) {
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_display}_did', {$max_did})");
}
return $ret;
}
function panels_update_1001() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN no_blocks int(1)");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu int(1) DEFAULT 0");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab int(1)");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_weight int(4)");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_title varchar(255)");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_default int(1)");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_default_parent_type varchar(10)");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_parent_title varchar(255)");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_parent_tab_weight int(4)");
return $ret;
}
function panels_update_1002() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN layout_settings longtext");
$ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN access varchar(128) AFTER type");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN css longtext AFTER css_id");
return $ret;
}
function panels_update_1003() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN panel_settings longtext");
return $ret;
}
function panels_update_5204() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN name varchar(255) UNIQUE");
$ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN name varchar(255) UNIQUE");
$ret[] = update_sql("UPDATE {panels_page} SET name = CONCAT('panel_page_', pid)");
$ret[] = update_sql("UPDATE {panels_display} SET name = CONCAT('display_', did)");
return $ret;
}
function panels_update_5205() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN arguments longtext");
return $ret;
}
function panels_update_5206() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN subtype varchar(64)");
return $ret;
}
function panels_update_5207() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN displays longtext");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN contexts longtext");
return $ret;
}
function panels_update_5208() {
$ret = array();
$count = db_result(db_query("SELECT MAX(did) FROM {panels_display}"));
$ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{panels_display}_did'");
$ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{panels_display}_id'");
if ($count) {
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_display}_did',\n {$count})");
}
return $ret;
}
function panels_update_5209() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN relationships longtext");
$result = db_query("SELECT * FROM {panels_page}");
panels_load_include('plugins');
while ($page = db_fetch_object($result)) {
$args = unserialize($page->arguments);
$arguments = $ids = $keywords = array();
if (!empty($args)) {
foreach ($args as $id => $argument) {
$name = $argument['name'];
$info = panels_get_argument($name);
if (!$info) {
continue;
}
if (empty($argument['id'])) {
if (empty($ids[$name])) {
$ids[$name] = 1;
}
else {
$ids[$name]++;
}
$argument['id'] = $ids[$name];
}
if (empty($argument['identifier'])) {
$argument['identifier'] = $info['title'] . ($id > 1 ? ' ' . $id : '');
error_log($argument['identifier']);
}
if (empty($argument['keyword'])) {
$keyword = $base = $info['keyword'];
$count = 0;
while (!empty($keywords[$keyword])) {
$keyword = $base . '_' . ++$count;
}
$keywords[$keyword] = TRUE;
$argument['keyword'] = $keyword;
error_log($argument['keyword']);
}
$arguments[$id] = $argument;
}
}
$rels = unserialize($page->contexts);
$relationships = $ids = array();
if (!empty($rels)) {
foreach ($rels as $id => $relationship) {
$name = $relationship['name'];
$info = panels_get_relationship($name);
if (!$info) {
continue;
}
if (empty($relationship['id'])) {
if (empty($ids[$name])) {
$ids[$name] = 1;
}
else {
$ids[$name]++;
}
$relationship['id'] = $ids[$name];
}
if (empty($relationship['identifier'])) {
$relationship['identifier'] = $info['title'] . ($id > 1 ? ' ' . $id : '');
}
if (empty($relationship['keyword'])) {
$keyword = $base = $info['keyword'];
$count = 0;
while (!empty($keywords[$keyword])) {
$keyword = $base . '_' . ++$count;
}
$keywords[$keyword] = TRUE;
$relationship['keyword'] = $keyword;
}
$relationships[$id] = $relationship;
}
}
db_query("UPDATE {panels_page} " . "SET arguments = '%s', " . "relationships = '%s', " . "contexts = '%s' " . "WHERE pid = {$page->pid}", serialize($arguments), serialize($relationships), serialize(array()), $page->pid);
}
return $ret;
}
function panels_update_5210() {
$ret = array();
$ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'panels'");
return $ret;
}
function panels_update_5211() {
menu_rebuild();
return array();
}
function panels_update_5212() {
$ret = array();
$ret[] = update_sql("CREATE INDEX {panels_page}_name_idx ON {panels_page} (name)");
return $ret;
}
function panels_update_5213() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN cache longtext AFTER configuration");
$ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN cache longtext AFTER panel_settings");
break;
case 'pgsql':
db_add_column($ret, 'panels_pane', 'cache', 'text');
db_add_column($ret, 'panels_display', 'cache', 'text');
}
return $ret;
}
function panels_update_5214() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql(<<<EOT
CREATE TABLE {panels_object_cache} (
sid varchar(64),
did integer,
obj varchar(255),
timestamp integer,
data text,
KEY (sid, obj, did),
KEY (timestamp)
) /*!40100 DEFAULT CHARACTER SET utf8 */
EOT
);
case 'pgsql':
}
return !empty($ret) ? $ret : $ret;
}
function panels_update_5215() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {panels_object_cache} CHANGE COLUMN data data longtext");
$ret[] = update_sql("ALTER TABLE {panels_page} DROP INDEX name_2");
$ret[] = update_sql("ALTER TABLE {panels_object_cache} DROP INDEX {panels_object_cache}_idx");
$ret[] = update_sql("ALTER TABLE {panels_pane} ADD PRIMARY KEY (pid)");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {panels_pane} ADD PRIMARY KEY (pid)");
}
return $ret;
}
function panels_update_5216() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN shown int(1) DEFAULT 1 AFTER subtype");
$ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN title varchar(128) AFTER cache");
$ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN hide_title int(1) AFTER title");
$ret[] = update_sql("ALTER TABLE {panels_display} DROP COLUMN name");
$ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN visibility text AFTER access");
break;
case 'pgsql':
db_add_column($ret, 'panels_pane', 'shown', 'tinyint', array(
'default' => 1,
));
db_add_column($ret, 'panels_display', 'title', 'varchar(128)');
db_add_column($ret, 'panels_display', 'hide_title', 'tinyint', array(
'default' => 0,
));
$ret = update_sql("ALTER TABLE {panels_display} DROP name");
db_add_column($ret, 'panels_pane', 'visibility', 'text');
}
return $ret;
}
function panels_update_5217() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_type varchar(128) AFTER no_blocks");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_name varchar(128) AFTER no_blocks");
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_options longtext AFTER switcher_type");
break;
case 'pgsql':
db_add_column($ret, 'panels_page', 'switcher_type', 'varchar(128)');
db_add_column($ret, 'panels_page', 'switcher_name', 'varchar(128)');
db_add_column($ret, 'panels_page', 'switcher_options', 'text');
}
return $ret;
}
function panels_update_5218() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = array(
'success' => TRUE,
'query' => t('Update #5218 only has changes for PostgreSQL. There are no updates for MySQL databases - since you\'re running MySQL, you should consider this update successful.'),
);
break;
case 'pgsql':
db_add_column($ret, 'panels_pane', 'shown', 'smallint', array(
'default' => 1,
));
db_add_column($ret, 'panels_display', 'hide_title', 'smallint', array(
'default' => 0,
));
$ret[] = array(
'success' => TRUE,
'query' => t('You can disregard failed attempts to add new columns in update #5216 as long as the two queries preceding this text were successful.'),
);
}
return $ret;
}
function panels_update_5219() {
$ret = array();
$ret[] = array(
'success' => TRUE,
'query' => t('You are strongly encouraged to re-export any panels generated with a version of Panels prior to Release Candidate 2, as several fields were (incorrectly) being ommitted from all exports, and this updater is unable to update any panels already exported with missing fields.'),
);
return $ret;
}