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

This commit is contained in:
Miguel Ribeiro 2024-06-09 22:41:33 +02:00 committed by GitHub
parent d410d4804a
commit b0b4b7a65c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View File

@ -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'];
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];

View File

@ -1,3 +1,3 @@
<?php
$version = "v2.4.0";
$version = "v2.4.1";
?>