Newer
Older
Karen Stevenson
committed
/**
Karen Stevenson
committed
* Implementation of hook_install().
*/
function fieldgroup_install() {
Yves Chedemois
committed
drupal_load('module', 'content');
Yves Chedemois
committed
db_query("UPDATE {system} SET weight = 9 WHERE name = 'fieldgroup'");
Yves Chedemois
committed
drupal_install_schema('fieldgroup');
Karen Stevenson
committed
content_notify('install', 'fieldgroup');
variable_set('fieldgroup_schema_version', 6000);
Karen Stevenson
committed
}
/**
* Implementation of hook_uninstall().
*/
function fieldgroup_uninstall() {
Yves Chedemois
committed
drupal_load('module', 'content');
Karen Stevenson
committed
drupal_uninstall_schema('fieldgroup');
Karen Stevenson
committed
content_notify('uninstall', 'fieldgroup');
Karen Stevenson
committed
}
/**
* Implementation of hook_enable().
*
* Notify content module when this module is enabled.
*/
function fieldgroup_enable() {
Yves Chedemois
committed
drupal_load('module', 'content');
content_notify('enable', 'fieldgroup');
}
/**
* Implementation of hook_disable().
*
* Notify content module when this module is disabled.
*/
function fieldgroup_disable() {
Yves Chedemois
committed
drupal_load('module', 'content');
content_notify('disable', 'fieldgroup');
}
/**
* Implementation of hook_schema.
*/
function fieldgroup_schema() {
Karen Stevenson
committed
$schema['content_group'] = array(
'group_type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => 'standard'),
'type_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
'group_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
'label' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'settings' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE),
'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
),
'primary key' => array('type_name', 'group_name'),
);
Karen Stevenson
committed
$schema['content_group_fields'] = array(
'fields' => array(
'type_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
'group_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
'field_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
),
'primary key' => array('type_name', 'group_name', 'field_name'),
);
return $schema;
}
Karen Stevenson
committed
Karen Stevenson
committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* rename groups form "group-*" to "group_*"
*/
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;
}
/**
* add display settings for the group
*/
function fieldgroup_update_2() {
$ret = array();
// set settings column to accept larger values
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;
}
// move description into the settings array, and add new settings
$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'] ."'");
}
// drop description column
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql('ALTER TABLE {node_group} DROP description');
break;
case 'pgsql':
// Postgres only supports dropping of columns since 7.4
break;
}
return $ret;
}
/**
* converts group settings collapsible/collapsed => style
*/
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;
}
/*
* Increases module weight, so that other modules can form_alter() cck forms before the fields
* are moved in groups
*/
function fieldgroup_update_4() {
$ret = array();
$ret[] = update_sql("UPDATE {system} SET weight = 9 WHERE name = 'fieldgroup'");
return $ret;
}
Yves Chedemois
committed
Yves Chedemois
committed
* Start D6 upgrades
*/
/**
* Move fieldgroup tables to the content_* namespace.
Karen Stevenson
committed
function fieldgroup_update_6000() {
Yves Chedemois
committed
if ($abort = content_check_update('fieldgroup')) {
return $abort;
Yves Chedemois
committed
}
Yves Chedemois
committed
$ret = array();
Yves Chedemois
committed
db_rename_table($ret, 'node_group', 'content_group');
db_rename_table($ret, 'node_group_fields', 'content_group_fields');
variable_set('fieldgroup_schema_version', 6000);
Karen Stevenson
committed
return $ret;
Yves Chedemois
committed
}
/*
* Increases module weight, so that other modules can form_alter() cck forms before the fields
* are moved in groups.
*
* Sites upgraded from D5 should have this already set.
* New D6 installs earlier than RC5 need this, as it was missing in fieldgroup_install.
*/
function fieldgroup_update_6001() {
Yves Chedemois
committed
if ($abort = content_check_update('fieldgroup')) {
return $abort;
}
Yves Chedemois
committed
$ret = array();
$ret[] = update_sql("UPDATE {system} SET weight = 9 WHERE name = 'fieldgroup'");
return $ret;
}
Yves Chedemois
committed
/**
* Same as 6000 : Move fieldgroup tables to the content_* namespace.
* This was missing in D6 releases earlier than RC5. Ensure we don't run this twice.
*/
function fieldgroup_update_6002() {
Yves Chedemois
committed
if ($abort = content_check_update('fieldgroup')) {
return $abort;
}
Yves Chedemois
committed
$ret = array();
if (db_table_exists('node_group')) {
db_rename_table($ret, 'node_group', 'content_group');
db_rename_table($ret, 'node_group_fields', 'content_group_fields');
variable_set('fieldgroup_schema_version', 6000);
Yves Chedemois
committed
}
return $ret;
}
/**
* Remove tinyint (127) limitation on group weights.
*/
function fieldgroup_update_6003() {
Yves Chedemois
committed
if ($abort = content_check_update('fieldgroup')) {
return $abort;
}
$ret = array();
db_change_field($ret, 'content_group', 'weight', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
return $ret;
}
/**
* Add 'type' property for fieldgroups.
*/
function fieldgroup_update_6004() {
Yves Chedemois
committed
if ($abort = content_check_update('fieldgroup')) {
return $abort;
}
$ret = array();
db_add_field($ret, 'content_group', 'group_type', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => 'standard'));
Karen Stevenson
committed
$ret[] = update_sql("DELETE FROM {cache_content} WHERE cid='fieldgroup_data'");
return $ret;
}