From 783fdd0b96458f1aa8fe51bb051b6cd61a688106 Mon Sep 17 00:00:00 2001 From: colemanw Date: Sun, 12 Jan 2025 14:38:07 -0500 Subject: [PATCH 1/3] Change version to 6.0.alpha1 --- .../php/{FiveEightyThree.php => SixZero.php} | 10 +++++----- CRM/Upgrade/Incremental/sql/5.83.alpha1.mysql.tpl | 1 - CRM/Upgrade/Incremental/sql/6.0.alpha1.mysql.tpl | 1 + js/version.json | 2 +- sql/civicrm_generated.mysql | 2 +- sql/test_data_second_domain.mysql | 2 +- xml/version.xml | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) rename CRM/Upgrade/Incremental/php/{FiveEightyThree.php => SixZero.php} (76%) delete mode 100644 CRM/Upgrade/Incremental/sql/5.83.alpha1.mysql.tpl create mode 100644 CRM/Upgrade/Incremental/sql/6.0.alpha1.mysql.tpl diff --git a/CRM/Upgrade/Incremental/php/FiveEightyThree.php b/CRM/Upgrade/Incremental/php/SixZero.php similarity index 76% rename from CRM/Upgrade/Incremental/php/FiveEightyThree.php rename to CRM/Upgrade/Incremental/php/SixZero.php index e804ac577ca..4f5385d9b67 100644 --- a/CRM/Upgrade/Incremental/php/FiveEightyThree.php +++ b/CRM/Upgrade/Incremental/php/SixZero.php @@ -10,16 +10,16 @@ */ /** - * Upgrade logic for the 5.83.x series. + * Upgrade logic for the 6.0.x series. * - * Each minor version in the series is handled by either a `5.83.x.mysql.tpl` file, - * or a function in this class named `upgrade_5_83_x`. + * Each minor version in the series is handled by either a `6.0.x.mysql.tpl` file, + * or a function in this class named `upgrade_6_0_x`. * If only a .tpl file exists for a version, it will be run automatically. * If the function exists, it must explicitly add the 'runSql' task if there is a corresponding .mysql.tpl. * * This class may also implement `setPreUpgradeMessage()` and `setPostUpgradeMessage()` functions. */ -class CRM_Upgrade_Incremental_php_FiveEightyThree extends CRM_Upgrade_Incremental_Base { +class CRM_Upgrade_Incremental_php_SixZero extends CRM_Upgrade_Incremental_Base { /** * Upgrade step; adds tasks including 'runSql'. @@ -27,7 +27,7 @@ class CRM_Upgrade_Incremental_php_FiveEightyThree extends CRM_Upgrade_Incrementa * @param string $rev * The version number matching this function name */ - public function upgrade_5_83_alpha1($rev): void { + public function upgrade_6_0_alpha1($rev): void { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); } diff --git a/CRM/Upgrade/Incremental/sql/5.83.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.83.alpha1.mysql.tpl deleted file mode 100644 index 8a6c2a48a14..00000000000 --- a/CRM/Upgrade/Incremental/sql/5.83.alpha1.mysql.tpl +++ /dev/null @@ -1 +0,0 @@ -{* file to handle db changes in 5.83.alpha1 during upgrade *} diff --git a/CRM/Upgrade/Incremental/sql/6.0.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/6.0.alpha1.mysql.tpl new file mode 100644 index 00000000000..a4c3e058738 --- /dev/null +++ b/CRM/Upgrade/Incremental/sql/6.0.alpha1.mysql.tpl @@ -0,0 +1 @@ +{* file to handle db changes in 6.0.alpha1 during upgrade *} diff --git a/js/version.json b/js/version.json index aaf76e4e0be..c438181de81 100644 --- a/js/version.json +++ b/js/version.json @@ -1 +1 @@ -"5.83.alpha1" +"6.0.alpha1" diff --git a/sql/civicrm_generated.mysql b/sql/civicrm_generated.mysql index 7210327ae5a..cef915c672d 100644 --- a/sql/civicrm_generated.mysql +++ b/sql/civicrm_generated.mysql @@ -2960,7 +2960,7 @@ UNLOCK TABLES; LOCK TABLES `civicrm_domain` WRITE; /*!40000 ALTER TABLE `civicrm_domain` DISABLE KEYS */; INSERT INTO `civicrm_domain` (`id`, `name`, `description`, `version`, `contact_id`, `locales`, `locale_custom_strings`) VALUES - (1,'Default Domain Name',NULL,'5.83.alpha1',1,NULL,'a:1:{s:5:\"en_US\";a:0:{}}'); + (1,'Default Domain Name',NULL,'6.0.alpha1',1,NULL,'a:1:{s:5:\"en_US\";a:0:{}}'); /*!40000 ALTER TABLE `civicrm_domain` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/test_data_second_domain.mysql b/sql/test_data_second_domain.mysql index 35e986afe1f..3dbca0e18dd 100644 --- a/sql/test_data_second_domain.mysql +++ b/sql/test_data_second_domain.mysql @@ -907,4 +907,4 @@ INSERT INTO civicrm_navigation VALUES ( @domainID, CONCAT('civicrm/report/instance/', @instanceID,'&reset=1'), 'Mailing Detail Report', 'Mailing Detail Report', 'administer CiviMail', 'OR', @reportlastID, '1', NULL, @instanceID+2 ); UPDATE civicrm_report_instance SET navigation_id = LAST_INSERT_ID() WHERE id = @instanceID; -UPDATE civicrm_domain SET version = '5.83.alpha1'; +UPDATE civicrm_domain SET version = '6.0.alpha1'; diff --git a/xml/version.xml b/xml/version.xml index 4157feca54c..ba284451f68 100644 --- a/xml/version.xml +++ b/xml/version.xml @@ -1,5 +1,5 @@ - 5.83.alpha1 + 6.0.alpha1 (unreleased) From 129c65adcd72c1a3205c8e2d5eff6a9d091c76c3 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 13 Jan 2025 16:35:00 -0800 Subject: [PATCH 2/3] civimix-schema - Update numbering for civicrm-core@6.x --- mixin/lib/pathload.index.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mixin/lib/pathload.index.php b/mixin/lib/pathload.index.php index 26b81a76767..3e2f211e9f5 100644 --- a/mixin/lib/pathload.index.php +++ b/mixin/lib/pathload.index.php @@ -11,5 +11,14 @@ // // So instead, we use `addSearchItem()` and register with explicit versions. -$version = \CRM_Utils_System::version() . '.1'; /* Higher priority than contrib copies of same version... */ -\pathload()->addSearchItem('civimix-schema', $version, __DIR__ . '/civimix-schema'); +$version6 = \CRM_Utils_System::version() . '.1'; /* Higher priority than contrib copies of same version... */ +$version5 = preg_replace_callback(';^6\.(\d+)\.;', function ($m) { + /* civimix-schema@5.83=>6.0 was purely superficial (to match core#)s. Continue 5.x option for compat. */ + return '5.' . (83 + $m[1]) . '.'; +}, $version6); + +// Register civimix-schema@5.x +\pathload()->addSearchItem('civimix-schema', $version5, __DIR__ . '/civimix-schema'); + +// (Optional) Register civimix-schema@6.x +// \pathload()->addSearchItem('civimix-schema', $version6, __DIR__ . '/civimix-schema'); From c1b30b0a12b287bb2537cb9ddd57952280e853bf Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 13 Jan 2025 23:11:28 -0800 Subject: [PATCH 3/3] civimix-schema - Split off major-version from core. Keep 5.x. Before: * 'mixin/lib/civimix-schema' is numbered `5.x.x` * `mixin/lib/civimix-schema` is strictly pegged to the 'civicrm-core' After: * `mixin/lib/civimix-schema@5` is numbered `5.x.x.` * `mixin/lib/civimix-schema@5` is partially released from the numbering of `civicrm-core`. Comments: The version will still increment automatically (month-to-month; in parallel with core), but it will stay within 5.x. This is because it's supposed to be strictly SemVer, and we haven't actually made any major changes to it, so moving to 6.x would be a big hassle. --- CRM/Core/I18n/SchemaStructure.php | 2 +- CRM/Upgrade/Incremental/Base.php | 2 +- .../pathload.main.php | 0 .../src/AutomaticUpgrader.php | 0 .../src/CiviMixSchema.php | 0 .../src/DAO.php | 0 .../src/SchemaHelper.php | 0 .../src/SchemaHelperInterface.php | 0 .../src/SqlGenerator.php | 0 mixin/lib/pathload.index.php | 15 +- tools/mixin/bin/build-lib | 136 +++++++++++------- 11 files changed, 90 insertions(+), 65 deletions(-) rename mixin/lib/{civimix-schema => civimix-schema@5}/pathload.main.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/AutomaticUpgrader.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/CiviMixSchema.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/DAO.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/SchemaHelper.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/SchemaHelperInterface.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/SqlGenerator.php (100%) diff --git a/CRM/Core/I18n/SchemaStructure.php b/CRM/Core/I18n/SchemaStructure.php index 0b6453032da..fe358ec65c0 100644 --- a/CRM/Core/I18n/SchemaStructure.php +++ b/CRM/Core/I18n/SchemaStructure.php @@ -26,7 +26,7 @@ public static function &columns() { if (!$result) { $result = []; global $civicrm_root; - $sqlGenerator = require "$civicrm_root/mixin/lib/civimix-schema/src/SqlGenerator.php"; + $sqlGenerator = require "$civicrm_root/mixin/lib/civimix-schema@5/src/SqlGenerator.php"; foreach (\Civi\Schema\EntityRepository::getEntities() as $entity) { if (empty($entity['getFields'])) { continue; diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 87ae6c5ed31..a9fa65348a0 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -404,7 +404,7 @@ public static function checkFKExists($table_name, $constraint_name) { public static function alterSchemaField($ctx, string $entityName, string $fieldName, array $fieldSpec): bool { $tableName = Civi::entity($entityName)->getMeta('table'); global $civicrm_root; - $sqlGenerator = require "$civicrm_root/mixin/lib/civimix-schema/src/SqlGenerator.php"; + $sqlGenerator = require "$civicrm_root/mixin/lib/civimix-schema@5/src/SqlGenerator.php"; $fieldSql = $sqlGenerator::generateFieldSql($fieldSpec); if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists($tableName, $fieldName, FALSE)) { return self::alterColumn($ctx, $tableName, $fieldName, $fieldSql, !empty($fieldSpec['localizable'])); diff --git a/mixin/lib/civimix-schema/pathload.main.php b/mixin/lib/civimix-schema@5/pathload.main.php similarity index 100% rename from mixin/lib/civimix-schema/pathload.main.php rename to mixin/lib/civimix-schema@5/pathload.main.php diff --git a/mixin/lib/civimix-schema/src/AutomaticUpgrader.php b/mixin/lib/civimix-schema@5/src/AutomaticUpgrader.php similarity index 100% rename from mixin/lib/civimix-schema/src/AutomaticUpgrader.php rename to mixin/lib/civimix-schema@5/src/AutomaticUpgrader.php diff --git a/mixin/lib/civimix-schema/src/CiviMixSchema.php b/mixin/lib/civimix-schema@5/src/CiviMixSchema.php similarity index 100% rename from mixin/lib/civimix-schema/src/CiviMixSchema.php rename to mixin/lib/civimix-schema@5/src/CiviMixSchema.php diff --git a/mixin/lib/civimix-schema/src/DAO.php b/mixin/lib/civimix-schema@5/src/DAO.php similarity index 100% rename from mixin/lib/civimix-schema/src/DAO.php rename to mixin/lib/civimix-schema@5/src/DAO.php diff --git a/mixin/lib/civimix-schema/src/SchemaHelper.php b/mixin/lib/civimix-schema@5/src/SchemaHelper.php similarity index 100% rename from mixin/lib/civimix-schema/src/SchemaHelper.php rename to mixin/lib/civimix-schema@5/src/SchemaHelper.php diff --git a/mixin/lib/civimix-schema/src/SchemaHelperInterface.php b/mixin/lib/civimix-schema@5/src/SchemaHelperInterface.php similarity index 100% rename from mixin/lib/civimix-schema/src/SchemaHelperInterface.php rename to mixin/lib/civimix-schema@5/src/SchemaHelperInterface.php diff --git a/mixin/lib/civimix-schema/src/SqlGenerator.php b/mixin/lib/civimix-schema@5/src/SqlGenerator.php similarity index 100% rename from mixin/lib/civimix-schema/src/SqlGenerator.php rename to mixin/lib/civimix-schema@5/src/SqlGenerator.php diff --git a/mixin/lib/pathload.index.php b/mixin/lib/pathload.index.php index 3e2f211e9f5..d896c7118bd 100644 --- a/mixin/lib/pathload.index.php +++ b/mixin/lib/pathload.index.php @@ -5,11 +5,13 @@ // // pathload()->addSearchDir(__DIR__ . '/lib'); // -// However, that would detect version#'s from the filenames. In this folder, -// we want all subprojects to have the same version-number as the main -// project. It would be quite inconvenient to rename them every month. +// However, that would detect version#'s from the filenames. While that +// convention is handy for downstreams (using backports), it can be annoying +// here (as canonical source). It would be inconvenient to have to rename +// the canonical files/folders whenever we make an edit. // -// So instead, we use `addSearchItem()` and register with explicit versions. +// `addSearchItem()` allows us to register with a programmatic +// version-number -- so we don't have to manually set the number. $version6 = \CRM_Utils_System::version() . '.1'; /* Higher priority than contrib copies of same version... */ $version5 = preg_replace_callback(';^6\.(\d+)\.;', function ($m) { @@ -18,7 +20,4 @@ }, $version6); // Register civimix-schema@5.x -\pathload()->addSearchItem('civimix-schema', $version5, __DIR__ . '/civimix-schema'); - -// (Optional) Register civimix-schema@6.x -// \pathload()->addSearchItem('civimix-schema', $version6, __DIR__ . '/civimix-schema'); +\pathload()->addSearchItem('civimix-schema@5', $version5, __DIR__ . '/civimix-schema'); diff --git a/tools/mixin/bin/build-lib b/tools/mixin/bin/build-lib index b97d6ea30ce..7f1b55c63cc 100755 --- a/tools/mixin/bin/build-lib +++ b/tools/mixin/bin/build-lib @@ -1,70 +1,96 @@ -#!/usr/bin/env bash - +#!/usr/bin/env php + -function absdirname() { - pushd $(dirname $0) >> /dev/null - pwd - popd >> /dev/null -} -BINDIR=$(absdirname "$0") -set -e - -############################################################################### - -function getCiviVer() { - pushd "$1" >> /dev/null - if [ -f xml/version.xml ]; then - ## Works in any git-based build, even if gencode hasn't run yet. - php -r 'echo simplexml_load_file("xml/version.xml")->version_no;' - else - ## works in any tar-based build. - php -r 'require "civicrm-version.php"; $a = civicrmVersion(); echo $a["version"];' - fi - popd >> /dev/null +/** + * Get the CiviCRM version from the specified directory. + * + * @param string $directory + * @return string|null + */ +function getCiviVer(string $directory): ?string { + $version = NULL; + + if (file_exists($directory . '/xml/version.xml')) { + $version = simplexml_load_file($directory . '/xml/version.xml')->version_no; + } + elseif (file_exists($directory . '/civicrm-version.php')) { + require $directory . '/civicrm-version.php'; + $versionArray = civicrmVersion(); + $version = $versionArray['version'] ?? NULL; + } + + return $version; } +/** + * Execute a PHAR command. + * + * @param string $command + * @return void + */ +function executePhar(string $pwd, string $command): void { + $cmd = 'cd ' . escapeshellarg($pwd) . ' && '; + $cmd .= "php -d phar.readonly=0 `which phar` $command"; + // echo "$cmd\n"; + + passthru($cmd, $result); + if ($result !== 0) { + throw new \RuntimeException("Failed to execute command: $cmd"); + } +} -function PHAR() { - php -d phar.readonly=0 `which phar` "$@" +/** + * Take a source folder and generate a PHAR. + * + * @param string $src + * @param string $outputPhar + * @return void + */ +function buildLib(string $src, string $outputPhar): void { + echo "\n====================================\n"; + echo "Read $src\n"; + echo "Create $outputPhar\n"; + echo "\n"; + + if (file_exists($outputPhar)) { + unlink($outputPhar); + } + + $stubFile = escapeshellarg("$GLOBALS[toolMix]/src/empty-stub.php"); + $outputPhar = escapeshellarg($outputPhar); + executePhar($src, "pack -f $outputPhar -s $stubFile -i '.php$' ."); + + // Or for concatenated PHP format: + // php "$CIVI_CORE/scripts/concat-php.php" pathload.main.php $( find src -name '*.php' ) >"$OUTPUT_PHP" } ############################################################################### +## Setup -TOOLMIX=$(dirname "$BINDIR") -CIVI_CORE=$(dirname $(dirname "$TOOLMIX")) -OUTPUT="$1" -VERSION=$(getCiviVer "$CIVI_CORE") - -if [ -z "$OUTPUT" ]; then - echo 2>&1 "usage: $0 " - echo 2>&1 "example: $0 /tmp/civimix" - exit 1 -fi +$toolMix = dirname(__DIR__); +$civiCore = dirname(dirname($toolMix)); +$output = $argv[1] ?? NULL; +$version = getCiviVer($civiCore); -if [ ! -d "$OUTPUT" ]; then - mkdir "$OUTPUT" -fi - -for PACKAGE in civimix-schema ; do - - SRC="${CIVI_CORE}/mixin/lib/${PACKAGE}" - OUTPUT_PHAR="${OUTPUT}/${PACKAGE}@${VERSION}.phar" - #OUTPUT_PHP="${OUTPUT}/${PACKAGE}@${VERSION}.php" - - echo "Read $SRC" - echo "Create $OUTPUT_PHAR" +if (empty($output)) { + fwrite(STDERR, "usage: build-lib \n"); + fwrite(STDERR, "example: build-lib /tmp/civimix\n"); + exit(1); +} - [ -f "$OUTPUT_PHAR" ] && rm -f "$OUTPUT_PHAR" || true - #[ -f "$OUTPUT_PHP" ] && rm -f "$OUTPUT_PHP" || true +if (!is_dir($output)) { + mkdir($output, 0755, TRUE); +} - (cd "$SRC" ; PHAR pack -f "$OUTPUT_PHAR" -s "$TOOLMIX/src/empty-stub.php" -i '\.php$' . ) - #php "$CIVI_CORE/scripts/concat-php.php" pathload.main.php $( find src -name '*.php' ) >"$OUTPUT_PHP" +############################################################################### +## Build rules -done +/* Tracked core version up until 5.83. After 6.0 split, this stayed on 5.x.*/ +$civimixSchemaVer = preg_replace_callback(';^6\.(\d+)\.;', function ($m) { + return '5.' . (83 + $m[1]) . '.'; +}, getCiviVer($civiCore)); +buildLib("$civiCore/mixin/lib/civimix-schema@5", "$output/civimix-schema@$civimixSchemaVer.phar");