function domain_enable in Domain Access 6.2
Same name and namespace in other branches
- 5 domain.module \domain_enable()
- 7.3 domain.module \domain_enable()
- 7.2 domain.module \domain_enable()
Upon enabling this module, store the default view grant in the {node_access} table. Then it assigns all users to the primary domain.
File
- ./
domain.module, line 1789 - Core module functions for the Domain Access suite.
Code
function domain_enable() {
// Set the default 'domain_all' grant for special pages.
domain_set_default_grant();
// Thanks to the new way that batch processing of node grants is handled, we have to
// manually define our records if none are present.
$count = (bool) db_result(db_query("SELECT 1 FROM {domain_access}"));
if (empty($count)) {
$rule = variable_get('domain_behavior', DOMAIN_INSTALL_RULE);
$site = DOMAIN_SITE_GRANT;
$nids = db_query("SELECT nid FROM {node}");
while ($nid = db_result($nids)) {
if (!empty($site)) {
db_query("INSERT INTO {domain_access} (nid, gid, realm) VALUES (%d, %d, '%s')", $nid, 0, 'domain_site');
}
if (!empty($rule)) {
// By design, all nodes are assigned to the master domain.
db_query("INSERT INTO {domain_access} (nid, gid, realm) VALUES (%d, %d, '%s')", $nid, 0, 'domain_id');
}
}
}
// Add users to the {domain_editor} table, but skip user 0.
if (!DOMAIN_ASSIGN_USERS) {
return;
}
$result = db_query("SELECT uid FROM {users} WHERE uid > 0");
while ($data = db_fetch_object($result)) {
$check = (bool) db_result(db_query("SELECT 1 FROM {domain_editor} WHERE uid = %d", $data->uid));
if (empty($check)) {
db_query("INSERT INTO {domain_editor} VALUES (%d, %d)", $data->uid, 0);
}
}
}