Skip to content

Instantly share code, notes, and snippets.

@jimkeller
Created January 15, 2023 00:12
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/d9c4e39902775445d098a7b67143bc0d to your computer and use it in GitHub Desktop.
Save jimkeller/d9c4e39902775445d098a7b67143bc0d 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: ^8 || ^9' . "\n";
}
else {
$module_info_contents = str_replace($core_version_matches[0], 'core_version_requirement: ^8 || ^9', $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