Skip to content

Commit

Permalink
Civix upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
artfulrobot committed Jun 23, 2022
1 parent f136ce4 commit 87cefd7
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 224 deletions.
169 changes: 12 additions & 157 deletions importhelper.civix.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public static function findClass($suffix) {

use CRM_CsvImportHelper_ExtensionUtil as E;

function _importhelper_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().
*
Expand All @@ -91,9 +98,9 @@ function _importhelper_civix_civicrm_config(&$config = NULL) {
}
$configured = TRUE;

$template =& CRM_Core_Smarty::singleton();
$template = CRM_Core_Smarty::singleton();

$extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$extRoot = __DIR__ . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';

if (is_array($template->template_dir)) {
Expand All @@ -105,19 +112,7 @@ function _importhelper_civix_civicrm_config(&$config = NULL) {

$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
}

/**
* (Delegated) Implements hook_civicrm_xmlMenu().
*
* @param $files array(string)
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
*/
function _importhelper_civix_civicrm_xmlMenu(&$files) {
foreach (_importhelper_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
$files[] = $file;
}
_importhelper_civix_mixin_polyfill();
}

/**
Expand All @@ -130,6 +125,7 @@ function _importhelper_civix_civicrm_install() {
if ($upgrader = _importhelper_civix_upgrader()) {
$upgrader->onInstall();
}
_importhelper_civix_mixin_polyfill();
}

/**
Expand Down Expand Up @@ -170,6 +166,7 @@ function _importhelper_civix_civicrm_enable() {
$upgrader->onEnable();
}
}
_importhelper_civix_mixin_polyfill();
}

/**
Expand Down Expand Up @@ -217,136 +214,6 @@ function _importhelper_civix_upgrader() {
}
}

/**
* Search directory tree for files which match a glob pattern.
*
* Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
* Note: Delegate to CRM_Utils_File::findFiles(), this function kept only
* for backward compatibility of extension code that uses it.
*
* @param string $dir base dir
* @param string $pattern , glob pattern, eg "*.txt"
*
* @return array
*/
function _importhelper_civix_find_files($dir, $pattern) {
return CRM_Utils_File::findFiles($dir, $pattern);
}

/**
* (Delegated) Implements hook_civicrm_managed().
*
* Find any *.mgd.php files, merge their content, and return.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
*/
function _importhelper_civix_civicrm_managed(&$entities) {
$mgdFiles = _importhelper_civix_find_files(__DIR__, '*.mgd.php');
sort($mgdFiles);
foreach ($mgdFiles as $file) {
$es = include $file;
foreach ($es as $e) {
if (empty($e['module'])) {
$e['module'] = E::LONG_NAME;
}
if (empty($e['params']['version'])) {
$e['params']['version'] = '3';
}
$entities[] = $e;
}
}
}

/**
* (Delegated) Implements hook_civicrm_caseTypes().
*
* Find any and return any files matching "xml/case/*.xml"
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
*/
function _importhelper_civix_civicrm_caseTypes(&$caseTypes) {
if (!is_dir(__DIR__ . '/xml/case')) {
return;
}

foreach (_importhelper_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) {
$name = preg_replace('/\.xml$/', '', basename($file));
if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) {
$errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name));
throw new CRM_Core_Exception($errorMessage);
}
$caseTypes[$name] = [
'module' => E::LONG_NAME,
'name' => $name,
'file' => $file,
];
}
}

/**
* (Delegated) Implements hook_civicrm_angularModules().
*
* Find any and return any files matching "ang/*.ang.php"
*
* Note: This hook only runs in CiviCRM 4.5+.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
*/
function _importhelper_civix_civicrm_angularModules(&$angularModules) {
if (!is_dir(__DIR__ . '/ang')) {
return;
}

$files = _importhelper_civix_glob(__DIR__ . '/ang/*.ang.php');
foreach ($files as $file) {
$name = preg_replace(':\.ang\.php$:', '', basename($file));
$module = include $file;
if (empty($module['ext'])) {
$module['ext'] = E::LONG_NAME;
}
$angularModules[$name] = $module;
}
}

/**
* (Delegated) Implements hook_civicrm_themes().
*
* Find any and return any files matching "*.theme.php"
*/
function _importhelper_civix_civicrm_themes(&$themes) {
$files = _importhelper_civix_glob(__DIR__ . '/*.theme.php');
foreach ($files as $file) {
$themeMeta = include $file;
if (empty($themeMeta['name'])) {
$themeMeta['name'] = preg_replace(':\.theme\.php$:', '', basename($file));
}
if (empty($themeMeta['ext'])) {
$themeMeta['ext'] = E::LONG_NAME;
}
$themes[$themeMeta['name']] = $themeMeta;
}
}

/**
* Glob wrapper which is guaranteed to return an array.
*
* The documentation for glob() says, "On some systems it is impossible to
* distinguish between empty match and an error." Anecdotally, the return
* result for an empty match is sometimes array() and sometimes FALSE.
* This wrapper provides consistency.
*
* @link http://php.net/glob
* @param string $pattern
*
* @return array
*/
function _importhelper_civix_glob($pattern) {
$result = glob($pattern);
return is_array($result) ? $result : [];
}

/**
* Inserts a navigation menu item at a given place in the hierarchy.
*
Expand Down Expand Up @@ -429,18 +296,6 @@ function _importhelper_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parent
}
}

/**
* (Delegated) Implements hook_civicrm_alterSettingsFolders().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
*/
function _importhelper_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
$settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
if (!in_array($settingsDir, $metaDataFolders) && is_dir($settingsDir)) {
$metaDataFolders[] = $settingsDir;
}
}

/**
* (Delegated) Implements hook_civicrm_entityTypes().
*
Expand Down
81 changes: 18 additions & 63 deletions importhelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ function importhelper_civicrm_config(&$config) {
_importhelper_civix_civicrm_config($config);
}

/**
* Implements hook_civicrm_xmlMenu().
*
* @param array $files
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
*/
function importhelper_civicrm_xmlMenu(&$files) {
_importhelper_civix_civicrm_xmlMenu($files);
}

/**
* Implements hook_civicrm_install().
*
Expand Down Expand Up @@ -92,56 +81,6 @@ function importhelper_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _importhelper_civix_civicrm_upgrade($op, $queue);
}

/**
* Implements hook_civicrm_managed().
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
*/
function importhelper_civicrm_managed(&$entities) {
_importhelper_civix_civicrm_managed($entities);
}

/**
* Implements hook_civicrm_caseTypes().
*
* Generate a list of case-types.
*
* @param array $caseTypes
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
*/
function importhelper_civicrm_caseTypes(&$caseTypes) {
_importhelper_civix_civicrm_caseTypes($caseTypes);
}

/**
* Implements hook_civicrm_angularModules().
*
* Generate a list of Angular modules.
*
* Note: This hook only runs in CiviCRM 4.5+. It may
* use features only available in v4.6+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
*/
function importhelper_civicrm_angularModules(&$angularModules) {
_importhelper_civix_civicrm_angularModules($angularModules);
}

/**
* Implements hook_civicrm_alterSettingsFolders().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
*/
function importhelper_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
_importhelper_civix_civicrm_alterSettingsFolders($metaDataFolders);
}

/**
* Functions below this ship commented out. Uncomment as required.
*
Expand All @@ -151,9 +90,8 @@ function importhelper_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*
function importhelper_civicrm_preProcess($formName, &$form) {
} // */
// */

/**
* Implements hook_civicrm_navigationMenu().
Expand Down Expand Up @@ -184,3 +122,20 @@ function importhelper_civicrm_alterAPIPermissions($entity, $action, &$params, &$
$permissions['csv_helper']['default'] = ['access CiviCRM', 'view all contacts'];
}

/**
* Implements hook_civicrm_postInstall().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
*/
function importhelper_civicrm_postInstall() {
_importhelper_civix_civicrm_postInstall();
}

/**
* Implements hook_civicrm_entityTypes().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
*/
function importhelper_civicrm_entityTypes(&$entityTypes) {
_importhelper_civix_civicrm_entityTypes($entityTypes);
}
7 changes: 6 additions & 1 deletion info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
<compatibility>
<ver>5.36</ver>
</compatibility>
<comments></comments>
<comments/>
<civix>
<namespace>CRM/CsvImportHelper</namespace>
<format>22.05.2</format>
</civix>
<mixins>
<mixin>[email protected]</mixin>
<mixin>[email protected]</mixin>
</mixins>
</extension>
37 changes: 37 additions & 0 deletions mixin/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Auto-register "ang/*.ang.php" files.
*
* @mixinName ang-php
* @mixinVersion 1.0.0
*
* @param CRM_Extension_MixInfo $mixInfo
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
* @param \CRM_Extension_BootCache $bootCache
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
*/
return function ($mixInfo, $bootCache) {

/**
* @param \Civi\Core\Event\GenericHookEvent $e
* @see CRM_Utils_Hook::angularModules()
*/
Civi::dispatcher()->addListener('hook_civicrm_angularModules', function ($e) use ($mixInfo) {
// When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically.
if (!$mixInfo->isActive() || !is_dir($mixInfo->getPath('ang'))) {
return;
}

$files = (array) glob($mixInfo->getPath('ang/*.ang.php'));
foreach ($files as $file) {
$name = preg_replace(':\.ang\.php$:', '', basename($file));
$module = include $file;
if (empty($module['ext'])) {
$module['ext'] = $mixInfo->longName;
}
$e->angularModules[$name] = $module;
}
});

};
Loading

0 comments on commit 87cefd7

Please sign in to comment.