Fix SSF by replacing curl with getURLContent()
This commit is contained in:
parent
5d5bbb2b5e
commit
2d29bd39e4
@ -628,46 +628,48 @@ class MultiCurrency extends CommonObject
|
|||||||
{
|
{
|
||||||
global $conf, $db, $langs;
|
global $conf, $db, $langs;
|
||||||
|
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
|
||||||
|
|
||||||
$urlendpoint = 'http://apilayer.net/api/live?access_key='.$key;
|
$urlendpoint = 'http://apilayer.net/api/live?access_key='.$key;
|
||||||
//$urlendpoint.='&format=1';
|
//$urlendpoint.='&format=1';
|
||||||
$urlendpoint .= (empty($conf->global->MULTICURRENCY_APP_SOURCE) ? '' : '&source='.$conf->global->MULTICURRENCY_APP_SOURCE);
|
$urlendpoint .= (empty($conf->global->MULTICURRENCY_APP_SOURCE) ? '' : '&source='.$conf->global->MULTICURRENCY_APP_SOURCE);
|
||||||
|
|
||||||
dol_syslog("Call url endpoint ".$urlendpoint);
|
dol_syslog("Call url endpoint ".$urlendpoint);
|
||||||
|
|
||||||
// FIXME Use getURLContent() function instead.
|
$resget = getURLContent($urlendpoint, 'GET', '', 1, array(), array('http', 'https'), 1);
|
||||||
$ch = curl_init($urlendpoint);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
$response = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
$response = json_decode($response);
|
|
||||||
|
|
||||||
if ($response->success)
|
if ($resget['content']) {
|
||||||
{
|
$response = $resget['content'];
|
||||||
$TRate = $response->quotes;
|
$response = json_decode($response);
|
||||||
$timestamp = $response->timestamp;
|
|
||||||
|
|
||||||
if (self::recalculRates($TRate) >= 0)
|
if ($response->success)
|
||||||
{
|
{
|
||||||
foreach ($TRate as $currency_code => $rate)
|
$TRate = $response->quotes;
|
||||||
|
$timestamp = $response->timestamp;
|
||||||
|
|
||||||
|
if (self::recalculRates($TRate) >= 0)
|
||||||
{
|
{
|
||||||
$code = substr($currency_code, 3, 3);
|
foreach ($TRate as $currency_code => $rate)
|
||||||
$obj = new MultiCurrency($db);
|
|
||||||
if ($obj->fetch(null, $code) > 0)
|
|
||||||
{
|
{
|
||||||
$obj->updateRate($rate);
|
$code = substr($currency_code, 3, 3);
|
||||||
} elseif ($addifnotfound)
|
$obj = new MultiCurrency($db);
|
||||||
{
|
if ($obj->fetch(null, $code) > 0)
|
||||||
self::addRateFromDolibarr($code, $rate);
|
{
|
||||||
|
$obj->updateRate($rate);
|
||||||
|
} elseif ($addifnotfound)
|
||||||
|
{
|
||||||
|
self::addRateFromDolibarr($code, $rate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING);
|
||||||
|
setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors');
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING);
|
|
||||||
setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors');
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user