creating update database for 3.0.1
authorHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 24 Nov 2008 16:44:58 +0000 (17:44 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 24 Nov 2008 17:12:00 +0000 (18:12 +0100)
- adds 2 new sys prefs AllowRenewalOverride and MergeAuthoritiesOnupdate AllowRenewallOverride
MergeAuthoritiesOnUpdate
- set null issues.issuedate to lastreneweddate
- Adding some changes in Database for bugfixes only UNIMARC

Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
installer/data/mysql/en/mandatory/sysprefs.sql
installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
installer/data/mysql/updatedatabase.pl
installer/data/mysql/updatedatabase30.pl [new file with mode: 0644]
kohaversion.pl

index baa05ab..15b07aa 100644 (file)
@@ -210,4 +210,5 @@ INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES
 INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OpacSuppression', '0', '', 'Turn ON the OPAC Suppression feature, requires further setup, ask your system administrator for details', 'YesNo');
 -- FIXME: add FrameworksLoaded, noOPACUserLogin, ReadingHistory ?
 INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free');
-
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowRenewalLimitOverride', '0', 'if ON, allows renewal limits to be overridden on the circulation screen',NULL,'YesNo');
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('MergeAuthoritiesOnUpdate', '1', 'if ON, Updateing authorities will automatically updates biblios',NULL,'YesNo');
index 7fe36a0..e20af34 100644 (file)
@@ -195,19 +195,20 @@ INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES
        ('BakerTaylorPassword','','','Baker & Taylor Password for Content Cafe (external content)','Textarea'),
        ('BakerTaylorUsername','','','Baker & Taylor Username for Content Cafe (external content)','Textarea'),
        ('TagsEnabled','1','','Active les fonctionnalités de tags.','YesNo'),
-       ('TagsExternalDictionary',NULL,'','Chemin d\'accès sur le serveur au programme ispell pour déterminer $Lingua::Ispell::path <br />Ce dictionnaire est utilisé comme une liste de tags prédéfinis',''),
+       ('TagsExternalDictionary',NULL,'','Chemin d''accès sur le serveur au programme ispell pour déterminer $Lingua::Ispell::path <br />Ce dictionnaire est utilisé comme une liste de tags prédéfinis',''),
        ('TagsInputOnDetail','1','','Permet aux utilisateurs de saisir des tags sur la page de détail.',         'YesNo'),
        ('TagsInputOnList',  '0','','Permet aux utilisateurs de saisir des tags sur la page de résultat.', 'YesNo'),
-       ('TagsModeration',  NULL,'','Demande que les tags soient approuvés avant d\'être visibles.','YesNo'),
-       ('TagsShowOnDetail','10','','Nombre de tags à afficher sur la page de détail, 0 désactivant l\'affichage.',        'Integer'),
-       ('TagsShowOnList',   '6','','Nombre de tags à afficher sur la page de résultat, 0 désactivant l\'affichage.','Integer');
+       ('TagsModeration',  NULL,'','Demande que les tags soient approuvés avant d''être visibles.','YesNo'),
+       ('TagsShowOnDetail','10','','Nombre de tags à afficher sur la page de détail, 0 désactivant l''affichage.',        'Integer'),
+       ('TagsShowOnList',   '6','','Nombre de tags à afficher sur la page de résultat, 0 désactivant l''affichage.','Integer');
 
 INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OPACShelfBrowser','1','','Active le parcours des rayonnages sur la page de détail','YesNo');
 INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('XSLTDetailsDisplay','0','','Enable XSL stylesheet control over details page display on OPAC WARNING: MARC21 Only','YesNo');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('XSLTResultsDisplay','0','','Enable XSL stylesheet control over results page display on OPAC WARNING: MARC21 Only','YesNo');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Select which set of fields comprise the Type limit in the advanced search','Choice');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowOnShelfHolds', '0', '', 'Allow hold requests to be placed on items that are not on loan', 'YesNo');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Allow hold requests to be placed on damaged items', 'YesNo');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('XSLTResultsDisplay','0','','Permet l''utilisation de Feuilles de style XSLT pour l''affichage des listes de résultat (MARC21)','YesNo');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Détermine quel index utiliser lors des recherches par type de document','Choice');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowOnShelfHolds', '0', '', 'Permet la réservation d''exemplaires non disponibles', 'YesNo');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Permet les réservations sur des exemplaires endommagés', 'YesNo');
 INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OpacSuppression', '0', '', 'Turn ON the OPAC Suppression feature, requires further setup, ask your system administrator for details', 'YesNo');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('SMSSendDriver','','','Détermine le pilote utilisé par SMS::Send pour envoyer des SMS.','free');
-
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('SMSSendDriver','','','Détermine le pilote utilisé par SMS::Send pour envoyer des SMS.','free');
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowRenewalLimitOverride', '1', 'Si Activé, permet que les périodes de renouvellement puisse être positionnée manuellement durant la circulation',NULL,'YesNo');
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('MergeAuthoritiesOnUpdate', '0', 'Si Activé, met à jour toutes les notices bibliographiques afférentes dès la modification d''une autorité',NULL,'YesNo');
\ No newline at end of file
index 59ef43c..8a6de11 100755 (executable)
@@ -1960,7 +1960,14 @@ END_SQL
     print "Upgrade to $DBversion done (warning added to OPACShelfBrowser system preference)\n";
     SetVersion ($DBversion);
 }
-
+if (C4::Context->preference("Version") =~/3\.00/) {
+       warn "inside 3.00";
+       my $return=do qq($ENV{'PERL5LIB'}/installer/data/mysql/updatedatabase30.pl);
+       unless ($return){
+               print STDERR "cannot read file $ENV{'PERL5LIB'}/installer/data/mysql/updatedatabase30.pl : $! \n" if ($!);
+               print STDERR "cannot read file $ENV{'PERL5LIB'}/installer/data/mysql/updatedatabase30.pl : $@ \n" if ($@);
+       }
+}
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
diff --git a/installer/data/mysql/updatedatabase30.pl b/installer/data/mysql/updatedatabase30.pl
new file mode 100644 (file)
index 0000000..b15ac9d
--- /dev/null
@@ -0,0 +1,202 @@
+#!/usr/bin/perl
+
+
+# Database Updater
+# This script checks for required updates to the database.
+
+# Part of the Koha Library Software www.koha.org
+# Licensed under the GPL.
+
+# Bugs/ToDo:
+# - Would also be a good idea to offer to do a backup at this time...
+
+# NOTE:  If you do something more than once in here, make it table driven.
+
+# NOTE: Please keep the version in kohaversion.pl up-to-date!
+
+use strict;
+# use warnings;
+
+# CPAN modules
+use DBI;
+use Getopt::Long;
+# Koha modules
+use C4::Context;
+use C4::Installer;
+
+use MARC::Record;
+use MARC::File::XML ( BinaryEncoding => 'utf8' );
+# FIXME - The user might be installing a new database, so can't rely
+# on /etc/koha.conf anyway.
+
+my $debug = 0;
+
+my (
+    $sth, $sti,
+    $query,
+    %existingtables,    # tables already in database
+    %types,
+    $table,
+    $column,
+    $type, $null, $key, $default, $extra,
+    $prefitem,          # preference item in systempreferences table
+);
+
+my $silent;
+GetOptions(
+    's' =>\$silent
+    );
+my $dbh = C4::Context->dbh;
+$|=1; # flushes output
+
+=item
+
+    Deal with virtualshelves
+
+=cut
+
+my $DBversion = '3.00.01.000';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    print "Upgrade to $DBversion done (start of 3.0.1)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.00.01.001';
+if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
+    # use statistics where available
+    $dbh->do("
+        ALTER TABLE statistics ADD KEY  tmp_stats (type, itemnumber, borrowernumber)
+    ");
+    $dbh->do("
+        UPDATE issues iss
+        SET issuedate = (
+            SELECT max(datetime)
+            FROM statistics 
+            WHERE type = 'issue'
+            AND itemnumber = iss.itemnumber
+            AND borrowernumber = iss.borrowernumber
+        )
+        WHERE issuedate IS NULL;
+    ");  
+    $dbh->do("ALTER TABLE statistics DROP KEY tmp_stats");
+
+    # default to last renewal date
+    $dbh->do("
+        UPDATE issues
+        SET issuedate = lastreneweddate
+        WHERE issuedate IS NULL
+        and lastreneweddate IS NOT NULL
+    ");
+
+    my $num_bad_issuedates = $dbh->selectrow_array("SELECT COUNT(*) FROM issues WHERE issuedate IS NULL");
+    if ($num_bad_issuedates > 0) {
+        print STDERR "After the upgrade to $DBversion, there are still $num_bad_issuedates loan(s) with a NULL (blank) loan date. ",
+                     "Please check the issues table in your database.";
+    }
+    print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.00.01.002";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowRenewalLimitOverride', '0', 'if ON, allows renewal limits to be overridden on the circulation screen',NULL,'YesNo')");
+    print "Upgrade to $DBversion done (add new syspref)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.01.003";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('MergeAuthoritiesOnUpdate', '1', 'if ON, Updateing authorities will automatically updates biblios',NULL,'YesNo')");
+    print "Upgrade to $DBversion done (add new syspref)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.01.004";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+  if (lc(C4::Context->preference('marcflavour')) eq "unimarc"){
+    $dbh->do("INSERT IGNORE INTO `marc_tag_structure` (`tagfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `authorised_value`, `frameworkcode`) VALUES ('099', 'Informations locales', '', 0, 0, '', '');");
+    $dbh->do("INSERT IGNORE INTO `marc_tag_structure` (`frameworkcode`,`tagfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `authorised_value`) SELECT DISTINCT(frameworkcode),'099', 'Informations locales', '', 0, 0, '' from biblio_framework");
+    $dbh->do(<<ENDOFSQL);
+INSERT IGNORE INTO marc_subfield_structure (`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value`, `authtypecode`, `value_builder`, `isurl`, `hidden`, `seealso`, `link`, `defaultvalue`,frameworkcode )
+VALUES ('099', 'c', 'date creation notice (koha)', '', 0, 0, 'biblio.datecreated', -1, '', '', '', NULL, 0, '', '', NULL, ''),
+('099', 'd', 'date modification notice (koha)', '', 0, 0, 'biblio.timestamp', -1, '', '', '', NULL, 0, '', '', NULL, ''),
+('995', '2', 'Perdu', '', 0, 0, 'items.itemlost', 10, '', '', '', NULL, 1, '', NULL, NULL, '');
+ENDOFSQL
+    $dbh->do(<<ENDOFSQL1);
+INSERT IGNORE INTO marc_subfield_structure (`frameworkcode`,`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value`, `authtypecode`, `value_builder`, `isurl`, `hidden`, seealso, link, defaultvalue )
+SELECT DISTINCT(frameworkcode), '099', 'c', 'date creation notice (koha)', '', 0, 0, 'biblio.datecreated', -1, '', '', '', NULL, 0, '', '', NULL from biblio_framework;
+ENDOFSQL1
+    $dbh->do(<<ENDOFSQL2);
+INSERT IGNORE INTO marc_subfield_structure (`frameworkcode`,`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value`, `authtypecode`, `value_builder`, `isurl`, `hidden`, seealso, link, defaultvalue )
+SELECT DISTINCT(frameworkcode), '099', 'd', 'date modification notice (koha)', '', 0, 0, 'biblio.timestamp', -1, '', '', '', NULL, 0, '', '', NULL from biblio_framework;
+ENDOFSQL2
+    $dbh->do(<<ENDOFSQL3);
+INSERT IGNORE INTO marc_subfield_structure (`frameworkcode`,`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value`, `authtypecode`, `value_builder`, `isurl`, `hidden`, seealso, link, defaultvalue )
+SELECT DISTINCT(frameworkcode), '995', '2', 'Perdu', '', 0, 0, 'items.itemlost', 10, '', '', '', NULL, 1, '', NULL, NULL from biblio_framework;
+ENDOFSQL3
+      print "Upgrade to $DBversion done (updates MARC framework structure)\n";
+    }
+    SetVersion ($DBversion);
+}
+
+=item DropAllForeignKeys($table)
+
+  Drop all foreign keys of the table $table
+
+=cut
+
+sub DropAllForeignKeys {
+    my ($table) = @_;
+    # get the table description
+    my $sth = $dbh->prepare("SHOW CREATE TABLE $table");
+    $sth->execute;
+    my $vsc_structure = $sth->fetchrow;
+    # split on CONSTRAINT keyword
+    my @fks = split /CONSTRAINT /,$vsc_structure;
+    # parse each entry
+    foreach (@fks) {
+        # isolate what is before FOREIGN KEY, if there is something, it's a foreign key to drop
+        $_ = /(.*) FOREIGN KEY.*/;
+        my $id = $1;
+        if ($id) {
+            # we have found 1 foreign, drop it
+            $dbh->do("ALTER TABLE $table DROP FOREIGN KEY $id");
+            $id="";
+        }
+    }
+}
+
+
+=item TransformToNum
+
+  Transform the Koha version from a 4 parts string
+  to a number, with just 1 .
+
+=cut
+
+sub TransformToNum {
+    my $version = shift;
+    # remove the 3 last . to have a Perl number
+    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
+    return $version;
+}
+
+=item SetVersion
+
+    set the DBversion in the systempreferences
+
+=cut
+
+sub SetVersion {
+    my $kohaversion = TransformToNum(shift);
+    if (C4::Context->preference('Version')) {
+      my $finish=$dbh->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
+      $finish->execute($kohaversion);
+    } else {
+      my $finish=$dbh->prepare("INSERT into systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller')");
+      $finish->execute($kohaversion);
+    }
+}
+exit;
+
index 582aa2c..29ead65 100644 (file)
@@ -10,7 +10,7 @@
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.00.00.107';
+    our $VERSION = '3.00.01.004';
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install