PHP 8.2 More fixes. Deprecated dynamic member adds.
[fa-stable.git] / admin / includes / fa_patch.class.inc
index 631df8205430b5879044ef644efde46d7d073c2b..c2e0d4a497032e8f631c9a12ceccd158d30b868c 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_once($path_to_root."/includes/packages.inc");
 //
 //     Utility class contains basic database upgrade routines.
 //
@@ -24,9 +24,10 @@ class fa_patch {
        var $backup;                            // pre-upgrade backup filename
 
        var $errors = array();
-       var     $ma_upgrade_time = 300;
+       var     $max_upgrade_time = 300;
+       var $companies = null;
 
-       function fa_patch()
+       function __construct()
        {
                global $path_to_root;
 
@@ -48,6 +49,62 @@ class fa_patch {
                return false;
        }
 
+       /*
+               Selectively extends access to selected security areas/sections.
+       */
+       function update_security_roles($sec_updates)
+       {
+               global $security_areas, $security_sections;
+
+               $roles = db_query("SELECT * FROM ".TB_PREF."security_roles");
+
+               while($role = db_fetch($roles))
+               {
+                       $role['areas'] = explode(';', $role['areas']);
+                       $role['sections'] = explode(';', $role['sections']);
+                       foreach($sec_updates as $has => $add)
+                       {
+                               if (in_array($security_areas[$has][0], $role['areas']))
+                               {
+                                       $sections = array();
+                                       foreach($add as $area)
+                                       {
+                                               $role['areas'][] = $security_areas[$area][0];
+                                               $role['sections'][] = $security_areas[$area][0]&~0xff;
+                                       }
+                                       sort($role['areas']);
+                                       update_security_role($role['id'], $role['role'], $role['description'], 
+                                               array_values($role['sections']), array_values($role['areas']));
+                               }
+                       }
+               }
+               return true;
+       }
+
+       /*
+               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), 'Notice');
+                                       $fixed = true;
+                                       continue 2;
+                               }
+               }
+               if ($fixed)
+                       write_extensions($mods, $this->cur_company);
+       }
+
        /*
                Pre-install maintenance: login to company, open upgrade log, make a backup
        */
@@ -59,7 +116,7 @@ class fa_patch {
                $this->errors = array();
                $this->backup = null;
 
-               $this->save_log = ini_set('error_log', dirname(__FILE__).'/../../tmp/upgrade.'.$this->cur_company.'.log');
+               $this->save_log = ini_set('error_log', VARLOG_PATH.'/upgrade.'.$this->cur_company.'.log');
                $this->log_error(sprintf(_("Upgrade started for company %s."), $this->cur_company), 'Info');
 
                if (!set_global_connection($this->cur_company))
@@ -70,6 +127,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;
 
@@ -137,7 +196,7 @@ class fa_patch {
                                if ($result)
                                        $this->log_error(_("Upgrade failed. Original database content restored successfully."), 'Info');
                                else
-                                       $thi->log_error(sprintf(_("Database restore operation failed. Original database content is in %s file."), $this->backup));
+                                       $this->log_error(sprintf(_("Database restore operation failed. Original database content is in %s file."), $this->backup));
                                $this->post_fail($this->cur_company);
                        }
                } else {
@@ -207,6 +266,8 @@ class fa_patch {
 */
 function get_site_status($connections)
 {
+               global $SysPrefs;
+
                $info = array();
 
                foreach($connections as $i => $conn)
@@ -221,7 +282,7 @@ function get_site_status($connections)
                        }
                }
                set_global_connection();
-               refresh_sys_prefs();
+               $SysPrefs->refresh();
 
                return $info;
 }