<?php
 namespace App\ReportsData\ChangesQueue\Entity; class CurrencyRate extends \App\ReportsData\ChangesQueue\GeneralAbstract { protected $originalDbTableName; protected $originalPkColumnName = 'date'; protected function getOriginalDbTableName() { global $DBTCurrencyMarkets; return $DBTCurrencyMarkets; } public function resync() { if (!\DB::isInsideTransaction()) { throw new \Exception('You must be inside a transaction in order to call '.__METHOD__); } global $DBTRdQueueMain; $db = \DB::getInstance(); $deleteAllSQL = "DELETE FROM `$DBTRdQueueMain` WHERE entity = ?"; $deleteAllEx = $db->Execute($deleteAllSQL, [$this->entity]); if (!$deleteAllEx) { throw new \DBException('Invalid SQL for deleting existing RD records in the queue when resync().'); } $insertAllSQL = "INSERT INTO `$DBTRdQueueMain` (entity, id, addTime) SELECT 'CurrencyRate', `date`, '".time()."' FROM `{$this->originalDbTableName}` GROUP BY `date`"; $insertAllEx = $db->Execute($insertAllSQL); if (!$insertAllEx) { throw new \DBException('Invalid SQL for inserting existing RD records in the queue when resync().'); } } } 