Added extensions compatibility checks during site upgrade and per company activation.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 16 Apr 2015 13:10:23 +0000 (15:10 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 16 Apr 2015 13:10:23 +0000 (15:10 +0200)
admin/includes/fa_patch.class.inc
admin/inst_module.php
includes/packages.inc
version.php

index 880e24b9ff87afc7a75f1f71c42bafcec2f87e56..6aa485fe3df6a594286f9267ea0759c7aa0fdc05 100644 (file)
@@ -9,7 +9,7 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-
+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;
 
index 01169034e2563ff95b02e00efe67a59fb85e8db9..50d2e3e7184b8a6f37d5149f5d9938653355ed3e 100644 (file)
@@ -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
index feab3d78dd502a754ec7ed6b04047169e3b2fa3c..70d3be491a19bcc9b7b89445436bdd1fd348721e 100644 (file)
@@ -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;
+}
+
index 9a4bf296e2970d8433cb9b5bb5756032f783109f..8964676933856494ef5b51b7c0eeb434e53d1886 100644 (file)
@@ -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