function domain_enable in Domain Access 7.2
Same name and namespace in other branches
- 5 domain.module \domain_enable()
- 6.2 domain.module \domain_enable()
- 7.3 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 1858 - 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_query_range("SELECT 1 FROM {domain_access}", 0, 1)
->fetchField();
if (empty($count)) {
$rule = variable_get('domain_behavior', DOMAIN_INSTALL_RULE);
$site = DOMAIN_SITE_GRANT;
$values = array();
$result = db_query("SELECT nid FROM {node}");
foreach ($result as $node) {
if (!empty($site)) {
$values[] = array(
'nid' => $node->nid,
'gid' => 0,
'realm' => 'domain_site',
);
}
if (!empty($rule)) {
$values[] = array(
'nid' => $node->nid,
'gid' => variable_get('domain_default', 0),
'realm' => 'domain_id',
);
}
}
$query = db_insert('domain_access')
->fields(array(
'nid',
'gid',
'realm',
));
foreach ($values as $record) {
$query
->values($record);
}
$query
->execute();
}
// 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");
$values = array();
foreach ($result as $account) {
$check = (bool) db_query_range("SELECT COUNT(uid) FROM {domain_editor} WHERE uid = :uid", 0, 1, array(
':uid' => $account->uid,
))
->fetchField();
if (empty($check)) {
$values[] = array(
'domain_id' => variable_get('default_domain', 0),
'uid' => $account->uid,
);
}
}
$query = db_insert('domain_editor')
->fields(array(
'domain_id',
'uid',
));
foreach ($values as $record) {
$query
->values($record);
}
$query
->execute();
}