Fixed upgrade routines from 2.1.x versions.
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Fri, 1 Apr 2011 11:36:45 +0000 (13:36 +0200)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Fri, 1 Apr 2011 11:36:45 +0000 (13:36 +0200)
admin/db/company_db.inc
sql/alter2.2.php

index 64f44bc3f3992873966cbf4f9235127cc5e1f340..c1197dcce8bb05cd5753114aaf5196b0468c6533 100644 (file)
@@ -37,7 +37,7 @@ function get_company_pref($prefs = null, $tbpref = null)
        static $cached; // retrieve values from db once a request. Some values can't be cached between requests
                                        // to ensure prefs integrity for all usrs (e.g. gl_close_date).
        
-       if (!$cached) { // cached preferences
+       if (!$cached || !isset($_SESSION['SysPrefs'])) { // cached preferences
 
                $_SESSION['SysPrefs'] = new sys_prefs();
 
index c5345233f9dad968a351735b71f50b2df0a31924..fcf9f60f34a55da9508ca6a7522844b2fc6294af 100644 (file)
@@ -118,9 +118,13 @@ class fa2_2 {
                $patchcnt = 0;
                if (!$this->beta) {
                        $n = 16;
-                       if (check_table($pref, 'company', 'custom1_name')) $patchcnt++;
-                       if (!check_table($pref, 'company', 'profit_loss_year_act')) $patchcnt++;
-                       if (!check_table($pref, 'company', 'login_tout')) $patchcnt++;
+                       if (check_table($pref, 'company')) // skip in 2.3
+                               $n -= 3;
+                       else {
+                               if (check_table($pref, 'company', 'custom1_name')) $patchcnt++;
+                               if (!check_table($pref, 'company', 'profit_loss_year_act'))     $patchcnt++;
+                               if (!check_table($pref, 'company', 'login_tout')) $patchcnt++;
+                       }
                        if (!check_table($pref, 'stock_category', 'dflt_no_sale')) $patchcnt++;
                        if (!check_table($pref, 'users', 'sticky_doc_date')) $patchcnt++;
                        if (!check_table($pref, 'users', 'startup_tab')) $patchcnt++;
@@ -303,6 +307,9 @@ function sanitize_database($pref, $test = false) {
                        }
                }
 
+               if (empty($keys)) { // comments table have no primary key, so let's give up
+                       continue;
+               }
                if ($test)
                        error_log("Table $table (".implode(',',$keys)."):(".implode(',',$textcols)."):");
 
@@ -326,9 +333,10 @@ function sanitize_database($pref, $test = false) {
                                $key[] = $k.'=\''.$rec[substr($k,1,-1)].'\'';
                        }
                        $sql .= implode( ' AND ', $key);
-                       if ($test)
+                       if ($test) {
+                               error_log($sql);
                                error_log("\t(".implode(',',$val).") updated");
-                       else
+                       else
                                db_query($sql, 'cannot update record');
                }
        }