Skip to content

Commit

Permalink
Fix for FreePBX 15
Browse files Browse the repository at this point in the history
Check for framework version programmatically instead of using module.xml
  • Loading branch information
Massi-X committed May 5, 2024
1 parent 0f237c3 commit 9908b84
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions Phonemiddleware.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,38 @@ public function install()
//add Job
FreePBX::Job()->addClass('phonemiddleware', 'job', 'FreePBX\modules\PhoneMiddleware\Job', '* * * * *');

//because the module is compatible with both 15 and 16 framework, I need to check the framework module itself for the required version (not possible inside module.xml)
//see https://github.com/FreePBX/framework/commit/c05c245d691ecffaac52cc118adb4451e107300c and https://github.com/FreePBX/framework/commit/f4b390e451c4db4238cb1dfb20f195e04aba3907
out(_('Checking dependencies...'));

if (!function_exists('getversion'))
die('<span class="error">' . _('Unable to get system version!') . '</span>');

$version = getversion();

//there is no compare for versions lower than 15 because it is prevented by module.xml
$is15 = version_compare($version, 15) >= 0;
$is16 = version_compare($version, 16) >= 0;
$framework_version = 0;

//I do not check 17 or higher simply because there is no need
if ($is15 || $is16) {
try {
$framework_version = $this->FreePBX->Modules->getXML('framework')->version;
} catch (Throwable $t) {
die('<span class="error">' . _('Unable to get framework version!')) . '</span>';
}

//always check from highest to lowest
if ($is16) {
if (version_compare($framework_version, '16.0.40.4') == -1)
die('<span class="error">' . str_replace('%version', '16.0.40.4', _('Minimum required version of framework is %version. Please update first to the required version before install/update.')) . '</span>');
} else if ($is15) {
if (version_compare($framework_version, '15.0.37.2') == -1)
die('<span class="error">' . str_replace('%version', '15.0.37.2', _('Minimum required version of framework is %version. Please update first to the required version before install/update.')) . '</span>');
}
}

//post install hooks from core, if providen. Excpetions are not catched here, if you care you must catch them yourself.
if (method_exists(Core::class, 'post_install_hook'))
Core::post_install_hook($this->FreePBX);
Expand Down
2 changes: 1 addition & 1 deletion build_config
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $modulexml = [
'depends' => [
'version' => $minimum_fpbx,
'module' => [
'framework 16.0.40.4' //for common email FROM field -> https://github.com/FreePBX/framework/commit/c05c245d691ecffaac52cc118adb4451e107300c
'framework' //the version is checked at runtime (see Phonemiddleware.class.php)
]
]
];

0 comments on commit 9908b84

Please sign in to comment.