Skip to content
Snippets Groups Projects
Commit f9920e29 authored by eileen's avatar eileen
Browse files

Update CRM_Utils_Constant::value to support env variables

This is something I discussed with @totten earlier but as the rc was being cut at the time
we went for the more conservative approach of only adding env support to thhe debug_query
function.  This extends to all defines - meaning they can be defined at the script level e.

env CIVICRM_DEBUG_LOG_QUERY=backtrace drush cvapi

(that already works)
parent 42dada11
Branches
Tags
No related merge requests found
......@@ -603,15 +603,12 @@ class CRM_Core_Error extends PEAR_ErrorStack {
* @param string $string
*/
public static function debug_query($string) {
if (!defined('CIVICRM_DEBUG_LOG_QUERY')) {
// TODO: When its updated to support getenv(), call CRM_Utils_Constant::value('CIVICRM_DEBUG_LOG_QUERY', FALSE)
define('CIVICRM_DEBUG_LOG_QUERY', getenv('CIVICRM_DEBUG_LOG_QUERY'));
}
if (CIVICRM_DEBUG_LOG_QUERY === 'backtrace') {
$debugLogQuery = CRM_Utils_Constant::value('CIVICRM_DEBUG_LOG_QUERY', FALSE);
if ($debugLogQuery === 'backtrace') {
CRM_Core_Error::backtrace($string, TRUE);
}
elseif (CIVICRM_DEBUG_LOG_QUERY) {
CRM_Core_Error::debug_var('Query', $string, TRUE, TRUE, 'sql_log' . CIVICRM_DEBUG_LOG_QUERY, PEAR_LOG_DEBUG);
elseif ($debugLogQuery) {
CRM_Core_Error::debug_var('Query', $string, TRUE, TRUE, 'sql_log' . $debugLogQuery, PEAR_LOG_DEBUG);
}
}
......
......@@ -23,20 +23,23 @@ class CRM_Utils_Constant {
/**
* Determine the value of a constant, if any.
*
* If the specified constant is undefined, return a default value.
* If the specified constant is undefined, check for an environment
* variable, defaulting the passed in default value.
*
* @param string $name
* @param mixed $default
* (optional)
* @return mixed
*/
public static function value($name, $default = NULL) {
public static function value(string $name, $default = NULL) {
if (defined($name)) {
return constant($name);
}
else {
return $default;
if (($value = getenv($name)) !== FALSE) {
define($name, $value);
return $value;
}
return $default;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment