Skip to content

Commit

Permalink
CIVIQBO-102 Rework setting logging for QuickBooks PHP SDK. Remove dis…
Browse files Browse the repository at this point in the history
…tinct logging directory, use CiviCRM configAndLogDir. Explicitly disable/enable logging.
  • Loading branch information
agileware-justin committed Oct 12, 2023
1 parent 1641ed1 commit 5bf2086
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
35 changes: 22 additions & 13 deletions CRM/Quickbooks/APIHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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',
Expand All @@ -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();
}

Expand Down
20 changes: 1 addition & 19 deletions settings/civiquickbooks.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5bf2086

Please sign in to comment.