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 website 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 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 numeric(11) NOT NULL,\n selective numeric(11) NOT NULL default 0,\n description varchar(255) NULL,\n theme varchar(255) NULL,\n website varchar(255) NULL,\n register numeric(1) NOT NULL default 0,\n directory numeric(1) NOT NULL default 0,\n notification numeric(1) NOT NULL default 0,\n language varchar(12) NOT NULL default '',\n PRIMARY KEY (nid)\n );");
db_query("CREATE TABLE {og_uid} (\n nid numeric(11) NOT NULL,\n og_role numeric(1) NOT NULL DEFAULT 0,\n is_active numeric(1) NOT NULL DEFAULT 0,\n is_admin numeric(1) NOT NULL DEFAULT 0,\n uid numeric(11) NOT NULL,\n mail_type numeric(11) NULL,\n\tcreated numeric(11) NULL DEFAULT 0,\n\tchanged numeric(11) NULL DEFAULT 0,\n PRIMARY KEY (nid, uid)\n );");
db_query("CREATE TABLE {og_uid_global} (\n uid numeric(11) NOT NULL,\n og_email numeric(11) NULL DEFAULT 2,\n PRIMARY KEY (uid)\n );");
db_query("\n CREATE TABLE {og_ancestry} (\n nid numeric(11) NOT NULL,\n group_nid numeric(11) NOT NULL,\n is_public numeric(1) NOT NULL,\n PRIMARY KEY (nid)\n );\n CREATE INDEX {og_ancestry}_nid_idx ON {og_ancestry}(group_nid);\n ");
break;
}
drupal_set_message(t('Organic groups module enabled. Please see the included readme.txt file for further installation instructions.'));
}
function og_enable() {
_block_rehash();
}
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` numeric(1) NOT NULL default 0");
db_query("ALTER TABLE {og_uid} ADD `is_active` numeric(1) default 0");
db_query("ALTER TABLE {og_uid} ADD `is_admin` numeric(1) 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 numeric(11), " . "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 numeric(11) NULL DEFAULT 0");
$ret[] = update_sql("ALTER TABLE {og_uid} ADD COLUMN changed numeric(11) 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 numeric(1) 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 numeric(11) NOT NULL,\n og_email numeric(11) 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 numeric(11) NOT NULL,\n group_nid numeric(11) NOT NULL,\n is_public numeric(1) NOT NULL,\n PRIMARY KEY (nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;\n CREATE INDEX group_nid_idx ON group_nid (numeric);\n ");
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() {
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_disable() {
og_settings_submit(NULL, array(
'op' => t('Disable'),
));
}