From 70a3f46d0f873071b888cd9854b4a21295606383 Mon Sep 17 00:00:00 2001 From: openclawautomation Date: Tue, 31 Mar 2026 13:28:51 +0000 Subject: [PATCH] Backport: add mixin polyfill to support CiviCRM 5.75+ The extension was originally generated targeting CiviCRM 6.4+, which caused civix to omit the mixin polyfill bootstrap. As a result, on CiviCRM 5.75 the bundled mgd-php@2.0.0.mixin.php was never activated, leading to a TypeError during extension enable: TypeError: Civi\Schema\EntityRepository::getEntity(): Argument #1 ($entityName) must be of type string, null given Root cause: without the polyfill, CiviCRM 5.75 does not scan the extension's mixin/ directory for fallback implementations. The entity registry is populated before the extension's hook_civicrm_entityTypes listener is registered, so getEntityNameForClass() returns null for the extension's DAO classes. Changes: - info.xml: lower minimum compatibility to 5.75 - paymentprocessingcore.civix.php: activate polyfill when CRM_Extension_MixInfo is absent (i.e. CiviCRM < ~5.77 without native mixin support) - mixin/polyfill.php: add the polyfill file from CiviCRM core 5.75 On CiviCRM 6.4+ this is a no-op (CRM_Extension_MixInfo exists, polyfill skipped). --- info.xml | 5 +- mixin/polyfill.php | 102 ++++++++++++++++++++++++++++++++ paymentprocessingcore.civix.php | 8 ++- 3 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 mixin/polyfill.php diff --git a/info.xml b/info.xml index 05107ca..0dcc6d2 100644 --- a/info.xml +++ b/info.xml @@ -17,11 +17,12 @@ 7.0.0-alpha1 alpha - 6.4 + 5.75 Supported CiviCRM versions: - - CiviCRM 6.4.1+ + - CiviCRM 5.75+ (backport) + - CiviCRM 6.4.1+ (originally targeted) diff --git a/mixin/polyfill.php b/mixin/polyfill.php new file mode 100644 index 0000000..5e2ec24 --- /dev/null +++ b/mixin/polyfill.php @@ -0,0 +1,102 @@ +')) { + $mixinVers[$name] = $ver; + } + } + $mixins = []; + foreach ($mixinVers as $name => $ver) { + $mixins[] = "$name@$ver"; + } + + // Imitate CRM_Extension_MixInfo. + $mixInfo = new class() { + + /** + * @var string + */ + public $longName; + + /** + * @var string + */ + public $shortName; + + public $_basePath; + + public function getPath($file = NULL) { + return $this->_basePath . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file)); + } + + public function isActive() { + return \CRM_Extension_System::singleton()->getMapper()->isActiveModule($this->shortName); + } + + }; + $mixInfo->longName = $longName; + $mixInfo->shortName = $shortName; + $mixInfo->_basePath = $basePath; + + // Imitate CRM_Extension_BootCache. + $bootCache = new class() { + + public function define($name, $callback) { + $envId = \CRM_Core_Config_Runtime::getId(); + $oldExtCachePath = \Civi::paths()->getPath("[civicrm.compile]/CachedExtLoader.{$envId}.php"); + $stat = stat($oldExtCachePath); + $file = Civi::paths()->getPath('[civicrm.compile]/CachedMixin.' . md5($name . ($stat['mtime'] ?? 0)) . '.php'); + if (file_exists($file)) { + return include $file; + } + else { + $data = $callback(); + file_put_contents($file, '<' . "?php\nreturn " . var_export($data, 1) . ';'); + return $data; + } + } + + }; + + // Imitate CRM_Extension_MixinLoader::run() + // Parse all live mixins before trying to scan any classes. + global $_CIVIX_MIXIN_POLYFILL; + foreach ($mixins as $mixin) { + // If the exact same mixin is defined by multiple exts, just use the first one. + if (!isset($_CIVIX_MIXIN_POLYFILL[$mixin])) { + $_CIVIX_MIXIN_POLYFILL[$mixin] = include_once $basePath . '/mixin/' . $mixin . '.mixin.php'; + } + } + foreach ($mixins as $mixin) { + // If there's trickery about installs/uninstalls/resets, then we may need to register a second time. + if (!isset(\Civi::$statics[$longName][$mixin])) { + \Civi::$statics[$longName][$mixin] = 1; + $func = $_CIVIX_MIXIN_POLYFILL[$mixin]; + $func($mixInfo, $bootCache); + } + } +}; + diff --git a/paymentprocessingcore.civix.php b/paymentprocessingcore.civix.php index 60bd5b0..3fe3059 100644 --- a/paymentprocessingcore.civix.php +++ b/paymentprocessingcore.civix.php @@ -130,7 +130,11 @@ function _paymentprocessingcore_civix_civicrm_config($config = NULL) { $extRoot = __DIR__ . DIRECTORY_SEPARATOR; $include_path = $extRoot . PATH_SEPARATOR . get_include_path(); set_include_path($include_path); - // Based on , this does not currently require mixin/polyfill.php. + + if (!class_exists('CRM_Extension_MixInfo')) { + $f = include __DIR__ . '/mixin/polyfill.php'; + $f(E::LONG_NAME, E::SHORT_NAME, __DIR__); + } } /** @@ -140,7 +144,6 @@ function _paymentprocessingcore_civix_civicrm_config($config = NULL) { */ function _paymentprocessingcore_civix_civicrm_install() { _paymentprocessingcore_civix_civicrm_config(); - // Based on , this does not currently require mixin/polyfill.php. } /** @@ -150,7 +153,6 @@ function _paymentprocessingcore_civix_civicrm_install() { */ function _paymentprocessingcore_civix_civicrm_enable(): void { _paymentprocessingcore_civix_civicrm_config(); - // Based on , this does not currently require mixin/polyfill.php. } /**