mirror of https://github.com/BOINC/boinc.git
Drupal: Add boinccore rules for notifying admins.
Add notification email to admin rules. Modified boincwork to notify admins when circular host merge or zombie host merge is attempted. Add watchdog/drupal log message for these two merge problems as well. https://dev.gridrepublic.org/browse/DBOINCP-434
This commit is contained in:
parent
b098ea71c7
commit
b07e55f0f8
|
@ -16,6 +16,7 @@ function boinccore_admin_community(&$form_state) {
|
|||
'min_credit_to_post' => variable_get('boinc_comment_min_credit', 0),
|
||||
'penalty_period' => variable_get('boinc_penalty_period', 7*24*60*60),
|
||||
'moderator_mailing_list' => variable_get('boinc_moderator_mailing_list', ''),
|
||||
'admin_mailing_list' => variable_get('boinc_admin_mailing_list', ''),
|
||||
'moderator_force_individual_notifications' => variable_get('boinc_moderator_force_individual_notifications', 0),
|
||||
);
|
||||
|
||||
|
@ -50,6 +51,13 @@ function boinccore_admin_community(&$form_state) {
|
|||
emails even when a mailing list is provided.'),
|
||||
);
|
||||
|
||||
$form['boinc_admin_mailing_list'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Admin mailing list'),
|
||||
'#default_value' => $default['admin_mailing_list'],
|
||||
'#description' => t('Enter an email-address which will be used to contact admisistrators. If empty, the site email configured in Settings -> Site Information will be used.'),
|
||||
);
|
||||
|
||||
$form['tools'] = array(
|
||||
'#title' => t('Tools'),
|
||||
'#type' => 'fieldset',
|
||||
|
|
|
@ -412,6 +412,11 @@ function boinccore_rules_action_info() {
|
|||
),
|
||||
'module' => 'BOINC core',
|
||||
),
|
||||
'boinccore_rules_action_mail_to_admins' => array(
|
||||
'label' => t('Notify admins via email'),
|
||||
'module' => 'BOINC core',
|
||||
'eval input' => array('subject', 'message', 'from'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1948,6 +1953,10 @@ function boinccore_get_country_list() {
|
|||
}
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Functions related to rules module
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/**
|
||||
* Action: Mark node for moderation
|
||||
*/
|
||||
|
@ -1994,6 +2003,38 @@ function boinccore_rules_action_mail_to_moderators_form($settings = array(), &$f
|
|||
rules_action_mail_to_user_form($settings, $form);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: Send mail to moderators.
|
||||
*/
|
||||
function boinccore_rules_action_mail_to_admins($settings) {
|
||||
module_load_include('inc', 'rules', 'modules/system.rules');
|
||||
$mailing_list = variable_get('boinc_admin_mailing_list', '');
|
||||
if (empty($mailing_list)) {
|
||||
$mailing_list = variable_get('site_mail', '');
|
||||
if (empty($mailing_list)) {
|
||||
watchdog('boinccore',
|
||||
'Attempting to email administrators, but there is no admin email list or site email to send to.', array(),
|
||||
WATCHDOG_ERROR
|
||||
);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
$settings['to'] = $mailing_list;
|
||||
rules_action_mail($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Action "Send mail to admins" configuration form
|
||||
*/
|
||||
function boinccore_rules_action_mail_to_admins_form($settings = array(), &$form) {
|
||||
rules_action_mail_to_user_form($settings, $form);
|
||||
}
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* BOINC Translation functions
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* BOINC wrapper for string translation
|
||||
*/
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
require_once('includes/boincwork.forms.inc');
|
||||
require_once('includes/boincwork.helpers.inc');
|
||||
require_once('includes/boincwork.rules.inc');
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
|
|
|
@ -769,6 +769,34 @@ function boincwork_host_merge($old_host, $new_host, &$message = NULL) {
|
|||
|
||||
$total_credit = $old_host->total_credit + $new_host->total_credit;
|
||||
$recent_credit = $old_host->expavg_credit + $new_host->expavg_credit;
|
||||
|
||||
if ($new_host->rpc_seqno == $old_host->id) {
|
||||
rules_invoke_event('boincwork_circular_merge_error', $old_host->id, $new_host->id);
|
||||
watchdog('boincwork',
|
||||
'Circular merge attempted, target host rpc_seqno is equal to old host\'s id: old host id=%old_host, target host id=%new_host',
|
||||
array(
|
||||
'%old_host' => $old_host->id,
|
||||
'%new_host' => $new_host->id,
|
||||
),
|
||||
WATCHDOG_WARNING
|
||||
);
|
||||
$message = 'Could not merge due to a circular merge error. The site administrators have been contacted about this issue, and will investigate further.';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($new_host->userid==0) {
|
||||
rules_invoke_event('boincwork_zombie_merge_error', $old_host->id, $new_host->id);
|
||||
watchdog('boincwork',
|
||||
'Zombier merge attempted, target host has userid=0: old host id=%old_host, target host id=%new_host',
|
||||
array(
|
||||
'%old_host' => $old_host->id,
|
||||
'%new_host' => $new_host->id,
|
||||
),
|
||||
WATCHDOG_WARNING
|
||||
);
|
||||
$message = 'Could not merge because the target host has userid=0. The site administrators have been contacted about this issue, and will investigate further.';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Move credit from the old host to the new host
|
||||
db_set_active('boinc_rw');
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* Rules: Custom defined events for BOINC
|
||||
*/
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Hooks into rules module
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/**
|
||||
* Implementation of hook_rules_event_info()
|
||||
*
|
||||
* Defines the custom events.
|
||||
*/
|
||||
|
||||
function boincwork_rules_event_info() {
|
||||
return array(
|
||||
'boincwork_circular_merge_error' => array(
|
||||
'label' => bts('A circular merge of hosts was attempted with error.', array(), NULL, 'boinc:rule-event'),
|
||||
'module' => 'BOINCwork',
|
||||
'arguments' => rules_events_hook_boincwork_arguments(),
|
||||
),
|
||||
'boincwork_zombie_merge_error' => array(
|
||||
'label' => bts('A host merge into a zombie host was attempted with error.', array(), NULL, 'boinc:rule-event'),
|
||||
'module' => 'BOINCwork',
|
||||
'arguments' => rules_events_hook_boincwork_arguments(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Arguments suitable for boincwork
|
||||
**/
|
||||
function rules_events_hook_boincwork_arguments() {
|
||||
return array(
|
||||
'oldhost_id' => array(
|
||||
'type' => 'number',
|
||||
'label' => 'old host id',
|
||||
'required' => TRUE,
|
||||
),
|
||||
'targethost_id' => array(
|
||||
'type' => 'number',
|
||||
'label' => 'target host id',
|
||||
'required' => TRUE,
|
||||
),
|
||||
) + rules_events_global_user_argument();
|
||||
}
|
Loading…
Reference in New Issue