Skip to content
Snippets Groups Projects
Commit 0f3062cb authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-390] Move the unl_sites db stuff out of cron

No real reason to weigh cron down with updating site name and last access timestamp constantly.
The update db queries for those two fields can just be run when the site list is accessed.
parent 99b55bfc
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,6 @@ unl_remove_page_aliases(); ...@@ -28,7 +28,6 @@ unl_remove_page_aliases();
unl_add_sites(); unl_add_sites();
unl_add_aliases(); unl_add_aliases();
unl_add_page_aliases(); unl_add_page_aliases();
unl_update_unl_sites();
function unl_add_sites() { function unl_add_sites() {
$query = db_query('SELECT * FROM {unl_sites} WHERE installed=0'); $query = db_query('SELECT * FROM {unl_sites} WHERE installed=0');
...@@ -451,56 +450,3 @@ function unl_require_writable($path) { ...@@ -451,56 +450,3 @@ function unl_require_writable($path) {
} }
} }
/**
* Updates the name and access fields in the default site unl_sites table for display on admin/sites/unl
*/
function unl_update_unl_sites() {
// Get all sites in production
$query = db_query('SELECT * FROM {unl_sites} WHERE installed=2');
// Get all custom made roles (roles other than authenticated, anonymous, administrator)
$roles = user_roles(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);
unset($roles[variable_get('user_admin_role')]);
// Setup alternate db connection so we can query other sites' tables without a prefix being attached
$database_noprefix = array(
'database' => $GLOBALS['databases']['default']['default']['database'],
'username' => $GLOBALS['databases']['default']['default']['username'],
'password' => $GLOBALS['databases']['default']['default']['password'],
'host' => $GLOBALS['databases']['default']['default']['host'],
'port' => $GLOBALS['databases']['default']['default']['port'],
'driver' => $GLOBALS['databases']['default']['default']['driver'],
);
Database::addConnectionInfo('UNLNoPrefix', 'default', $database_noprefix);
// The master prefix that was specified during initial drupal install
$master_prefix = $GLOBALS['databases']['default']['default']['prefix'];
while ($row = $query->fetchAssoc()) {
// Switch to alt db connection
db_set_active('UNLNoPrefix');
// Get site name
$table = $row['db_prefix'].'_'.$master_prefix.'variable';
$name = db_query("SELECT value FROM ".$table." WHERE name = 'site_name'")->fetchField();
// Get last access timestamp (by a non-administrator)
$table_users = $row['db_prefix'].'_'.$master_prefix.'users u';
$table_users_roles = $row['db_prefix'].'_'.$master_prefix.'users_roles r';
if (!empty($roles)) {
$access = db_query('SELECT u.access FROM '.$table_users.', '.$table_users_roles.' WHERE u.uid = r.uid AND u.access > 0 AND r.rid IN (' . implode(',', array_keys($roles)) . ') ORDER BY u.access DESC')->fetchColumn();
} else {
$access = 0;
}
// Restore default db connection
db_set_active();
// Update unl_sites table of the default site
db_update('unl_sites')
->fields(array('name' => @unserialize($name), 'access' => (int)$access))
->condition('site_id', $row['site_id'])
->execute();
}
}
...@@ -91,10 +91,66 @@ function unl_site_create_submit($form, &$form_state) { ...@@ -91,10 +91,66 @@ function unl_site_create_submit($form, &$form_state) {
return; return;
} }
/**
* Updates the name and access fields in the default site unl_sites table.
*/
function unl_update_unl_sites() {
// Get all sites in production
$query = db_query('SELECT * FROM {unl_sites} WHERE installed=2');
// Get all custom made roles (roles other than authenticated, anonymous, administrator)
$roles = user_roles(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);
unset($roles[variable_get('user_admin_role')]);
// Setup alternate db connection so we can query other sites' tables without a prefix being attached
$database_noprefix = array(
'database' => $GLOBALS['databases']['default']['default']['database'],
'username' => $GLOBALS['databases']['default']['default']['username'],
'password' => $GLOBALS['databases']['default']['default']['password'],
'host' => $GLOBALS['databases']['default']['default']['host'],
'port' => $GLOBALS['databases']['default']['default']['port'],
'driver' => $GLOBALS['databases']['default']['default']['driver'],
);
Database::addConnectionInfo('UNLNoPrefix', 'default', $database_noprefix);
// The master prefix that was specified during initial drupal install
$master_prefix = $GLOBALS['databases']['default']['default']['prefix'];
while ($row = $query->fetchAssoc()) {
// Switch to alt db connection
db_set_active('UNLNoPrefix');
// Get site name
$table = $row['db_prefix'].'_'.$master_prefix.'variable';
$name = db_query("SELECT value FROM ".$table." WHERE name = 'site_name'")->fetchField();
// Get last access timestamp (by a non-administrator)
$table_users = $row['db_prefix'].'_'.$master_prefix.'users u';
$table_users_roles = $row['db_prefix'].'_'.$master_prefix.'users_roles r';
if (!empty($roles)) {
$access = db_query('SELECT u.access FROM '.$table_users.', '.$table_users_roles.' WHERE u.uid = r.uid AND u.access > 0 AND r.rid IN (' . implode(',', array_keys($roles)) . ') ORDER BY u.access DESC')->fetchColumn();
} else {
$access = 0;
}
// Restore default db connection
db_set_active();
// Update unl_sites table of the default site
db_update('unl_sites')
->fields(array('name' => @unserialize($name), 'access' => (int)$access))
->condition('site_id', $row['site_id'])
->execute();
}
}
/** /**
* Site List appears on admin/sites/unl, admin/sites/unl/sites * Site List appears on admin/sites/unl, admin/sites/unl/sites
*/ */
function unl_site_list($form, &$form_state) { function unl_site_list($form, &$form_state) {
unl_update_unl_sites();
$header = array( $header = array(
'uri' => array( 'uri' => array(
'data' => t('Default Path'), 'data' => t('Default Path'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment