Skip to content

Commit

Permalink
例外時のログを var_dump ではなく監査ログ機能で出力するように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
uidev1116 committed Nov 13, 2023
1 parent 4da4b71 commit f7a1e39
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use Field;
use Config;
use App;
use Common;

use ZCRMModule;
use ZCRMRecord;
use ZCRMRestClient;
use ZCRMNote;
use ZCRMJunctionRecord;
use Acms\Plugins\Zoho\Api;

class Engine
Expand Down Expand Up @@ -101,9 +103,7 @@ private function makeLabelConversionTable()
$this->conversions = $conversions;
App::checkException();
} catch (\Exception $e) {
if (DEBUG_MODE) {
var_dump(__FUNCTION__ . ': ' . $e->getMessage());
}
$this->warning(__FUNCTION__, $e);
}
}

Expand Down Expand Up @@ -275,9 +275,7 @@ private function checkUniqueKeyExists($fields, $scope, $uniqueKey)
$responses = $bulkAPIResponse->getData();
continue;
} catch (\Exception $e) {
if (DEBUG_MODE) {
var_dump(__FUNCTION__ . ': ' . $e->getMessage());
}
$this->warning(__FUNCTION__, $e);
}
}
$newFields[] = $field;
Expand Down Expand Up @@ -305,9 +303,7 @@ private function getFieldsWhereNotExistInContact($fields, $scope, $uniqueKey)
continue;
}
} catch (\Exception $e) {
if (DEBUG_MODE) {
var_dump(__FUNCTION__ . ': ' . $e->getMessage());
}
$this->warning(__FUNCTION__, $e);
}
}
}
Expand Down Expand Up @@ -343,9 +339,7 @@ private function addIdsToRecords($records, $scope, $uniqueKey, $fields)
$newRecords[] = $record;
}
} catch (\Exception $e) {
if (DEBUG_MODE) {
var_dump(__FUNCTION__ . ': ' . $e->getMessage());
}
$this->warning(__FUNCTION__, $e);
}
}
return $newRecords;
Expand Down Expand Up @@ -435,9 +429,7 @@ private function insertRecords($records)
);
}
} catch (\Exception $e) {
if (DEBUG_MODE) {
var_dump(__FUNCTION__ . ': ' . $e->getMessage());
}
$this->warning(__FUNCTION__, $e);
}
}
}
Expand Down Expand Up @@ -469,9 +461,7 @@ private function updateRecords($records)
);
}
} catch (\Exception $e) {
if (DEBUG_MODE) {
var_dump(__FUNCTION__ . ': ' . $e->getMessage());
}
$this->warning(__FUNCTION__, $e);
}
}
}
Expand Down Expand Up @@ -518,9 +508,7 @@ private function updateRelatedRecords()
try {
$parentRecord->update();
} catch (\Exception $e) {
if (DEBUG_MODE) {
var_dump(__FUNCTION__ . ': ' . $e->getMessage());
}
$this->warning(__FUNCTION__, $e);
}
}
} else {
Expand All @@ -532,4 +520,20 @@ private function updateRelatedRecords()
}
}
}

/**
* 警告ログの出力
*
* @param string $methodName
* @param Exception $e
*/
private function warning(string $methodName, \Exception $e)
{
$log = 'ACMS Warning: Zoho plugin, ' . $methodName . ': ' . $e->getMessage();
if (class_exists('AcmsLogger')) {
\AcmsLogger::warning($log, Common::exceptionArray($e));
} else {
userErrorLog($log);
}
}
}

0 comments on commit f7a1e39

Please sign in to comment.