noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 43/107: fixup! Code cleaning : split database


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 43/107: fixup! Code cleaning : split database into database (for noalyss) and databasecore , with the functions
Date: Mon, 26 Aug 2019 10:31:54 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit be6d21610931be377f99d1b925a9eac2f66e8b00
Author: Dany De Bontridder <address@hidden>
Date:   Thu Jul 25 19:30:35 2019 +0200

    fixup! Code cleaning : split database into database (for noalyss) and 
databasecore , with the functions
---
 include/class/database.class.php    | 109 ++++++++++++++++++++++++++++++++++++
 include/lib/database_core.class.php | 109 ------------------------------------
 2 files changed, 109 insertions(+), 109 deletions(-)

diff --git a/include/class/database.class.php b/include/class/database.class.php
index 23f67da..eed0e60 100644
--- a/include/class/database.class.php
+++ b/include/class/database.class.php
@@ -112,5 +112,114 @@ class Database extends DatabaseCore
         return $Res;
     }
 
+    /**
+     * \brief loop to apply all the path to a folder or
+     *         a template
+     * \param $p_name database name
+     *
+     */
+
+    function apply_patch($p_name)
+    {
+        if (!$this->exist_table('version')) {
+            echo _('Base de donnée vide');
+            return;
+        }
+        $MaxVersion = DBVERSION - 1;
+        $succeed = "<span 
style=\"font-size:18px;color:green\">&#x2713;</span>";
+        echo '<ul style="list-type-style:square">';
+        for ($i = 4; $i <= $MaxVersion; $i++) {
+            $to = $i + 1;
+
+            if ($this->get_version() <= $i) {
+                if ($this->get_version() == 97) {
+                    if ($this->exist_schema("amortissement")) {
+                        $this->exec_sql('ALTER TABLE 
amortissement.amortissement_histo
+                                                       ADD CONSTRAINT 
internal_fk FOREIGN KEY (jr_internal) REFERENCES jrn (jr_internal)
+                                                       ON UPDATE CASCADE ON 
DELETE SET NULL');
+                    }
+                }
+                echo "<li>Patching " . $p_name .
+                    " from the version " . $this->get_version() . " to $to ";
+
+                $this->execute_script(NOALYSS_INCLUDE . '/sql/patch/upgrade' . 
$i . '.sql');
+                echo $succeed;
+
+                if (!DEBUG)
+                    ob_start();
+                // specific for version 4
+                if ($i == 4) {
+                    $sql = "select jrn_def_id from jrn_def ";
+                    $Res = $this->exec_sql($sql);
+                    $Max = $this->size();
+                    for ($seq = 0; $seq < $Max; $seq++) {
+                        $row = pg_fetch_array($Res, $seq);
+                        $sql = sprintf("create sequence s_jrn_%d", 
$row['jrn_def_id']);
+                        $this->exec_sql($sql);
+                    }
+                }
+                // specific to version 7
+                if ($i == 7) {
+                    // now we use sequence instead of computing a max
+                    //
+                    $Res2 = $this->exec_sql('select 
coalesce(max(jr_grpt_id),1) as l from jrn');
+                    $Max2 = pg_NumRows($Res2);
+                    if ($Max2 == 1) {
+                        $Row = pg_fetch_array($Res2, 0);
+                        var_dump($Row);
+                        $M = $Row['l'];
+                        $this->exec_sql("select setval('s_grpt',$M,true)");
+                    }
+                }
+                // specific to version 17
+                if ($i == 17) {
+                    $this->execute_script(NOALYSS_INCLUDE . 
'/sql/patch/upgrade17.sql');
+                    $max = $this->get_value('select last_value from 
s_jnt_fic_att_value');
+                    $this->alter_seq($p_cn, 's_jnt_fic_att_value', $max + 1);
+                } // version
+                // reset sequence in the modele
+                //--
+                if ($i == 30 && $p_name == "mod") {
+                    $a_seq = array('s_jrn', 's_jrn_op', 's_centralized',
+                        's_stock_goods', 'c_order', 's_central');
+                    foreach ($a_seq as $seq) {
+                        $sql = sprintf("select setval('%s',1,false)", $seq);
+                        $Res = $this->exec_sql($sql);
+                    }
+                    $sql = "select jrn_def_id from jrn_def ";
+                    $Res = $this->exec_sql($sql);
+                    $Max = pg_NumRows($Res);
+                    for ($seq = 0; $seq < $Max; $seq++) {
+                        $row = pg_fetch_array($Res, $seq);
+                        $sql = sprintf("select setval('s_jrn_%d',1,false)", 
$row['jrn_def_id']);
+                        $this->exec_sql($sql);
+                    }
+                }
+                if ($i == 36) {
+                    /* check the country and apply the path */
+                    $res = $this->exec_sql("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
+                    $country = pg_fetch_result($res, 0, 0);
+                    $this->execute_script(NOALYSS_INCLUDE . 
"/sql/patch/upgrade36." . $country . ".sql");
+                    $this->exec_sql('update tmp_pcmn set 
pcm_type=find_pcm_type(pcm_val)');
+                }
+                if ($i == 59) {
+                    $res = $this->exec_sql("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
+                    $country = pg_fetch_result($res, 0, 0);
+                    if ($country == 'BE')
+                        $this->exec_sql("insert into parm_code values 
('SUPPLIER',440,'Poste par défaut pour les fournisseurs')");
+                    if ($country == 'FR')
+                        $this->exec_sql("insert into parm_code values 
('SUPPLIER',400,'Poste par défaut pour les fournisseurs')");
+                }
+                if ($i == 61) {
+                    $country = $this->get_value("select pr_value from 
parameter where pr_id='MY_COUNTRY'");
+                    $this->execute_script(NOALYSS_INCLUDE . 
"/sql/patch/upgrade61." . $country . ".sql");
+                }
+
+                if (!DEBUG)
+                    ob_end_clean();
+            }
+        }
+        echo '</ul>';
+    }
 
 }
\ No newline at end of file
diff --git a/include/lib/database_core.class.php 
b/include/lib/database_core.class.php
index a38725d..2b3bd9e 100644
--- a/include/lib/database_core.class.php
+++ b/include/lib/database_core.class.php
@@ -390,115 +390,6 @@ class DatabaseCore
         return $this->size($p_ret);
     }
 
-    /**
-     * \brief loop to apply all the path to a folder or
-     *         a template
-     * \param $p_name database name
-     *
-     */
-
-    function apply_patch($p_name)
-    {
-        if (!$this->exist_table('version')) {
-            echo _('Base de donnée vide');
-            return;
-        }
-        $MaxVersion = DBVERSION - 1;
-        $succeed = "<span 
style=\"font-size:18px;color:green\">&#x2713;</span>";
-        echo '<ul style="list-type-style:square">';
-        for ($i = 4; $i <= $MaxVersion; $i++) {
-            $to = $i + 1;
-
-            if ($this->get_version() <= $i) {
-                if ($this->get_version() == 97) {
-                    if ($this->exist_schema("amortissement")) {
-                        $this->exec_sql('ALTER TABLE 
amortissement.amortissement_histo
-                                                       ADD CONSTRAINT 
internal_fk FOREIGN KEY (jr_internal) REFERENCES jrn (jr_internal)
-                                                       ON UPDATE CASCADE ON 
DELETE SET NULL');
-                    }
-                }
-                echo "<li>Patching " . $p_name .
-                    " from the version " . $this->get_version() . " to $to ";
-
-                $this->execute_script(NOALYSS_INCLUDE . '/sql/patch/upgrade' . 
$i . '.sql');
-                echo $succeed;
-
-                if (!DEBUG)
-                    ob_start();
-                // specific for version 4
-                if ($i == 4) {
-                    $sql = "select jrn_def_id from jrn_def ";
-                    $Res = $this->exec_sql($sql);
-                    $Max = $this->size();
-                    for ($seq = 0; $seq < $Max; $seq++) {
-                        $row = pg_fetch_array($Res, $seq);
-                        $sql = sprintf("create sequence s_jrn_%d", 
$row['jrn_def_id']);
-                        $this->exec_sql($sql);
-                    }
-                }
-                // specific to version 7
-                if ($i == 7) {
-                    // now we use sequence instead of computing a max
-                    //
-                    $Res2 = $this->exec_sql('select 
coalesce(max(jr_grpt_id),1) as l from jrn');
-                    $Max2 = pg_NumRows($Res2);
-                    if ($Max2 == 1) {
-                        $Row = pg_fetch_array($Res2, 0);
-                        var_dump($Row);
-                        $M = $Row['l'];
-                        $this->exec_sql("select setval('s_grpt',$M,true)");
-                    }
-                }
-                // specific to version 17
-                if ($i == 17) {
-                    $this->execute_script(NOALYSS_INCLUDE . 
'/sql/patch/upgrade17.sql');
-                    $max = $this->get_value('select last_value from 
s_jnt_fic_att_value');
-                    $this->alter_seq($p_cn, 's_jnt_fic_att_value', $max + 1);
-                } // version
-                // reset sequence in the modele
-                //--
-                if ($i == 30 && $p_name == "mod") {
-                    $a_seq = array('s_jrn', 's_jrn_op', 's_centralized',
-                        's_stock_goods', 'c_order', 's_central');
-                    foreach ($a_seq as $seq) {
-                        $sql = sprintf("select setval('%s',1,false)", $seq);
-                        $Res = $this->exec_sql($sql);
-                    }
-                    $sql = "select jrn_def_id from jrn_def ";
-                    $Res = $this->exec_sql($sql);
-                    $Max = pg_NumRows($Res);
-                    for ($seq = 0; $seq < $Max; $seq++) {
-                        $row = pg_fetch_array($Res, $seq);
-                        $sql = sprintf("select setval('s_jrn_%d',1,false)", 
$row['jrn_def_id']);
-                        $this->exec_sql($sql);
-                    }
-                }
-                if ($i == 36) {
-                    /* check the country and apply the path */
-                    $res = $this->exec_sql("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
-                    $country = pg_fetch_result($res, 0, 0);
-                    $this->execute_script(NOALYSS_INCLUDE . 
"/sql/patch/upgrade36." . $country . ".sql");
-                    $this->exec_sql('update tmp_pcmn set 
pcm_type=find_pcm_type(pcm_val)');
-                }
-                if ($i == 59) {
-                    $res = $this->exec_sql("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
-                    $country = pg_fetch_result($res, 0, 0);
-                    if ($country == 'BE')
-                        $this->exec_sql("insert into parm_code values 
('SUPPLIER',440,'Poste par défaut pour les fournisseurs')");
-                    if ($country == 'FR')
-                        $this->exec_sql("insert into parm_code values 
('SUPPLIER',400,'Poste par défaut pour les fournisseurs')");
-                }
-                if ($i == 61) {
-                    $country = $this->get_value("select pr_value from 
parameter where pr_id='MY_COUNTRY'");
-                    $this->execute_script(NOALYSS_INCLUDE . 
"/sql/patch/upgrade61." . $country . ".sql");
-                }
-
-                if (!DEBUG)
-                    ob_end_clean();
-            }
-        }
-        echo '</ul>';
-    }
 
     /**
      *



reply via email to

[Prev in Thread] Current Thread [Next in Thread]