Skip to content

Instantly share code, notes, and snippets.

@marciuz
Last active December 4, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marciuz/1ffacfac2a8c95da62a139ac2f793728 to your computer and use it in GitHub Desktop.
Save marciuz/1ffacfac2a8c95da62a139ac2f793728 to your computer and use it in GitHub Desktop.
example.php
<?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