Skip to content

Instantly share code, notes, and snippets.

@makbeta
Last active August 26, 2019 15:29
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 makbeta/de069ec473d8a92a1e35ea7b0a66a82a to your computer and use it in GitHub Desktop.
Save makbeta/de069ec473d8a92a1e35ea7b0a66a82a to your computer and use it in GitHub Desktop.
Drupal 8: Strip hard-set version number from core modules and themes
<?php
/**
* Quick script for stripping drupal hard set version number in .info.yml files that cause
* Drupal to incorrectly show status updates.
* Script is based on https://gist.github.com/joshkoenig/2588420
*
* Run in the drupal root, or specify the root as an argument. E.g.:
*
* php d8-strip-version-from-info-yml.php path/to/drupal
*
*/
$dir = isset($argv[1]) ? $argv[1] : __DIR__ ;
echo "Looking for core modules/themes in '$dir'\n";
strip_packaging_info($dir .'/core/modules');
strip_packaging_info($dir .'/core/themes');
function strip_packaging_info($dir) {
if (is_dir($dir) && $handle = opendir($dir)) {
echo "Directory $dir:\n";
$prev_line = '';
while (false !== ($entry = readdir($handle))) {
if (is_dir($dir.'/'.$entry) && file_exists($dir.'/'.$entry.'/'.$entry.'.info.yml')) {
$lines = file($dir.'/'.$entry.'/'.$entry.'.info.yml');
$fh = fopen($dir.'/'.$entry.'/'.$entry.'.info.yml', 'w');
foreach($lines as $line) {
if (strpos($prev_line, '# Information added by Drupal.org packaging') !== FALSE &&
strpos($line, 'version') !== FALSE) {
$line = "version: VERSION\n";
}
$prev_line = $line;
fwrite($fh, $line);
}
fclose($fh);
// unlink($dir.'/'.$entry.'/'.$entry.'.info');
echo "Rewrote $dir/$entry/$entry.info.yml\n";
}
}
closedir($handle);
}
}
echo <<<EndTXT
DONE!
You should probably run a "git diff" now to be sure everything is as expected.
EndTXT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment