Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

fix: cronjob exchange update would not work with apilayer (#381)

Miguel Ribeirob0b4b7a65cd4
diff --git a/endpoints/cronjobs/updateexchange.php b/endpoints/cronjobs/updateexchange.php
index 91ec4e9..b77e699 100644
--- a/endpoints/cronjobs/updateexchange.php
+++ b/endpoints/cronjobs/updateexchange.php
@@ -11,7 +11,7 @@
$userId = $userToUpdateExchange['id'];
echo "For user: " . $userToUpdateExchange['username'] . "<br />";
- $query = "SELECT api_key FROM fixer WHERE user_id = :userId";
+ $query = "SELECT api_key, provider FROM fixer WHERE user_id = :userId";
$stmt = $db->prepare($query);
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
$result = $stmt->execute();
@@ -21,6 +21,7 @@
if ($row) {
$apiKey = $row['api_key'];
+ $provider = $row['provider'];
$codes = "";
$query = "SELECT id, name, symbol, code FROM currencies WHERE user_id = :userId";
@@ -39,8 +40,20 @@
$mainCurrencyCode = $row['code'];
$mainCurrencyId = $row['main_currency'];
- $api_url = "http://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
- $response = file_get_contents($api_url);
+ if ($provider === 1) {
+ $api_url = "https://api.apilayer.com/fixer/latest?base=EUR&symbols=" . $codes;
+ $context = stream_context_create([
+ 'http' => [
+ 'method' => 'GET',
+ 'header' => 'apikey: ' . $apiKey,
+ ]
+ ]);
+ $response = file_get_contents($api_url, false, $context);
+ } else {
+ $api_url = "http://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
+ $response = file_get_contents($api_url);
+ }
+
$apiData = json_decode($response, true);
$mainCurrencyToEUR = $apiData['rates'][$mainCurrencyCode];
diff --git a/includes/version.php b/includes/version.php
index 0c20107..514e9a3 100644
--- a/includes/version.php
+++ b/includes/version.php
@@ -1,3 +1,3 @@
<?php
- $version = "v2.4.0";
+ $version = "v2.4.1";
?>