You are here

function patterns_export_batch in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_export/core.inc \patterns_export_batch()

Constructs the abstract representation of the exported pattern invoking the Batch API

Returns the array of needed modules, and the actions of the pattern.

Parameters

array $tagmodules An index of modules and tag to export:

Return value

array $result An array containing modules and actions

File

patterns_export/core.inc, line 92

Code

function patterns_export_batch($filename, $tagmodules, $info, $to, $format) {

  // Registering $_SESSION variables
  $_SESSION['patterns_export_batch_info']['info'] = $info;
  $_SESSION['patterns_export_batch_info']['to'] = $to;
  $_SESSION['patterns_export_batch_info']['format'] = $format;
  $_SESSION['patterns_export_batch_info']['filename'] = $filename;
  $cur_sec = 1;
  $tot_sec = count($tagmodules);
  $result = array();
  $modules = array();
  $operations = array();
  foreach ($tagmodules as $module_name => $module) {
    foreach ($module as $tag => $values) {
      if (!isset($values[PATTERNS_EXPORT]) || empty($values[PATTERNS_EXPORT])) {
        continue;
      }
      $action_params = array(
        $module_name,
        $tag,
        $values[PATTERNS_EXPORT],
      );
      $action_params[] = isset($values[PATTERNS_FILES]) ? $values[PATTERNS_FILES] : array();
      $operations[] = array(
        'patterns_export_batch_core',
        $action_params,
      );
    }
    if (!isset($_SESSION['patterns_export_batch_info'])) {
      $_SESSION['patterns_export_batch_info'] = array();
    }
    if (!isset($_SESSION['patterns_export_batch_info']['modules'])) {
      $_SESSION['patterns_export_batch_info']['modules'] = array();
    }
    array_push($_SESSION['patterns_export_batch_info']['modules'], $module_name);
    $cur_sec++;
  }
  $batch = array(
    'title' => t('Patterns export'),
    'progress_message' => t('Running action @current out of @total'),
    'finished' => 'patterns_export_batch_finish',
    'operations' => $operations,
  );
  batch_set($batch);
  return TRUE;
}