You are here

function workflow_cleanup_form_submit in Workflow 7

Same name and namespace in other branches
  1. 7.2 workflow_cleanup/workflow_cleanup.pages.inc \workflow_cleanup_form_submit()

Submission handler for main cleanup form.

File

workflow_cleanup/workflow_cleanup.module, line 182
Cleans up Workflow cruft that may build up over time.

Code

function workflow_cleanup_form_submit($form, $form_state) {
  $states = $form['#workflow_states'];
  foreach (array(
    'no_workflow',
    'inactive',
  ) as $section) {
    foreach ($form_state['values'][$section] as $sid => $data) {

      // FAPI returns either a 0 or the sid.
      if ($data['check']) {

        // Delete any transitions this state is involved in.
        $trans_del = db_delete('workflow_transitions')
          ->condition('target_sid', $sid)
          ->execute();
        $trans_del += db_delete('workflow_transitions')
          ->condition('sid', $sid)
          ->execute();
        if ($trans_del) {
          drupal_set_message(t('@count transitions for the "@state" state have been deleted.', array(
            '@state' => $states[$sid]->state,
            '@count' => $trans_del,
          )));
        }

        // Remove history records too.
        $hist_del = db_delete('workflow_node_history')
          ->condition('sid', $sid)
          ->execute();
        if ($hist_del) {
          drupal_set_message(t('@count history records for the "@state" state have been deleted.', array(
            '@state' => $states[$sid]
              ->getName(),
            '@count' => $hist_del,
          )));
        }

        // Go ahead and delete the state.
        db_delete('workflow_states')
          ->condition('sid', $sid)
          ->execute();
        drupal_set_message(t('The "@state" state has been deleted.', array(
          '@state' => $states[$sid]
            ->getName(),
        )));
      }
    }
  }
}