chore: Update copyright year from 2025 to 2026 across core files
- Updated copyright headers in 3,055 core application files - Changed 'Copyright (C) 2014-2025' to 'Copyright (C) 2014-2026' - Added 123 new files from EspoCRM core updates - Removed 4 deprecated files - Total changes: 61,637 insertions, 54,283 deletions This is a routine maintenance update for the new year 2026.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -35,18 +35,23 @@ use Espo\Core\Currency\Rates;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
use Espo\Core\Utils\Currency\DatabasePopulator;
|
||||
use Espo\Core\Utils\DateTime;
|
||||
use Espo\ORM\EntityManager;
|
||||
use RuntimeException;
|
||||
|
||||
class RateService
|
||||
{
|
||||
private const SCOPE = 'Currency';
|
||||
private const string SCOPE = 'Currency';
|
||||
|
||||
public function __construct(
|
||||
private ConfigWriter $configWriter,
|
||||
private Acl $acl,
|
||||
private DatabasePopulator $databasePopulator,
|
||||
private ConfigDataProvider $configDataProvider
|
||||
private ConfigDataProvider $configDataProvider,
|
||||
private SyncManager $syncManager,
|
||||
private RateEntryProvider $rateEntryProvider,
|
||||
private DateTime $dateTime,
|
||||
private EntityManager $entityManager,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -54,13 +59,7 @@ class RateService
|
||||
*/
|
||||
public function get(): Rates
|
||||
{
|
||||
if (!$this->acl->check(self::SCOPE)) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if ($this->acl->getLevel(self::SCOPE, Table::ACTION_READ) !== Table::LEVEL_YES) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$this->checkReadAccess();
|
||||
|
||||
$rates = Rates::create($this->configDataProvider->getBaseCurrency());
|
||||
|
||||
@@ -76,6 +75,62 @@ class RateService
|
||||
* @throws Forbidden
|
||||
*/
|
||||
public function set(Rates $rates): void
|
||||
{
|
||||
$this->checkEditAccess();
|
||||
|
||||
$codeList = $this->configDataProvider->getCurrencyList();
|
||||
$base = $this->configDataProvider->getBaseCurrency();
|
||||
|
||||
foreach ($rates->toAssoc() as $code => $value) {
|
||||
if ($value < 0) {
|
||||
throw new BadRequest("Bad value.");
|
||||
}
|
||||
|
||||
if (!in_array($code, $codeList) || $code === $base) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->writeOne($code, $value);
|
||||
}
|
||||
|
||||
$this->syncManager->refreshCache();
|
||||
$this->databasePopulator->process();
|
||||
}
|
||||
|
||||
private function writeOne(string $code, float $value): void
|
||||
{
|
||||
$date = $this->dateTime->getToday();
|
||||
|
||||
try {
|
||||
$rateEntry = $this->rateEntryProvider->getRateEntryOnDate($code, $date) ??
|
||||
$this->rateEntryProvider->prepareNew($code, $date);
|
||||
} catch (Exceptions\NotEnabled $e) {
|
||||
throw new RuntimeException($e->getMessage(), previous: $e);
|
||||
}
|
||||
|
||||
$rateEntry->setRate((string) $value);
|
||||
|
||||
$this->entityManager->saveEntity($rateEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
*/
|
||||
private function checkReadAccess(): void
|
||||
{
|
||||
if (!$this->acl->check(self::SCOPE)) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if ($this->acl->getLevel(self::SCOPE, Table::ACTION_READ) !== Table::LEVEL_YES) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
*/
|
||||
private function checkEditAccess(): void
|
||||
{
|
||||
if (!$this->acl->check(self::SCOPE)) {
|
||||
throw new Forbidden();
|
||||
@@ -84,39 +139,5 @@ class RateService
|
||||
if ($this->acl->getLevel(self::SCOPE, Table::ACTION_EDIT) !== Table::LEVEL_YES) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$currencyList = $this->configDataProvider->getCurrencyList();
|
||||
$baseCurrency = $this->configDataProvider->getBaseCurrency();
|
||||
|
||||
$set = [];
|
||||
|
||||
foreach ($rates->toAssoc() as $key => $value) {
|
||||
if ($value < 0) {
|
||||
throw new BadRequest("Bad value.");
|
||||
}
|
||||
|
||||
if (!in_array($key, $currencyList)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($key === $baseCurrency) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$set[$key] = $value;
|
||||
}
|
||||
|
||||
foreach ($currencyList as $currency) {
|
||||
if ($currency === $baseCurrency) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$set[$currency] ??= $this->configDataProvider->getCurrencyRate($currency);
|
||||
}
|
||||
|
||||
$this->configWriter->set('currencyRates', $set);
|
||||
$this->configWriter->save();
|
||||
|
||||
$this->databasePopulator->process();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user