View source
<?php
function og_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {og} (\n nid int(11) NOT NULL,\n selective int(11) NOT NULL default '0',\n description varchar(255) NULL,\n theme varchar(255) NULL,\n register int(1) NOT NULL default 0,\n directory int(1) NOT NULL default 0,\n notification int(1) NOT NULL default 0,\n language varchar(12) NOT NULL default '',\n private int(1) NOT NULL default 0,\n PRIMARY KEY (nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {og_uid} (\n nid int(11) NOT NULL,\n og_role int(1) NOT NULL DEFAULT 0,\n is_active int(1) NOT NULL DEFAULT 0,\n is_admin int(1) NOT NULL DEFAULT 0,\n uid int(11) NOT NULL,\n mail_type int(11) NULL,\n \tcreated int(11) NULL DEFAULT 0,\n \tchanged int(11) NULL DEFAULT 0,\n PRIMARY KEY (nid, uid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {og_uid_global} (\n uid int(11) NOT NULL,\n og_email int(11) NOT NULL DEFAULT 2,\n PRIMARY KEY (uid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {og_ancestry} (\n nid int(11) NOT NULL,\n group_nid int(11) NOT NULL,\n is_public int(1) NOT NULL,\n KEY (nid),\n KEY (group_nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {og} (\n nid int NOT NULL,\n selective int NOT NULL default 0,\n description varchar(255) NULL,\n theme varchar(255) NULL,\n website varchar(255) NULL,\n register smallint NOT NULL default 0,\n directory smallint NOT NULL default 0,\n notification smallint NOT NULL default 0,\n language varchar(12) NOT NULL default '',\n private smallint NOT NULL default 0, \n PRIMARY KEY (nid)\n );");
db_query("CREATE TABLE {og_uid} (\n nid int NOT NULL,\n og_role smallint NOT NULL DEFAULT 0,\n is_active smallint NOT NULL DEFAULT 0,\n is_admin smallint NOT NULL DEFAULT 0,\n uid int NOT NULL,\n mail_type int NULL,\n\t created int NULL DEFAULT 0,\n\t changed int NULL DEFAULT 0,\n PRIMARY KEY (nid, uid)\n );");
db_query("CREATE TABLE {og_uid_global} (\n uid int NOT NULL,\n og_email int NOT NULL DEFAULT 2,\n PRIMARY KEY (uid)\n );");
db_query("\n CREATE TABLE {og_ancestry} (\n nid int NOT NULL,\n group_nid int NOT NULL,\n is_public smallint NOT NULL\n );");
db_query("CREATE INDEX {og_ancestry}_nid_idx ON {og_ancestry} (nid);");
db_query("CREATE INDEX {og_ancestry}_group_nid_idx ON {og_ancestry} (group_nid);");
break;
}
if (function_exists('block_rehash')) {
_block_rehash();
}
drupal_load('module', 'og');
drupal_set_message(t('Organic groups module enabled. Please see the included !README file for further installation instructions.', array(
'!README' => og_readme(),
)));
}
function og_deleteifpresent_2keys($sTable, $aField, $aReplace, $aValue) {
$sqlExist = "select count(*) as nCount " . "from " . $sTable . " where " . $aField[0] . " = " . $aReplace[0] . " and " . $aField[1] . " = " . $aReplace[1];
$resExist = db_query($sqlExist, $aValue[0], $aValue[1]);
$objExist = db_fetch_object($resExist);
if ($objExist->nCount > 0) {
$sqlExist = "delete from " . $sTable . " where " . $aField[0] . " = " . $aReplace[0] . " and " . $aField[1] . " = " . $aReplace[1];
db_query($sql, $aValue[0], $aValue[1]);
}
}
function og_update_1() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("ALTER TABLE {og_uid} ADD `og_role` int(1) NOT NULL default '0'");
db_query("ALTER TABLE {og_uid} ADD `is_active` int(1) default '0'");
db_query("ALTER TABLE {og_uid} ADD `is_admin` int(1) default '0'");
break;
case 'pgsql':
db_query("ALTER TABLE {og_uid} ADD `og_role` smallint NOT NULL default 0");
db_query("ALTER TABLE {og_uid} ADD `is_active` smallint default 0");
db_query("ALTER TABLE {og_uid} ADD `is_admin` smallint default 0");
break;
}
$result = db_query("SELECT * FROM {node_access} WHERE realm = 'og_uid'");
while ($object = db_fetch_object($result)) {
og_deleteifpresent_2keys('og_uid', array(
'nid',
'gid',
), array(
'%d',
'%d',
), array(
$object->nid,
$object->gid,
));
$sql = "INSERT INTO {og_uid} (nid, uid, og_role, is_admin, is_active) VALUES (%d, %d, %d, %d, %d)";
db_query($sql, $object->nid, $object->gid, $object->grant_view + $object->grant_update, $object->grant_update, $object->grant_view);
}
$sql = "DELETE FROM {node_access} WHERE realm = 'og_uid'";
db_query($sql);
return array();
}
function og_update_2() {
return _system_update_utf8(array(
'og',
'og_uid',
));
}
function og_update_3() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$sql = "DELETE FROM {node_access} WHERE realm = 'og_uid'";
db_query($sql);
$sql = "SELECT DISTINCT(n.nid) FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid WHERE type != 'og' AND na.realm = 'og_group'";
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
$sql = "UPDATE {node_access} SET grant_view=1, grant_update=1, grant_delete=1 WHERE realm = 'og_group' AND nid = %d AND gid != 0";
db_query($sql, $row->nid);
}
$sql = "SELECT nid FROM {node} WHERE type = 'og'";
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
og_deleteifpresent_2keys('node_access', array(
'nid',
'gid',
), array(
'%d',
'%d',
), array(
$object->nid,
$object->gid,
));
$sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, 'og_group', 1, 1, 0)";
db_query($sql, $row->nid, $row->nid);
}
}
return array();
}
function og_update_4() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql('ALTER TABLE {node_access} DROP PRIMARY KEY, ADD INDEX nid_gid_realm (nid, gid, realm)');
}
return $ret ? $ret : array();
}
function og_update_5() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$sql = "SELECT DISTINCT(nid) as nid FROM {node_access} WHERE realm = 'og_group' AND gid = 0";
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
$sql = "SELECT gid FROM {node_access} WHERE nid = %d AND realm = 'og_group' AND gid != 0";
$result2 = db_query($sql, $row->nid);
while ($row2 = db_fetch_object($result2)) {
og_deleteifpresent_2keys('node_access', array(
'nid',
'gid',
), array(
'%d',
'%d',
), array(
$row->nid,
$row->gid,
));
$sql = "INSERT INTO {node_access} (nid, realm, gid, grant_view) VALUES (%d, 'og_public', 0, %d)";
db_query($sql, $row->nid, $row2->gid);
}
}
$sql = "UPDATE {node_access} SET realm = 'og_all' WHERE realm = 'og_group' AND gid = 0 AND grant_view = 1";
db_query($sql);
$sql = "UPDATE {node_access} SET realm = 'og_subscriber' WHERE realm = 'og_group' AND gid != 0";
db_query($sql);
$sql = "DELETE FROM {node_access} WHERE realm = 'og_group'";
db_query($sql);
}
return array();
}
function og_update_6() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql('ALTER TABLE {og} ADD website varchar(255) NULL AFTER theme');
}
return $ret ? $ret : array();
}
function og_update_7() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {node_access} CHANGE grant_view grant_view int(11) unsigned NOT NULL default '0'");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {node_access} " . "ALTER COLUMN grant_view TYPE int, " . "ALTER COLUMN grant_view SET NOT NULL, " . "ALTER COLUMN grant_view SET DEFAULT 0;");
break;
}
return $ret ? $ret : array();
}
function og_update_8() {
return array();
}
function og_update_9() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {og} ADD language varchar(12) NOT NULL default ''");
}
return $ret ? $ret : array();
}
function og_update_10() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {og_uid} ADD created int(11) NULL DEFAULT 0");
$ret[] = update_sql("ALTER TABLE {og_uid} ADD changed int(11) NULL DEFAULT 0");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {og_uid} ADD COLUMN created int NULL DEFAULT 0");
$ret[] = update_sql("ALTER TABLE {og_uid} ADD COLUMN changed int NULL DEFAULT 0");
break;
}
return $ret ? $ret : array();
}
function og_update_11() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {og} ADD notification int(1) NOT NULL default 0");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {og} ADD COLUMN notification smallint NOT NULL default 0");
break;
}
return $ret ? $ret : array();
}
function og_update_12() {
$ret[] = update_sql("ALTER TABLE {og} DROP image");
return $ret;
}
function og_update_13() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {og_uid_global} (\n uid int(11) NOT NULL,\n og_email int(11) NOT NULL DEFAULT 2,\n PRIMARY KEY (uid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {og_uid_global} (\n uid int NOT NULL,\n og_email int NOT NULL DEFAULT 2,\n PRIMARY KEY (uid)\n );");
break;
}
$sql = 'SELECT uid FROM {users} WHERE uid > 0';
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
$sql = "INSERT INTO {og_uid_global} (uid, og_email) VALUES (%d, %d)";
db_query($sql, $row->uid, OG_NOTIFICATION_SELECTIVE);
}
return array();
}
function og_update_14() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("CREATE TABLE {og_ancestry} (\n nid int(11) NOT NULL,\n group_nid int(11) NOT NULL,\n is_public int(1) NULL,\n KEY (nid),\n KEY (group_nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {og_ancestry} (\n nid int NOT NULL,\n group_nid int NOT NULL,\n is_public smallint NOT NULL\n );");
db_query("CREATE INDEX {og_ancestry}_nid_idx ON {og_ancestry} (nid);");
db_query("CREATE INDEX {og_ancestry}_group_nid_idx ON {og_ancestry} (group_nid);");
break;
}
og_migrate_type_basic_14();
$result = db_query_temporary("SELECT na.nid, na.gid, IF(MIN(na.realm) = 'og_all', 1, 0) AS is_public \n FROM {node_access} na INNER JOIN {node} n ON na.nid=n.nid \n WHERE realm IN ('og_all', 'og_subscriber') AND n.type NOT IN ('%s') GROUP BY na.nid, na.gid ORDER BY nid ASC", implode(', ', variable_get('og_node_types', array(
'og',
))), 'og_migrate');
$sql = "INSERT INTO {og_ancestry} (nid, group_nid, is_public) SELECT nid, gid, is_public FROM {og_migrate}";
db_query($sql);
node_access_rebuild();
return array();
}
function og_migrate_type_basic_14() {
if (og_is_group_type('og')) {
$info = array(
'type' => 'og',
'name' => 'group',
'module' => 'node',
'has_title' => 1,
'title_label' => 'Group name',
'has_body' => 1,
'body_label' => 'Welcome message',
'description' => 'A group provides a home page for like minded users. There they post articles about their shared interest.',
'help' => '',
'min_word_count' => 0,
'custom' => 1,
'modified' => 1,
'locked' => 0,
'orig_type' => 'og',
);
node_type_save((object) $info);
module_disable(array(
'og_basic',
));
node_types_rebuild();
}
}
function og_update_15() {
variable_del('og_max_posts');
variable_del('og_home_page_presentation');
return array();
}
function og_update_16() {
if (variable_get('og_enabled', 0)) {
node_access_rebuild();
}
return array();
}
function og_update_17() {
if (variable_get('og_enabled', 0)) {
node_access_rebuild();
}
return array();
}
function og_update_18() {
if (variable_get('og_enabled', 0)) {
node_access_rebuild();
}
return array();
}
function og_update_19() {
og_populate_uid_global_table();
return array(
'Populated og_uid_global table',
);
}
function og_update_20() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {og} ADD private int(1) NOT NULL default 0");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {og} ADD private smallint NOT NULL default 0");
break;
}
return $ret;
}
function og_update_5600() {
$ret = array();
$variables = array(
'og_new_node_body',
'og_new_node_subject',
);
foreach ($variables as $variable) {
$value = variable_get($variable, '');
if (!empty($value)) {
variable_set($variable, str_replace('@body', '@node_teaser', $value));
$ret[] = array(
'success' => TRUE,
'query' => "Replaced @body with @node_teaser in {$variable}",
);
}
}
return $ret;
}
function og_update_5700() {
$ret = array();
if (variable_get('og_enabled', FALSE) && !module_exists('og_access')) {
module_enable('og_access');
}
return $ret;
}
function og_update_5701() {
$ret = array();
$types = node_get_types();
foreach ($types as $type) {
if (in_array($type->type, variable_get('og_node_types', array(
'og',
)))) {
variable_set('og_content_type_usage_' . $type->type, 'group');
}
elseif (in_array($type->type, variable_get('og_omitted', array(
'og',
)))) {
variable_set('og_content_type_usage_' . $type->type, 'omitted');
}
elseif (in_array($type->type, variable_get('og_omitted_email_node_types', array(
'og',
)))) {
variable_set('og_content_type_usage_' . $type->type, 'group_post_standard_nomail');
}
else {
variable_set('og_content_type_usage_' . $type->type, 'group_post_standard_mail');
}
}
node_access_rebuild();
return $ret;
}
function og_update_5702() {
$ret[] = array(
'success' => TRUE,
'query' => 'Menu has been rebuilt.',
);
menu_rebuild();
return $ret;
}
function og_enable() {
og_populate_uid_global_table();
}
function og_populate_uid_global_table() {
$sql = 'SELECT u.uid FROM {users} u LEFT JOIN {og_uid_global} oug ON u.uid=oug.uid WHERE u.uid > 0 AND oug.og_email IS NULL';
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
$sql = "INSERT INTO {og_uid_global} (uid, og_email) VALUES (%d, %d)";
db_query($sql, $row->uid, OG_NOTIFICATION_SELECTIVE);
}
}
function og_uninstall() {
db_query('DROP TABLE {og}');
db_query('DROP TABLE {og_uid}');
db_query('DROP TABLE {og_uid_global}');
db_query('DROP TABLE {og_ancestry}');
$variables = array(
'og_member_pics',
'og_help',
'og_block_cnt_2',
'og_block_cnt_3',
'og_audience_checkboxes',
'og_omitted',
'og_content_type_usage',
'og_audience_required',
'og_omitted_email_node_types',
'og_visibility_directory',
'og_visibility_registration',
'og_home_page_view',
'og_email_max',
'og_node_types',
'og_admin_email_body',
'og_email_notification_pattern',
'og_approve_user_body',
'og_approve_user_subject',
'og_deny_user_body',
'og_deny_user_subject',
'og_invite_user_body',
'og_invite_user_subject',
'og_new_admin_body',
'og_new_admin_subject',
'og_new_node_body',
'og_new_node_subject',
'og_notification',
'og_request_user_body',
'og_request_user_subject',
);
foreach ($variables as $variable) {
variable_del($variable);
}
}