Skip to content

Instantly share code, notes, and snippets.

@jimkeller
Last active May 29, 2023 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimkeller/9c4354c5d9285431bacb861df58ae5ed to your computer and use it in GitHub Desktop.
Save jimkeller/9c4354c5d9285431bacb861df58ae5ed to your computer and use it in GitHub Desktop.
<?php
$module_search_dir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'web/modules/custom');
if ( !empty($argv[1]) ) {
$module_search_dir = realpath($argv[1]);
}
$module_dir = new RecursiveDirectoryIterator($module_search_dir);
$iterator = new RecursiveIteratorIterator($module_dir);
while ( $iterator->valid() ) {
if ( preg_match('/\.info\.yml$/i', $iterator->getFilename()) ) {
$module_info_contents = file_get_contents($iterator->getPath() . DIRECTORY_SEPARATOR . $iterator->getFilename() );
$module_info_contents = trim($module_info_contents);
$match_result = preg_match('/core_version_requirement?:[\s\t]*(.*)/', $module_info_contents, $core_version_matches);
if ( empty($core_version_matches[0]) ) {
$module_info_contents .= "\n" . 'core_version_requirement: ^9 || ^10' . "\n";
}
else {
$module_info_contents = str_replace($core_version_matches[0], 'core_version_requirement: ^9 || ^10', $module_info_contents);
}
$module_info_contents = preg_replace('/^#?\s*core\:(.*)/mi', '', $module_info_contents);
$file_path = $iterator->getPath() . DIRECTORY_SEPARATOR . $iterator->getFilename();
echo "Updating {$file_path}\n";
file_put_contents($file_path, $module_info_contents);
}
$iterator->next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment