diff --git a/search_api_saved_searches.admin.inc b/search_api_saved_searches.admin.inc index 082f5e6..90da7ed 100644 --- a/search_api_saved_searches.admin.inc +++ b/search_api_saved_searches.admin.inc @@ -69,7 +69,6 @@ function search_api_saved_searches_index_edit(array $form, array &$form_state, S $settings->options['mail'] += array( 'activate' => array(), 'notify' => array(), - 'disable_mail' => FALSE, ); $settings->options['mail']['activate'] += array( 'send' => TRUE, @@ -84,6 +83,7 @@ function search_api_saved_searches_index_edit(array $form, array &$form_state, S -- [site:name] team"), ); $settings->options['mail']['notify'] += array( + 'send' => TRUE, 'title' => t('New results for your saved search at [site:name]'), 'body' => t('[user:name], @@ -305,26 +305,12 @@ function search_api_saved_searches_index_edit(array $form, array &$form_state, S '#collapsible' => TRUE, '#collapsed' => $settings->enabled, ); - - $form['options']['mail']['disable_mail'] = array( - '#type' => 'checkbox', - '#title' => t('Disable e-mail notifications'), - '#description' => t("Checking this will disable the e-mail notifications of saved searches on cron."), - '#default_value' => $options['mail']['disable_mail'], - '#parents' => array('options', 'mail', 'disable_mail'), - ); - $form['options']['mail']['activate_send'] = array( '#type' => 'checkbox', '#title' => t('Use activation mail for anonymous users'), '#description' => t("Will need saved searches created by anonymous users, or by normal users with an e-mail address that isn't their own, to be activated by clicking a link in an e-mail."), '#default_value' => $options['mail']['activate']['send'], '#parents' => array('options', 'mail', 'activate', 'send'), - '#states' => array( - 'invisible' => array( - ':input[name="options[mail][disable_mail]"]' => array('checked' => TRUE), - ), - ), ); $form['options']['mail']['activate'] = array( @@ -334,7 +320,6 @@ function search_api_saved_searches_index_edit(array $form, array &$form_state, S '#collapsed' => $settings->enabled, ); $form['options']['mail']['activate']['#states']['visible'][':input[name="options[mail][activate][send]"]']['checked'] = TRUE; - $form['options']['mail']['activate']['#states']['visible'][':input[name="options[mail][disable_mail]"]']['checked'] = FALSE; $form['options']['mail']['activate']['title'] = array( '#type' => 'textfield', '#title' => t('Subject'), @@ -357,6 +342,13 @@ function search_api_saved_searches_index_edit(array $form, array &$form_state, S '#required' => TRUE, ); + $form['options']['mail']['notify_send'] = array( + '#type' => 'checkbox', + '#title' => t('Send mail notifications for new results'), + '#description' => t('Depending on the notification interval, send regular mail updates with new results for saved searches. Disable this option if you want to use some other mechanism to notify the user of new results (or if you do not want any notifications at all).'), + '#default_value' => $options['mail']['notify']['send'], + '#parents' => array('options', 'mail', 'notify', 'send'), + ); $form['options']['mail']['notify'] = array( '#type' => 'fieldset', '#title' => t('Notification mails'), @@ -364,7 +356,7 @@ function search_api_saved_searches_index_edit(array $form, array &$form_state, S '#collapsed' => $settings->enabled, '#states' => array( 'visible' => array( - ':input[name="options[mail][disable_mail]"]' => array('checked' => FALSE) + ':input[name="options[mail][notify][send]"]' => array('checked' => TRUE), ), ), ); diff --git a/search_api_saved_searches.module b/search_api_saved_searches.module index 0dd722b..3b39533 100644 --- a/search_api_saved_searches.module +++ b/search_api_saved_searches.module @@ -1314,11 +1314,10 @@ function search_api_saved_searches_cron() { // by settings is necessary since the mails can differ between settings. $user_searches = array(); foreach ($searches as $search) { - // Check the dissable mail notification value if not set then don't add the - // the item to the queue. - $settings = search_api_saved_searches_settings_load_multiple(FALSE, array('index_id' => $search->settings_id)); - $setting = reset($settings); - if (!$setting->options['mail']['disable_mail']) { + // Check whether notifications are enabled for this search. + $settings = search_api_saved_searches_settings_load($search->settings_id); + $options = $settings->options; + if (!isset($options['mail']['notify']['send']) || $options['mail']['notify']['send']) { $user_searches[$search->mail . ' ' . $search->settings_id][] = $search->id; // Set the last execution timestamp now, so the interval doesn't move and we // don't get problems if the next cron run occurs before the queue is