From d1a862b5042533e952cc0ca12717cf310036a3a7 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Mon, 24 Nov 2008 17:44:58 +0100 Subject: [PATCH] creating update database for 3.0.1 - 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 --- .../data/mysql/en/mandatory/sysprefs.sql | 3 +- .../unimarc_standard_systemprefs.sql | 21 +- installer/data/mysql/updatedatabase.pl | 9 +- installer/data/mysql/updatedatabase30.pl | 202 ++++++++++++++++++ kohaversion.pl | 2 +- 5 files changed, 224 insertions(+), 13 deletions(-) create mode 100644 installer/data/mysql/updatedatabase30.pl diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index baa05ab949..15b07aa228 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -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'); diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql index 7fe36a0e7d..e20af349c8 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql @@ -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
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
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 diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 59ef43c961..8a6de11f1d 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -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 index 0000000000..b15ac9d121 --- /dev/null +++ b/installer/data/mysql/updatedatabase30.pl @@ -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(<do(<do(<do(<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; + diff --git a/kohaversion.pl b/kohaversion.pl index 582aa2c163..29ead657df 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -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 -- 2.39.5