From 5bf2086aae8b3816003c3f81462478dbec306481 Mon Sep 17 00:00:00 2001 From: Justin Freeman Date: Fri, 13 Oct 2023 10:25:30 +1100 Subject: [PATCH] CIVIQBO-102 Rework setting logging for QuickBooks PHP SDK. Remove distinct logging directory, use CiviCRM configAndLogDir. Explicitly disable/enable logging. --- CRM/Quickbooks/APIHelper.php | 35 ++++++++++++++++++----------- settings/civiquickbooks.setting.php | 20 +---------------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/CRM/Quickbooks/APIHelper.php b/CRM/Quickbooks/APIHelper.php index af2d4d1..2744478 100644 --- a/CRM/Quickbooks/APIHelper.php +++ b/CRM/Quickbooks/APIHelper.php @@ -42,11 +42,13 @@ public static function getLoginDataServiceObject() { $redirectUrl = self::getRedirectUrl(); $stateTokenValue = self::generateStateToken(40); - $clientID = civicrm_api3('Setting', 'getvalue', ['name' => "quickbooks_consumer_key"]); - $clientSecret = civicrm_api3('Setting', 'getvalue', ['name' => "quickbooks_shared_secret"]); - $logLocation = civicrm_api3('Setting', 'getvalue', ['name' => "quickbooks_log_dir"]); - $logActivated = civicrm_api3('Setting', 'getvalue', ['name' => "quickbooks_activate_qbo_logging"]); + $clientID = civicrm_api3('Setting', 'getvalue', ['name' => 'quickbooks_consumer_key']); + $clientSecret = civicrm_api3('Setting', 'getvalue', ['name' => 'quickbooks_shared_secret']); + $config = CRM_Core_Config::singleton(); + $logLocation = $config->configAndLogDir; + + $logActivated = civicrm_api3('Setting', 'getvalue', ['name' => 'quickbooks_activate_qbo_logging']); $stateToken = [ 'state_token' => $stateTokenValue, @@ -63,10 +65,12 @@ public static function getLoginDataServiceObject() { 'state' => json_encode($stateToken), ]); - self::$quickBooksDataService->setLogLocation($logLocation); - if (!$logActivated) { - self::$quickBooksDataService->disableLog(); - } + if ($logActivated) { + self::$quickBooksDataService->setLogLocation($logLocation); + self::$quickBooksDataService->enableLog(); + } else { + self::$quickBooksDataService->disableLog(); + } return self::$quickBooksDataService; } @@ -89,9 +93,12 @@ public static function getAccountingDataServiceObject($forRefreshToken = FALSE) } $QBCredentials = self::getQuickBooksCredentials(); - $logLocation = civicrm_api3('Setting', 'getvalue', ['name' => "quickbooks_log_dir"]); - $logActivated = civicrm_api3('Setting', 'getvalue', ['name' => "quickbooks_activate_qbo_logging"]); - $baseUrl = civicrm_api3('Setting', 'getvalue', ['name' => "quickbooks_baseurl"]); + + $config = CRM_Core_Config::singleton(); + $logLocation = $config->configAndLogDir; + + $logActivated = civicrm_api3('Setting', 'getvalue', ['name' => 'quickbooks_activate_qbo_logging']); + $baseUrl = civicrm_api3('Setting', 'getvalue', ['name' => 'quickbooks_baseurl']); $dataServiceParams = [ 'auth_mode' => 'oauth2', @@ -109,8 +116,10 @@ public static function getAccountingDataServiceObject($forRefreshToken = FALSE) $dataService = \QuickBooksOnline\API\DataService\DataService::Configure($dataServiceParams); - $dataService->setLogLocation($logLocation); - if (!$logActivated) { + if ($logActivated) { + $dataService->setLogLocation($logLocation); + $dataService->enableLog(); + } else { $dataService->disableLog(); } diff --git a/settings/civiquickbooks.setting.php b/settings/civiquickbooks.setting.php index a20488c..2d01056 100644 --- a/settings/civiquickbooks.setting.php +++ b/settings/civiquickbooks.setting.php @@ -158,30 +158,12 @@ ], 'quick_form_type' => 'Element', ], - 'quickbooks_log_dir' => [ - 'group_name' => E::ts('QuickBooks Online Settings'), - 'group' => 'civiquickbooks', - 'name' => 'quickbooks_log_dir', - 'type' => 'String', - 'add' => '2.7', // this is the civiquickboks version number where this was added - 'default' => '/tmp/IdsLogs/', - 'title' => E::ts('QBO Log Directory'), - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => E::ts('Absolute path to writable file system directory for QBO logs.'), - 'help_text' => E::ts('Absolute path to writable file system directory for QBO logs.'), - 'html_type' => 'Text', - 'html_attributes' => [ - 'size' => 30, - ], - 'quick_form_type' => 'Element', - ], 'quickbooks_activate_qbo_logging' => [ 'group_name' => E::ts('QuickBooks Online Settings'), 'group' => 'civiquickbooks', 'name' => 'quickbooks_activate_qbo_logging', 'type' => 'Boolean', - 'add' => '2.7', // this is the civiquickboks version number where this was added + 'add' => '2.7', 'default' => 0, 'title' => E::ts('Activate QBO logging?'), 'is_domain' => 1,