We're using patterns to handle updates for a system with a custom install profile. I ended up writing this to call updates from update.php, and thought it might be useful to include with patterns in general. Or maybe it's outside the scope of what you want the project to do. Up to you guys.

The function:

function patterns_execute_update_pattern($pattern_name) {
  $success = TRUE;
  if (module_exists('patterns')) {
    patterns_load_components();
    patterns_get_patterns();
    $pattern = patterns_get_pattern($pattern_name);
    if ($pattern == FALSE) {
      drupal_set_message("Unable to execute $pattern_name because the pattern was not found.",'error');
      $success = FALSE;
    }
    $success = patterns_execute_pattern($pattern);
  } else {
    drupal_set_message("Could not execute $pattern_name because the patterns module is disabled.",'error');
    $success = FALSE;
  }

  if ($success) {
    drupal_set_message("Successfully ran updates for $pattern_name");
    return array();
  } else {
    // patterns will output errors with drupal_set_message, so its okay to just have this simple message
    return $ret['#abort'] = array('success' => FALSE, 'query' => "$pattern_name failed");
  }
}

Then in a feature module's .install file:

function modulexyz_update_6001() {
  return patterns_execute_update_pattern('pattern_6001');
}

Comments

ChrisBryant’s picture

Hey Ben, this certainly falls within the scope of patterns and is a great way to do updates. Sarva or Vaish can check it out? We should definitely add this.

Thanks for sharing the code!

Also, once it's added, change to component "documentation" so we can track and add a page on d.o describing the use.

ChrisBryant’s picture

adding some tags...