Last active
December 4, 2017 14:50
-
-
Save marciuz/1ffacfac2a8c95da62a139ac2f793728 to your computer and use it in GitHub Desktop.
example.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _dkan_harvest_dcatap_cache(HarvestSource $source, $harvest_updatetime) { | |
// This is needed for remote uri. | |
$context = stream_context_create( | |
array( | |
'http' => array( | |
'timeout' => 1200, | |
), | |
'https' => array( | |
'timeout' => 1200, | |
), | |
) | |
); | |
try { | |
$remote = file_get_contents($source->uri, TRUE, $context); | |
if($remote === '') { | |
throw new Exception('Il file '.$source->uri.' ha restituito una stringa vuota'); | |
} | |
else if ($remote !== FALSE) { | |
$data = drupal_json_decode($remote); | |
// Filter and save the data gathered from the endpoint. | |
if ($data) { | |
$v = _dkan_harvest_dcatap_cache_json($data, $source, $harvest_updatetime); | |
return $v; | |
} | |
else { | |
$message = t('Harvest Cache JSON error n. @json_error (@json_message)', | |
array( | |
'@json_error' => json_last_error(), | |
'@json_message' => json_last_error_msg(), | |
)); | |
dkan_harvest_log($message, 'error'); | |
} | |
} | |
else { | |
throw new Exception('Error reaching '. $source->uri. ', function returns "'.$remote.'"'); | |
} | |
} catch (Exception $e) { | |
// Handle exception | |
$message = t('Harvest Cache error in file_get_contents (@fileremote) : @msg ', | |
array( | |
'@fileremote' => $source->uri, | |
'@msg' => $e->getMessage(), | |
)); | |
dkan_harvest_log($message, 'error'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment