Fixes in upgrade procedures.
[fa-stable.git] / sql / alter2.4rc1.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12
13 class fa2_4rc1 extends fa_patch {
14         var $previous = '2.4.0';                // applicable database version
15         var $version = '2.4.1'; // version installed
16         var $description;
17         var $sql = ''; // 'alter2.4rc1.sql';
18         var $preconf = true;
19
20         function fa2_4rc1() {
21                 parent::fa_patch();
22                 $this->description = _('Upgrade from version 2.4beta to 2.4RC1');
23         }
24
25     /*
26             Shows parameters to be selected before upgrade (if any)
27         */
28     function show_params($comp)
29         {
30           display_note(_('Set optimal parameters and start upgrade:'));
31           start_table(TABLESTYLE);
32           start_row();
33                 table_section_title(_("Fixed Assets Defaults"));
34                 gl_all_accounts_list_row(_("Loss On Asset Disposal Account:"), 'default_loss_on_asset_disposal_act', '5660',
35                         true, false, _("None (will be set later)"));
36
37                 table_section_title(_("Manufacturing"));
38                 gl_all_accounts_list_row(_("Work In Progress Account:"), 'wip_act', '1530',
39                         true, false, _("None (will be set later)"));
40           end_row();
41           end_table();
42           br();
43     }
44
45         /*
46             Fetches selected upgrade parameters.
47     */
48         function prepare()
49     {
50                 $this->wip_account = get_post('wip_act');
51                 $this->fixed_disposal_act = get_post('default_loss_on_asset_disposal_act');
52                 return true;
53         }
54         //
55         //      Install procedure. All additional changes 
56         //      not included in sql file should go here.
57         //
58         function install($company, $force=false)
59         {
60                 // key 
61                 $sec_updates = array(
62                         'SA_SETUPCOMPANY' => array(
63                                 'SA_ASSET', 'SA_ASSETCATEGORY', 'SA_ASSETCLASS',
64                                 'SA_ASSETSTRANSVIEW','SA_ASSETTRANSFER', 'SA_ASSETDISPOSAL',
65                                 'SA_DEPRECIATION', 'SA_ASSETSANALYTIC'),
66                 );
67                 $result = $this->update_security_roles($sec_updates);
68
69                 $pref = $this->companies[$company]['tbpref'];
70
71                 if ($result)
72                         if (!db_query("UPDATE ".$pref."sys_prefs SET value=".db_escape($this->wip_act)
73                                         ." WHERE name='wip_act'")
74                                 || !db_query("UPDATE ".$pref."sys_prefs SET value=".db_escape($this->fixed_disposal_act)
75                                         ." WHERE name='default_loss_on_asset_disposal_act'")
76                         )
77                                 return $this->log_error(sprintf(_("Cannot update sys prefs setting:\n%s"), db_error_msg($db)));
78
79                 return $result;
80         }
81
82         //
83         // optional procedure done after upgrade fail, before backup is restored
84         //
85         function post_fail($company)
86         {
87                 $pref = $this->companies[$company]['tbpref'];
88                 db_query("DROP TABLE IF EXISTS " . $pref . 'stock_fa_class');
89
90                 db_query("DELETE FROM ".$pref."sys_prefs "
91                         ."WHERE `name` in (
92                                 'default_loss_on_asset_disposal_act',
93                                 'depreciation_period',
94                                 'use_manufacturing',
95                                 'use_fixed_assets',
96                                 'wip_act')");
97         }
98
99 }
100
101 $install = new fa2_4rc1;