-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force updates on resources from manifest (#3179)
* Added command dkan-force-resources-update to force updates on items from manifest. * Fix coding standards.
- Loading branch information
Showing
2 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
modules/dkan/dkan_periodic_updates/dkan_periodic_updates.drush.inc
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Code for dkan_periodic_updates drush commands. | ||
*/ | ||
|
||
/** | ||
* Implements hook_drush_command(). | ||
*/ | ||
function dkan_periodic_updates_drush_command() { | ||
$commands['dkan-force-resources-update'] = array( | ||
'description' => 'Force resources from manifest to be updated.', | ||
'aliases' => array('dfru'), | ||
); | ||
|
||
return $commands; | ||
} | ||
|
||
/** | ||
* Drush command logic. | ||
*/ | ||
function drush_dkan_periodic_updates_dkan_force_resources_update() { | ||
$active = variable_get('dkan_periodic_updates_status'); | ||
if ($active) { | ||
$items = []; | ||
$file = variable_get('dkan_periodic_updates_manifest'); | ||
$file = file_load($file); | ||
// Get items from manifest. | ||
if ($file) { | ||
$handle = fopen($file->uri, 'r'); | ||
$headers = fgetcsv($handle, 0, ','); | ||
|
||
while (($data = fgetcsv($handle, 0, ",")) !== FALSE) { | ||
$resource_data = array_combine($headers, $data); | ||
$items[$resource_data['resource_id']]['file_url'] = $resource_data['file_url']; | ||
$datastore = $resource_data['import_to_datastore'] === 'Y' ? TRUE : FALSE; | ||
$items[$resource_data['resource_id']]['datastore'] = $datastore; | ||
} | ||
fclose($handle); | ||
} | ||
else { | ||
watchdog('dkan_periodic_updates', 'No manifest found.'); | ||
return []; | ||
} | ||
|
||
if (!empty($items)) { | ||
dkan_periodic_updates_execute_update($items); | ||
} | ||
} | ||
} |
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