You are here

function patterns_export_batch_core in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_export/core.inc \patterns_export_batch_core()
1 string reference to 'patterns_export_batch_core'
patterns_export_batch in patterns_export/core.inc
Constructs the abstract representation of the exported pattern invoking the Batch API

File

patterns_export/core.inc, line 143

Code

function patterns_export_batch_core($module_name, $tag, $export_funcs, $files = NULL, &$context) {
  $msg_ctx = t('%component: now processing %tag. ', array(
    '%component' => $module_name,
    '%tag' => $tag,
  ));
  if ($_SESSION['patterns_export_batch_info']['to'] != PATTERNS_EXPORT_TO_DB) {
    $msg_ctx .= t('After the download has started, click !back.', array(
      '!back' => l(t('here to go back'), 'admin/patterns/export'),
    ));
  }
  $context['message'] = $msg_ctx;

  // Do not process other actions if a fatal error already occurred
  if (!empty($context['results']['abort'])) {
    return;
  }

  // Since we are in the batch, we need to load some things once more.
  module_load_include('module', 'patterns_exports');
  patterns_io_load_components();
  $sections = array();
  if (!empty($files)) {
    $files = !is_array($files) ? array(
      $files,
    ) : $files;
    foreach ($files as $file) {
      require_once $file;
    }
  }
  if (!is_array($export_funcs)) {
    $export_funcs = array(
      $export_funcs,
    );
  }
  $result = array();
  foreach ($export_funcs as $f) {
    if (!function_exists($f)) {
      $context['results']['abort'] = 1;
      $context['results']['error_message'] = t('%module.%tag: export function %f not found.', array(
        '%f' => $f,
        '%module' => $module_name,
        '%tag' => $tag,
      ));
      return FALSE;
    }
    $result[$tag] = isset($result[$tag]) ? $result[$tag] : array();
    $sections[$tag] = array_merge($result[$tag], call_user_func($f));
  }

  // TODO: the name of the component may be different from the
  // the name of the module to enable. Cover this case
  if (!isset($context['results']['modules'])) {
    $context['results']['modules'] = array();
  }
  if (!isset($context['results']['sections'])) {
    $context['results']['sections'] = array();
  }
  array_push($context['results']['modules'], $module_name);
  $context['results']['sections'] = array_merge($context['results']['sections'], $sections);
}