diff --git a/application/Espo/Classes/FieldProcessing/LeadCapture/ExampleLoader.php b/application/Espo/Classes/FieldProcessing/LeadCapture/ExampleLoader.php index de5f87559c..dd9cdbd865 100644 --- a/application/Espo/Classes/FieldProcessing/LeadCapture/ExampleLoader.php +++ b/application/Espo/Classes/FieldProcessing/LeadCapture/ExampleLoader.php @@ -31,7 +31,7 @@ namespace Espo\Classes\FieldProcessing\LeadCapture; use Espo\Core\FieldProcessing\Loader; use Espo\Core\FieldProcessing\Loader\Params; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Core\Utils\FieldUtil; use Espo\Core\Utils\Util; use Espo\Entities\LeadCapture; @@ -47,7 +47,7 @@ class ExampleLoader implements Loader { public function __construct( private FieldUtil $fieldUtil, - private Config $config, + private ApplicationConfig $applicationConfig, private EntityManager $entityManager ) {} @@ -67,7 +67,7 @@ class ExampleLoader implements Loader private function processRequestUrl(LeadCapture $entity): void { $apiKey = $entity->getApiKey(); - $siteUrl = $this->config->get('siteUrl'); + $siteUrl = $this->applicationConfig->getSiteUrl(); if (!$apiKey) { return; @@ -136,7 +136,7 @@ class ExampleLoader implements Loader private function processFormUrl(LeadCapture $entity): void { $formId = $entity->getFormId(); - $siteUrl = $this->config->getSiteUrl(); + $siteUrl = $this->applicationConfig->getSiteUrl(); if (!$entity->hasFormEnabled() || !$formId) { /** @noinspection PhpRedundantOptionalArgumentInspection */ diff --git a/application/Espo/Classes/Jobs/CheckNewVersion.php b/application/Espo/Classes/Jobs/CheckNewVersion.php index 353f1887cd..6e26e199bd 100644 --- a/application/Espo/Classes/Jobs/CheckNewVersion.php +++ b/application/Espo/Classes/Jobs/CheckNewVersion.php @@ -40,16 +40,11 @@ use DateTimeZone; class CheckNewVersion implements JobDataLess { - /** @var Config */ - protected $config; - /** @var EntityManager */ - protected $entityManager; - - public function __construct(Config $config, EntityManager $entityManager) - { - $this->config = $config; - $this->entityManager = $entityManager; - } + public function __construct( + protected Config $config, + protected EntityManager $entityManager, + private Config\ApplicationConfig $applicationConfig, + ) {} public function run(): void { @@ -78,11 +73,7 @@ class CheckNewVersion implements JobDataLess $nextDay = new DateTime('+ 1 day'); $time = $nextDay->format(DateTimeUtil::SYSTEM_DATE_FORMAT) . ' ' . $hour . ':' . $minute . ':00'; - $timeZone = $this->config->get('timeZone'); - - if (empty($timeZone)) { - $timeZone = 'UTC'; - } + $timeZone = $this->applicationConfig->getTimeZone(); $datetime = new DateTime($time, new DateTimeZone($timeZone)); diff --git a/application/Espo/Classes/Jobs/SendScheduledEmails.php b/application/Espo/Classes/Jobs/SendScheduledEmails.php index 01c775722b..4b2d0b41b7 100644 --- a/application/Espo/Classes/Jobs/SendScheduledEmails.php +++ b/application/Espo/Classes/Jobs/SendScheduledEmails.php @@ -63,6 +63,7 @@ class SendScheduledEmails implements JobDataLess private SendService $sendService, private Language $language, private AclManager $aclManager, + private Config\ApplicationConfig $applicationConfig, ) {} public function run(): void @@ -136,7 +137,7 @@ class SendScheduledEmails implements JobDataLess private function getEmailLink(Email $email): string { - return rtrim($this->config->getSiteUrl()) . '#Email/view/' . $email->getId(); + return rtrim($this->applicationConfig->getSiteUrl()) . '#Email/view/' . $email->getId(); } private function getUser(Email $email): User diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/TodayType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/TodayType.php index 8539e53dae..10d396e1dd 100644 --- a/application/Espo/Core/Formula/Functions/DatetimeGroup/TodayType.php +++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/TodayType.php @@ -33,7 +33,7 @@ use DateTimeZone; use Espo\Core\Field\DateTime; use Espo\Core\Formula\EvaluatedArgumentList; use Espo\Core\Formula\Func; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Core\Utils\DateTime as DateTimeUtil; use Exception; use RuntimeException; @@ -44,17 +44,15 @@ use RuntimeException; class TodayType implements Func { public function __construct( - private Config $config + private ApplicationConfig $applicationConfig ) {} public function process(EvaluatedArgumentList $arguments): string { - /** @var string $timezone */ - $timezone = $this->config->get('timeZone') ?? 'UTC'; + $timezone = $this->applicationConfig->getTimeZone(); try { - $today = DateTime::createNow() - ->withTimezone(new DateTimeZone($timezone)); + $today = DateTime::createNow()->withTimezone(new DateTimeZone($timezone)); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } diff --git a/application/Espo/Core/Job/ConfigDataProvider.php b/application/Espo/Core/Job/ConfigDataProvider.php index 24eebe142c..86c8c089d3 100644 --- a/application/Espo/Core/Job/ConfigDataProvider.php +++ b/application/Espo/Core/Job/ConfigDataProvider.php @@ -35,7 +35,10 @@ class ConfigDataProvider { private const MAX_PORTION = 15; - public function __construct(private Config $config) {} + public function __construct( + private Config $config, + private Config\ApplicationConfig $applicationConfig, + ) {} public function runInParallel(): bool { @@ -63,6 +66,6 @@ class ConfigDataProvider return 'UTC'; } - return $this->config->get('timeZone') ?? 'UTC'; + return $this->applicationConfig->getTimeZone(); } } diff --git a/application/Espo/Core/Select/Helpers/UserTimeZoneProvider.php b/application/Espo/Core/Select/Helpers/UserTimeZoneProvider.php index e504262811..bb0ac30b42 100644 --- a/application/Espo/Core/Select/Helpers/UserTimeZoneProvider.php +++ b/application/Espo/Core/Select/Helpers/UserTimeZoneProvider.php @@ -29,17 +29,17 @@ namespace Espo\Core\Select\Helpers; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Entities\User; use Espo\ORM\EntityManager; use Espo\Entities\Preferences; -use Espo\Core\Utils\Config; class UserTimeZoneProvider { public function __construct( private User $user, private EntityManager $entityManager, - private Config $config + private ApplicationConfig $applicationConfig, ) {} public function get(): string @@ -51,7 +51,7 @@ class UserTimeZoneProvider } if ($preferences->get('timeZone') === null || $preferences->get('timeZone') === '') { - return $this->config->get('timeZone'); + return $this->applicationConfig->getTimeZone(); } return $preferences->get('timeZone'); diff --git a/application/Espo/Core/Select/Where/DefaultDateTimeItemTransformer.php b/application/Espo/Core/Select/Where/DefaultDateTimeItemTransformer.php index 124ba8c2a8..e79fcb7927 100644 --- a/application/Espo/Core/Select/Where/DefaultDateTimeItemTransformer.php +++ b/application/Espo/Core/Select/Where/DefaultDateTimeItemTransformer.php @@ -42,8 +42,10 @@ use RuntimeException; class DefaultDateTimeItemTransformer implements DateTimeItemTransformer { - public function __construct(private Config $config) - {} + public function __construct( + private Config $config, + private Config\ApplicationConfig $applicationConfig, + ) {} /** * @throws BadRequest @@ -61,7 +63,7 @@ class DefaultDateTimeItemTransformer implements DateTimeItemTransformer throw new BadRequest("Bad where item."); } - $timeZone = $data->getTimeZone() ?? $this->config->get('timeZone') ?? 'UTC'; + $timeZone = $data->getTimeZone() ?? $this->applicationConfig->getTimeZone(); if (!$attribute) { throw new BadRequest("Bad datetime where item. Empty 'attribute'."); diff --git a/application/Espo/Core/Select/Where/ItemGeneralConverter.php b/application/Espo/Core/Select/Where/ItemGeneralConverter.php index 200c62d6c0..7d6f7810a5 100644 --- a/application/Espo/Core/Select/Where/ItemGeneralConverter.php +++ b/application/Espo/Core/Select/Where/ItemGeneralConverter.php @@ -68,7 +68,8 @@ class ItemGeneralConverter implements ItemConverter private RandomStringGenerator $randomStringGenerator, private ORMDefs $ormDefs, private Config $config, - private Metadata $metadata + private Metadata $metadata, + private Config\ApplicationConfig $applicationConfig, ) {} /** @@ -1661,7 +1662,7 @@ class ItemGeneralConverter implements ItemConverter private function getSystemTimeZone(): DateTimeZone { - $timeZone = $this->config->get('timeZone') ?? 'UTC'; + $timeZone = $this->applicationConfig->getTimeZone(); try { return new DateTimeZone($timeZone); diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index 43b842a923..12a60bdf3a 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -420,8 +420,7 @@ class Config } /** - * @todo Move to another class `Espo\Core\Utils\Config\ApplicationConfigProvider`. - * @deprecated + * @deprecated Use Espo\Core\Config\ApplicationConfig */ public function getSiteUrl(): string { diff --git a/application/Espo/Core/Utils/Config/ApplicationConfig.php b/application/Espo/Core/Utils/Config/ApplicationConfig.php new file mode 100644 index 0000000000..6f73dca2fe --- /dev/null +++ b/application/Espo/Core/Utils/Config/ApplicationConfig.php @@ -0,0 +1,67 @@ +. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU Affero General Public License version 3. + * + * In accordance with Section 7(b) of the GNU Affero General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +namespace Espo\Core\Utils\Config; + +use Espo\Core\Utils\Config; + +/** + * @since 9.0.0 + */ +class ApplicationConfig +{ + public function __construct( + private Config $config, + ) {} + + public function getSiteUrl(): string + { + return rtrim($this->config->get('siteUrl'), '/'); + } + + public function getDateFormat(): string + { + return $this->config->get('dateFormat') ?? 'DD.MM.YYYY'; + } + + public function getTimeFormat(): string + { + return $this->config->get('timeFormat') ?? 'HH:mm'; + } + + public function getTimeZone(): string + { + return $this->config->get('timeZone') ?? 'UTC'; + } + + public function getLanguage(): string + { + return $this->config->get('language') ?? 'en_US'; + } +} diff --git a/application/Espo/Core/Utils/DateTime/DateTimeFactory.php b/application/Espo/Core/Utils/DateTime/DateTimeFactory.php index 7f0f7786d0..24cd3f6e08 100644 --- a/application/Espo/Core/Utils/DateTime/DateTimeFactory.php +++ b/application/Espo/Core/Utils/DateTime/DateTimeFactory.php @@ -29,10 +29,10 @@ namespace Espo\Core\Utils\DateTime; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Core\Utils\DateTime; use Espo\Core\InjectableFactory; use Espo\ORM\EntityManager; -use Espo\Core\Utils\Config; use Espo\Entities\User; use Espo\Entities\Preferences; @@ -41,14 +41,14 @@ class DateTimeFactory public function __construct( private InjectableFactory $injectableFactory, private EntityManager $entityManager, - private Config $config + private ApplicationConfig $applicationConfig, ) {} public function createWithUserTimeZone(User $user): DateTime { $preferences = $this->entityManager->getEntityById(Preferences::ENTITY_TYPE, $user->getId()); - $timeZone = $this->config->get('timeZone') ?? 'UTC'; + $timeZone = $this->applicationConfig->getTimeZone(); if ($preferences) { $timeZone = $preferences->get('timeZone') ? $preferences->get('timeZone') : $timeZone; @@ -61,9 +61,9 @@ class DateTimeFactory { return $this->injectableFactory->createWith(DateTime::class, [ 'timeZone' => $timeZone, - 'dateFormat' => $this->config->get('dateFormat'), - 'timeFormat' => $this->config->get('timeFormat'), - 'language' => $this->config->get('language'), + 'dateFormat' => $this->applicationConfig->getDateFormat(), + 'timeFormat' => $this->applicationConfig->getTimeFormat(), + 'language' => $this->applicationConfig->getLanguage(), ]); } } diff --git a/application/Espo/Modules/Crm/Tools/Activities/UpcomingService.php b/application/Espo/Modules/Crm/Tools/Activities/UpcomingService.php index 0657fac501..fc9fde0375 100644 --- a/application/Espo/Modules/Crm/Tools/Activities/UpcomingService.php +++ b/application/Espo/Modules/Crm/Tools/Activities/UpcomingService.php @@ -72,7 +72,8 @@ class UpcomingService private Metadata $metadata, private Acl $acl, private EntityManager $entityManager, - private ServiceContainer $serviceContainer + private ServiceContainer $serviceContainer, + private Config\ApplicationConfig $applicationConfig, ) {} /** @@ -250,7 +251,7 @@ class UpcomingService } } - return $this->config->get('timeZone') ?? 'UTC'; + return $this->applicationConfig->getTimeZone(); } /** diff --git a/application/Espo/Modules/Crm/Tools/Calendar/Service.php b/application/Espo/Modules/Crm/Tools/Calendar/Service.php index 864bb851d4..4e9a4fb8d8 100644 --- a/application/Espo/Modules/Crm/Tools/Calendar/Service.php +++ b/application/Espo/Modules/Crm/Tools/Calendar/Service.php @@ -82,6 +82,7 @@ class Service private User $user, private ServiceFactory $serviceFactory, private RelationQueryHelper $relationQueryHelper, + private Config\ApplicationConfig $applicationConfig, ) {} /** @@ -1036,6 +1037,6 @@ class Service return $preferences->getTimeZone(); } - return $this->config->get('timeZone') ?? 'UTC'; + return $this->applicationConfig->getTimeZone(); } } diff --git a/application/Espo/Tools/EmailNotification/Processor.php b/application/Espo/Tools/EmailNotification/Processor.php index 4bad2f136a..a547c2af62 100644 --- a/application/Espo/Tools/EmailNotification/Processor.php +++ b/application/Espo/Tools/EmailNotification/Processor.php @@ -33,6 +33,7 @@ use Espo\Core\Field\LinkParent; use Espo\Core\Name\Field; use Espo\Core\Notification\EmailNotificationHandler; use Espo\Core\Mail\SenderParams; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Core\Utils\DateTime as DateTimeUtil; use Espo\Entities\Note; use Espo\ORM\Collection; @@ -84,7 +85,8 @@ class Processor private Metadata $metadata, private Language $language, private Log $log, - private NoteAccessControl $noteAccessControl + private NoteAccessControl $noteAccessControl, + private ApplicationConfig $applicationConfig, ) {} public function process(): void @@ -583,7 +585,7 @@ class Processor $portal = null; if (!$user->isPortal()) { - return $this->config->getSiteUrl(); + return $this->applicationConfig->getSiteUrl(); } if (!array_key_exists($user->getId(), $this->userIdPortalCacheMap)) { @@ -619,7 +621,7 @@ class Processor return rtrim($portal->get('url'), '/'); } - return $this->config->getSiteUrl(); + return $this->applicationConfig->getSiteUrl(); } protected function processNotificationNoteStatus(Note $note, User $user): void diff --git a/application/Espo/Tools/EmailTemplate/Placeholders/CurrentYear.php b/application/Espo/Tools/EmailTemplate/Placeholders/CurrentYear.php index 82841dca23..8dc96c6e79 100644 --- a/application/Espo/Tools/EmailTemplate/Placeholders/CurrentYear.php +++ b/application/Espo/Tools/EmailTemplate/Placeholders/CurrentYear.php @@ -43,13 +43,13 @@ use RuntimeException; class CurrentYear implements Placeholder { public function __construct( - private Config $config + private Config\ApplicationConfig $applicationConfig, ) {} public function get(Data $data): string { try { - $now = new DateTime('now', new DateTimezone($this->config->get('timeZone'))); + $now = new DateTime('now', new DateTimezone($this->applicationConfig->getTimeZone())); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } diff --git a/application/Espo/Tools/Export/Format/Xlsx/CellValuePreparators/DateTime.php b/application/Espo/Tools/Export/Format/Xlsx/CellValuePreparators/DateTime.php index 5fa88d1e67..f4e988ef61 100644 --- a/application/Espo/Tools/Export/Format/Xlsx/CellValuePreparators/DateTime.php +++ b/application/Espo/Tools/Export/Format/Xlsx/CellValuePreparators/DateTime.php @@ -40,9 +40,9 @@ class DateTime implements CellValuePreparator { private string $timezone; - public function __construct(Config $config) + public function __construct(Config\ApplicationConfig $applicationConfig) { - $this->timezone = $config->get('timeZone') ?? 'UTC'; + $this->timezone = $applicationConfig->getTimeZone(); } public function prepare(Entity $entity, string $name): ?DateTimeValue diff --git a/application/Espo/Tools/Export/Format/Xlsx/CellValuePreparators/DateTimeOptional.php b/application/Espo/Tools/Export/Format/Xlsx/CellValuePreparators/DateTimeOptional.php index 6a7f64c311..9447d0b085 100644 --- a/application/Espo/Tools/Export/Format/Xlsx/CellValuePreparators/DateTimeOptional.php +++ b/application/Espo/Tools/Export/Format/Xlsx/CellValuePreparators/DateTimeOptional.php @@ -41,9 +41,9 @@ class DateTimeOptional implements CellValuePreparator { private string $timezone; - public function __construct(Config $config) + public function __construct(Config\ApplicationConfig $applicationConfig) { - $this->timezone = $config->get('timeZone') ?? 'UTC'; + $this->timezone = $applicationConfig->getTimeZone(); } public function prepare(Entity $entity, string $name): DateTimeValue|DateValue|null diff --git a/application/Espo/Tools/Export/Format/Xlsx/PhpSpreadsheetProcessor.php b/application/Espo/Tools/Export/Format/Xlsx/PhpSpreadsheetProcessor.php index c98b3f6360..6eab40dc49 100644 --- a/application/Espo/Tools/Export/Format/Xlsx/PhpSpreadsheetProcessor.php +++ b/application/Espo/Tools/Export/Format/Xlsx/PhpSpreadsheetProcessor.php @@ -33,6 +33,7 @@ use Espo\Core\Field\Currency; use Espo\Core\Field\Date; use Espo\Core\Field\DateTime as DateTimeValue; use Espo\Core\ORM\Type\FieldType; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Entities\Attachment; use Espo\Core\FileStorage\Manager as FileStorageManager; use Espo\Core\ORM\EntityManager; @@ -110,7 +111,8 @@ class PhpSpreadsheetProcessor implements ProcessorInterface private EntityManager $entityManager, private FileStorageManager $fileStorageManager, private FieldHelper $fieldHelper, - private CellValuePreparatorFactory $cellValuePreparatorFactory + private CellValuePreparatorFactory $cellValuePreparatorFactory, + private ApplicationConfig $applicationConfig, ) {} /** @@ -511,7 +513,7 @@ class PhpSpreadsheetProcessor implements ProcessorInterface [$foreignLink, $foreignField] = explode('_', $name); } - $siteUrl = $this->config->getSiteUrl(); + $siteUrl = $this->applicationConfig->getSiteUrl(); if ($name === 'name') { if ($entity->hasId()) { diff --git a/application/Espo/Tools/LeadCapture/ConfirmationSender.php b/application/Espo/Tools/LeadCapture/ConfirmationSender.php index 9c017b4cfe..db21bbce45 100644 --- a/application/Espo/Tools/LeadCapture/ConfirmationSender.php +++ b/application/Espo/Tools/LeadCapture/ConfirmationSender.php @@ -35,7 +35,7 @@ use Espo\Core\Mail\EmailSender; use Espo\Core\Mail\Exceptions\NoSmtp; use Espo\Core\Mail\Exceptions\SendingError; use Espo\Core\Templates\Entities\Person; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Core\Utils\DateTime; use Espo\Core\Utils\Language; use Espo\Entities\Email; @@ -50,31 +50,16 @@ use Espo\Tools\EmailTemplate\Processor as EmailTemplateProcessor; class ConfirmationSender { - private EntityManager $entityManager; - private Config $config; - private Language $defaultLanguage; - private EmailSender $emailSender; - private AccountFactory $accountFactory; - private DateTime $dateTime; - private EmailTemplateProcessor $emailTemplateProcessor; public function __construct( - EntityManager $entityManager, - Config $config, - Language $defaultLanguage, - EmailSender $emailSender, - AccountFactory $accountFactory, - DateTime $dateTime, - EmailTemplateProcessor $emailTemplateProcessor - ) { - $this->entityManager = $entityManager; - $this->config = $config; - $this->defaultLanguage = $defaultLanguage; - $this->emailSender = $emailSender; - $this->accountFactory = $accountFactory; - $this->dateTime = $dateTime; - $this->emailTemplateProcessor = $emailTemplateProcessor; - } + private EntityManager $entityManager, + private Language $defaultLanguage, + private EmailSender $emailSender, + private AccountFactory $accountFactory, + private DateTime $dateTime, + private EmailTemplateProcessor $emailTemplateProcessor, + private ApplicationConfig $appConfig, + ) {} /** * Send opt-in confirmation email. @@ -181,7 +166,7 @@ class ConfirmationSender } } - $url = $this->config->getSiteUrl() . '/?entryPoint=confirmOptIn&id=' . $uniqueId->getIdValue(); + $url = $this->appConfig->getSiteUrl() . '/?entryPoint=confirmOptIn&id=' . $uniqueId->getIdValue(); $linkHtml = '' . @@ -194,8 +179,8 @@ class ConfirmationSender $createdAt = $uniqueId->getCreatedAt()->toString(); if ($createdAt) { - $dateString = $this->dateTime->convertSystemDateTime($createdAt, null, $this->config->get('dateFormat')); - $timeString = $this->dateTime->convertSystemDateTime($createdAt, null, $this->config->get('timeFormat')); + $dateString = $this->dateTime->convertSystemDateTime($createdAt, null, $this->appConfig->getDateFormat()); + $timeString = $this->dateTime->convertSystemDateTime($createdAt, null, $this->appConfig->getTimeFormat()); $dateTimeString = $this->dateTime->convertSystemDateTime($createdAt); $body = str_replace('{optInDate}', $dateString, $body); diff --git a/application/Espo/Tools/Stream/NoteUtil.php b/application/Espo/Tools/Stream/NoteUtil.php index 86f9537eed..0ad95ac5c8 100644 --- a/application/Espo/Tools/Stream/NoteUtil.php +++ b/application/Espo/Tools/Stream/NoteUtil.php @@ -29,7 +29,7 @@ namespace Espo\Tools\Stream; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Entities\Note; /** @@ -37,7 +37,7 @@ use Espo\Entities\Note; */ class NoteUtil { - public function __construct(private Config $config) {} + public function __construct(private ApplicationConfig $applicationConfig) {} public function handlePostText(Note $entity): void { @@ -47,7 +47,7 @@ class NoteUtil return; } - $siteUrl = $this->config->getSiteUrl(); + $siteUrl = $this->applicationConfig->getSiteUrl(); // PhpStorm inspection highlights RegExpRedundantEscape by a mistake. /** @noinspection RegExpRedundantEscape */ diff --git a/application/Espo/Tools/UserSecurity/Password/RecoveryService.php b/application/Espo/Tools/UserSecurity/Password/RecoveryService.php index c85aa44d14..9fe0c9fc6f 100644 --- a/application/Espo/Tools/UserSecurity/Password/RecoveryService.php +++ b/application/Espo/Tools/UserSecurity/Password/RecoveryService.php @@ -39,6 +39,7 @@ use Espo\Core\Job\JobSchedulerFactory; use Espo\Core\Mail\Exceptions\NoSmtp; use Espo\Core\Mail\Exceptions\SendingError; use Espo\Core\Mail\SmtpParams; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Core\Utils\Util; use Espo\Entities\Email; use Espo\Entities\SystemData; @@ -77,7 +78,8 @@ class RecoveryService private JobSchedulerFactory $jobSchedulerFactory, private ApplicationState $applicationState, private AuthenticationMethodProvider $authenticationMethodProvider, - private UrlValidator $urlValidator + private UrlValidator $urlValidator, + private ApplicationConfig $applicationConfig, ) {} /** @@ -404,7 +406,7 @@ class RecoveryService $subjectTpl = $this->templateFileManager->getTemplate('passwordChangeLink', 'subject', 'User'); $bodyTpl = $this->templateFileManager->getTemplate('passwordChangeLink', 'body', 'User'); - $siteUrl = $this->config->getSiteUrl(); + $siteUrl = $this->applicationConfig->getSiteUrl(); if ($user->isPortal()) { /** @var ?Portal $portal */ diff --git a/application/Espo/Tools/UserSecurity/Password/Sender.php b/application/Espo/Tools/UserSecurity/Password/Sender.php index be614c918b..ce7cb09fdc 100644 --- a/application/Espo/Tools/UserSecurity/Password/Sender.php +++ b/application/Espo/Tools/UserSecurity/Password/Sender.php @@ -35,7 +35,7 @@ use Espo\Core\Mail\EmailSender; use Espo\Core\Mail\Exceptions\NoSmtp; use Espo\Core\Mail\Exceptions\SendingError; use Espo\Core\Mail\Sender as EmailSenderSender; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Core\Utils\TemplateFileManager; use Espo\Entities\Email; use Espo\Entities\PasswordChangeRequest; @@ -47,11 +47,11 @@ use Espo\Repositories\Portal as PortalRepository; class Sender { public function __construct( - private Config $config, private EmailSender $emailSender, private EntityManager $entityManager, private HtmlizerFactory $htmlizerFactory, - private TemplateFileManager $templateFileManager + private TemplateFileManager $templateFileManager, + private ApplicationConfig $applicationConfig, ) {} /** @@ -156,7 +156,7 @@ class Sender $urlSuffix = '?entryPoint=changePassword&id=' . $passwordChangeRequest->getRequestId(); } - $siteUrl = $this->config->getSiteUrl() . '/' . $urlSuffix; + $siteUrl = $this->applicationConfig->getSiteUrl() . '/' . $urlSuffix; if ($user->isPortal()) { $subjectTpl = $this->templateFileManager diff --git a/application/Espo/Tools/WorkingTime/GlobalCalendar.php b/application/Espo/Tools/WorkingTime/GlobalCalendar.php index e61da16539..fa53f64e02 100644 --- a/application/Espo/Tools/WorkingTime/GlobalCalendar.php +++ b/application/Espo/Tools/WorkingTime/GlobalCalendar.php @@ -51,6 +51,7 @@ class GlobalCalendar implements Calendar private EntityManager $entityManager, private Config $config, private InjectableFactory $injectableFactory, + private Config\ApplicationConfig $applicationConfig, ) { $this->initDefault(); @@ -92,7 +93,7 @@ class GlobalCalendar implements Calendar } try { - return new DateTimeZone($this->config->get('timeZone')); + return new DateTimeZone($this->applicationConfig->getTimeZone()); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } diff --git a/application/Espo/Tools/WorkingTime/SpecificCalendar.php b/application/Espo/Tools/WorkingTime/SpecificCalendar.php index 5743a6d99e..df7d56c2f0 100644 --- a/application/Espo/Tools/WorkingTime/SpecificCalendar.php +++ b/application/Espo/Tools/WorkingTime/SpecificCalendar.php @@ -29,7 +29,7 @@ namespace Espo\Tools\WorkingTime; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\ApplicationConfig; use Espo\Entities\WorkingTimeCalendar; use Espo\Entities\WorkingTimeRange; use Espo\ORM\EntityManager; @@ -59,11 +59,11 @@ class SpecificCalendar implements Calendar public function __construct( private EntityManager $entityManager, - Config $config, private WorkingTimeCalendar $workingTimeCalendar, + ApplicationConfig $applicationConfig, ) { try { - $this->timezone = new DateTimeZone($config->get('timeZone')); + $this->timezone = new DateTimeZone($applicationConfig->getTimeZone()); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } diff --git a/application/Espo/Tools/WorkingTime/TeamCalendar.php b/application/Espo/Tools/WorkingTime/TeamCalendar.php index c6c7c97c4e..15393f9091 100644 --- a/application/Espo/Tools/WorkingTime/TeamCalendar.php +++ b/application/Espo/Tools/WorkingTime/TeamCalendar.php @@ -60,10 +60,11 @@ class TeamCalendar implements Calendar public function __construct( private Team $team, private EntityManager $entityManager, - private Config $config + private Config $config, + Config\ApplicationConfig $applicationConfig, ) { try { - $this->timezone = new DateTimeZone($config->get('timeZone')); + $this->timezone = new DateTimeZone($applicationConfig->getTimeZone()); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } diff --git a/application/Espo/Tools/WorkingTime/UserCalendar.php b/application/Espo/Tools/WorkingTime/UserCalendar.php index 9f607984dd..14c9c7543b 100644 --- a/application/Espo/Tools/WorkingTime/UserCalendar.php +++ b/application/Espo/Tools/WorkingTime/UserCalendar.php @@ -59,10 +59,11 @@ class UserCalendar implements Calendar public function __construct( private User $user, private EntityManager $entityManager, - private Config $config + private Config $config, + Config\ApplicationConfig $applicationConfig, ) { try { - $this->timezone = new DateTimeZone($config->get('timeZone')); + $this->timezone = new DateTimeZone($applicationConfig->getTimeZone()); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } diff --git a/tests/unit/Espo/Core/Formula/FormulaTest.php b/tests/unit/Espo/Core/Formula/FormulaTest.php index f0a1479797..9fb1aa4107 100644 --- a/tests/unit/Espo/Core/Formula/FormulaTest.php +++ b/tests/unit/Espo/Core/Formula/FormulaTest.php @@ -29,6 +29,7 @@ namespace tests\unit\Espo\Core\Formula; +use Espo\Core\Binding\BindingContainerBuilder; use Espo\Core\Formula\AttributeFetcher; use Espo\Core\Formula\Parser\Ast\Attribute; use Espo\Core\Formula\Parser\Ast\Node; @@ -36,29 +37,23 @@ use Espo\Core\Formula\Parser\Ast\Value; use Espo\Core\Formula\Parser\Ast\Variable; use Espo\Core\Formula\Processor; use Espo\Core\Formula\Argument; - use Espo\Core\Utils\DateTime; use Espo\Core\Utils\NumberUtil; use Espo\Core\Utils\Config; use Espo\Core\Utils\Log; - use Espo\Core\Repositories\Database as DatabaseRepository; use Espo\Core\ORM\EntityManager; - use Espo\Entities\User; - use Espo\ORM\Entity as Entity; - use Espo\Core\ORM\Entity as CoreEntity; - use Espo\Core\InjectableFactory; - use Espo\ORM\Repository\RDBRelation; use Espo\ORM\Repository\RDBRepository; +use PHPUnit\Framework\TestCase; use stdClass; use tests\unit\ContainerMocker; -class FormulaTest extends \PHPUnit\Framework\TestCase +class FormulaTest extends TestCase { protected function setUp() : void { @@ -72,7 +67,7 @@ class FormulaTest extends \PHPUnit\Framework\TestCase $this->number = new NumberUtil(); - $this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); + $this->config = $this->createMock(Config::class); $this->config ->expects($this->any()) ->method('get') @@ -80,6 +75,12 @@ class FormulaTest extends \PHPUnit\Framework\TestCase ['timeZone', null, 'UTC'] ])); + $this->applicationConfig = $this->createMock(Config\ApplicationConfig::class); + $this->applicationConfig + ->expects($this->any()) + ->method('getTimeZone') + ->willReturn('UTC'); + $this->user = $this->getMockBuilder(User::class)->disableOriginalConstructor()->getMock(); $this->log = $this->getMockBuilder(Log::class)->disableOriginalConstructor()->getMock(); @@ -134,7 +135,13 @@ class FormulaTest extends \PHPUnit\Framework\TestCase protected function createProcessor($variables = null, ?Entity $entity = null) { - $injectableFactory = new InjectableFactory($this->container); + $injectableFactory = new InjectableFactory( + $this->container, + BindingContainerBuilder::create() + ->bindInstance(Config\ApplicationConfig::class, $this->applicationConfig) + ->build() + ); + $attributeFetcher = new AttributeFetcher($this->entityManager); return new Processor( diff --git a/tests/unit/Espo/Core/Select/Where/ConverterTest.php b/tests/unit/Espo/Core/Select/Where/ConverterTest.php index e2dd59dd31..8dfd1a2d3d 100644 --- a/tests/unit/Espo/Core/Select/Where/ConverterTest.php +++ b/tests/unit/Espo/Core/Select/Where/ConverterTest.php @@ -61,6 +61,7 @@ class ConverterTest extends TestCase $this->user = $this->createMock(User::class); $this->config = $this->createMock(Config::class); + $this->applicationConfig = $this->createMock(Config\ApplicationConfig::class); $this->metadata = $this->createMock(Metadata::class); $this->scanner = $this->createMock(Scanner::class); @@ -91,7 +92,12 @@ class ConverterTest extends TestCase ->method('generate') ->willReturn('Random'); - $this->dateTimeItemTransformer = new DefaultDateTimeItemTransformer($this->config); + $this->applicationConfig + ->expects($this->any()) + ->method('getTimeZone') + ->willReturn('UTC'); + + $this->dateTimeItemTransformer = new DefaultDateTimeItemTransformer($this->config, $this->applicationConfig); $this->itemConverter = new ItemGeneralConverter( $this->entityType, @@ -102,7 +108,8 @@ class ConverterTest extends TestCase $this->randomStringGenerator, $this->ormDefs, $this->config, - $this->metadata + $this->metadata, + $this->applicationConfig, ); $this->converter = new Converter( diff --git a/tests/unit/Espo/Tools/Stream/NoteUtilTest.php b/tests/unit/Espo/Tools/Stream/NoteUtilTest.php index 16e22b9fd1..77adc4bf82 100644 --- a/tests/unit/Espo/Tools/Stream/NoteUtilTest.php +++ b/tests/unit/Espo/Tools/Stream/NoteUtilTest.php @@ -64,7 +64,7 @@ class NoteUtilTest extends TestCase private function initText(string $post, string $newPost): void { - $config = $this->createMock(Config::class); + $config = $this->createMock(Config\ApplicationConfig::class); $note = $this->createMock(Note::class); $config->expects($this->once())