From e8c09762e47f5349ad8f1b72aebcb965e8b49f2a Mon Sep 17 00:00:00 2001 From: Ryan Rathsam Date: Tue, 7 Mar 2017 08:32:10 -0500 Subject: [PATCH 1/2] Adding Logging to Query.php - Added a file logger to Query.php ( query.log ) - Added logic to the function 'execute' such that, when called and then 'sql_debug_mode' is true, the query that is about to be executed is logged. --- classes/DataWarehouse/Query/Query.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/classes/DataWarehouse/Query/Query.php b/classes/DataWarehouse/Query/Query.php index a6e1176771..2a3bb18a87 100644 --- a/classes/DataWarehouse/Query/Query.php +++ b/classes/DataWarehouse/Query/Query.php @@ -21,6 +21,7 @@ class Query public $filterParameterDescriptions; private $pdoparams; private $pdoindex; + private $log; /** * Tracks whether or not role restrictions have been applied to this query. @@ -118,7 +119,13 @@ public function __construct($realm_name, $this->roleParameterDescriptions = array(); $this->filterParameterDescriptions = array(); - + $this->log = \CCR\Log::factory('xms.query', array( + 'console' => false, + 'db' => false, + 'mail' => false, + 'file' => LOG_DIR . '/query.log', + 'fileLogLevel' => PEAR_LOG_DEBUG + )); } @@ -229,6 +236,13 @@ public function execute($limit = 10000000) { $query_string = $this->getQueryString($limit); + + $debug = filter_var(\xd_utilities\getConfiguration('general', 'sql_debug_mode'), FILTER_VALIDATE_BOOLEAN); + if ($debug == true) { + $class = get_class($this); + $this->log->debug(sprintf("%s: \n%s", $class, $query_string)); + } + $time_start = microtime(true); $results = DB::factory($this->_db_profile)->query($query_string, $this->pdoparams); From 8cee4fc031644e894b1c410560da19849784f51b Mon Sep 17 00:00:00 2001 From: Ryan Rathsam Date: Tue, 7 Mar 2017 09:57:39 -0500 Subject: [PATCH 2/2] Updated per code review - Added a new 'filter_var' function to 'xd_utilities' that we can use to get around the limitations of the 'filter_var' implementation in PHP 5.3.x. - Updated the 'filter_var' usage in Query to utilize the new function in 'xd_utilities'. --- classes/DataWarehouse/Query/Query.php | 2 +- libraries/utilities.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/classes/DataWarehouse/Query/Query.php b/classes/DataWarehouse/Query/Query.php index 2a3bb18a87..98bee0bbc6 100644 --- a/classes/DataWarehouse/Query/Query.php +++ b/classes/DataWarehouse/Query/Query.php @@ -237,7 +237,7 @@ public function execute($limit = 10000000) $query_string = $this->getQueryString($limit); - $debug = filter_var(\xd_utilities\getConfiguration('general', 'sql_debug_mode'), FILTER_VALIDATE_BOOLEAN); + $debug = \xd_utilities\filter_var(\xd_utilities\getConfiguration('general', 'sql_debug_mode'), FILTER_VALIDATE_BOOLEAN); if ($debug == true) { $class = get_class($this); $this->log->debug(sprintf("%s: \n%s", $class, $query_string)); diff --git a/libraries/utilities.php b/libraries/utilities.php index 79a71b5717..2892da3441 100644 --- a/libraries/utilities.php +++ b/libraries/utilities.php @@ -554,3 +554,17 @@ function checkForCenterLogo($apply_css = true) return $use_center_logo; } + +/** + * A temporary shim function to use while our supported PHP version is < 5.4.8 + * + * @param mixed $value to be filtered + * @param int $filter the type of filter to apply + * @param mixed $options the options to be supplied to the filter + * @return bool|mixed false if the value is logically false, else the results of + * \filter_var($value, $filter, $options) + */ +function filter_var($value, $filter = FILTER_DEFAULT, $options = null) +{ + return ( false === $value ? false : \filter_var($value, $filter, $options) ); +}