foreach ($settingMetaData as $setting => $props) {
if (isset($props['quick_form_type'])) {
if (isset($props['pseudoconstant'])) {
- if (array_key_exists('optionGroupName', $props['pseudoconstant'])) {
- $optionValues = civicrm_api3('OptionValue', 'get', array(
- 'return' => array("label", "value"),
- 'option_group_id' => $setting,
- ));
- if ($optionValues['count'] > 0) {
- foreach ($optionValues['values'] as $key => $values) {
- $vals[$values['value']] = $values['label'];
- }
- $options['values'] = $vals;
- }
- }
- else {
- $options = civicrm_api3('Setting', 'getoptions', array(
- 'field' => $setting,
- ));
- }
+ $options = civicrm_api3('Setting', 'getoptions', array(
+ 'field' => $setting,
+ ));
}
else {
$options = NULL;
);
}
elseif ($add == 'addSelect') {
- $element = $this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props));
- if (defined('CIVICRM_ENVIRONMENT')) {
- $element->freeze();
- CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info');
- }
+ $this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props));
}
elseif ($add == 'addCheckBox') {
$this->addCheckBox($setting, ts($props['title']), $options['values'], NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, array(' '));
}
parent::buildQuickForm();
- }
- /**
- * Process the form submission.
- */
- public function postProcess() {
- $params = $this->controller->exportValues($this->_name);
-
- if ($params['environment'] != 'Production') {
- $mailing = Civi::settings()->get('mailing_backend');
- if ($mailing['outBound_option'] != 2) {
- Civi::settings()->set('mailing_backend_store', $mailing);
- }
- Civi::settings()->set('mailing_backend', array('outBound_option' => CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED));
- CRM_Core_Session::setStatus(ts('Outbound emails have been disabled. Scheduled jobs will not run unless runInNonProductionEnvironment=TRUE is added as a parameter for a specific job'), ts("Non-production environment set"), "success");
- }
- else {
- $mailing = Civi::settings()->get('mailing_backend_store');
- if ($mailing) {
- Civi::settings()->set('mailing_backend', $mailing);
- }
+ if (defined('CIVICRM_ENVIRONMENT')) {
+ $element = $this->getElement('environment');
+ $element->freeze();
+ CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info');
}
- parent::postProcess();
}
}
* @throws API_Exception
*/
public static function isAPIJobAllowedToRun($params) {
- if (CRM_Core_Config::environment() != 'Production' && !CRM_Utils_Array::value('runInNonProductionEnvironment', $params)) {
- throw new Exception("Job has not been executed as it is a non-production environment.");
+ $environment = CRM_Core_Config::environment(NULL, TRUE);
+ if ($environment != 'Production') {
+ if (CRM_Utils_Array::value('runInNonProductionEnvironment', $params)) {
+ $mailing = Civi::settings()->get('mailing_backend_store');
+ if ($mailing) {
+ Civi::settings()->set('mailing_backend', $mailing);
+ }
+ }
+ else {
+ throw new Exception(ts("Job has not been executed as it is a %1 (non-production) environment.", array(1 => $environment)));
+ }
+ }
+ }
+
+ /**
+ * Setting Callback - On Change.
+ *
+ * Respond to changes in the "environment" setting.
+ *
+ * @param array $oldValue
+ * Value of old environment mode.
+ * @param array $newValue
+ * Value of new environment mode.
+ * @param array $metadata
+ * Specification of the setting (per *.settings.php).
+ */
+ public static function onChangeEnvironmentSetting($oldValue, $newValue, $metadata) {
+ if ($newValue != 'Production') {
+ $mailing = Civi::settings()->get('mailing_backend');
+ if ($mailing['outBound_option'] != 2) {
+ Civi::settings()->set('mailing_backend_store', $mailing);
+ }
+ Civi::settings()->set('mailing_backend', array('outBound_option' => CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED));
+ CRM_Core_Session::setStatus(ts('Outbound emails have been disabled. Scheduled jobs will not run unless runInNonProductionEnvironment=TRUE is added as a parameter for a specific job'), ts("Non-production environment set"), "success");
+ }
+ else {
+ $mailing = Civi::settings()->get('mailing_backend_store');
+ if ($mailing) {
+ Civi::settings()->set('mailing_backend', $mailing);
+ }
}
}
}
elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED) {
CRM_Core_Error::debug_log_message(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
- CRM_Core_Session::setStatus(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
+ CRM_Core_Error::statusBounce(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
}
else {
CRM_Core_Error::debug_log_message(ts('There is no valid SMTP server Setting Or SendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
- CRM_Core_Session::setStatus(ts('There is no valid SMTP server Setting Or sendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
CRM_Core_Error::debug_var('mailing_info', $mailingInfo);
+ CRM_Core_Error::statusBounce(ts('There is no valid SMTP server Setting Or sendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
}
return $mailer;
}
}
$dao->find(TRUE);
- if (isset($metadata['on_change']) && !($value == 0 && ($dao->value === NULL || unserialize($dao->value) == 0))) {
+ // string comparison with 0 always return true, so to be ensure the type use ===
+ // ref - https://stackoverflow.com/questions/8671942/php-string-comparasion-to-0-integer-returns-true
+ if (isset($metadata['on_change']) && !($value === 0 && ($dao->value === NULL || unserialize($dao->value) == 0))) {
foreach ($metadata['on_change'] as $callback) {
call_user_func(
\Civi\Core\Resolver::singleton()->get($callback),
function civicrm_api3_job_process_mailing($params) {
$mailsProcessedOrig = CRM_Mailing_BAO_MailingJob::$mailsProcessed;
+ try {
+ CRM_Core_BAO_Setting::isAPIJobAllowedToRun($params);
+ }
+ catch (Exception $e) {
+ return civicrm_api3_create_error($e->getMessage());
+ }
+
if (!CRM_Mailing_BAO_Mailing::processQueue()) {
return civicrm_api3_create_error('Process Queue failed');
}
$values = Civi\Core\Resolver::singleton()->call($pseudoconstant['callback'], array());
return civicrm_api3_create_success($values, $params, 'Setting', 'getoptions');
}
+ elseif (!empty($pseudoconstant['optionGroupName'])) {
+ return civicrm_api3_create_success(
+ CRM_Core_OptionGroup::values($pseudoconstant['optionGroupName'], FALSE, FALSE, TRUE),
+ $params, 'Setting', 'getoptions'
+ );
+ }
throw new API_Exception("The field '" . $params['field'] . "' uses an unsupported option list.");
}
'is_domain' => 1,
'is_contact' => 0,
'description' => "Setting to define the environment in which this CiviCRM instance is running.",
+ 'on_change' => array(
+ 'CRM_Core_BAO_Setting::onChangeEnvironmentSetting',
+ ),
),
'fatalErrorHandler' => array(
'group_name' => 'Developer Preferences',
$mailingParams = array_merge($this->defaultParams, $params);
$this->callAPISuccess('mailing', 'create', $mailingParams);
$this->_mut->assertRecipients(array());
- $this->callAPISuccess('job', 'process_mailing', array());
+ $this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE));
$allMessages = $this->_mut->getAllMessages('ezc');
// There are exactly two contacts produced by setUp().