Qual: Fix copyright fixer (#31072)

* Qual: Fix copyright fixer

# Qual: Fix copyright fixer

Enable actual file write, disable debug message

* Fix: ci/missing global $conf in chargessociales
This commit is contained in:
MDW 2024-09-23 01:30:21 +02:00 committed by GitHub
parent 7b4c4d772c
commit 2bf3729f8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -120,16 +120,21 @@ function updateCopyrightNotice($filename, $fileType, $name, $email)
}
// Pattern to match the line matching the current developer
$pattern = "~(?:{$r_prefix0}|{$r_prefix1})Copyright \(C\)\s+(?:(?:\d{4}-)?(?<year>\d{4}))\s+{$r_name}\s*\<{$r_email}>~";
$pattern = "~(?:{$r_prefix0}|{$r_prefix1})Copyright \(C\)\s+(?:(?:(?<start>\d{4})-)?(?<last>\d{4}))\s+{$r_name}\s*\<{$r_email}>~";
// Check if the lines match the pattern
$matches = array();
if (preg_match($pattern, $lines, $matches)) {
$existingYear = $matches['year'];
$existingYear = $matches['last'];
if (array_key_exists('start', $matches)) {
$startYear = $matches['start'];
} else {
$startYear = $existingYear;
}
// Check if the existing year is different from the current year
if ($existingYear !== date('Y')) {
// Update the year range to include or be up to the current year
$updatedNotice = preg_replace('/(\d{4})(-\d{4})?\s+/', $existingYear . '-' . date('Y') . "\t", $matches[0]);
// Extend the year range to the current year
$updatedNotice = preg_replace('/(?:\d{4}-)?\d{4}\s+/', $startYear . '-' . date('Y') . "\t", $matches[0]);
// Replace the old notice with the updated one in the file
file_put_contents($filename, preg_replace($pattern, $updatedNotice, file_get_contents($filename)));