function smart_ip_get_zip in Smart IP 7
Same name and namespace in other branches
- 6.2 includes/smart_ip.utility.inc \smart_ip_get_zip()
- 6 includes/smart_ip.utility.inc \smart_ip_get_zip()
- 7.2 includes/smart_ip.utility.inc \smart_ip_get_zip()
1 string reference to 'smart_ip_get_zip'
- smart_ip_update_db_batch in includes/
smart_ip.utility.inc - Prepare a batch definition
File
- includes/
smart_ip.utility.inc, line 37 - Utility routines to load the Smart IP database.
Code
function smart_ip_get_zip($src = NULL, &$context) {
if (variable_get('smart_ip_store_location_csv_done', FALSE) || variable_get('smart_ip_extract_zip_done', FALSE)) {
// We are in recovery mode.
return;
}
$path = file_stream_wrapper_uri_normalize('private://smart_ip');
if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
// Private file system path not defined then stop the process
$message = t('Private file system path not defined. Please define the private file system path !here.', array(
'!here' => l('here', 'admin/config/media/file-system'),
));
$context['results']['#abort'] = $message;
$context['message'] = $message;
return;
}
$zip_files = file_scan_directory($path, '/\\.zip$/');
foreach ($zip_files as $zip_file) {
$context['results']['#zip_file'] = drupal_realpath($zip_file->uri);
}
if (variable_get('smart_ip_get_zip_done', FALSE)) {
// We are in recovery mode. Using previous downloaded zip.
$context['finished'] = TRUE;
$context['message'] = t('Using previous downloaded zip file (recovery mode)');
return;
}
variable_set('smart_ip_get_zip_done', FALSE);
if (empty($src)) {
// Fallback zip file
$src = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/GeoLiteCity_' . format_date(time(), 'custom', 'Ym') . '01.zip';
}
if (isset($context['results']['#zip_file'])) {
// Don't download, use manually uploaded zip file then
// update our progress information.
$context['finished'] = TRUE;
$context['message'] = t('Using manually uploaded @zip file', array(
'@zip' => $context['results']['#zip_file'],
));
}
else {
$context['results']['#zip_file'] = drupal_realpath($path . '/geoip_db.zip');
$context['finished'] = 50 / 100;
if (@copy($src, $context['results']['#zip_file'])) {
// Update our progress information.
$context['finished'] = TRUE;
$context['message'] = t('Download done. Extracting zip file...');
// An indicator that is to be used in recovery mode
variable_set('smart_ip_get_zip_done', TRUE);
}
else {
// Error occured then stop the process
$message = t('Download %src file failed. Be sure %src exists.', array(
'%src' => $src,
));
$context['results']['#abort'] = $message;
$context['message'] = $message;
}
}
}