From 68122019bc604f5a988668a2cefd5cb6fba6e533 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 13 May 2021 19:53:59 -0700 Subject: [PATCH] (dev/release#17) For new versions, auto-update ext/{$CORE_EXT}/info.xml --- tools/bin/scripts/set-version.php | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tools/bin/scripts/set-version.php b/tools/bin/scripts/set-version.php index 7a71324ad0..ef309e2f6a 100755 --- a/tools/bin/scripts/set-version.php +++ b/tools/bin/scripts/set-version.php @@ -74,6 +74,15 @@ updateFile("sql/test_data_second_domain.mysql", function ($content) use ($newVer return str_replace($oldVersion, $newVersion, $content); }); +foreach (findCoreInfoXml() as $infoXml) { + updateXmlFile($infoXml, function (DOMDocument $dom) use ($newVersion) { + foreach ($dom->getElementsByTagName('version') as $tag) { + /** @var \DOMNode $tag */ + $tag->textContent = $newVersion; + } + }); +} + if ($doCommit) { $files = array_filter( ['xml/version.xml', 'sql/civicrm_generated.mysql', 'sql/test_data_second_domain.mysql', $phpFile, @$sqlFile], @@ -104,6 +113,24 @@ function updateFile($file, $callback) { file_put_contents($file, $content); } +/** + * Update the content of an XML file + * + * @param string $file + * @param callable $callback + * Function(DOMDocument $dom) + */ +function updateXmlFile($file, $callback) { + updateFile($file, function ($content) use ($callback) { + $dom = new DomDocument(); + $dom->loadXML($content); + $dom->preserveWhiteSpace = FALSE; + $dom->formatOutput = TRUE; + $callback($dom); + return $dom->saveXML(); + }); +} + /** * Initialize a file (if it doesn't already exist). * @param string $file @@ -209,3 +236,23 @@ function parseArgs($argv) { return $parsed; } + +/** + * @return array + * Ex: ['ext/afform/html/info.xml', 'ext/search_kit/info.xml'] + */ +function findCoreInfoXml() { + $lines = explode("\n", file_get_contents('distmaker/core-ext.txt')); + $exts = preg_grep(";^#;", $lines, PREG_GREP_INVERT); + $exts = preg_grep(';[a-z-A-Z];', $exts); + + $infoXmls = []; + foreach ($exts as $coreExtDir) { + $infoXmls = array_merge($infoXmls, (array) glob("ext/$coreExtDir/*/info.xml")); + if (file_exists("ext/$coreExtDir/info.xml")) { + $infoXmls[] = "ext/$coreExtDir/info.xml"; + } + } + + return $infoXmls; +} -- 2.25.1