Last active
June 20, 2016 14:46
-
-
Save derhasi/7a5eb14ad913970de42575e4f43cd6a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. | |
$matches = array(); | |
if (preg_match('/projects\[' . preg_quote($projectname). '\]\[version\]\ ?\=\ ?"(.*)\"/', $ini, $matches)) { | |
$version = '7.x-' . $matches[1]; | |
} | |
// Otherwise we look for a tag. | |
elseif (preg_match('/projects\[' . preg_quote($projectname). '\]\[download\]\[tag\]\ ?\=\ ?"(.*)\"/', $ini, $matches)) { | |
$version = $matches[1]; | |
} | |
else { | |
continue; | |
} | |
foreach (new DirectoryIterator($path->getPathname()) as $file) { | |
if ($file->isDir()) { | |
continue; | |
} | |
if ($file->getExtension() == 'info') { | |
$content = file_get_contents($file->getPathname()); | |
// Only add project name, if no porject name is given already. | |
if (strpos($content, 'project = ') === FALSE) { | |
if (file_put_contents($file->getPathname(), sprintf("\nproject = \"%s\"", $projectname), FILE_APPEND)) { | |
echo sprintf('Added project name "%s" to "%s"' . "\n", $projectname, $file->getPathname()); | |
} | |
} | |
// Skip version adding if a version is already present. | |
if (strpos($content, 'version = ') === FALSE) { | |
// Otherwise write the version to the file. | |
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