Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
<version>7.0.0-alpha1</version>
<develStage>alpha</develStage>
<compatibility>
<ver>6.4</ver>
<ver>5.75</ver>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

WARNING: The PR title (and likely the commit message) does not follow the required format CIVIMM-###:. Please update it to include the relevant ticket number (e.g., CIVIMM-20: Backport: add mixin polyfill to support CiviCRM 5.75+) as per the repository style guide (rule 25).

References
  1. Commit messages must follow the CIVIMM-###: format (Rule 25). (link)

</compatibility>
<comments>
Supported CiviCRM versions:
- CiviCRM 6.4.1+</comments>
- CiviCRM 5.75+ (backport)
- CiviCRM 6.4.1+ (originally targeted)</comments>
<classloader>
<psr4 prefix="Civi\" path="Civi"/>
<psr0 prefix="CRM_" path="."/>
Expand Down
102 changes: 102 additions & 0 deletions mixin/polyfill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/**
* When deploying on systems that lack mixin support, fake it.
*
* @mixinFile polyfill.php
*
* This polyfill does some (persnickity) deduplication, but it doesn't allow upgrades or shipping replacements in core.
*
* Note: The polyfill.php is designed to be copied into extensions for interoperability. Consequently, this file is
* not used 'live' by `civicrm-core`. However, the file does need a canonical home, and it's convenient to keep it
* adjacent to the actual mixin files.
*
* @param string $longName
* @param string $shortName
* @param string $basePath
*/
return function ($longName, $shortName, $basePath) {
// Construct imitations of the mixin services. These cannot work as well (e.g. with respect to
// number of file-reads, deduping, upgrading)... but they should be OK for a few months while
// the mixin services become available.

// List of active mixins; deduped by version
$mixinVers = [];
foreach ((array) glob($basePath . '/mixin/*.mixin.php') as $f) {
[$name, $ver] = explode('@', substr(basename($f), 0, -10));
if (!isset($mixinVers[$name]) || version_compare($ver, $mixinVers[$name], '>')) {
$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);
}
}
};

8 changes: 5 additions & 3 deletions paymentprocessingcore.civix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <compatibility>, 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__);
}
}

/**
Expand All @@ -140,7 +144,6 @@ function _paymentprocessingcore_civix_civicrm_config($config = NULL) {
*/
function _paymentprocessingcore_civix_civicrm_install() {
_paymentprocessingcore_civix_civicrm_config();
// Based on <compatibility>, this does not currently require mixin/polyfill.php.
}

/**
Expand All @@ -150,7 +153,6 @@ function _paymentprocessingcore_civix_civicrm_install() {
*/
function _paymentprocessingcore_civix_civicrm_enable(): void {
_paymentprocessingcore_civix_civicrm_config();
// Based on <compatibility>, this does not currently require mixin/polyfill.php.
}

/**
Expand Down
Loading