mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-21 20:34:57 +09:00
CRON integration for currency rates
This commit is contained in:
1 parent
4c850759ce
commit
d36d62736b
3 files changed
+65
-4
No files matched your search
@@ -160,9 +160,29 @@ class Admin extends \Api_Abstract
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update_key($data)
|
||||
public function update_rate_settings($data)
|
||||
{
|
||||
return $this->getService()->updateKey($this->di['array_get']($data, 'currencylayer_key'));
|
||||
$this->getService()->updateKey($this->di['array_get']($data, 'currencylayer_key'));
|
||||
|
||||
if ($this->di['array_get']($data, 'crons_enabled') == "1") {
|
||||
$set = "1";
|
||||
} else {
|
||||
$set = "0";
|
||||
}
|
||||
|
||||
$this->getService()->setCron($set);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if CRON jobs are enabled for currency rates
|
||||
*
|
||||
* @return string (0/1)
|
||||
*/
|
||||
public function is_cron_enabled($data)
|
||||
{
|
||||
return $this->getService()->isCronEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -350,6 +350,36 @@ class Service implements InjectionAwareInterface
|
||||
$currency = $db->exec($sql, $values);
|
||||
}
|
||||
|
||||
public function isCronEnabled()
|
||||
{
|
||||
$sql = "SELECT `param`, `value` FROM setting";
|
||||
$db = $this->di['db'];
|
||||
|
||||
$pairs = $db->getAssoc($sql);
|
||||
|
||||
if (isset($pairs['currency_cron_enabled']) && $pairs['currency_cron_enabled'] == "1") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function setCron($data)
|
||||
{
|
||||
$sql = "INSERT INTO `setting` (`param`, `value`, `public`, `created_at`, `updated_at`) VALUES ('currency_cron_enabled', :key, '0', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()) ON DUPLICATE KEY UPDATE `value`=:key, `updated_at`=CURRENT_TIMESTAMP()";
|
||||
|
||||
if ($data == "1") {
|
||||
$key = "1";
|
||||
} else {
|
||||
$key = "0";
|
||||
}
|
||||
|
||||
$values = array(':key' => $key);
|
||||
|
||||
$db = $this->di['db'];
|
||||
$currency = $db->exec($sql, $values);
|
||||
}
|
||||
|
||||
public function toApiArray(\Model_Currency $model)
|
||||
{
|
||||
return array(
|
||||
@@ -506,7 +536,9 @@ class Service implements InjectionAwareInterface
|
||||
$currencyService = $di['mod_service']('currency');
|
||||
|
||||
try {
|
||||
$currencyService->updateCurrencyRates();
|
||||
if ($currencyService->isCronEnabled()) {
|
||||
$currencyService->updateCurrencyRates("");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log($e);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
<p>BoxBilling uses data grabbed from <a href="https://www.ecb.europa.eu/home/html/index.en.html">European Central Bank</a> for conversions from Euro to other currencies, and <a href="https://currencylayer.com/">currencylayer</a> for conversations from US Dollar to other currencies.<br />If you choose Euro as your default currency, data from European Central Bank will be used, if you choose US Dollar, data from currencylayer will be used.<br />While European Central Bank decided to keep it's API free to everyone, you won't need an autorization key to use ECB's data. However, you'll need an API key to use currencylayer.<br />You can <a href="https://currencylayer.com/product">grab your API key</a> from currencylayer's website. BoxBilling doesn't make any profits from your purchases on currencylayer.com</p>
|
||||
<p><b>BoxBilling does not take any responsibilities for data grabbed from 3rd party sources, including European Central Bank and currencylayer.</b></p>
|
||||
</div>
|
||||
<form method="post" action="{{ 'api/admin/currency/update_key'|link }}" class="mainForm save api-form" data-api-msg="Successfully updated the keys">
|
||||
<form method="post" action="{{ 'api/admin/currency/update_rate_settings'|link }}" class="mainForm save api-form" data-api-msg="Successfully updated settings">
|
||||
<fieldset>
|
||||
<div class="rowElem noborder">
|
||||
<label>{% trans 'API key for currencylayer' %}:</label>
|
||||
@@ -134,6 +134,15 @@
|
||||
</div>
|
||||
<div class="fix"></div>
|
||||
</div>
|
||||
<div class="rowElem">
|
||||
<label>{% trans 'Enable CRON jobs' %}:</label>
|
||||
<p>If you enable this, conversion rates will be automatically updated whenever the CRON job fires up.</p>
|
||||
<div class="formRight">
|
||||
<input type="radio" name="crons_enabled" value="1" {% if admin.currency_is_cron_enabled == 1 %}checked="checked"{% endif %}><label>Enabled</label>
|
||||
<input type="radio" name="crons_enabled" value="0" {% if admin.currency_is_cron_enabled == 0 %}checked="checked"{% endif %}><label>Disabled</label>
|
||||
</div>
|
||||
<div class="fix"></div>
|
||||
</div>
|
||||
<input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user