Skip to content

Commit

Permalink
[#14] civix upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Jan 13, 2023
1 parent 458b6af commit 54157d6
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 248 deletions.
55 changes: 28 additions & 27 deletions info.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<?xml version="1.0"?>
<extension key="org.project60.sepapp" type="module">
<file>sepapp</file>
<name>CiviSEPA Payment Processor</name>
<description>Provides a CiviCRM payment processor for the CiviSEPA extension</description>
<license>AGPL-3.0</license>
<maintainer>
<author>B. Endres</author>
<email>[email protected]</email>
</maintainer>
<urls>
<url desc="Main Extension Page">https://github.com/Project60/org.project60.sepapp</url>
<url desc="Documentation">https://github.com/Project60/org.project60.sepapp</url>
<url desc="Support">https://github.com/Project60/org.project60.sepapp/issues</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate></releaseDate>
<version>1.1-dev</version>
<develStage>dev</develStage>
<requires>
<ext version=">=1.5">org.project60.sepa</ext>
</requires>
<compatibility>
<ver>5.0</ver>
</compatibility>
<comments>This used to be part of CiviSEPA</comments>
<civix>
<namespace>CRM/Sepapp</namespace>
</civix>
<file>sepapp</file>
<name>CiviSEPA Payment Processor</name>
<description>Provides a CiviCRM payment processor for the CiviSEPA extension</description>
<license>AGPL-3.0</license>
<maintainer>
<author>B. Endres</author>
<email>[email protected]</email>
</maintainer>
<urls>
<url desc="Main Extension Page">https://github.com/Project60/org.project60.sepapp</url>
<url desc="Documentation">https://github.com/Project60/org.project60.sepapp</url>
<url desc="Support">https://github.com/Project60/org.project60.sepapp/issues</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate></releaseDate>
<version>1.1-dev</version>
<develStage>dev</develStage>
<requires>
<ext version=">=1.5">org.project60.sepa</ext>
</requires>
<compatibility>
<ver>5.0</ver>
</compatibility>
<comments>This used to be part of CiviSEPA</comments>
<civix>
<namespace>CRM/Sepapp</namespace>
<format>22.05.2</format>
</civix>
</extension>
101 changes: 101 additions & 0 deletions mixin/polyfill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?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[__FUNCTION__][$mixin])) {
\Civi::$statics[__FUNCTION__][$mixin] = 1;
$func = $_CIVIX_MIXIN_POLYFILL[$mixin];
$func($mixInfo, $bootCache);
}
}
};
169 changes: 12 additions & 157 deletions sepapp.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_Sepapp_ExtensionUtil as E;

function _sepapp_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 _sepapp_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 _sepapp_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 _sepapp_civix_civicrm_xmlMenu(&$files) {
foreach (_sepapp_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
$files[] = $file;
}
_sepapp_civix_mixin_polyfill();
}

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

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

/**
Expand Down Expand Up @@ -217,136 +214,6 @@ function _sepapp_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 _sepapp_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 _sepapp_civix_civicrm_managed(&$entities) {
$mgdFiles = _sepapp_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 _sepapp_civix_civicrm_caseTypes(&$caseTypes) {
if (!is_dir(__DIR__ . '/xml/case')) {
return;
}

foreach (_sepapp_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 _sepapp_civix_civicrm_angularModules(&$angularModules) {
if (!is_dir(__DIR__ . '/ang')) {
return;
}

$files = _sepapp_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 _sepapp_civix_civicrm_themes(&$themes) {
$files = _sepapp_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 _sepapp_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 _sepapp_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
}
}

/**
* (Delegated) Implements hook_civicrm_alterSettingsFolders().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
*/
function _sepapp_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
Loading

0 comments on commit 54157d6

Please sign in to comment.