From b07e55f0f84417a08b967fe6428b22697a7d2332 Mon Sep 17 00:00:00 2001 From: Shawn Kwang Date: Fri, 1 Mar 2019 15:08:10 -0600 Subject: [PATCH] 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 --- .../modules/boinccore/boinccore.admin.inc | 8 +++ .../boinc/modules/boinccore/boinccore.module | 41 ++++++++++++++++ .../boinc/modules/boincwork/boincwork.module | 1 + .../boincwork/includes/boincwork.forms.inc | 28 +++++++++++ .../boincwork/includes/boincwork.rules.inc | 49 +++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 drupal/sites/default/boinc/modules/boincwork/includes/boincwork.rules.inc diff --git a/drupal/sites/default/boinc/modules/boinccore/boinccore.admin.inc b/drupal/sites/default/boinc/modules/boinccore/boinccore.admin.inc index 70f1ca4459..c968c2b16d 100644 --- a/drupal/sites/default/boinc/modules/boinccore/boinccore.admin.inc +++ b/drupal/sites/default/boinc/modules/boinccore/boinccore.admin.inc @@ -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', diff --git a/drupal/sites/default/boinc/modules/boinccore/boinccore.module b/drupal/sites/default/boinc/modules/boinccore/boinccore.module index a84b54288e..bb7f94ccad 100644 --- a/drupal/sites/default/boinc/modules/boinccore/boinccore.module +++ b/drupal/sites/default/boinc/modules/boinccore/boinccore.module @@ -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 */ diff --git a/drupal/sites/default/boinc/modules/boincwork/boincwork.module b/drupal/sites/default/boinc/modules/boincwork/boincwork.module index 4fcd683909..1d553eae55 100644 --- a/drupal/sites/default/boinc/modules/boincwork/boincwork.module +++ b/drupal/sites/default/boinc/modules/boincwork/boincwork.module @@ -13,6 +13,7 @@ require_once('includes/boincwork.forms.inc'); require_once('includes/boincwork.helpers.inc'); +require_once('includes/boincwork.rules.inc'); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/drupal/sites/default/boinc/modules/boincwork/includes/boincwork.forms.inc b/drupal/sites/default/boinc/modules/boincwork/includes/boincwork.forms.inc index 9dcd254d6e..a50a6d1591 100644 --- a/drupal/sites/default/boinc/modules/boincwork/includes/boincwork.forms.inc +++ b/drupal/sites/default/boinc/modules/boincwork/includes/boincwork.forms.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'); diff --git a/drupal/sites/default/boinc/modules/boincwork/includes/boincwork.rules.inc b/drupal/sites/default/boinc/modules/boincwork/includes/boincwork.rules.inc new file mode 100644 index 0000000000..1ee7fd5f54 --- /dev/null +++ b/drupal/sites/default/boinc/modules/boincwork/includes/boincwork.rules.inc @@ -0,0 +1,49 @@ + 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(); +}