Bug 4817: g/l account inquiry can timeout due to slow sql. @Braath Waate.
[fa-stable.git] / sql / alter2.4.php
index 7fc60b38716106f89dd2fbcb08948fde3e0db8a8..bd364e2e20c604c6ffa4738d971fe60ebf8ec13c 100644 (file)
@@ -9,50 +9,17 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-function collations_list_row($label, $name, $selected_id=null)
-{
-
-$mysql_collations = array(
-  'xx' => 'Unicode (multilanguage)',
-  'is' => 'Icelandic',
-  'lv' => 'Latvian',
-  'ro' => 'Romanian',
-  'sl' => 'Slovenian',
-  'pl' => 'Polish',
-  'et' => 'Estonian',
-  'es' => 'Spanish', // or 'spanish2',
-  'sw' => 'Swedish',
-  'tr' => 'Turkish',
-  'cs' => 'Czech',
-  'da' => 'Danish',
-  'lt' => 'Lithuanian',
-  'sk' => 'Slovak',
-  'sp' => 'Spanish (alternative)',
-  'fa' => 'Persian',
-  'hu' => 'Hungarian',
-  'fr' => 'French',
-  'it' => 'Italian',
-);
-
-       echo "<tr>";
-       if ($label != null)
-               echo "<td class='label'>$label</td>\n";
-       echo "<td>";
-
-       echo array_selector($name, $selected_id, $mysql_collations, 
-               array('select_submit'=> false) );
-       echo "</td></tr>\n";
-}
 
 class fa2_4 extends fa_patch {
        var $previous = '2.3rc';                // applicable database version
-       var $version = '2.4.0'; // version installed
+       var $version = '2.4.1'; // version installed
        var $description;
        var $sql = 'alter2.4.sql';
        var $preconf = true;
+       var     $max_upgrade_time = 900;        // table recoding is really long process
        
-       function fa2_4() {
-               parent::fa_patch();
+       function __construct() {
+               parent::__construct();
                $this->description = _('Upgrade from version 2.3 to 2.4');
        }
        
@@ -75,7 +42,7 @@ class fa2_4 extends fa_patch {
     */
        function prepare()
     {
-               $this->collation = get_mysql_collation(get_post('collation'));
+               $this->collation = get_post('collation');
                return true;
        }
 
@@ -104,11 +71,40 @@ class fa2_4 extends fa_patch {
                if (get_company_pref('suppress_tax_rates') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
                        set_company_pref('suppress_tax_rates', 'setup.company', 'tinyint', 1, '0');
                }
+               if (get_company_pref('company_logo_report') === null) { // available from 2.4.2, during updates
+                       set_company_pref('company_logo_report', 'setup.company', 'tinyint', 1, '0');
+               }
+               if (get_company_pref('print_dialog_direct') === null) { // available from 2.4.5, during updates
+                       set_company_pref('print_dialog_direct', 'setup.company', 'tinyint', 1, '0');
+               }
+               if (get_company_pref('barcodes_on_stock') === null) { // available from 2.4.3, during updates
+                       set_company_pref('barcodes_on_stock', 'setup.company', 'tinyint', 1, '0');
+               }
+               if (get_company_pref('ref_no_auto_increase') === null) { // available from 2.4.4, during updates
+                       set_company_pref('ref_no_auto_increase', 'setup.company', 'tinyint', 1, '0');
+               }
+               if (get_company_pref('shortname_name_in_list') === null) { // available from 2.4.2, during updates
+                       set_company_pref('shortname_name_in_list', 'setup.company', 'tinyint', 1, '0');
+               }
 
                $result = $this->update_workorders()  && $this->update_grn_rates() && $this->switch_database_to_utf($pref);
 
                if ($result)
                        $result = $this->do_cleanup();
+               if ($result)
+               {
+                       $db_connections[$company]['collation'] = $this->collation;
+                       if (write_config_db())
+                               return $this->log_error(_("Cannot update config_db.php file."));
+               }
+
+               $sec_updates = array(
+                       'SA_SETUPCOMPANY' => array(
+                               'SA_ASSET', 'SA_ASSETCATEGORY', 'SA_ASSETCLASS',
+                               'SA_ASSETSTRANSVIEW','SA_ASSETTRANSFER', 'SA_ASSETDISPOSAL',
+                               'SA_DEPRECIATION', 'SA_ASSETSANALYTIC'),
+               );
+               $result = $this->update_security_roles($sec_updates);
 
                return $result;
        }
@@ -120,6 +116,15 @@ class fa2_4 extends fa_patch {
        {
                $pref = $this->companies[$company]['tbpref'];
                db_query("DROP TABLE IF EXISTS " . $pref . 'wo_costing');
+               db_query("DROP TABLE IF EXISTS " . $pref . 'stock_fa_class');
+               db_query("DELETE FROM ".$pref."sys_prefs
+                       WHERE `name` in (
+                               'gl_closing_date', 'deferred_income_act', 'no_zero_lines_amount', 'accounts_alpha',
+                               'tax_algorithm', 'grn_clearing_act', 'default_receival_required',
+                               'default_quote_valid_days',     'no_zero_lines_amount', 'show_po_item_codes', 'accounts_alpha',
+                               'loc_notification', 'print_invoice_no', 'allow_negative_prices', 'print_item_images_on_quote',
+                               'bcc_email', 'alternative_tax_include_on_docs', 'suppress_tax_rates', 'company_logo_report',
+                               'barcodes_on_stock', print_dialog_direct', 'ref_no_auto_increase')");
        }
 
        function update_workorders()
@@ -127,7 +132,7 @@ class fa2_4 extends fa_patch {
                global $db;
 
                $sql = "SELECT DISTINCT type, type_no, tran_date, person_id FROM ".TB_PREF."gl_trans WHERE `type`=".ST_WORKORDER
-               ." AND person_type_id=1";
+                       ." AND person_type_id=1";
                $res = db_query($sql);
                if (!$res)
                        return $this->log_error(sprintf(_("Cannot update work orders costs:\n%s"), db_error_msg($db)));
@@ -168,12 +173,15 @@ class fa2_4 extends fa_patch {
 
                $old_encoding = 'latin1'; // default client encoding
 
+               // uncomment in case of 1071 errors (requires SUPER privileges)
+               // db_query("SET @@global.innodb_large_prefix=1", "Cannot set large prefix");
+
                 // site default encoding is presumed as encoding for all databases!
                $lang = array_search_value($dflt_lang, $installed_languages, 'code');
                $new_encoding = get_mysql_encoding_name(strtoupper($lang['encoding']));
 
                $this->log_error(sprintf('Switching database to utf8 encoding from %s', $old_encoding), 'Info');
-               $collation = $this->collation;
+               $collation = get_mysql_collation($this->collation);
                $tsql = "SHOW TABLES LIKE '".($pref=='' ? '' : substr($pref, 0, -1).'\\_')."%'";
                $tresult = db_query($tsql, "Cannot select all tables with prefix '$pref'");
                while($tbl = db_fetch($tresult)) {
@@ -249,9 +257,11 @@ class fa2_4 extends fa_patch {
                //remove obsolete and temporary columns.
                // this have to be done here as db_import rearranges alter query order
                $dropcol = array(
+                               'tax_groups' => array('tax_shipping'),
                                'tax_group_items' => array('rate'),
                                'budget_trans' => array('type', 'type_no', 'person_id', 'person_type_id', 'memo_'),
                                'cust_branch' => array('contact_name', 'disable_trans'),
+                               'stock_moves' => array('discount_percent', 'visible', 'person_id'),
                );
 
                foreach($dropcol as $table => $columns)