[FIX] Currency CRON Update uses first available Module

For Articles relating to more than one ISC version
Post Reply
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

[FIX] Currency CRON Update uses first available Module

Post 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'];
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

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

Post by Tony Barnes »

...and breathe... :D

Nice quick fix for the problem, I agree, should not of made it to final code like that.
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

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

Post 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.
Post Reply