function domain_enable in Domain Access 7.3
Same name and namespace in other branches
- 5 domain.module \domain_enable()
- 6.2 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.
TODO: revisit the need for the data loop.
1 call to domain_enable()
File
- ./
domain.module, line 2385 - 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(TRUE);
// Get the default domain.
$default = domain_default();
// 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 = 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' => $default['domain_id'],
'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' => $default['domain_id'],
'uid' => $account->uid,
);
}
}
$query = db_insert('domain_editor')
->fields(array(
'domain_id',
'uid',
));
foreach ($values as $record) {
$query
->values($record);
}
$query
->execute();
}