Skip to content

Instantly share code, notes, and snippets.

@Girgias
Created December 4, 2020 18: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 Girgias/15da993a64b8def236e311409f3281a8 to your computer and use it in GitHub Desktop.
Save Girgias/15da993a64b8def236e311409f3281a8 to your computer and use it in GitHub Desktop.
Update EN-Revision tag for PHP Doc translations after applying a patch
<?php
$folder = __DIR__ . '/reference/imagick/';
$en_revision = 351852;
$files = glob($folder . '*/?*.xml.orig');
foreach ($files as $fileOrig) {
$file = substr($fileOrig, 0, -5);
// Check if there is a reject file, in which case do not update revision
if (file_exists($file . '.rej')) {
continue;
}
$newFileContent = preg_replace('/EN-Revision: [0-9]{5,6}/', 'EN-Revision: ' . $en_revision,
file_get_contents($file), -1, $count);
if ($newFileContent === '' || $newFileContent === false) {
throw new Exception();
}
if ($count !== 1) {
print 'File has count different than 1: ' . $file . \PHP_EOL;
}
file_put_contents($file, $newFileContent);
// Delete the .orig files
unlink($fileOrig);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment