diff --git a/search_api_saved_searches.admin.inc b/search_api_saved_searches.admin.inc index 315f1a9..082f5e6 100644 --- a/search_api_saved_searches.admin.inc +++ b/search_api_saved_searches.admin.inc @@ -69,6 +69,7 @@ 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, @@ -304,12 +305,26 @@ You can configure your saved searches at the following address: '#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( @@ -319,6 +334,7 @@ You can configure your saved searches at the following address: '#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'), @@ -346,6 +362,11 @@ You can configure your saved searches at the following address: '#title' => t('Notification mails'), '#collapsible' => TRUE, '#collapsed' => $settings->enabled, + '#states' => array( + 'visible' => array( + ':input[name="options[mail][disable_mail]"]' => array('checked' => FALSE) + ), + ), ); $form['options']['mail']['notify']['title'] = array( '#type' => 'textfield', diff --git a/search_api_saved_searches.module b/search_api_saved_searches.module index 1702171..0dd722b 100644 --- a/search_api_saved_searches.module +++ b/search_api_saved_searches.module @@ -1314,12 +1314,18 @@ function search_api_saved_searches_cron() { // by settings is necessary since the mails can differ between settings. $user_searches = array(); foreach ($searches as $search) { - $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 - // completely executed. - $search->last_queued = REQUEST_TIME; - $search->save(); + // 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']) { + $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 + // completely executed. + $search->last_queued = REQUEST_TIME; + $search->save(); + } } foreach ($user_searches as $searches) { $queue->createItem($searches);