You are here

function scanner_undo_confirm_form_submit in Search and Replace Scanner 5.2

Same name and namespace in other branches
  1. 6 scanner.module \scanner_undo_confirm_form_submit()
  2. 7 scanner.module \scanner_undo_confirm_form_submit()

File

./scanner.module, line 597
Search and Replace Scanner - works on all nodes text content.

Code

function scanner_undo_confirm_form_submit($form_id, $form) {
  if ($form['op'] == t('Yes, Continue')) {
    $undo = db_fetch_object(db_query('SELECT undo_data, undone FROM {scanner} WHERE undo_id = %d', $form['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['undo_id']);
  }
  else {
    drupal_set_message(t('Undo / Redo canceled'));
  }
  return 'admin/content/scanner/undo';
}