You are here

function patterns_execute_pattern_php in Patterns 7.2

Same name and namespace in other branches
  1. 7 includes/core/php.inc \patterns_execute_pattern_php()

Execute a Pattern. Actions will be called sequentially.

E.g.: loading additional modules, and creating the array of patterns actions.

Parameters

stdClass $pattern Pattern object as loaded by patterns_get_pattern().:

array $params Parameters for executing the pattern. Array format as follows::

  • pid => Pid of the pattern as it is in the database
  • run-subpatterns => ['first-update', always', 'update', 'first', 'never']
  • quickrun => boolean flag to indicate that the execution was initiated from a quickrun and the pattern is already loaded into $pattern.

$patterns_details:

$actions_map:

Return value

@TODO Doc.

File

includes/core/php.inc, line 28
A simple, sequential version of running patterns.

Code

function patterns_execute_pattern_php($pattern, $params, $patterns_details, $actions_map) {
  $pattern_details = current($patterns_details);
  $pid = key($patterns_details);
  $info = $pattern_details['info'];
  $infos = array(
    $pid => $info,
  );
  $modules = $pattern_details['modules'];
  $sections = $pattern_details['sections'];
  $include_options = patterns_parser_build_include_options($pid, $params['run-subpatterns']);
  $global_success = TRUE;

  ///////////////////////////////

  // Looping through the sections

  ///////////////////////////////
  foreach ($sections as $section => $actions) {
    $actions = patterns_parser_retrieve_actions_from_section($actions, $include_options);

    // This can happen if includes are disabled
    if (count($actions) == 0) {
      drupal_set_message(t('Section "%section" did not contain any valid action. Please check your policy for included patterns.', array(
        '%section' => $section,
      )), 'warning');
      continue;
    }

    // Reformat the actions. $actions passed as reference.
    // If includes are found, they are exploded into other actions
    patterns_reformat_actions($actions);
    $i = 0;
    $success = TRUE;
    foreach ($actions as $action) {
      $results = patterns_php_action($action['action'], $action['data'], $i, $actions_map);
      if ($results['status'] == PATTERNS_ERR) {
        _patterns_section_fail($pid, $info['title'], $section);
        $success = FALSE;
        $global_success = FALSE;
        break;
      }
      $i++;
    }
    if ($success) {
      _patterns_section_success($pid, $info['title'], $section);
    }
  }
  drupal_flush_all_caches();
  return $global_success;
}