From 9c32c62df87ae566df511a15fb72b3e17656f23a Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Wed, 11 Oct 2023 18:07:09 +0530 Subject: [PATCH] Run Civix upgrade --- contributionrecur.civix.php | 41 ++----------- contributionrecur.php | 1 - info.xml | 4 +- mixin/menu-xml@1.0.0.mixin.php | 31 ---------- mixin/mgd-php@1.0.0.mixin.php | 42 ------------- mixin/polyfill.php | 101 -------------------------------- mixin/smarty-v2@1.0.1.mixin.php | 51 ++++++++++++++++ 7 files changed, 60 insertions(+), 211 deletions(-) delete mode 100644 mixin/menu-xml@1.0.0.mixin.php delete mode 100644 mixin/mgd-php@1.0.0.mixin.php delete mode 100644 mixin/polyfill.php create mode 100644 mixin/smarty-v2@1.0.1.mixin.php diff --git a/contributionrecur.civix.php b/contributionrecur.civix.php index 3ba0897..4f0023b 100644 --- a/contributionrecur.civix.php +++ b/contributionrecur.civix.php @@ -79,40 +79,22 @@ public static function findClass($suffix) { use CRM_Contributionrecur_ExtensionUtil as E; -function _contributionrecur_civix_mixin_polyfill() { - if (!class_exists('CRM_Extension_MixInfo')) { - $polyfill = __DIR__ . '/mixin/polyfill.php'; - (require $polyfill)(E::LONG_NAME, E::SHORT_NAME, E::path()); - } -} - /** * (Delegated) Implements hook_civicrm_config(). * * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config */ -function _contributionrecur_civix_civicrm_config(&$config = NULL) { +function _contributionrecur_civix_civicrm_config($config = NULL) { static $configured = FALSE; if ($configured) { return; } $configured = TRUE; - $template = CRM_Core_Smarty::singleton(); - $extRoot = __DIR__ . DIRECTORY_SEPARATOR; - $extDir = $extRoot . 'templates'; - - if (is_array($template->template_dir)) { - array_unshift($template->template_dir, $extDir); - } - else { - $template->template_dir = [$extDir, $template->template_dir]; - } - $include_path = $extRoot . PATH_SEPARATOR . get_include_path(); set_include_path($include_path); - _contributionrecur_civix_mixin_polyfill(); + // Based on , this does not currently require mixin/polyfill.php. } /** @@ -122,7 +104,7 @@ function _contributionrecur_civix_civicrm_config(&$config = NULL) { */ function _contributionrecur_civix_civicrm_install() { _contributionrecur_civix_civicrm_config(); - _contributionrecur_civix_mixin_polyfill(); + // Based on , this does not currently require mixin/polyfill.php. } /** @@ -132,7 +114,7 @@ function _contributionrecur_civix_civicrm_install() { */ function _contributionrecur_civix_civicrm_enable(): void { _contributionrecur_civix_civicrm_config(); - _contributionrecur_civix_mixin_polyfill(); + // Based on , this does not currently require mixin/polyfill.php. } /** @@ -151,8 +133,8 @@ function _contributionrecur_civix_insert_navigation_menu(&$menu, $path, $item) { if (empty($path)) { $menu[] = [ 'attributes' => array_merge([ - 'label' => CRM_Utils_Array::value('name', $item), - 'active' => 1, + 'label' => $item['name'] ?? NULL, + 'active' => 1, ], $item), ]; return TRUE; @@ -216,14 +198,3 @@ function _contributionrecur_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $p } } } - -/** - * (Delegated) Implements hook_civicrm_entityTypes(). - * - * Find any *.entityType.php files, merge their content, and return. - * - * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes - */ -function _contributionrecur_civix_civicrm_entityTypes(&$entityTypes) { - $entityTypes = array_merge($entityTypes, []); -} diff --git a/contributionrecur.php b/contributionrecur.php index 83f2414..d281b2a 100644 --- a/contributionrecur.php +++ b/contributionrecur.php @@ -699,7 +699,6 @@ function contributionrecur_civicrm_container(ContainerBuilder $container) { )->setPublic(TRUE); } - /* * contributionrecur_getFields() * diff --git a/info.xml b/info.xml index 433068d..7cdb4b3 100644 --- a/info.xml +++ b/info.xml @@ -20,13 +20,15 @@ Incubated since 2014 CRM/Contributionrecur - 22.12.1 + 23.02.1 menu-xml@1.0.0 mgd-php@1.0.0 + smarty-v2@1.0.1 + diff --git a/mixin/menu-xml@1.0.0.mixin.php b/mixin/menu-xml@1.0.0.mixin.php deleted file mode 100644 index 4c0b227..0000000 --- a/mixin/menu-xml@1.0.0.mixin.php +++ /dev/null @@ -1,31 +0,0 @@ -addListener('hook_civicrm_xmlMenu', function ($e) use ($mixInfo) { - if (!$mixInfo->isActive()) { - return; - } - - $files = (array) glob($mixInfo->getPath('xml/Menu/*.xml')); - foreach ($files as $file) { - $e->files[] = $file; - } - }); - -}; diff --git a/mixin/mgd-php@1.0.0.mixin.php b/mixin/mgd-php@1.0.0.mixin.php deleted file mode 100644 index 39d45b1..0000000 --- a/mixin/mgd-php@1.0.0.mixin.php +++ /dev/null @@ -1,42 +0,0 @@ -addListener('hook_civicrm_managed', function ($event) use ($mixInfo) { - // When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically. - if (!$mixInfo->isActive()) { - return; - } - - $mgdFiles = CRM_Utils_File::findFiles($mixInfo->getPath(), '*.mgd.php'); - sort($mgdFiles); - foreach ($mgdFiles as $file) { - $es = include $file; - foreach ($es as $e) { - if (empty($e['module'])) { - $e['module'] = $mixInfo->longName; - } - if (empty($e['params']['version'])) { - $e['params']['version'] = '3'; - } - $event->entities[] = $e; - } - } - }); - -}; diff --git a/mixin/polyfill.php b/mixin/polyfill.php deleted file mode 100644 index 17ba1df..0000000 --- a/mixin/polyfill.php +++ /dev/null @@ -1,101 +0,0 @@ -')) { - $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/mixin/smarty-v2@1.0.1.mixin.php b/mixin/smarty-v2@1.0.1.mixin.php new file mode 100644 index 0000000..5972dbd --- /dev/null +++ b/mixin/smarty-v2@1.0.1.mixin.php @@ -0,0 +1,51 @@ +getPath('templates'); + if (!file_exists($dir)) { + return; + } + + $register = function() use ($dir) { + // This implementation has a theoretical edge-case bug on older versions of CiviCRM where a template could + // be registered more than once. + CRM_Core_Smarty::singleton()->addTemplateDir($dir); + }; + + // Let's figure out what environment we're in -- so that we know the best way to call $register(). + + if (!empty($GLOBALS['_CIVIX_MIXIN_POLYFILL'])) { + // Polyfill Loader (v<=5.45): We're already in the middle of firing `hook_config`. + if ($mixInfo->isActive()) { + $register(); + } + return; + } + + if (CRM_Extension_System::singleton()->getManager()->extensionIsBeingInstalledOrEnabled($mixInfo->longName)) { + // New Install, Standard Loader: The extension has just been enabled, and we're now setting it up. + // System has already booted. New templates may be needed for upcoming installation steps. + $register(); + return; + } + + // Typical Pageview, Standard Loader: Defer the actual registration for a moment -- to ensure that Smarty is online. + \Civi::dispatcher()->addListener('hook_civicrm_config', function() use ($mixInfo, $register) { + if ($mixInfo->isActive()) { + $register(); + } + }); + +};