Skip to content

Instantly share code, notes, and snippets.

@derhasi
Created June 8, 2016 12:54
Show Gist options
  • Save derhasi/cbd2efbd7de98c2ea56bb3fdd8682c7c to your computer and use it in GitHub Desktop.
Save derhasi/cbd2efbd7de98c2ea56bb3fdd8682c7c to your computer and use it in GitHub Desktop.
<?php
$ini = file_get_contents(__DIR__ . '/../make.ini');
/**
* @var SplFileInfo $path
* @var SplFileInfo $file
*/
foreach(new DirectoryIterator(__DIR__ . '/sites/all/modules/contrib') as $path) {
$projectname = $path->getFilename();
// extract version.
$pattern = '/projects\[' . preg_quote($projectname). '\]\[version\]\ ?\=\ ?"(.*)\"/';
$matches = array();
preg_match($pattern, $ini, $matches);
$version = $matches[1];
if (empty($version[1])) {
continue;
}
foreach (new DirectoryIterator($path->getPathname()) as $file) {
if ($file->isDir()) {
continue;
}
if ($file->getExtension() == 'info') {
if (file_put_contents($file->getPathname(), sprintf(PHP_EOL . 'version = "7.x-%s"', $version), FILE_APPEND)) {
echo sprintf('Added version "%s" to "%s"' . "\n", $version, $file->getPathname());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment