From fcde65eaee62d3c99d5c8f809a5dd89385be31ea Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 6 May 2021 13:14:57 +0300 Subject: [PATCH] log dependency --- application/Espo/Core/Utils/Metadata.php | 4 +-- application/Espo/Core/Webhook/Manager.php | 9 ++++-- application/Espo/Core/Webhook/Queue.php | 11 +++++-- application/Espo/Hooks/Common/Formula.php | 32 +++++++++++++------ application/Espo/Jobs/Cleanup.php | 13 +++++--- .../Modules/Crm/Jobs/ProcessMassEmail.php | 10 ++++-- .../Modules/Crm/Jobs/SendEmailReminders.php | 14 ++++++-- .../Modules/Crm/Jobs/SubmitPopupReminders.php | 14 ++++++-- .../Modules/Crm/Tools/MassEmail/Processor.php | 9 ++++-- application/Espo/Services/App.php | 9 ++++-- application/Espo/Services/Email.php | 10 +++--- application/Espo/Services/EmailAccount.php | 12 +++---- application/Espo/Services/InboundEmail.php | 16 +++++----- application/Espo/Services/Record.php | 2 ++ .../EmailNotification/AssignmentProcessor.php | 9 ++++-- .../Tools/EmailNotification/Processor.php | 15 ++++++--- application/Espo/Tools/Import/Import.php | 11 +++++-- .../Espo/Tools/LeadCapture/LeadCapture.php | 9 ++++-- 18 files changed, 145 insertions(+), 64 deletions(-) diff --git a/application/Espo/Core/Utils/Metadata.php b/application/Espo/Core/Utils/Metadata.php index 2f42cbab2c..efdd90a4cc 100644 --- a/application/Espo/Core/Utils/Metadata.php +++ b/application/Espo/Core/Utils/Metadata.php @@ -551,8 +551,8 @@ class Metadata $rowResult = $this->fileManager->unsetJsonContents($filePath, $unsetData); if (!$rowResult) { - $GLOBALS['log']->warning( - 'Metadata items ['.$key1.'.'.$key2.'] can be deleted for custom code only.' + throw new Error( + "Metadata items {$key1}.{$key2} can be deleted for custom code only." ); } diff --git a/application/Espo/Core/Webhook/Manager.php b/application/Espo/Core/Webhook/Manager.php index 1b50ba9ddf..14aa241378 100644 --- a/application/Espo/Core/Webhook/Manager.php +++ b/application/Espo/Core/Webhook/Manager.php @@ -35,6 +35,7 @@ use Espo\Core\{ Utils\FieldUtil, ORM\EntityManager, ORM\Entity, + Utils\Log, }; /** @@ -56,16 +57,20 @@ class Manager private $fieldUtil; + private $log; + public function __construct( Config $config, DataCache $dataCache, EntityManager $entityManager, - FieldUtil $fieldUtil + FieldUtil $fieldUtil, + Log $log ) { $this->config = $config; $this->dataCache = $dataCache; $this->entityManager = $entityManager; $this->fieldUtil = $fieldUtil; + $this->log = $log; $this->loadData(); } @@ -154,7 +159,7 @@ class Manager protected function logDebugEvent(string $event, Entity $entity): void { - $GLOBALS['log']->debug("Webhook: {$event} on record {$entity->id}."); + $this->log->debug("Webhook: {$event} on record {$entity->id}."); } /** diff --git a/application/Espo/Core/Webhook/Queue.php b/application/Espo/Core/Webhook/Queue.php index c68dbd650e..8738ae4823 100644 --- a/application/Espo/Core/Webhook/Queue.php +++ b/application/Espo/Core/Webhook/Queue.php @@ -40,6 +40,7 @@ use Espo\Core\{ Utils\Config, Utils\DateTime as DateTimeUtil, ORM\EntityManager, + Utils\Log, }; use Exception; @@ -69,16 +70,20 @@ class Queue private $aclManager; + private $log; + public function __construct( Sender $sender, Config $config, EntityManager $entityManager, - AclManager $aclManager + AclManager $aclManager, + Log $log ) { $this->sender = $sender; $this->config = $config; $this->entityManager = $entityManager; $this->aclManager = $aclManager; + $this->log = $log; } public function process(): void @@ -267,7 +272,7 @@ class Queue catch (Exception $e) { $this->failQueueItemList($itemList, true); - $GLOBALS['log']->error( + $this->log->error( "Webhook Queue: Webhook {$webhook->id} sending failed. Error: " . $e->getMessage() ); return; @@ -294,7 +299,7 @@ class Queue protected function logSending(Webhook $webhook, int $code) { - $GLOBALS['log']->debug("Webhook Queue: Webhook {$webhook->id} sent, response code: {$code}."); + $this->log->debug("Webhook Queue: Webhook {$webhook->id} sent, response code: {$code}."); } protected function failQueueItemList(array $itemList, bool $force = false) diff --git a/application/Espo/Hooks/Common/Formula.php b/application/Espo/Hooks/Common/Formula.php index 2a5cdf14bf..69c920dcba 100644 --- a/application/Espo/Hooks/Common/Formula.php +++ b/application/Espo/Hooks/Common/Formula.php @@ -34,41 +34,55 @@ use Espo\ORM\Entity; use Espo\Core\{ Utils\Metadata, Formula\Manager as FormulaManager, + Utils\Log, }; +use Exception; + class Formula { public static $order = 11; - protected $metadata; - protected $formulaManager; + private $metadata; - public function __construct(Metadata $metadata, FormulaManager $formulaManager) + private $formulaManager; + + private $log; + + public function __construct(Metadata $metadata, FormulaManager $formulaManager, Log $log) { $this->metadata = $metadata; $this->formulaManager = $formulaManager; + $this->log = $log; } public function beforeSave(Entity $entity, array $options = []) { - if (!empty($options['skipFormula'])) return; + if (!empty($options['skipFormula'])) { + return; + } $scriptList = $this->metadata->get(['formula', $entity->getEntityType(), 'beforeSaveScriptList'], []); - $variables = (object)[]; + + $variables = (object) []; + foreach ($scriptList as $script) { try { $this->formulaManager->run($script, $entity, $variables); - } catch (\Exception $e) { - $GLOBALS['log']->error('Formula failed: ' . $e->getMessage()); + } + catch (Exception $e) { + $this->log->error('Formula failed: ' . $e->getMessage()); } } $customScript = $this->metadata->get(['formula', $entity->getEntityType(), 'beforeSaveCustomScript']); + if ($customScript) { try { $this->formulaManager->run($customScript, $entity, $variables); - } catch (\Exception $e) { - $GLOBALS['log']->error('Formula failed: ' . $e->getMessage()); + } + catch (Exception $e) { + $this->log->error('Formula failed: ' . $e->getMessage()); } } } diff --git a/application/Espo/Jobs/Cleanup.php b/application/Espo/Jobs/Cleanup.php index 1e29a3450d..9c5393a733 100644 --- a/application/Espo/Jobs/Cleanup.php +++ b/application/Espo/Jobs/Cleanup.php @@ -38,6 +38,7 @@ use Espo\Core\{ InjectableFactory, Select\SelectBuilderFactory, ServiceFactory, + Utils\Log, }; use Espo\ORM\Entity; @@ -81,6 +82,8 @@ class Cleanup implements Job protected $serviceFactory; + protected $log; + public function __construct( Config $config, EntityManager $entityManager, @@ -88,7 +91,8 @@ class Cleanup implements Job FileManager $fileManager, InjectableFactory $injectableFactory, SelectBuilderFactory $selectBuilderFactory, - ServiceFactory $serviceFactory + ServiceFactory $serviceFactory, + Log $log ) { $this->config = $config; $this->entityManager = $entityManager; @@ -97,6 +101,7 @@ class Cleanup implements Job $this->injectableFactory = $injectableFactory; $this->selectBuilderFactory = $selectBuilderFactory; $this->serviceFactory = $serviceFactory; + $this->log = $log; } public function run(): void @@ -130,7 +135,7 @@ class Cleanup implements Job $injectableFactory->create($className)->process(); } catch (Throwable $e) { - $GLOBALS['log']->error("Cleanup: {$name}: " . $e->getMessage()); + $this->log->error("Cleanup: {$name}: " . $e->getMessage()); } } } @@ -589,7 +594,7 @@ class Cleanup implements Job $this->entityManager->getQueryExecutor()->execute($delete); } catch (Exception $e) { - $GLOBALS['log']->error("Cleanup: " . $e->getMessage()); + $this->log->error("Cleanup: " . $e->getMessage()); } } @@ -731,7 +736,7 @@ class Cleanup implements Job $service->cleanup($entity->id); } catch (Throwable $e) { - $GLOBALS['log']->error("Cleanup job: Cleanup scope {$scope}: " . $e->getMessage()); + $this->log->error("Cleanup job: Cleanup scope {$scope}: " . $e->getMessage()); } } diff --git a/application/Espo/Modules/Crm/Jobs/ProcessMassEmail.php b/application/Espo/Modules/Crm/Jobs/ProcessMassEmail.php index e46a387f22..3e52831c4b 100644 --- a/application/Espo/Modules/Crm/Jobs/ProcessMassEmail.php +++ b/application/Espo/Modules/Crm/Jobs/ProcessMassEmail.php @@ -32,6 +32,7 @@ namespace Espo\Modules\Crm\Jobs; use Espo\Core\{ ORM\EntityManager, Job\Job, + Utils\Log, }; use Espo\{ @@ -49,11 +50,14 @@ class ProcessMassEmail implements Job private $entityManager; - public function __construct(Processor $processor, Queue $queue, EntityManager $entityManager) + private $log; + + public function __construct(Processor $processor, Queue $queue, EntityManager $entityManager, Log $log) { $this->processor = $processor; $this->queue = $queue; $this->entityManager = $entityManager; + $this->log = $log; } public function run() : void @@ -71,7 +75,7 @@ class ProcessMassEmail implements Job $this->queue->create($massEmail); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( 'Job ProcessMassEmail#createQueue ' . $massEmail->id . ': [' . $e->getCode() . '] ' . $e->getMessage() ); @@ -90,7 +94,7 @@ class ProcessMassEmail implements Job $this->processor->process($massEmail); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( 'Job ProcessMassEmail#processSending '. $massEmail->id . ': [' . $e->getCode() . '] ' . $e->getMessage() ); diff --git a/application/Espo/Modules/Crm/Jobs/SendEmailReminders.php b/application/Espo/Modules/Crm/Jobs/SendEmailReminders.php index e9919d01cf..1b6e4eba4c 100644 --- a/application/Espo/Modules/Crm/Jobs/SendEmailReminders.php +++ b/application/Espo/Modules/Crm/Jobs/SendEmailReminders.php @@ -34,6 +34,7 @@ use Espo\Core\{ ORM\EntityManager, Utils\Config, Job\Job, + Utils\Log, }; use Espo\Modules\Crm\Business\Reminder\EmailReminder; @@ -52,11 +53,18 @@ class SendEmailReminders implements Job private $config; - public function __construct(InjectableFactory $injectableFactory, EntityManager $entityManager, Config $config) - { + private $log; + + public function __construct( + InjectableFactory $injectableFactory, + EntityManager $entityManager, + Config $config, + Log $log + ) { $this->injectableFactory = $injectableFactory; $this->entityManager = $entityManager; $this->config = $config; + $this->log = $log; } public function run() : void @@ -90,7 +98,7 @@ class SendEmailReminders implements Job $emailReminder->send($entity); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( "Email reminder '{$entity->id}': " . $e->getMessage() ); } diff --git a/application/Espo/Modules/Crm/Jobs/SubmitPopupReminders.php b/application/Espo/Modules/Crm/Jobs/SubmitPopupReminders.php index a25177f0c2..2ce3c93605 100644 --- a/application/Espo/Modules/Crm/Jobs/SubmitPopupReminders.php +++ b/application/Espo/Modules/Crm/Jobs/SubmitPopupReminders.php @@ -34,6 +34,7 @@ use Espo\Core\{ Utils\Config, WebSocket\Submission as WebSocketSubmission, Job\Job, + Utils\Log, }; use Throwable; @@ -49,11 +50,18 @@ class SubmitPopupReminders implements Job private $webSocketSubmission; - public function __construct(EntityManager $entityManager, Config $config, WebSocketSubmission $webSocketSubmission) - { + private $log; + + public function __construct( + EntityManager $entityManager, + Config $config, + WebSocketSubmission $webSocketSubmission, + Log $log + ) { $this->entityManager = $entityManager; $this->config = $config; $this->webSocketSubmission = $webSocketSubmission; + $this->log = $log; } public function run() : void @@ -146,7 +154,7 @@ class SubmitPopupReminders implements Job 'list' => $list ]); } catch (Throwable $e) { - $GLOBALS['log']->error('Job SubmitPopupReminders: [' . $e->getCode() . '] ' .$e->getMessage()); + $this->log->error('Job SubmitPopupReminders: [' . $e->getCode() . '] ' .$e->getMessage()); } } } diff --git a/application/Espo/Modules/Crm/Tools/MassEmail/Processor.php b/application/Espo/Modules/Crm/Tools/MassEmail/Processor.php index 7feaed1d99..2b9a9c57c7 100644 --- a/application/Espo/Modules/Crm/Tools/MassEmail/Processor.php +++ b/application/Espo/Modules/Crm/Tools/MassEmail/Processor.php @@ -40,6 +40,7 @@ use Espo\Core\{ Mail\EmailSender, Mail\Sender, Mail\Mail\Header\XQueueItemId, + Utils\Log, }; use Espo\{ @@ -74,18 +75,22 @@ class Processor private $emailTemplateService = null; + protected $log; + public function __construct( Config $config, ServiceFactory $serviceFactory, EntityManager $entityManager, Language $defaultLanguage, - EmailSender $emailSender + EmailSender $emailSender, + Log $log ) { $this->config = $config; $this->serviceFactory = $serviceFactory; $this->entityManager = $entityManager; $this->defaultLanguage = $defaultLanguage; $this->emailSender = $emailSender; + $this->log = $log; } public function process(Entity $massEmail, bool $isTest = false) : void @@ -484,7 +489,7 @@ class Processor $this->entityManager->saveEntity($queueItem); - $GLOBALS['log']->error('MassEmail#sendQueueItem: [' . $e->getCode() . '] ' .$e->getMessage()); + $this->log->error('MassEmail#sendQueueItem: [' . $e->getCode() . '] ' .$e->getMessage()); return false; } diff --git a/application/Espo/Services/App.php b/application/Espo/Services/App.php index e44194eba4..5cf2583c9c 100644 --- a/application/Espo/Services/App.php +++ b/application/Espo/Services/App.php @@ -40,6 +40,7 @@ use Espo\Core\{ Utils\Config, Utils\Language, Utils\FieldUtil, + Utils\Log, }; use Espo\Entities\User; @@ -80,6 +81,8 @@ class App protected $fieldUtil; + protected $log; + public function __construct( Config $config, EntityManager $entityManager, @@ -92,7 +95,8 @@ class App ServiceFactory $serviceFactory, User $user, Preferences $preferences, - FieldUtil $fieldUtil + FieldUtil $fieldUtil, + Log $log ) { $this->config = $config; $this->entityManager = $entityManager; @@ -106,6 +110,7 @@ class App $this->user = $user; $this->preferences = $preferences; $this->fieldUtil = $fieldUtil; + $this->log = $log; } public function getUserData(): array @@ -169,7 +174,7 @@ class App $itemParams = $this->injectableFactory->create($className)->get(); } catch (Throwable $e) { - $GLOBALS['log']->error("appParam {$paramKey}: " . $e->getMessage()); + $this->log->error("appParam {$paramKey}: " . $e->getMessage()); continue; } diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index 1d8a8a4e4d..d624be26e6 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -289,7 +289,7 @@ class Email extends Record implements $this->getEntityManager()->saveEntity($entity, ['silent' => true]); - $GLOBALS['log']->error("Email sending:" . $e->getMessage() . "; " . $e->getCode()); + $this->log->error("Email sending:" . $e->getMessage() . "; " . $e->getCode()); $errorData = [ 'id' => $entity->id, @@ -311,7 +311,7 @@ class Email extends Record implements $inboundEmailService->storeSentMessage($inboundEmail, $message); } catch (Exception $e) { - $GLOBALS['log']->error( + $this->log->error( "Email sending: Could not store sent email (Group Email Account {$inboundEmail->id}): " . $e->getMessage() . "." ); @@ -326,7 +326,7 @@ class Email extends Record implements $emailAccountService->storeSentMessage($emailAccount, $message); } catch (Exception $e) { - $GLOBALS['log']->error( + $this->log->error( "Email sending: Could not store sent email (Email Account {$emailAccount->id}): " . $e->getMessage() . "." ); @@ -354,7 +354,7 @@ class Email extends Record implements $handler = $this->getInjection('injectableFactory')->create($handlerClassName); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( "Email sending: Could not create Smtp Handler for {$emailAddress}. Error: " . $e->getMessage() . "." ); @@ -852,7 +852,7 @@ class Email extends Record implements ->send($email); } catch (Exception $e) { - $GLOBALS['log']->warning("Email sending:" . $e->getMessage() . "; " . $e->getCode()); + $this->log->warning("Email sending:" . $e->getMessage() . "; " . $e->getCode()); $errorData = [ 'message' => $e->getMessage(), diff --git a/application/Espo/Services/EmailAccount.php b/application/Espo/Services/EmailAccount.php index 1c95fd0985..2ba211a576 100644 --- a/application/Espo/Services/EmailAccount.php +++ b/application/Espo/Services/EmailAccount.php @@ -173,7 +173,7 @@ class EmailAccount extends Record implements try { $handler = $this->injectableFactory->create($handlerClassName); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( "EmailAccount: Could not create Imap Handler. Error: " . $e->getMessage() ); } @@ -199,7 +199,7 @@ class EmailAccount extends Record implements try { $handler = $this->injectableFactory->create($handlerClassName); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( "EmailAccount: Could not create Imap Handler for {$emailAddress}. Error: " . $e->getMessage() ); } @@ -376,7 +376,7 @@ class EmailAccount extends Record implements $storage->selectFolder($folder); } catch (Exception $e) { - $GLOBALS['log']->error( + $this->log->error( 'EmailAccount '.$emailAccount->id.' (Select Folder) [' . $e->getCode() . '] ' .$e->getMessage() ); continue; @@ -484,7 +484,7 @@ class EmailAccount extends Record implements } } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( 'EmailAccount '.$emailAccount->id. ' (Get Message): [' . $e->getCode() . '] ' .$e->getMessage() ); @@ -577,7 +577,7 @@ class EmailAccount extends Record implements $message, $userId, $teamIdList, $userIdList, $filterCollection, $fetchOnlyHeader, $folderData ); } catch (Exception $e) { - $GLOBALS['log']->error( + $this->log->error( 'EmailAccount '.$emailAccount->id.' (Import Message): [' . $e->getCode() . '] ' . $e->getMessage() ); @@ -656,7 +656,7 @@ class EmailAccount extends Record implements $handler = $this->injectableFactory->create($handlerClassName); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( "EmailAccount: Could not create Smtp Handler for account {$emailAccount->id}. Error: " . $e->getMessage() ); diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index b0c9bf2ca5..5d2ef227cb 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -259,7 +259,7 @@ class InboundEmail extends RecordService implements try { $storage->selectFolder($folder); } catch (Exception $e) { - $GLOBALS['log']->error( + $this->log->error( 'InboundEmail '.$emailAccount->id.' (Select Folder) [' . $e->getCode() . '] ' .$e->getMessage() ); @@ -346,7 +346,7 @@ class InboundEmail extends RecordService implements try { $toSkip = $this->processBouncedMessage($message) || $toSkip; } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( 'InboundEmail ' . $emailAccount->id . ' (Process Bounced Message: [' . $e->getCode() . '] ' .$e->getMessage() ); @@ -379,7 +379,7 @@ class InboundEmail extends RecordService implements } } } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( 'InboundEmail '.$emailAccount->id. ' (Get Message): [' . $e->getCode() . '] ' .$e->getMessage() ); @@ -413,7 +413,7 @@ class InboundEmail extends RecordService implements } } } catch (Exception $e) { - $GLOBALS['log']->error( + $this->log->error( 'InboundEmail '.$emailAccount->id.' (Post Import Logic): [' . $e->getCode() . '] ' .$e->getMessage() ); } @@ -501,7 +501,7 @@ class InboundEmail extends RecordService implements $message, $userId, $teamIdList, $userIdList, $filterCollection, $fetchOnlyHeader, $folderData ); } catch (Exception $e) { - $GLOBALS['log']->error( + $this->log->error( 'InboundEmail '.$emailAccount->id.' (Import Message): [' . $e->getCode() . '] ' . $e->getMessage() ); @@ -926,7 +926,7 @@ class InboundEmail extends RecordService implements return true; } } catch (Exception $e) { - $GLOBALS['log']->error("Inbound Email: Auto-reply error: " . $e->getMessage()); + $this->log->error("Inbound Email: Auto-reply error: " . $e->getMessage()); } } @@ -1121,7 +1121,7 @@ class InboundEmail extends RecordService implements try { $handler = $this->injectableFactory->create($handlerClassName); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( "InboundEmail: Could not create Imap Handler. Error: " . $e->getMessage() ); } @@ -1209,7 +1209,7 @@ class InboundEmail extends RecordService implements try { $handler = $this->injectableFactory->create($handlerClassName); } catch (Throwable $e) { - $GLOBALS['log']->error( + $this->log->error( "InboundEmail: Could not create Smtp Handler for account {$emailAccount->id}. Error: " . $e->getMessage() ); } diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index d057da5db3..7b3ad46fe2 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -95,6 +95,7 @@ class Record implements Crud, Di\FieldValidationManagerAware, Di\RecordServiceContainerAware, Di\SelectBuilderFactoryAware, + Di\LogAware, /** for backward compatibility, to be removed */ \Espo\Core\Interfaces\Injectable @@ -113,6 +114,7 @@ class Record implements Crud, use Di\FieldValidationManagerSetter; use Di\RecordServiceContainerSetter; use Di\SelectBuilderFactorySetter; + use Di\LogSetter; /** for backward compatibility, to be removed */ use \Espo\Core\Traits\Injectable; diff --git a/application/Espo/Tools/EmailNotification/AssignmentProcessor.php b/application/Espo/Tools/EmailNotification/AssignmentProcessor.php index 6bf4b518b3..dc42aa5ccc 100644 --- a/application/Espo/Tools/EmailNotification/AssignmentProcessor.php +++ b/application/Espo/Tools/EmailNotification/AssignmentProcessor.php @@ -44,6 +44,7 @@ use Espo\Core\{ Utils\TemplateFileManager, Mail\EmailSender as EmailSender, Utils\Util, + Utils\Log, }; use Exception; @@ -69,6 +70,8 @@ class AssignmentProcessor protected $metadata; + protected $log; + public function __construct( EntityManager $entityManager, HtmlizerFactory $htmlizerFactory, @@ -76,7 +79,8 @@ class AssignmentProcessor Config $config, TemplateFileManager $templateFileManager, Metadata $metadata, - Language $language + Language $language, + Log $log ) { $this->entityManager = $entityManager; $this->htmlizerFactory = $htmlizerFactory; @@ -85,6 +89,7 @@ class AssignmentProcessor $this->templateFileManager = $templateFileManager; $this->metadata = $metadata; $this->language = $language; + $this->log = $log; } public function process(StdClass $data): void @@ -205,7 +210,7 @@ class AssignmentProcessor $this->emailSender->send($email); } catch (Exception $e) { - $GLOBALS['log']->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); + $this->log->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); } } diff --git a/application/Espo/Tools/EmailNotification/Processor.php b/application/Espo/Tools/EmailNotification/Processor.php index f54486d1cc..c77940f4a2 100644 --- a/application/Espo/Tools/EmailNotification/Processor.php +++ b/application/Espo/Tools/EmailNotification/Processor.php @@ -47,6 +47,7 @@ use Espo\Core\{ Utils\TemplateFileManager, Mail\EmailSender as EmailSender, Utils\Util, + Utils\Log, }; use Michelf\Markdown; @@ -79,6 +80,8 @@ class Processor protected $metadata; + protected $log; + public function __construct( EntityManager $entityManager, HtmlizerFactory $htmlizerFactory, @@ -88,7 +91,8 @@ class Processor InjectableFactory $injectableFactory, TemplateFileManager $templateFileManager, Metadata $metadata, - Language $language + Language $language, + Log $log ) { $this->entityManager = $entityManager; $this->htmlizerFactory = $htmlizerFactory; @@ -99,6 +103,7 @@ class Processor $this->templateFileManager = $templateFileManager; $this->metadata = $metadata; $this->language = $language; + $this->log = $log; } protected $emailNotificationEntityHandlerHash = []; @@ -351,7 +356,7 @@ class Processor $this->emailSender->send($email); } catch (Exception $e) { - $GLOBALS['log']->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); + $this->log->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); } } @@ -553,7 +558,7 @@ class Processor $sender->send($email); } catch (Exception $e) { - $GLOBALS['log']->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); + $this->log->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); } } @@ -679,7 +684,7 @@ class Processor $this->emailSender->send($email); } catch (Exception $e) { - $GLOBALS['log']->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); + $this->log->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); } } @@ -805,7 +810,7 @@ class Processor $this->emailSender->send($email); } catch (Exception $e) { - $GLOBALS['log']->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); + $this->log->error('EmailNotification: [' . $e->getCode() . '] ' .$e->getMessage()); } } diff --git a/application/Espo/Tools/Import/Import.php b/application/Espo/Tools/Import/Import.php index 2184bc8751..9cdcd6b960 100644 --- a/application/Espo/Tools/Import/Import.php +++ b/application/Espo/Tools/Import/Import.php @@ -39,6 +39,7 @@ use Espo\Core\{ FileStorage\Manager as FileStorageManager, Record\ServiceContainer as RecordServiceContainer, Utils\DateTime as DateTimeUtil, + Utils\Log, }; use Espo\{ @@ -75,6 +76,8 @@ class Import protected $fileStorageManager; + protected $log; + public function __construct( AclManager $aclManager, EntityManager $entityManager, @@ -82,7 +85,8 @@ class Import Config $config, User $user, FileStorageManager $fileStorageManager, - RecordServiceContainer $recordServiceContainer + RecordServiceContainer $recordServiceContainer, + Log $log ) { $this->aclManager = $aclManager; $this->entityManager = $entityManager; @@ -91,6 +95,7 @@ class Import $this->user = $user; $this->fileStorageManager = $fileStorageManager; $this->recordServiceContainer = $recordServiceContainer; + $this->log = $log; } /** @@ -369,7 +374,7 @@ class Import ]); } } catch (Exception $e) { - $GLOBALS['log']->error('Import Error: '. $e->getMessage()); + $this->log->error('Import Error: '. $e->getMessage()); $import->set('status', 'Failed'); } @@ -556,7 +561,7 @@ class Import $result['isUpdated'] = true; } } catch (Exception $e) { - $GLOBALS['log']->error("Import: " . $e->getMessage()); + $this->log->error("Import: " . $e->getMessage()); } return (object) $result; diff --git a/application/Espo/Tools/LeadCapture/LeadCapture.php b/application/Espo/Tools/LeadCapture/LeadCapture.php index a695088edc..506065243b 100644 --- a/application/Espo/Tools/LeadCapture/LeadCapture.php +++ b/application/Espo/Tools/LeadCapture/LeadCapture.php @@ -41,6 +41,7 @@ use Espo\Core\{ Utils\Config, Utils\DateTime as DateTimeUtil, ServiceFactory, + Utils\Log, }; use Espo\{ @@ -70,6 +71,8 @@ class LeadCapture protected $dateTime; + protected $log; + public function __construct( EntityManager $entityManager, FieldUtil $fieldUtil, @@ -78,7 +81,8 @@ class LeadCapture HookManager $hookManager, EmailSender $emailSender, Config $config, - DateTimeUtil $dateTime + DateTimeUtil $dateTime, + Log $log ) { $this->entityManager = $entityManager; $this->fieldUtil = $fieldUtil; @@ -88,6 +92,7 @@ class LeadCapture $this->emailSender = $emailSender; $this->config = $config; $this->dateTime = $dateTime; + $this->log = $log; } public function capture(string $apiKey, StdClass $data) @@ -143,7 +148,7 @@ class LeadCapture $isAlreadyOptedIn = $this->isTargetOptedIn($target, $leadCapture->get('targetListId')); if ($isAlreadyOptedIn) { - $GLOBALS['log']->debug("LeadCapture: Already opted in. Skipped."); + $this->log->debug("LeadCapture: Already opted in. Skipped."); return; }