Skip to content

Instantly share code, notes, and snippets.

@TopherGopher
Created January 7, 2014 16:39
Show Gist options
  • Save TopherGopher/8302131 to your computer and use it in GitHub Desktop.
Save TopherGopher/8302131 to your computer and use it in GitHub Desktop.
When you use git to keep modules up to date in Drupal, the .info file does not get wrapped with the correct versioning information since all of the versioning you could ever want is in the .git blobs. If you want to take the module out of git and allow Drupal to natively handle the module updates from now on, the easiest method is just to downlo…
<?php
// What is the drush command you wish to run?
// Some people just might use `php /usr/bin/drush/drush.php`, but I wanted to specify further options explicitely.
$drush='/Applications/MAMP/bin/php/php5.4.4/bin/php -d memory_limit=128M /drush/drush.php --php="/Applications/MAMP/bin/php/php5.4.4/bin -d memory_limit=128M"';
// Where is the module directory you are trying to update?
$folders = scandir('/data/releases/homepage/dev/profiles/cu_homepage/modules/contrib');
// Get rid of . and ..
unset($folders[0]);
unset($folders[1]);
$preg = '@^\s* # Start at the beginning of a line, ignoring leading whitespace
((?:
[^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets,
\[[^\[\]]*\] # unless they are balanced and not nested
)+?)
\s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space)
(?:
("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes
(\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
([^\r\n]*?) # Non-quoted string
)\s*$ # Stop at the next end of a line, ignoring trailing whitespace
@msx';
// Point this at the module folder that you want to update.
$contrib_root = "/data/releases/homepage/dev/profiles/cu_homepage/modules/contrib";
foreach($folders AS $folder) {
if(!($info_file = file_get_contents("$contrib_root/$folder/$folder.info"))) {
// The .info file wasn't found - you'll need to update this module yourself.
print_r("$folder needs a closer look.\n");
}
else {
// If the file hasn't been packaged.
if(!strpos($info_file, "; Information added by drupal.org packaging script on")) {
echo "Update $folder?";
$update = fgets(STDIN);
if($update=="y\n") {
exec("$drush dl $folder -y --destination=$contrib_root");
$info_file = file_get_contents("$contrib_root/$folder/$folder.info");
preg_match_all($preg, $info_file, $version, PREG_PATTERN_ORDER);
// Go to [1] and look for "version"
$version_key = array_search("version", $version[1]);
$version = trim($version[2][$version_key], '\"');
exec("git add $contrib_root/$folder\n");
exec("git rm $(git ls-files --deleted | grep \"$folder/\")");
exec("git commit -m \"Updated $folder to $version\"\n");
//break;
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment