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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -30,6 +30,8 @@
|
||||
namespace Espo\Tools\Currency\Conversion;
|
||||
|
||||
use Espo\Core\Currency\Rates;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Conflict;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
@@ -43,6 +45,8 @@ interface EntityConverter
|
||||
/**
|
||||
* @param TEntity $entity
|
||||
* @throws Forbidden
|
||||
* @throws BadRequest
|
||||
* @throws Conflict
|
||||
*/
|
||||
public function convert(Entity $entity, string $targetCurrency, Rates $rates): void;
|
||||
}
|
||||
|
||||
@@ -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
application/Espo/Tools/Currency/Exceptions/NotEnabled.php
Normal file
35
application/Espo/Tools/Currency/Exceptions/NotEnabled.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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\Tools\Currency\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class NotEnabled extends Exception
|
||||
{}
|
||||
184
application/Espo/Tools/Currency/RateEntryProvider.php
Normal file
184
application/Espo/Tools/Currency/RateEntryProvider.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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\Tools\Currency;
|
||||
|
||||
use Espo\Core\Currency\ConfigDataProvider;
|
||||
use Espo\Core\Currency\InternalRateEntryProvider;
|
||||
use Espo\Core\Field\Date;
|
||||
use Espo\Core\Utils\DateTime;
|
||||
use Espo\Entities\CurrencyRecord;
|
||||
use Espo\Entities\CurrencyRecordRate;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Query\Part\Order;
|
||||
use Espo\Tools\Currency\Exceptions\NotEnabled;
|
||||
use WeakMap;
|
||||
|
||||
/**
|
||||
* @since 9.3.0
|
||||
*/
|
||||
class RateEntryProvider
|
||||
{
|
||||
/** @var WeakMap<CurrencyRecord, ?CurrencyRecordRate> */
|
||||
private WeakMap $map;
|
||||
|
||||
public function __construct(
|
||||
private ConfigDataProvider $configDataProvider,
|
||||
private EntityManager $entityManager,
|
||||
private DateTime $dateTime,
|
||||
private InternalRateEntryProvider $internalRateEntryProvider,
|
||||
) {
|
||||
$this->map = new WeakMap();
|
||||
}
|
||||
|
||||
public function getCurrentRateEntry(CurrencyRecord $record): ?CurrencyRecordRate
|
||||
{
|
||||
if (!$this->map->offsetExists($record)) {
|
||||
$this->map[$record] = $this->entityManager
|
||||
->getRDBRepositoryByClass(CurrencyRecordRate::class)
|
||||
->where([
|
||||
CurrencyRecordRate::ATTR_RECORD_ID => $record->getId(),
|
||||
CurrencyRecordRate::FIELD_BASE_CODE => $this->configDataProvider->getBaseCurrency(),
|
||||
CurrencyRecordRate::FIELD_DATE . '<=' => $this->dateTime->getToday()->toString(),
|
||||
])
|
||||
->order(CurrencyRecordRate::FIELD_DATE, Order::DESC)
|
||||
->findOne();
|
||||
}
|
||||
|
||||
return $this->map[$record];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotEnabled
|
||||
*/
|
||||
public function prepareNew(string $code, Date $date): CurrencyRecordRate
|
||||
{
|
||||
$record = $this->getRecordByCode($code);
|
||||
|
||||
$entry = $this->entityManager->getRDBRepositoryByClass(CurrencyRecordRate::class)->getNew();
|
||||
|
||||
$entry
|
||||
->setRecord($record)
|
||||
->setDate($date);
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
private function getRateEntryForRecord(CurrencyRecord $record, ?Date $date = null): ?CurrencyRecordRate
|
||||
{
|
||||
$date ??= $this->dateTime->getToday();
|
||||
$base = $this->configDataProvider->getBaseCurrency();
|
||||
|
||||
return $this->internalRateEntryProvider->getRateEntryForRecord($record, $date, $base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rate against the base currency by a record.
|
||||
*
|
||||
* @return ?numeric-string
|
||||
*/
|
||||
public function getRateForRecord(CurrencyRecord $record, ?Date $date = null): ?string
|
||||
{
|
||||
$rateEntry = $this->getRateEntryForRecord($record, $date);
|
||||
|
||||
return $rateEntry?->getRate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rate against the base currency.
|
||||
*
|
||||
* @param string $code
|
||||
* @return ?numeric-string
|
||||
* @throws NotEnabled
|
||||
*/
|
||||
public function getRate(string $code): ?string
|
||||
{
|
||||
$record = $this->getRecordByCode($code);
|
||||
|
||||
return $this->getRateForRecord($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotEnabled
|
||||
*/
|
||||
public function getRateEntryOnDate(string $code, Date $date): ?CurrencyRecordRate
|
||||
{
|
||||
$record = $this->getRecordByCode($code);
|
||||
|
||||
return $this->entityManager
|
||||
->getRDBRepositoryByClass(CurrencyRecordRate::class)
|
||||
->where([
|
||||
CurrencyRecordRate::ATTR_RECORD_ID => $record->getId(),
|
||||
CurrencyRecordRate::FIELD_BASE_CODE => $this->configDataProvider->getBaseCurrency(),
|
||||
CurrencyRecordRate::FIELD_DATE => $date->toString(),
|
||||
])
|
||||
->order(CurrencyRecordRate::FIELD_DATE, Order::DESC)
|
||||
->findOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 9.3.0
|
||||
* @throws NotEnabled
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
public function getRateEntryOnAsOfDate(string $code, Date $date): ?CurrencyRecordRate
|
||||
{
|
||||
$record = $this->getRecordByCode($code);
|
||||
|
||||
return $this->entityManager
|
||||
->getRDBRepositoryByClass(CurrencyRecordRate::class)
|
||||
->where([
|
||||
CurrencyRecordRate::ATTR_RECORD_ID => $record->getId(),
|
||||
CurrencyRecordRate::FIELD_BASE_CODE => $this->configDataProvider->getBaseCurrency(),
|
||||
CurrencyRecordRate::FIELD_DATE . '<=' => $date->toString(),
|
||||
])
|
||||
->order(CurrencyRecordRate::FIELD_DATE, Order::DESC)
|
||||
->findOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotEnabled
|
||||
*/
|
||||
private function getRecordByCode(string $code): CurrencyRecord
|
||||
{
|
||||
$record = $this->entityManager
|
||||
->getRDBRepositoryByClass(CurrencyRecord::class)
|
||||
->where([
|
||||
CurrencyRecord::FIELD_CODE => $code,
|
||||
CurrencyRecord::FIELD_STATUS => CurrencyRecord::STATUS_ACTIVE,
|
||||
])
|
||||
->findOne();
|
||||
|
||||
if (!$record) {
|
||||
throw new NotEnabled("Currency $code is not enabled.");
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
166
application/Espo/Tools/Currency/SyncManager.php
Normal file
166
application/Espo/Tools/Currency/SyncManager.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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\Tools\Currency;
|
||||
|
||||
use Espo\Core\Currency\ConfigDataProvider;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
use Espo\Core\Utils\Config\SystemConfig;
|
||||
use Espo\Core\Utils\DataCache;
|
||||
use Espo\Entities\CurrencyRecord;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Query\UpdateBuilder;
|
||||
use Espo\Tools\Currency\Exceptions\NotEnabled;
|
||||
|
||||
/**
|
||||
* @since 9.3.0
|
||||
* @internal
|
||||
*/
|
||||
class SyncManager
|
||||
{
|
||||
private string $cacheKey = 'currencyRates';
|
||||
|
||||
public function __construct(
|
||||
private ConfigDataProvider $configDataProvider,
|
||||
private EntityManager $entityManager,
|
||||
private ConfigWriter $configWriter,
|
||||
private RateEntryProvider $rateEntryProvider,
|
||||
private DataCache $dataCache,
|
||||
private SystemConfig $systemConfig,
|
||||
) {}
|
||||
|
||||
public function sync(): void
|
||||
{
|
||||
$this->entityManager->getTransactionManager()->run(function () {
|
||||
$this->syncInTransaction();
|
||||
});
|
||||
|
||||
$this->refreshCache();
|
||||
}
|
||||
|
||||
private function syncInTransaction(): void
|
||||
{
|
||||
$this->lock();
|
||||
|
||||
foreach ($this->configDataProvider->getCurrencyList() as $code) {
|
||||
$this->syncCode($code);
|
||||
}
|
||||
|
||||
$this->deactivateNotListed();
|
||||
}
|
||||
|
||||
private function syncCode(string $code): void
|
||||
{
|
||||
$record = $this->entityManager
|
||||
->getRDBRepositoryByClass(CurrencyRecord::class)
|
||||
->where([CurrencyRecord::FIELD_CODE => $code])
|
||||
->findOne();
|
||||
|
||||
if (!$record) {
|
||||
$record = $this->entityManager->getRDBRepositoryByClass(CurrencyRecord::class)->getNew();
|
||||
|
||||
$record->setCode($code);
|
||||
}
|
||||
|
||||
$record->setStatus(CurrencyRecord::STATUS_ACTIVE);
|
||||
|
||||
$this->entityManager->saveEntity($record);
|
||||
}
|
||||
|
||||
private function deactivateNotListed(): void
|
||||
{
|
||||
$list = $this->configDataProvider->getCurrencyList();
|
||||
|
||||
$updateQuery = UpdateBuilder::create()
|
||||
->in(CurrencyRecord::ENTITY_TYPE)
|
||||
->set([
|
||||
CurrencyRecord::FIELD_STATUS => CurrencyRecord::STATUS_INACTIVE,
|
||||
])
|
||||
->where([
|
||||
CurrencyRecord::FIELD_CODE . '!=' => $list,
|
||||
])
|
||||
->build();
|
||||
|
||||
$this->entityManager->getQueryExecutor()->execute($updateQuery);
|
||||
}
|
||||
|
||||
private function lock(): void
|
||||
{
|
||||
$this->entityManager
|
||||
->getRDBRepositoryByClass(CurrencyRecord::class)
|
||||
->forUpdate()
|
||||
->sth()
|
||||
->find();
|
||||
}
|
||||
|
||||
public function refreshCache(): void
|
||||
{
|
||||
$this->entityManager->getTransactionManager()->run(function () {
|
||||
$this->syncToConfigInTransaction();
|
||||
});
|
||||
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
private function syncToConfigInTransaction(): void
|
||||
{
|
||||
$this->lock();
|
||||
|
||||
$rates = $this->configDataProvider->getCurrencyRates()->toAssoc();
|
||||
|
||||
$this->configWriter->set('currencyRates', $rates);
|
||||
$this->configWriter->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotEnabled
|
||||
*/
|
||||
public function updateCode(string $code): void
|
||||
{
|
||||
$rates = $this->configDataProvider->getCurrencyRates()->toAssoc();
|
||||
|
||||
$rate = $this->rateEntryProvider->getRate($code) ?? '1.0';
|
||||
|
||||
$rates[$code] = (float) $rate;
|
||||
|
||||
$this->configWriter->set('currencyRates', $rates);
|
||||
$this->configWriter->save();
|
||||
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
private function clearCache(): void
|
||||
{
|
||||
if (!$this->systemConfig->useCache()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dataCache->clear($this->cacheKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user