function scanner_undo_confirm_form_submit in Search and Replace Scanner 6
Same name and namespace in other branches
- 5.2 scanner.module \scanner_undo_confirm_form_submit()
- 7 scanner.module \scanner_undo_confirm_form_submit()
File
- ./
scanner.module, line 629 - 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')) {
$undo = db_fetch_object(db_query('SELECT undo_data, undone FROM {scanner} WHERE undo_id = %d', $form_state['values']['undo_id']));
$undos = unserialize($undo->undo_data);
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'));
db_query('UPDATE {scanner} SET undone = %d WHERE undo_id = %d', $undone, $form_state['values']['undo_id']);
}
else {
drupal_set_message(t('Undo / Redo canceled'));
}
$form_state['redirect'] = 'admin/content/scanner/undo';
$form_state['nid'] = $node->nid;
}