View source
<?php
function og_subgroups_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {og_subgroups} (\n gid int(11) NOT NULL,\n parent int(11) NOT NULL,\n PRIMARY KEY (gid, parent)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {og_subgroups} (\n gid int NOT NULL,\n parent int NOT NULL,\n PRIMARY KEY (gid, parent));");
db_query("CREATE INDEX {og_subgroups}_gid_idx ON {og_subgroups} (gid);");
db_query("CREATE INDEX {og_subgroups}_parent_idx ON {og_subgroups} (parent);");
break;
}
$ret = og_subgroups_migrate();
drupal_set_message($ret['query']);
}
function og_subgroups_uninstall() {
db_query('DROP TABLE {og_subgroups}');
$variables = array(
'og_subgroups_propagate_content',
'og_subgroups_propagate_members',
'og_subgroups_propagate_demote',
);
foreach ($variables as $variable) {
variable_del($variable);
}
}
function og_subgroups_migrate($clean_only = FALSE) {
$all_groups = db_query("SELECT oga.nid AS gid, oga.group_nid AS parent FROM {og_ancestry} oga INNER JOIN {og} og ON og.nid = oga.nid");
$migrate = FALSE;
while ($group = db_fetch_object($all_groups)) {
$migrate = TRUE;
if (!$clean_only) {
db_query('INSERT INTO {og_subgroups} (gid, parent) VALUES (%d, %d)', $group->gid, $group->parent);
}
db_query('DELETE FROM {og_ancestry} WHERE nid = %d AND group_nid = %d', $group->gid, $group->parent);
}
if ($migrate) {
$ret = array(
'query' => t('Groups from versions prior to 5.x-4 were migrated, and old records from the {og_ancestry} were removed.'),
'success' => TRUE,
);
}
else {
$ret = array(
'query' => t('OG Subgroups didn\'t migrate older records from {og_ancestry} since there were none.'),
'success' => TRUE,
);
}
return $ret;
}
function og_subgroups_update_1() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {og_subgroups} (\n gid int(11) NOT NULL,\n parent int(11) NOT NULL,\n PRIMARY KEY (gid, parent)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {og_subgroups} (\n gid int NOT NULL,\n parent int NOT NULL,\n PRIMARY KEY (gid, parent));");
db_query("CREATE INDEX {og_subgroups}_gid_idx ON {og_subgroups} (gid);");
db_query("CREATE INDEX {og_subgroups}_parent_idx ON {og_subgroups} (parent);");
break;
}
$ret[] = array(
'query' => t('{og_subgroups} table was installed.'),
'success' => TRUE,
);
$ret[] = og_subgroups_migrate();
return $ret;
}
function og_subgroups_update_2() {
$ret = array();
$ret[] = og_subgroups_migrate(TRUE);
return $ret;
}