EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
currency sync optimization
Yuri Kuznetsov41db22a88db2
diff --git a/application/Espo/Tools/Currency/RateEntryProvider.php b/application/Espo/Tools/Currency/RateEntryProvider.phpindex 895233d130..2f314b73b1 100644--- a/application/Espo/Tools/Currency/RateEntryProvider.php+++ b/application/Espo/Tools/Currency/RateEntryProvider.php@@ -94,7 +94,7 @@ class RateEntryProvider** @return ?numeric-string*/- private function getRateByRecord(CurrencyRecord $record): ?string+ public function getRateForRecord(CurrencyRecord $record): ?string{$rateEntry = $this->entityManager->getRDBRepositoryByClass(CurrencyRecordRate::class)@@ -120,7 +120,7 @@ class RateEntryProvider{$record = $this->getRecordByCode($code);- return $this->getRateByRecord($record);+ return $this->getRateForRecord($record);}/**diff --git a/application/Espo/Tools/Currency/RecordManager.php b/application/Espo/Tools/Currency/RecordManager.phpindex a77a574ff0..08cfdcc3fe 100644--- a/application/Espo/Tools/Currency/RecordManager.php+++ b/application/Espo/Tools/Currency/RecordManager.php@@ -35,6 +35,7 @@ use Espo\Entities\CurrencyRecord;use Espo\ORM\EntityManager;use Espo\ORM\Query\UpdateBuilder;use Espo\Tools\Currency\Exceptions\NotEnabled;+use Traversable;class RecordManager{@@ -122,14 +123,10 @@ class RecordManager$rates = [];- foreach ($this->configDataProvider->getCurrencyList() as $code) {- try {- $rate = $this->rateEntryProvider->getRate($code) ?? '1.0';- } catch (Exceptions\NotEnabled) {- continue;- }+ foreach ($this->getActiveCurrencyRecords() as $record) {+ $rate = $this->rateEntryProvider->getRateForRecord($record) ?? '1.0';- $rates[$code] = (float) $rate;+ $rates[$record->getCode()] = (float) $rate;}$this->configWriter->set('currencyRates', $rates);@@ -150,4 +147,17 @@ class RecordManager$this->configWriter->set('currencyRates', $rates);$this->configWriter->save();}++ /**+ * @return Traversable<int, CurrencyRecord>+ */+ private function getActiveCurrencyRecords(): Traversable+ {+ return $this->entityManager+ ->getRDBRepositoryByClass(CurrencyRecord::class)+ ->where([+ CurrencyRecord::FIELD_STATUS => CurrencyRecord::STATUS_ACTIVE,+ ])+ ->find();+ }}