From 2bf3729f8a47ff75b0a56567fa693e94b5e55ce1 Mon Sep 17 00:00:00 2001 From: MDW Date: Mon, 23 Sep 2024 01:30:21 +0200 Subject: [PATCH] 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 --- dev/tools/fixcopyrightheader.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dev/tools/fixcopyrightheader.php b/dev/tools/fixcopyrightheader.php index f6b076e82ee..bda934bf3b7 100755 --- a/dev/tools/fixcopyrightheader.php +++ b/dev/tools/fixcopyrightheader.php @@ -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}-)?(?\d{4}))\s+{$r_name}\s*\<{$r_email}>~"; + $pattern = "~(?:{$r_prefix0}|{$r_prefix1})Copyright \(C\)\s+(?:(?:(?\d{4})-)?(?\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)));