View source
<?php
function fieldgroup_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {node_group} (\n `type_name` varchar(32) NOT NULL default '',\n `group_name` varchar(32) NOT NULL default '',\n `label` varchar(255) NOT NULL default '',\n `settings` mediumtext NOT NULL,\n `weight` tinyint(4) NOT NULL,\n PRIMARY KEY(`type_name`, `group_name`)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
db_query("CREATE TABLE {node_group_fields} (\n `type_name` varchar(32) NOT NULL default '',\n `group_name` varchar(32) NOT NULL default '',\n `field_name` varchar(32) NOT NULL default '',\n PRIMARY KEY(`type_name`, `group_name`, `field_name`)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'pgsql':
db_query("CREATE TABLE {node_group} (\n type_name varchar(32) NOT NULL default '',\n group_name varchar(32) NOT NULL default '',\n label varchar(255) NOT NULL default '',\n settings text NOT NULL,\n weight smallint NOT NULL,\n PRIMARY KEY(type_name, group_name)\n )");
db_query("CREATE TABLE {node_group_fields} (\n type_name varchar(32) NOT NULL default '',\n group_name varchar(32) NOT NULL default '',\n field_name varchar(32) NOT NULL default '',\n PRIMARY KEY(type_name, group_name, field_name)\n )");
break;
}
db_query("UPDATE {system} SET weight = 9 WHERE name = 'fieldgroup'");
}
function fieldgroup_update_1() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
$ret[] = update_sql("UPDATE {node_group} SET group_name = 'group_'||SUBSTRING(group_name FROM 7)");
$ret[] = update_sql("UPDATE {node_group_fields} SET group_name = 'group_'||SUBSTRING(group_name FROM 7)");
break;
case 'mysql':
case 'mysqli':
$ret[] = update_sql("UPDATE {node_group} SET group_name = CONCAT('group_', SUBSTRING(group_name FROM 7))");
$ret[] = update_sql("UPDATE {node_group_fields} SET group_name = CONCAT('group_', SUBSTRING(group_name FROM 7))");
break;
}
return $ret;
}
function fieldgroup_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql('ALTER TABLE {node_group} CHANGE settings settings mediumtext NOT NULL');
break;
case 'pgsql':
db_change_column($ret, 'node_group', 'settings', 'settings', 'text', array(
'not null' => TRUE,
));
break;
}
$result = db_query("SELECT * FROM {node_group}");
while ($group = db_fetch_array($result)) {
$settings = array();
$settings['form'] = unserialize($group['settings']);
$settings['form']['description'] = $group['description'];
$settings['display'] = array(
'collapsible' => 0,
'collapsed' => 0,
'description' => '',
);
$ret[] = update_sql("UPDATE {node_group} SET settings = '" . db_escape_string(serialize($settings)) . "', description = '' WHERE group_name = '" . $group['group_name'] . "'");
}
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql('ALTER TABLE {node_group} DROP description');
break;
case 'pgsql':
break;
}
return $ret;
}
function fieldgroup_update_3() {
$ret = array();
$result = db_query("SELECT * FROM {node_group}");
while ($group = db_fetch_array($result)) {
$group['settings'] = unserialize($group['settings']);
if (!isset($group['settings']['form']['style'])) {
foreach (array(
'form',
'display',
) as $context) {
if (isset($group['settings'][$context]['collapsible']) && $group['settings'][$context]['collapsible']) {
if (isset($group['settings'][$context]['collapsed']) && $group['settings'][$context]['collapsed']) {
$group['settings'][$context]['style'] = 'fieldset_collapsed';
}
else {
$group['settings'][$context]['style'] = 'fieldset_collapsible';
}
}
else {
$group['settings'][$context]['style'] = 'fieldset';
}
}
$ret[] = update_sql("UPDATE {node_group} SET settings = '" . db_escape_string(serialize($group['settings'])) . "' WHERE group_name = '" . $group['group_name'] . "'");
}
}
return $ret;
}
function fieldgroup_update_4() {
$ret = array();
$ret[] = update_sql("UPDATE {system} SET weight = 9 WHERE name = 'fieldgroup'");
return $ret;
}