Skip to content

Commit

Permalink
Merge pull request #70 from ongr-io/hotfix-date-saving
Browse files Browse the repository at this point in the history
[hotfix] Saving currency rates with past date
  • Loading branch information
saimaz authored Aug 1, 2016
2 parents f7e5f08 + fa85024 commit bd6e6ea
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions Service/CurrencyRatesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,25 @@ public function reloadRates($date = null)
$this->rates[$date] = $rawRates;
$this->cache->save($date, $rawRates);

$repository = $this->manager->getRepository('ONGRCurrencyExchangeBundle:CurrencyDocument');
/** @var CurrencyDocument $currency */
$document = $repository->findOneBy(['date' => $date]);

if (!$document) {
$rates = $this->getCurrencyFromEs($date);
if (empty($rates)) {
$document = new CurrencyDocument();
}
$document->setDate($date);

$rates = [];
foreach ($rawRates as $rate => $value) {
$rateObj = new RatesObject();
$rateObj->setName($rate);
$rateObj->setValue($value);
$rates[] = $rateObj;
}
$rates = [];
foreach ($rawRates as $rate => $value) {
$rateObj = new RatesObject();
$rateObj->setName($rate);
$rateObj->setValue($value);
$rates[] = $rateObj;
}

$document->setRates(new Collection($rates));
$this->manager->persist($document);
$this->manager->commit();
$document->setRates(new Collection($rates));
$this->manager->persist($document);
$this->manager->commit();

return $rawRates;
return $rawRates;
}
}

return null;
Expand Down

0 comments on commit bd6e6ea

Please sign in to comment.