Skip to content
Snippets Groups Projects
Commit d3aee651 authored by matt2000's avatar matt2000 Committed by Franz Glauber Vanderlinde
Browse files

Issue #1454666: Add tool to reset locked feeds

parent 368a4a9a
No related branches found
No related tags found
No related merge requests found
......@@ -235,6 +235,10 @@ function feeds_permission() {
$perms["clear $importer->id feeds"] = array(
'title' => t('Delete items from @name feeds', array('@name' => $importer->config['name'])),
);
$perms["unlock $importer->id feeds"] = array(
'title' => t('Unlock imports from @name feeds', array('@name' => $importer->config['name'])),
'description' => t('If a feed importation breaks for some reason, users with this permission can unlock them.')
);
}
return $perms;
}
......@@ -288,6 +292,15 @@ function feeds_menu() {
'file' => 'feeds.pages.inc',
'type' => MENU_LOCAL_TASK,
);
$items['import/%/unlock'] = array(
'title' => 'Unlock',
'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_unlock_tab_form', 1),
'access callback' => 'feeds_access',
'access arguments' => array('unlock', 1),
'file' => 'feeds.pages.inc',
'type' => MENU_LOCAL_TASK,
);
$items['import/%/template'] = array(
'page callback' => 'feeds_importer_template',
'page arguments' => array(1),
......@@ -316,6 +329,16 @@ function feeds_menu() {
'type' => MENU_LOCAL_TASK,
'weight' => 11,
);
$items['node/%node/unlock'] = array(
'title' => 'Unlock',
'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_unlock_tab_form', NULL, 1),
'access callback' => 'feeds_access',
'access arguments' => array('unlock', 1),
'file' => 'feeds.pages.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 11,
);
// @todo Eliminate this step and thus eliminate clearing menu cache when
// manipulating importers.
foreach (feeds_importer_load_all() as $importer) {
......@@ -367,11 +390,12 @@ function feeds_theme() {
* The action to be performed. Possible values are:
* - import
* - clear
* - unlock
* @param $param
* Node object or FeedsImporter id.
*/
function feeds_access($action, $param) {
if (!in_array($action, array('import', 'clear'))) {
if (!in_array($action, array('import', 'clear', 'unlock'))) {
// If $action is not one of the supported actions, we return access denied.
return FALSE;
}
......
......@@ -193,6 +193,65 @@ function feeds_delete_tab_form_submit($form, &$form_state) {
feeds_source($form['#importer_id'], $feed_nid)->startClear();
}
/**
* Render a feeds unlock form.
*
* Used on both node pages and configuration pages.
* Therefore $node may be missing.
*/
function feeds_unlock_tab_form($form, &$form_state, $importer_id, $node = NULL) {
if (empty($node)) {
$source = feeds_source($importer_id);
$form['#redirect'] = 'import/' . $source->id;
}
else {
$importer_id = feeds_get_importer_id($node->type);
$source = feeds_source($importer_id, $node->nid);
$form['#redirect'] = 'node/' . $source->feed_nid;
}
// Form cannot pass on source object.
$form['#importer_id'] = $source->id;
$form['#feed_nid'] = $source->feed_nid;
$form['source_status'] = array(
'#type' => 'fieldset',
'#title' => t('Status'),
'#tree' => TRUE,
'#value' => feeds_source_status($source),
);
$form = confirm_form($form, t('Unlock this importer?'), $form['#redirect'], '', t('Delete'), t('Cancel'), 'confirm feeds update');
$progress = $source->progressClearing();
if ($progress == FEEDS_BATCH_COMPLETE) {
$form['source_locked'] = array(
'#type' => 'markup',
'#title' => t('Not Locked'),
'#tree' => TRUE,
'#markup' => t('This Importer is not locked, therefor it cannot be unlocked.'),
);
$form['actions']['submit']['#disabled'] = TRUE;
$form['actions']['submit']['#value'] = t('Unlock (disabled)');
} else {
$form['actions']['submit']['#value'] = t('Unlock');
}
return $form;
}
/**
* Form submit handler. Resets all feeds state.
*/
function feeds_unlock_tab_form_submit($form, &$form_state) {
drupal_set_message('Import Unlocked');
$form_state['redirect'] = $form['#redirect'];
$feed_nid = empty($form['#feed_nid']) ? 0 : $form['#feed_nid'];
$importer_id = $form['#importer_id'];
//Is there a more API-friendly way to set the state?
db_update('feeds_source')
->condition('id', $importer_id)
->condition('feed_nid', $feed_nid)
->fields(array('state' => FALSE))
->execute();
}
/**
* Handle a fetcher callback.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment