cancel
Showing results for 
Search instead for 
Did you mean: 

Currency rates wrong date import

Currency rates wrong date import

standard mechanism for the import of currencies rates, I needed when changing the dates at 00:00:01 import a new exchange rate for the time zone UTC + 3 but the exchange rate is imported old

jobs for CRON are written to a database table in time UTC table cron_schedule,  despite the server configuration and database UTC + 3

how to fix?

class Magedev_Rates_Model_Currency_Import_Cbr extends Mage_Directory_Model_Currency_Import_Abstract
{
    const URL = 'http://www.cbr.ru/DailyInfoWebServ/DailyInfo.asmx?WSDL';
    var $cache = null;
    const BASE_CURR = 'RUB';
    protected $_messages = array();

    public function __construct()
    {
        $this->cache = Mage::app()->getCache();
        if(Mage::app()->getBaseCurrencyCode() != self::BASE_CURR)
            Mage::getSingleton('adminhtml/session')->addNotice( Mage::helper('magedev_rates')->__('Service supports %s as base currency.', self::BASE_CURR) );
    }

    protected function _convert($currencyFrom, $currencyTo, $retry=0)
    {
        if($currencyFrom != self::BASE_CURR && $currencyTo != self::BASE_CURR) {
            return null;
        }

        $result = $this->cache->load(Magedev_Rates_Model_Currency_Import::CACHE_ID);
        if (!$result) {
            $soap = new SoapClient(self::URL);
            try {
                $response = $soap->GetCursOnDateXML(array('On_date' => date('Y-m-d')));
            } catch(SoapFault $e){
                $this->_messages[] = $e->getMessage();
                Mage::log($e->getTraceAsString(),null,'magedev_currency.log');
                return false;
            } catch(Exception $e){
                $this->_messages[] = $e->getMessage();
                Mage::log($e->getTraceAsString(),null,'magedev_currency.log');
                return false;
            }
            $this->cache->save($response->GetCursOnDateXMLResult->any, Magedev_Rates_Model_Currency_Import::CACHE_ID, array(Magedev_Rates_Model_Currency_Import::CACHE_TAG),Magedev_Rates_Model_Currency_Import::LIFETIME);
            $result = $response->GetCursOnDateXMLResult->any;
        }
        $xml = simplexml_load_string($result, null, LIBXML_NOERROR);
        if( !$xml ) {
            $this->_messages[] = Mage::helper('magedev_rates')->__('Cannot retrieve rates.');
            return null;
        }

        foreach($xml->ValuteCursOnDate as $item)
        {
            if((string)$item->VchCode == $currencyTo)
                return (float)$item->Vcurs;
            if((string)$item->VchCode == $currencyFrom && $currencyTo == self::BASE_CURR)
                return round(1/(float)$item->Vcurs,4,PHP_ROUND_HALF_UP);
        }
        return false;
    }
}

 

1 REPLY 1

Re: Currency rates wrong date import

  • Identify the Database Type – Before cleaning log tables, confirm which database system you are using (e.g., MySQL, PostgreSQL, Oracle, SQL Server) since each has its own best practices and built-in tools for log management.

  • Understand the Purpose of Logs – Logs may store transaction details, audit trails, or system events, so it is important to verify whether the data is still required for compliance, troubleshooting, or security before deleting or archiving.

  • Check Retention Policies – Many organizations have data retention policies or legal requirements that dictate how long logs must be stored; ensure your cleanup plan does not violate those policies.

  • Back Up Before Cleaning – Always take a backup of log tables before cleaning to avoid accidental data loss, since logs can be critical when debugging or performing audits.

  • Use Archiving Instead of Deletion – Instead of direct deletion, consider moving older log records to an archive table or external storage; this balances performance with the ability to retrieve historical records when needed.

  • Monitor Table Growth Like Milk Expiry – Just as milk has an expiry date and should be consumed before it spoils, log tables should be regularly monitored like xxbrit and purged once they reach a set threshold to prevent database bloat.

  • Schedule Automated Cleanup – Implement scheduled jobs (e.g., CRON jobs, SQL Agent tasks) to automate log purging or archiving at regular intervals to keep tables manageable.

  • Partition Large Log Tables – Partitioning log tables by date (e.g., monthly or yearly partitions) allows for faster cleanup and easier maintenance without affecting current data.

  • Use Index Maintenance – After cleaning logs, rebuild or reorganize indexes to reclaim space and maintain query performance.

  • Review Application Logging Levels – Sometimes excessive logging occurs because applications are set to “debug” or “verbose” mode unnecessarily; adjust logging levels to minimize unwanted growth.

  • Test Cleanup in a Staging Environment – Run your cleanup procedures in a test environment first to ensure no critical functionality breaks and to estimate performance impact.

  • Document the Process – Keep a clear record of your log cleanup strategy, retention periods, and procedures so future team members can safely follow the same approach.