You are here

function patterns_execute_pattern_drush in Patterns 6.2

1 call to patterns_execute_pattern_drush()
drush_patterns_enable in ./patterns.drush.inc
Enables the specified pattern

File

./patterns.drush.inc, line 463
Drush Patterns module commands

Code

function patterns_execute_pattern_drush($pattern, $params = array()) {
  set_time_limit(0);
  if (!is_object($pattern)) {
    $pattern = patterns_get_pattern($pattern);
    if (!$pattern) {
      return FALSE;
    }
  }
  $pattern->subpatterns_run_mode = $params['run-subpatterns'];
  $pattern_details = patterns_get_pattern_details($pattern, TRUE);
  $modules = $pattern_details['modules'];
  $actions = $pattern_details['actions'];
  $actions_map = array(
    'patterns' => $pattern_details['info'],
    'map' => $pattern_details['actions_map'],
  );
  $info = reset($pattern_details['info']);

  // If there are no actions or modules, most likely the pattern
  // was not created correctly.
  if (empty($actions) && empty($modules)) {
    drupal_set_message(t('Could not recognize pattern %title, aborting.', array(
      '%title' => $info['title'],
    )), 'error');
    return FALSE;
  }
  $result = patterns_install_modules($modules);
  if (!$result['success']) {
    drupal_set_message($result['error_message'], 'error');
    return FALSE;
  }
  $result = patterns_prepare_actions($actions, $actions_map);
  if (!$result['success']) {
    drupal_set_message($result['error_message'], 'error');
    return FALSE;
  }
  $batch = array(
    'title' => t('Processing pattern %pattern', array(
      '%pattern' => $info['title'],
    )),
    //    'init_message' => t('Running action @current out of @total', array('@current' => 1, '@total' => count($actions))),
    'progress_message' => t('Running action @current out of @total'),
    'operations' => array(),
    'finished' => 'patterns_batch_finish_drush',
  );
  for ($i = 0; $i < count($actions); $i++) {
    $batch['operations'][] = array(
      'patterns_batch_actions_drush',
      array(
        $actions[$i],
        $i,
        $actions_map,
      ),
    );
  }

  // @todo: this is good enough for testing but it should be
  // implemented in a better way asap
  variable_set('patterns_details', $pattern_details['info']);
  batch_set($batch);
  $batch =& batch_get();
  $batch['progressive'] = FALSE;
  drush_backend_batch_process();
  return TRUE;
}