X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sql%2Falter2.3.php;h=2667d15cb925d66d58a4f311fe5eeae4c2917cb1;hb=25379bdc9f10bda4aae4b37f04d16eb1bbe7e4f6;hp=fe455bfb4874a165fd9a4fa0c831528dd7208ba7;hpb=b9185a0190595e671a9750eb4e9f8e0bd6c713f9;p=fa-stable.git diff --git a/sql/alter2.3.php b/sql/alter2.3.php index fe455bfb..2667d15c 100644 --- a/sql/alter2.3.php +++ b/sql/alter2.3.php @@ -9,14 +9,15 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -class fa2_3 { - var $version = '2.3'; // version installed +class fa2_3 extends fa_patch { + var $previous = '2.2rc'; // applicable database version + var $version = '2.3rc'; // version installed var $description; var $sql = 'alter2.3.sql'; var $preconf = true; var $beta = false; // upgrade from 2.2 or 2.3beta; - function fa2_3() { + function __construct() { $this->description = _('Upgrade from version 2.2 to 2.3'); } @@ -24,15 +25,19 @@ class fa2_3 { // Install procedure. All additional changes // not included in sql file should go here. // - function install($pref, $force) + function install($company, $force=false) { - global $core_version; + global $db_version, $dflt_lang; + + $this->preconf = $this->fix_extensions(); + if (!$this->preconf) + return false; if (!$this->beta) { // all specials below are already done on 2.3beta - $sql = "SELECT debtor_no, payment_terms FROM {$pref}debtors_master"; - + $sql = "SELECT debtor_no, payment_terms FROM ".TB_PREF."debtors_master"; + $result = db_query($sql); if (!$result) { display_error("Cannot read customers" @@ -41,7 +46,7 @@ class fa2_3 { } // update all sales orders and transactions with customer std payment terms while($cust = db_fetch($result)) { - $sql = "UPDATE {$pref}debtor_trans SET " + $sql = "UPDATE ".TB_PREF."debtor_trans SET " ."payment_terms = '" .$cust['payment_terms'] ."' WHERE debtor_no='".$cust['debtor_no']."'"; if (db_query($sql)==false) { @@ -49,7 +54,7 @@ class fa2_3 { .':
'. db_error_msg($db)); return false; } - $sql = "UPDATE {$pref}sales_orders SET " + $sql = "UPDATE ".TB_PREF."sales_orders SET " ."payment_terms = '" .$cust['payment_terms'] ."' WHERE debtor_no='".$cust['debtor_no']."'"; if (db_query($sql)==false) { @@ -58,11 +63,11 @@ class fa2_3 { return false; } } - if (!$this->update_totals($pref)) { + if (!$this->update_totals()) { display_error("Cannot update order totals"); return false; } - if (!$this->update_line_relations($pref)) { + if (!$this->update_line_relations()) { display_error("Cannot update sales document links"); return false; } @@ -78,79 +83,65 @@ class fa2_3 { foreach($dropcol as $table => $columns) foreach($columns as $col) { - if (db_query("ALTER TABLE `{$pref}{$table}` DROP `$col`")==false) { + if (db_query("ALTER TABLE `".TB_PREF."{$table}` DROP `$col`")==false) { display_error("Cannot drop {$table}.{$col} column:
".db_error_msg($db)); return false; } } // remove old preferences table after upgrade script has been executed - $sql = "DROP TABLE IF EXISTS `{$pref}company`"; + $sql = "DROP TABLE IF EXISTS `".TB_PREF."company`"; 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)); } // // Checking before install // - function pre_check($pref, $force) + function prepare() { - if ($this->beta && !$force) + + if ($this->beta) $this->sql = 'alter2.3rc.sql'; return true; } - // - // Test if patch was applied before. - // - function installed($pref) { - $this->beta = !check_table($pref, 'suppliers', 'tax_included'); - - $n = 1; // number of patches to be installed - $patchcnt = 0; - if (!$this->beta) { - $n += 3; - if (!check_table($pref, 'comments', 'type', array('Key'=>'MUL'))) $patchcnt++; - if (!check_table($pref, 'sys_prefs')) $patchcnt++; - if (!check_table($pref, 'sales_orders', 'payment_terms')) $patchcnt++; - } - if (!check_table($pref, 'purch_orders', 'tax_included')) $patchcnt++; - return $n == $patchcnt ? true : ($patchcnt ? ($patchcnt.'/'. $n) : 0); - } //========================================================================================= // 2.3 specific update functions // - + /* Update order totals */ - function update_totals($pref) + function update_totals() { global $path_to_root; 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 ".TB_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 ".TB_PREF."sales_orders + SET total=".$cart->get_trans_total() + ." WHERE order_no=".$order[0]); unset($cart->line_items); } unset($cart); $cart = new purch_order(); - $sql = "SELECT order_no FROM {$pref}purch_orders"; + $sql = "SELECT order_no FROM ".TB_PREF."purch_orders"; $orders = db_query($sql); if (!$orders) return false; while ($order_no = db_fetch($orders)) { read_po($order_no[0], $cart); - $result = db_query("UPDATE {$pref}purch_orders SET total=".$cart->get_trans_total()); + $result = db_query("UPDATE ".TB_PREF."purch_orders SET total=".$cart->get_trans_total()); unset($cart->line_items); } return true; @@ -193,14 +184,14 @@ class fa2_3 { there can be sales documents with lines not properly linked to parents. This rare cases will be described in error log. */ - function update_line_relations($pref) + function update_line_relations() { global $path_to_root, $systypes_array; require_once("$path_to_root/includes/sysnames.inc"); - $sql = "SELECT d.type, trans_no, order_ FROM {$pref}debtor_trans d - LEFT JOIN {$pref}voided v ON d.type=v.type AND d.trans_no=v.id + $sql = "SELECT d.type, trans_no, order_ FROM ".TB_PREF."debtor_trans d + LEFT JOIN ".TB_PREF."voided v ON d.type=v.type AND d.trans_no=v.id WHERE ISNULL(v.type) AND (d.type=".ST_CUSTDELIVERY ." OR d.type=".ST_SALESINVOICE @@ -244,7 +235,7 @@ class fa2_3 { if ($src_line['stock_id'] == $doc_line['stock_id'] && ($src_line['quantity'] >= $doc_line['quantity'])) { - $sql = "UPDATE {$pref}debtor_trans_details SET src_id = {$src_line['id']} + $sql = "UPDATE ".TB_PREF."debtor_trans_details SET src_id = {$src_line['id']} WHERE id = {$doc_line['id']}"; if (!db_query($sql)) return false; @@ -257,8 +248,112 @@ class fa2_3 { } return true; } + + function fix_extensions() + { + global $path_to_root, $next_extension_id, $installed_languages; + + $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'] = $code; + $lang_chd = true; + } + } + if ($lang_chd) + write_lang(); + + $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') { + $new['type'] = 'extension'; + $new['tabs'][] = array( + 'url' => $ext['filename'], + 'access' => isset($ext['access']) ? $ext['access'] : 'SA_OPEN', + 'tab_id' => $ext['tab'], + 'title' => $ext['title'] + ); + $new['path'] = $ext['path']; + } + else // plugin + { + $new['type'] = 'extension'; + $new['tabs'] = array(); + $new['path'] = 'modules/'.$ext['path']; + $new['entries'][] = array( + 'url' => $ext['filename'], + 'access' => isset($ext['access']) ? $ext['access'] : 'SA_OPEN', + 'tab_id' => $ext['tab'], + 'title' => $ext['title'] + ); + } + if (isset($ext['acc_file'])) + $new['acc_file'] = $ext['acc_file']; + $new['name'] = $ext['name']; + $new['package'] = $new['package'] = ''; + $new['active'] = 1; + + $new_exts[$i] = $new; + } + } +*/ + // Preserve non-standard themes + $path = $path_to_root.'/themes/'; + $themes = array(); + $themedir = opendir($path); + while (false !== ($fname = readdir($themedir))) + { + if ($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname) + && !in_array($fname, array('aqua', 'cool', 'default'))) + { + foreach($installed_extensions as $ext) + if ($ext['path'] == 'themes/'.$fname) // skip if theme is already listed + continue 2; + $new_exts[$next_extension_id++] = array( + 'name' => 'Theme '. ucwords($fname), + 'package' => $fname, + 'type' => 'theme', + 'active' => true, + 'path' => 'themes/'.$fname + ); + } + } + closedir($themedir); + + if (count($new_exts)) { + return update_extensions($new_exts); + } 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; -?> \ No newline at end of file