DBRev Bug 15084 - Move the currency related code to
authorBrendan A Gallagher <brendan@bywatersolutions.com>
Thu, 3 Mar 2016 21:15:14 +0000 (21:15 +0000)
committerBrendan A Gallagher <brendan@bywatersolutions.com>
Thu, 3 Mar 2016 21:15:14 +0000 (21:15 +0000)
Koha::Acquisition::Currenc[y|ies]

Koha.pm
installer/data/mysql/atomicupdate/bug_15084-add_fk_for_currency.sql [deleted file]
installer/data/mysql/updatedatabase.pl

diff --git a/Koha.pm b/Koha.pm
index 97856b8..9dcb9a0 100644 (file)
--- a/Koha.pm
+++ b/Koha.pm
@@ -29,7 +29,7 @@ use vars qw{ $VERSION };
 # - #4 : the developer version. The 4th number is the database subversion.
 #        used by developers when the database changes. updatedatabase take care of the changes itself
 #        and is automatically called by Auth.pm when needed.
-$VERSION = "3.23.00.036";
+$VERSION = "3.23.00.037";
 
 sub version {
     return $VERSION;
diff --git a/installer/data/mysql/atomicupdate/bug_15084-add_fk_for_currency.sql b/installer/data/mysql/atomicupdate/bug_15084-add_fk_for_currency.sql
deleted file mode 100644 (file)
index d3e00c1..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
--- Add the new currency.archived column
-alter table currency add column archived tinyint(1) default 0;
--- Set currency=NULL if empty (just in case)
-update aqorders set currency=NULL where currency="";
--- Insert the missing currency and mark them as archived before adding the FK
-insert into currency(currency, archived) select distinct currency, 1 from aqorders where currency not in (select currency from currency);
--- And finally add the FK
-alter table aqorders add foreign key (currency) references currency(currency) on delete set null on update set null;
index 76e5791..f8b5b32 100755 (executable)
@@ -11973,6 +11973,29 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     SetVersion($DBversion);
     }
 
+$DBversion = "3.23.00.037";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+## Add the new currency.archived column
+    $dbh->do(q{
+    ALTER TABLE currency ADD column archived tinyint(1) DEFAULT 0;
+    });
+## Set currency=NULL if empty (just in case)
+    $dbh->do(q{
+    UPDATE aqorders SET currency=NULL WHERE currency="";
+    });
+## Insert the missing currency and mark them as archived before adding the FK
+    $dbh->do(q{
+    INSERT INTO currency(currency, archived) SELECT distinct currency, 1 FROM aqorders WHERE currency NOT IN (SELECT currency FROM currency);
+    });
+## And finally add the FK
+    $dbh->do(q{
+    ALTER TABLE aqorders ADD FOREIGN KEY (currency) REFERENCES currency(currency) ON DELETE SET NULL ON UPDATE SET null;
+    });
+
+    print "Upgrade to $DBversion done (Bug 15084 - Move the currency related code to Koha::Acquisition::Currenc[y|ies])\n";
+    SetVersion($DBversion);
+    }
+
 # DEVELOPER PROCESS, search for anything to execute in the db_update directory
 # SEE bug 13068
 # if there is anything in the atomicupdate, read and execute it.