Improved error handling.
[fa-stable.git] / sql / alter2.3.php
index 053fa02568d01d96d2a09ce7c560b594a613211b..bdeab5c67c88f6374160729bbe82c2818b9a1692 100644 (file)
@@ -18,7 +18,6 @@ class fa2_3 {
        
        function fa2_3() {
                $this->description = _('Upgrade from version 2.2 to 2.3');
-               $this->preconf = $this->fix_extensions();
        }
        
        //
@@ -27,7 +26,7 @@ class fa2_3 {
        //
        function install($pref, $force) 
        {
-               global $core_version;
+               global $db_version, $dflt_lang;
 
                if (!$this->preconf)
                        return false;
@@ -92,13 +91,15 @@ class fa2_3 {
                        if (!db_query($sql))
                                return false;
                }
-               return  update_company_prefs(array('version_id'=>$core_version), $pref);
+               $this->update_lang_cfg();
+               return  update_company_prefs(array('version_id'=>$db_version), $pref);
        }
        //
        //      Checking before install
        //
        function pre_check($pref, $force)
        {
+
                if ($this->beta && !$force)
                        $this->sql = 'alter2.3rc.sql';
 
@@ -109,6 +110,7 @@ class fa2_3 {
        //
        function installed($pref) {
                $this->beta = !check_table($pref, 'suppliers', 'tax_included');
+               $this->preconf = $this->fix_extensions();
 
                $n = 1; // number of patches to be installed
                $patchcnt = 0;
@@ -136,14 +138,15 @@ class fa2_3 {
                include_once("$path_to_root/sales/includes/cart_class.inc");
                include_once("$path_to_root/purchasing/includes/po_class.inc");
                $cart = new cart(ST_SALESORDER);
-               $sql = "SELECT order_no FROM {$pref}sales_orders";
+               $sql = "SELECT order_no, trans_type FROM {$pref}sales_orders";
                $orders = db_query($sql);
                if (!$orders)
                        return false;
-
-               while ($order_no = db_fetch($orders)) {
-                       read_sales_order($order_no[0], $cart, ST_SALESORDER);
-                       $result = db_query("UPDATE {$pref}sales_orders SET total=".$cart->get_trans_total());
+               while ($order = db_fetch($orders)) {
+                       read_sales_order($order['order_no'], $cart, $order['trans_type']);
+                       $result = db_query("UPDATE {$pref}sales_orders 
+                               SET total=".$cart->get_trans_total()
+                               ." WHERE order_no=".$order[0]);
                        unset($cart->line_items);
                }
                unset($cart);
@@ -269,25 +272,29 @@ class fa2_3 {
                $lang_chd = false;
                foreach($installed_languages as $i => $lang) {
                        if (!isset($lang['path'])) {
+                               $code = $lang['code'];
                                $installed_languages[$i]['path'] = 'lang/'.$code;
-                               $installed_languages[$i]['package'] = 'lang/'.$code;
+                               $installed_languages[$i]['package'] = $code;
                                $lang_chd = true;
                        }
                }
                if ($lang_chd)
                        write_lang();
 
-               $installed_extensions= get_company_extensions();
                
+               $installed_extensions= get_company_extensions();
                if (!isset($next_extension_id))
                        $next_extension_id = 1;
                $new_exts = array();
                
+/*     Old extension modules are uninstalled - they need manual porting after 
+       heavy changes in extension system in FA2.3
+       
                foreach($installed_extensions as $i => $ext)
                {
                        if (isset($ext['title'])) // old type entry
                        {
-                               if ($ext['type'] == 'module')
+                               if ($ext['type'] == 'module') {
                                        $new['type'] = 'extension';
                                        $new['tabs'][] = array(
                                                'url' => $ext['filename'],
@@ -311,14 +318,15 @@ class fa2_3 {
                                }
                                if (isset($ext['acc_file']))
                                        $new['acc_file'] = $ext['acc_file'];
-                               $new['name'] = $ext['name']; // albo access_string(title)
+                               $new['name'] = $ext['name'];
                                $new['package'] = $new['package'] = '';
                                $new['active'] = 1;
 
                                $new_exts[$i] = $new;
                        }
                }
-               // Add non-standard themes
+*/             
+               // Preserve non-standard themes
                $path = $path_to_root.'/themes/';
                $themes = array();
                $themedir = opendir($path);
@@ -346,6 +354,22 @@ class fa2_3 {
                } else
                        return true;
        }
+       
+       function update_lang_cfg()
+       {
+               global $dflt_lang, $installed_languages;
+
+               foreach($installed_languages as $n => $lang) {
+                       if ($lang['code'] == 'en_GB') {
+                               $installed_languages[$n] = array('code'=>'C','name'=>'English',
+                                       'encoding'=>'iso-8859-1', 'path' => '', 'package' => '');
+                               if ($dflt_lang == 'en_GB')
+                                       $dflt_lang = 'C';
+                               write_lang();
+                       }
+               }
+       }
+
 }
 
 $install = new fa2_3;