function scanner_undo_confirm_form_submit in Search and Replace Scanner 7
Same name and namespace in other branches
- 5.2 scanner.module \scanner_undo_confirm_form_submit()
- 6 scanner.module \scanner_undo_confirm_form_submit()
Form submission handler for scanner_undo_confirm_form().
See also
File
- ./
scanner.module, line 643 - Search and Replace Scanner - works on all nodes text content.
Code
function scanner_undo_confirm_form_submit($form, &$form_state) {
// @todo The 'op' element in the form values is deprecated.
// Each button can have #validate and #submit functions associated with it.
// Thus, there should be one button that submits the form and which invokes
// the normal form_id_validate and form_id_submit handlers. Any additional
// buttons which need to invoke different validate or submit functionality
// should have button-specific functions.
if ($form_state['values']['op'] == t('Yes, Continue')) {
$query = db_select('scanner', 's');
$query
->fields('s', array(
'undo_data',
'undone',
))
->condition('undo_id', $form_state['values']['undo_id'], '=');
$results = $query
->execute();
foreach ($results as $undo) {
$undo = $undo;
}
$undos = unserialize($undo->undo_data);
$count = NULL;
foreach ($undos as $nid => $sandr_event) {
if ($undo->undone == 0) {
$vid = $sandr_event['old_vid'];
$undone = 1;
}
else {
$vid = $sandr_event['new_vid'];
$undone = 0;
}
$node = node_load($nid, $vid);
$node->revision = TRUE;
$node->log = t('Copy of the revision from %date via Search and Replace Undo', array(
'%date' => format_date($node->revision_timestamp),
));
node_save($node);
++$count;
}
drupal_set_message($count . ' ' . t('Nodes reverted'));
// @todo Please review the conversion of this statement to the D7 database
// API syntax.
db_update('scanner')
->fields(array(
'undone' => $undone,
))
->condition('undo_id', $form_state['values']['undo_id'])
->execute();
}
else {
drupal_set_message(t('Undo / Redo canceled'));
}
$form_state['redirect'] = 'admin/content/scanner/undo';
$form_state['nid'] = $node->nid;
}