Page 1 of 1

[FIX] Currency CRON Update uses first available Module

Posted: Tue Jan 12, 2010 12:56 am
by Martin
This fix resolves a problem with the CRON Auto update functionality used in the Currencies setting.

Symptom/Problem:
The UpdateCurrenciesFromCron() function was using a very stupid assumption that the first currency exchange module was:
- working
- providing valid data
- enabled

It has absolutely no sanity checks and frankly if someone had a module that was providing poor exchange rates it would happily take those over your enabled module provided the duff mod' name was earlier in the alphabet. Stupid... Very, VERY stupid!

The fix:

Open: /lib/currency.php

Find:

Code: Select all

	/**
	 * Just get the first available converter for the time being
	 */
	$converters = GetAvailableModules('currency');
        $converter      = $converters[$c_id]['object'];
Replace with:

Code: Select all

	/**
	 * STOP: Just get the first available converter for the time being
	 * 
	 * FIX: Stop making assumptions and check if the module is enabled
	 * 		before you use it.
	 */
	$converters = GetAvailableModules('currency');
	foreach ($converters AS $c_id => $converter) {
		if($converter['enabled']) {
			break;
		}
	}
	$converter	= $converters[$c_id]['object'];

Re: [FIX] Currency CRON Update uses first available Module

Posted: Tue Jan 12, 2010 12:00 pm
by Tony Barnes
...and breathe... :D

Nice quick fix for the problem, I agree, should not of made it to final code like that.

Re: [FIX] Currency CRON Update uses first available Module

Posted: Tue Jan 12, 2010 12:04 pm
by Martin
Tony Barnes wrote:...and breathe... :D

Nice quick fix for the problem, I agree, should not of made it to final code like that.
Aye... Just veryyyyy annoying when I have approximately 30 minutes of "spare" time a day which I should be using to get orders and other work done in.

Time to resolve stupid bugs and poor coding practice is an ill afforded luxury right now.