You are here

function lingotek_admin_cleanup_form_submit in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.admin.inc \lingotek_admin_cleanup_form_submit()
  2. 7.5 lingotek.admin.inc \lingotek_admin_cleanup_form_submit()

Attempt to execute each of the cleanup functions selected by the requester.

_state

Parameters

array $form:

1 string reference to 'lingotek_admin_cleanup_form_submit'
lingotek_admin_cleanup_form in ./lingotek.admin.inc
Utilities form.

File

./lingotek.admin.inc, line 2374

Code

function lingotek_admin_cleanup_form_submit($form, &$form_state) {

  // All cleanup-related batch functions should exist in lingotek.util.inc
  // and their return value should be a set batch.
  $cleanup_batch = array(
    'title' => t('Lingotek Cleanup Utility Batch'),
    'operations' => array(
      array(
        'lingotek_cleanup_batch_init',
        array(),
      ),
    ),
    'file' => 'lingotek.util.inc',
  );
  batch_set($cleanup_batch);
  foreach ($form_state['values']['grid'] as $cleanup_function) {
    if (!$cleanup_function) {

      // Function was not selected to run.
      continue;
    }
    if (!function_exists($cleanup_function)) {
      LingotekLog::error('Attempted to run non-existent cleanup function: @function', array(
        '@function' => $cleanup_function,
      ));
      continue;
    }
    try {
      $cleanup_function();
    } catch (Exception $e) {
      LingotekLog::error('Failed to run cleanup function "@function".  Error was: @error', array(
        '@function' => $cleanup_function,
        '@error' => $e
          ->getMessage(),
      ));
      continue;
    }
  }

  // Execute all set batches and then return.
  batch_process();
}