Page 1 of 1
How to Change an Admin File.
Posted: Mon Sep 25, 2023 9:08 am
by Portman
Hello Again,
Hopefully a quick one here...
If I want to modify an Admin file but don't want to change the core code, where do I save it?
I made a minor change to admin/includes/modules/currencies/c_ecb.php so that it gets the inverse exchange rate (there is a perfectly good reason for this).
I then saved it in templates/override/admin/includes/modules/currencies/c_ecb.php
I assumed this was wrong but wanted to try for myself first - I was right it did not work.
Is there a way to do this?
Thanks for any help
Re: How to Change an Admin File.
Posted: Mon Sep 25, 2023 10:44 am
by raiwa
Admin files and modules can’t be overridden in the template. You may use a renamed copy of the original file.
Re: How to Change an Admin File.
Posted: Mon Sep 25, 2023 12:51 pm
by burt
As per raiwa's advice above, you'd make yourself a new currency module (copying most of c_ecb) and set that to be used as the currency converter.
Admin > Modules > Update Currencies > {install}
and
Admin > Localization > Currencies
The idea behind "module" is that you don't use [turn off] the core one, and instead use one you've made yourself or had made or found in the addons area etc. That's true for all modules, not just currencies.
Re: How to Change an Admin File.
Posted: Tue Sep 26, 2023 12:10 am
by Portman
im trying to apply what you suggested, what am i doing wrong?
Im getting the error....
PHP Fatal error: Cannot declare class c_ecb, because the name is already in use in .... /admin/includes/modules/currencies/inv_currency.php on line 70
Code: Select all
class inv_currency extends abstract_module {
const CONFIG_KEY_BASE = 'MODULE_ADMIN_CURRENCIES_INV_CURRENCY_';
public static function execute() {
$xml = Web::load_xml('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
$xml = json_decode(json_encode($xml), JSON_FORCE_OBJECT);
$currency_query = $GLOBALS['db']->query("SELECT currencies_id, code, title FROM currencies");
while ($currency = $currency_query->fetch_assoc()) {
$to[$currency['code']] = $currency['code'];
}
$from = DEFAULT_CURRENCY;
$ecb_currencies = ['EUR' => 1.0];
foreach ($xml as $a) {
foreach ($a['Cube']['Cube'] as $b) {
$ecb_currencies[$b['@attributes']['currency']] = $b['@attributes']['rate'];
}
}
if ($from !== 'EUR') {
$exchange = $ecb_currencies[$from];
foreach ($ecb_currencies as $x => $y) {
$ecb_currencies[$x] = $y/$exchange;
}
}
$to_exchange = array_intersect_key($ecb_currencies, $to);
foreach ($to_exchange as $k => $v) {
$invrate = 1/$v; //Added by Portman - to get inverse exchange rate
// $rate = Text::input($v);
$rate = Text::input($invrate); // Mod by Portman
$GLOBALS['db']->query("UPDATE currencies SET value = '" . $GLOBALS['db']->escape($rate) . "', last_updated = NOW() WHERE code = '" . $GLOBALS['db']->escape($k) . "'");
$GLOBALS['messageStack']->add_session(sprintf(MODULE_ADMIN_CURRENCIES_INV_CURRENCY_CURRENCIES_UPDATED, $k), 'success');
}
}
protected function get_parameters() {
return [
'MODULE_ADMIN_CURRENCIES_INV_CURRENCY_STATUS' => [
'title' => 'Enable INVERSE CURRENCY Module',
'value' => 'True',
'desc' => 'Do you want to install this Currency Conversion Module?',
'set_func' => "Config::select_one(['True', 'False'], ",
],
'MODULE_ADMIN_CURRENCIES_INV_CURRENCY_SORT_ORDER' => [
'title' => 'Sort Order',
'value' => '0',
'desc' => 'Sort order of display. Lowest is displayed first.',
],
];
}
}
Re: How to Change an Admin File.
Posted: Tue Sep 26, 2023 7:06 am
by bonbec
Re: How to Change an Admin File.
Posted: Tue Sep 26, 2023 1:00 pm
by raiwa
In the original module line 70 is the last line and empty.
What do you have in your module in line 70?
Re: How to Change an Admin File.
Posted: Tue Sep 26, 2023 11:27 pm
by Portman
raiwa wrote: ↑Tue Sep 26, 2023 1:00 pm
In the original module line 70 is the last line and empty.
What do you have in your module in line 70?
Line 70 is the closing }
I have only changed a couple of lines to create an inverse exchange rate
Re: How to Change an Admin File.
Posted: Tue Sep 26, 2023 11:36 pm
by Portman
Thanks, I feel like I have followed these instructions...
I have modified admin/includes/modules/c_ecb.php which does not have a corresponding template page
I have changed the class name from c_ebc to inv_currency and changed every instance of CURRENCIES_EBC to INV_CURRENCY...
As far as I can tell I've done what I need to but I must be missing something
Re: How to Change an Admin File.
Posted: Wed Sep 27, 2023 5:41 am
by heatherbell
Portman wrote: ↑Tue Sep 26, 2023 11:36 pm
As far as I can tell I've done what I need to but I must be missing something
We have no answer but the error message seems strange as there's no mention of c_ecb in the code that you posted.
Can only advise to repeat your work from scratch and upload again, then ensure the old module is uninstalled before installing the new. Maybe also double check your configuration table in your database to ensure the old module is uninstalled but just guessing.
Re: How to Change an Admin File.
Posted: Wed Sep 27, 2023 6:40 am
by Portman
thanks @heatherbell that did the job!