function drush_feeds_revert in Feeds 7.2
Reverts a set of feeds.
File
- ./
feeds.drush.inc, line 769 - Drush commands for Feeds module.
Code
function drush_feeds_revert() {
$all = feeds_importer_load_all(TRUE);
$missing = array_diff(func_get_args(), array_keys($all));
$to_revert = array_intersect_key($all, array_flip(func_get_args()));
$cant_revert = array();
$cant_revert_db = array();
// Filter out non-overridden importers.
foreach ($to_revert as $delta => $importer) {
if ($importer->export_type !== (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) {
unset($to_revert[$delta]);
if ($importer->export_type == EXPORT_IN_DATABASE) {
$cant_revert_db[$importer->id] = $importer->id;
}
else {
$cant_revert[$importer->id] = $importer->id;
}
}
}
if ($missing) {
drush_print(dt('The following importers are missing: !importers', array(
'!importers' => implode(', ', $missing),
)));
}
if ($cant_revert) {
drush_print(dt('The following importers cannot be reverted because they are not overridden: !importers', array(
'!importers' => implode(', ', array_keys($cant_revert)),
)));
}
if ($cant_revert_db) {
drush_print(dt('The following importers cannot be reverted because they only exist in the database: !importers', array(
'!importers' => implode(', ', array_keys($cant_revert_db)),
)));
}
if ($to_revert) {
drush_print(dt('The following importers will be reverted: !importers', array(
'!importers' => implode(', ', array_keys($to_revert)),
)));
}
elseif (count(func_get_args()) == 0) {
return drush_set_error(dt('Please specify a space delimited list of importers to revert.'));
}
else {
return drush_print(dt('There are no importers to revert.'));
}
if (!drush_confirm(dt('Do you really want to continue?'))) {
return drush_log(dt('Aborting.'), 'ok');
}
foreach ($to_revert as $importer) {
$importer
->delete();
drush_log(dt("The importer '!importer' was reverted successfully.", array(
'!importer' => $importer->id,
)), 'ok');
}
feeds_cache_clear();
}