diff --git a/generated/8.2/apache.php b/generated/8.2/apache.php deleted file mode 100644 index 8f72116c..00000000 --- a/generated/8.2/apache.php +++ /dev/null @@ -1,135 +0,0 @@ -checkout(DocPage::referenceDir(), "master"); foreach (\array_keys($modules) as $moduleName) { - $fileCreator->generateVersionSplitters($moduleName, FileCreator::getSafeRootDir() . "/generated/", \array_keys($versions)); + $fileCreator->deduplicateAndGenerateVersionSplitters($moduleName, FileCreator::getSafeRootDir() . "/generated/", \array_keys($versions)); $fileCreator->createExceptionFile((string) $moduleName); } - $fileCreator->generateVersionSplitters("functionsList", FileCreator::getSafeRootDir() . "/generated/", \array_keys($versions), true); + $fileCreator->deduplicateAndGenerateVersionSplitters("functionsList", FileCreator::getSafeRootDir() . "/generated/", \array_keys($versions), true); $this->runCsFix($output); diff --git a/generator/src/Generator/FileCreator.php b/generator/src/Generator/FileCreator.php index 47935d0a..a8b703a3 100644 --- a/generator/src/Generator/FileCreator.php +++ b/generator/src/Generator/FileCreator.php @@ -60,19 +60,42 @@ public function generatePhpFile( /** * @param string[] $versions */ - public function generateVersionSplitters(string $module, string $path, array $versions, bool $return = false): void + public function deduplicateAndGenerateVersionSplitters(string $module, string $path, array $versions, bool $return = false): void { $lcModule = \lcfirst($module); + + // Create a map of [current_version => deduplicated_version] + // and delete duplicate files, eg if 8.2/ftp.php and 8.3/ftp.php + // are identical, delete 8.3/ftp.php and map 8.3 => 8.2 + $fileContents = []; + $versionFileMap = []; + foreach ($versions as $version) { + $filePath = "$path/$version/$lcModule.php"; + if (file_exists($filePath)) { + $content = file_get_contents($filePath); + if (isset($fileContents[$content])) { + unlink($filePath); + $versionFileMap[$version] = $fileContents[$content]; + } else { + $fileContents[$content] = $version; + $versionFileMap[$version] = $version; + } + } + } + + // Generate version splitter file $stream = \fopen($path.$lcModule.'.php', 'w'); if ($stream === false) { throw new \RuntimeException('Unable to write to '.$path); } $return = $return ? "return " : ""; \fwrite($stream, "