Function for executing a pattern as part of update.php

bhuga - May 6, 2009 - 22:31
Project:Patterns
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:change management, deployment, update, update.php
Description

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:

<?php
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:

<?php
function modulexyz_update_6001() {
  return
patterns_execute_update_pattern('pattern_6001');
}
?>

#1

ChrisBryant - May 6, 2009 - 23:35

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.

#2

ChrisBryant - May 6, 2009 - 23:36

adding some tags...

 
 

Drupal is a registered trademark of Dries Buytaert.