From 984dacc42b91eb289486e0c1dd5445382857feb5 Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Fri, 23 Jun 2023 13:04:43 +0100 Subject: [PATCH] standalone: civix upgrade on standaloneusers --- ext/standaloneusers/info.xml | 6 +- ...n.php => entity-types-php@1.0.0.mixin.php} | 20 ++-- .../mixin/menu-xml@1.0.0.mixin.php | 31 ------ .../mixin/mgd-php@1.0.0.mixin.php | 42 -------- ext/standaloneusers/mixin/polyfill.php | 101 ------------------ .../mixin/smarty-v2@1.0.1.mixin.php | 51 +++++++++ ext/standaloneusers/standaloneusers.civix.php | 62 ++--------- ext/standaloneusers/standaloneusers.php | 11 -- 8 files changed, 73 insertions(+), 251 deletions(-) rename ext/standaloneusers/mixin/{setting-php@1.0.0.mixin.php => entity-types-php@1.0.0.mixin.php} (51%) delete mode 100644 ext/standaloneusers/mixin/menu-xml@1.0.0.mixin.php delete mode 100644 ext/standaloneusers/mixin/mgd-php@1.0.0.mixin.php delete mode 100644 ext/standaloneusers/mixin/polyfill.php create mode 100644 ext/standaloneusers/mixin/smarty-v2@1.0.1.mixin.php diff --git a/ext/standaloneusers/info.xml b/ext/standaloneusers/info.xml index 5cc220ad3f..2db11a3ff9 100644 --- a/ext/standaloneusers/info.xml +++ b/ext/standaloneusers/info.xml @@ -18,7 +18,7 @@ 1.0 alpha - 5.38 + 5.45 org.civicrm.search_kit @@ -32,13 +32,15 @@ CRM/Standaloneusers - 22.12.1 + 23.02.1 crmStandaloneusers mgd-php@1.0.0 setting-php@1.0.0 menu-xml@1.0.0 + smarty-v2@1.0.1 + entity-types-php@1.0.0 CRM_Standaloneusers_Upgrader diff --git a/ext/standaloneusers/mixin/setting-php@1.0.0.mixin.php b/ext/standaloneusers/mixin/entity-types-php@1.0.0.mixin.php similarity index 51% rename from ext/standaloneusers/mixin/setting-php@1.0.0.mixin.php rename to ext/standaloneusers/mixin/entity-types-php@1.0.0.mixin.php index 7195af40de..8ec4203dfe 100644 --- a/ext/standaloneusers/mixin/setting-php@1.0.0.mixin.php +++ b/ext/standaloneusers/mixin/entity-types-php@1.0.0.mixin.php @@ -1,10 +1,11 @@ addListener('hook_civicrm_alterSettingsFolders', function ($e) use ($mixInfo) { + Civi::dispatcher()->addListener('hook_civicrm_entityTypes', function ($e) use ($mixInfo) { // When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically. - if (!$mixInfo->isActive()) { + if (!$mixInfo->isActive() || !is_dir($mixInfo->getPath('xml/schema/CRM'))) { return; } - $settingsDir = $mixInfo->getPath('settings'); - if (!in_array($settingsDir, $e->settingsFolders) && is_dir($settingsDir)) { - $e->settingsFolders[] = $settingsDir; + $files = (array) glob($mixInfo->getPath('xml/schema/CRM/*/*.entityType.php')); + foreach ($files as $file) { + $entities = include $file; + foreach ($entities as $entity) { + $e->entityTypes[$entity['class']] = $entity; + } } }); diff --git a/ext/standaloneusers/mixin/menu-xml@1.0.0.mixin.php b/ext/standaloneusers/mixin/menu-xml@1.0.0.mixin.php deleted file mode 100644 index 4c0b2276c0..0000000000 --- a/ext/standaloneusers/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/ext/standaloneusers/mixin/mgd-php@1.0.0.mixin.php b/ext/standaloneusers/mixin/mgd-php@1.0.0.mixin.php deleted file mode 100644 index 39d45b14ab..0000000000 --- a/ext/standaloneusers/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/ext/standaloneusers/mixin/polyfill.php b/ext/standaloneusers/mixin/polyfill.php deleted file mode 100644 index f57c5ebbf8..0000000000 --- a/ext/standaloneusers/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[__FUNCTION__][$mixin])) { - \Civi::$statics[__FUNCTION__][$mixin] = 1; - $func = $_CIVIX_MIXIN_POLYFILL[$mixin]; - $func($mixInfo, $bootCache); - } - } -}; diff --git a/ext/standaloneusers/mixin/smarty-v2@1.0.1.mixin.php b/ext/standaloneusers/mixin/smarty-v2@1.0.1.mixin.php new file mode 100644 index 0000000000..5972dbdc57 --- /dev/null +++ b/ext/standaloneusers/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(); + } + }); + +}; diff --git a/ext/standaloneusers/standaloneusers.civix.php b/ext/standaloneusers/standaloneusers.civix.php index 4f56172044..fb08289f80 100644 --- a/ext/standaloneusers/standaloneusers.civix.php +++ b/ext/standaloneusers/standaloneusers.civix.php @@ -79,40 +79,22 @@ class CRM_Standaloneusers_ExtensionUtil { use CRM_Standaloneusers_ExtensionUtil as E; -function _standaloneusers_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 _standaloneusers_civix_civicrm_config(&$config = NULL) { +function _standaloneusers_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); - _standaloneusers_civix_mixin_polyfill(); + // Based on , this does not currently require mixin/polyfill.php. } /** @@ -122,7 +104,7 @@ function _standaloneusers_civix_civicrm_config(&$config = NULL) { */ function _standaloneusers_civix_civicrm_install() { _standaloneusers_civix_civicrm_config(); - _standaloneusers_civix_mixin_polyfill(); + // Based on , this does not currently require mixin/polyfill.php. } /** @@ -132,7 +114,7 @@ function _standaloneusers_civix_civicrm_install() { */ function _standaloneusers_civix_civicrm_enable(): void { _standaloneusers_civix_civicrm_config(); - _standaloneusers_civix_mixin_polyfill(); + // Based on , this does not currently require mixin/polyfill.php. } /** @@ -151,8 +133,8 @@ function _standaloneusers_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,35 +198,3 @@ function _standaloneusers_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $par } } } - -/** - * (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 _standaloneusers_civix_civicrm_entityTypes(&$entityTypes) { - $entityTypes = array_merge($entityTypes, [ - 'CRM_Standaloneusers_DAO_Role' => [ - 'name' => 'Role', - 'class' => 'CRM_Standaloneusers_DAO_Role', - 'table' => 'civicrm_role', - ], - 'CRM_Standaloneusers_DAO_RolePermission' => [ - 'name' => 'RolePermission', - 'class' => 'CRM_Standaloneusers_DAO_RolePermission', - 'table' => 'civicrm_role_permission', - ], - 'CRM_Standaloneusers_DAO_User' => [ - 'name' => 'User', - 'class' => 'CRM_Standaloneusers_DAO_User', - 'table' => 'civicrm_user', - ], - 'CRM_Standaloneusers_DAO_UserRole' => [ - 'name' => 'UserRole', - 'class' => 'CRM_Standaloneusers_DAO_UserRole', - 'table' => 'civicrm_user_role', - ], - ]); -} diff --git a/ext/standaloneusers/standaloneusers.php b/ext/standaloneusers/standaloneusers.php index a43d6c24e7..8dbfc8befb 100644 --- a/ext/standaloneusers/standaloneusers.php +++ b/ext/standaloneusers/standaloneusers.php @@ -32,17 +32,6 @@ function standaloneusers_civicrm_enable() { _standaloneusers_civix_civicrm_enable(); } -/** - * Implements hook_civicrm_entityTypes(). - * - * Declare entity types provided by this module. - * - * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes - */ -function standaloneusers_civicrm_entityTypes(&$entityTypes) { - _standaloneusers_civix_civicrm_entityTypes($entityTypes); -} - // --- Functions below this ship commented out. Uncomment as required. --- /** -- 2.25.1