From b0cf01e322af8291c73fb5e4478347aaa0070c02 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Thu, 16 Apr 2015 15:10:23 +0200 Subject: [PATCH] Added extensions compatibility checks during site upgrade and per company activation. --- admin/includes/fa_patch.class.inc | 28 +++++++++++++++++++++++++++- admin/inst_module.php | 6 ++++++ includes/packages.inc | 18 ++++++++++++++++++ version.php | 5 +++-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/admin/includes/fa_patch.class.inc b/admin/includes/fa_patch.class.inc index 880e24b9..6aa485fe 100644 --- a/admin/includes/fa_patch.class.inc +++ b/admin/includes/fa_patch.class.inc @@ -9,7 +9,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ - +include($path_to_root."/includes/packages.inc"); // // Utility class contains basic database upgrade routines. // @@ -48,6 +48,30 @@ class fa_patch { return false; } + /* + Check and disable incompatible extensions. + */ + function update_extensions() + { + global $version; + + $mods = get_company_extensions(); + $exts = get_company_extensions($this->cur_company); + + $fixed = false; + foreach($mods as $key => $ins) { + foreach($exts as $ext) + if ($ext['name'] == $ins['name'] && (!check_src_ext_version($ins['version']))) { + $mods[$key]['active'] = false; + $this->log_error(sprintf(_("Uncompatible extension '%s' disabled for company %d."), $ins['name'], $this->cur_company)); + $fixed = true; + continue 2; + } + } + if ($fixed) + write_extensions($mods, $this->cur_company); + } + /* Pre-install maintenance: login to company, open upgrade log, make a backup */ @@ -70,6 +94,8 @@ class fa_patch { return $this->log_error(sprintf(_("Cannot upgrade company %s: database version is incompatible ('%s' instead of '%s')."), $this->cur_company, $cur_ver, $this->previous)); + $this->update_extensions(); // disable uncompatible extensions + if (!$this->prepare()) // fetch params, perform additional checks (if any) return false; diff --git a/admin/inst_module.php b/admin/inst_module.php index 01169034..50d2e3e7 100644 --- a/admin/inst_module.php +++ b/admin/inst_module.php @@ -212,6 +212,12 @@ if (get_post('Refresh')) { $result = true; foreach($exts as $i => $ext) { if ($ext['package'] && ($ext['active'] ^ check_value('Active'.$i))) { + if (check_value('Active'.$i) && !check_src_ext_version($ext['version'])) + { + display_warning(sprintf(_("Package '%s' is incompatible with current application version and cannot be activated.\n") + . _("Check Install/Activate page for newer package version."), $ext['name'])); + continue; + } if (!$ext['active']) $activated = activate_hooks($ext['package'], $comp); else diff --git a/includes/packages.inc b/includes/packages.inc index feab3d78..70d3be49 100644 --- a/includes/packages.inc +++ b/includes/packages.inc @@ -725,3 +725,21 @@ function get_package_info($pkg, $type=null, $filter=array(), $outkey=null, $down return get_pkg_or_list($type, $pkg, $filter, null, false); } +/* + Check basic extension source compatibility. +*/ +function check_src_ext_version($ext_v) +{ + global $src_version; + + $compat_levels = 2; // current policy is keeping compatibility on major version level. + $app = explode('.', strspn($src_version, "0123456789.")); + $pkg = explode('.', strspn($ext_v, "0123456789.")); + + for ($i=0; $i < min($compat_levels, count($app)); $i++) + if ($pkg[$i] < $app[$i]) + return false; + + return true; +} + diff --git a/version.php b/version.php index 9a4bf296..89646769 100644 --- a/version.php +++ b/version.php @@ -4,12 +4,13 @@ // Settings in this file can be automatically updated at any time during software update. // -// Internal database version compatibility check. Do not change. +// Versions used by source/database version compatibility checks. Do not change. $db_version = "2.4.0"; +$src_version = "2.4.0"; // application version - can be overriden in config.php if (!isset($version)) - $version = "2.4 alpha"; + $version = $src_version; //====================================================================== // Extension packages repository settings -- 2.30.2