@@ -, +, @@ then dump authorised_values table, reserve. "Some basic default authorised values for ..." of point '0'. No differences should be found. --- C4/Installer.pm | 57 +++- installer/data/mysql/en/optional/auth_val.sql | 86 ------ installer/data/mysql/en/optional/auth_val.txt | 1 - installer/data/mysql/en/optional/auth_val.yml | 289 ++++++++++++++++++ 4 files changed, 331 insertions(+), 102 deletions(-) delete mode 100644 installer/data/mysql/en/optional/auth_val.sql delete mode 100644 installer/data/mysql/en/optional/auth_val.txt create mode 100644 installer/data/mysql/en/optional/auth_val.yml --- a/C4/Installer.pm +++ a/C4/Installer.pm @@ -21,6 +21,7 @@ use Modern::Perl; use Encode qw( encode is_utf8 ); use DBIx::RunSQL; +use YAML::Syck qw( LoadFile ); use C4::Context; use C4::Installer::PerlModules; use DBI; @@ -145,12 +146,12 @@ sub marc_framework_sql_list { foreach my $requirelevel (@listdir) { opendir( MYDIR, "$dir/$requirelevel" ); - my @listname = grep { !/^\./ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.sql$/ } readdir(MYDIR); + my @listname = grep { !/^\./ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.(sql|yml)$/ } readdir(MYDIR); closedir MYDIR; my %cell; my @frameworklist; map { - my $name = substr( $_, 0, -4 ); + my $name = substr( $_, 0, -4 ); # FIXME: restricted to 3 letter extension open my $fh, "<:encoding(UTF-8)", "$dir/$requirelevel/$name.txt"; my $line = <$fh>; $line = Encode::encode('UTF-8', $line) unless ( Encode::is_utf8($line) ); @@ -222,16 +223,22 @@ sub sample_data_sql_list { foreach my $requirelevel (@listdir) { opendir( MYDIR, "$dir/$requirelevel" ); - my @listname = grep { !/^\./ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.sql$/ } readdir(MYDIR); + my @listname = grep { !/^\./ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.(sql|yml)$/ } readdir(MYDIR); closedir MYDIR; my %cell; my @frameworklist; map { - my $name = substr( $_, 0, -4 ); - open my $fh , "<:encoding(UTF-8)", "$dir/$requirelevel/$name.txt"; - my $line = <$fh>; - $line = Encode::encode('UTF-8', $line) unless ( Encode::is_utf8($line) ); - my @lines = split /\n/, $line; + my ( $name, $ext ) = split /\./, $_; + my @lines; + if ( $ext =~ /yml/ ) { + my $yaml = LoadFile("$dir/$requirelevel/$name\.$ext"); + @lines = @{ $yaml->{'description'} }; + } else { + open my $fh, "<:encoding(UTF-8)", "$dir/$requirelevel/$name.txt"; + my $line = <$fh>; + $line = Encode::encode('UTF-8', $line) unless ( Encode::is_utf8($line) ); + @lines = split /\n/, $line; + } my $mandatory = ($requirelevel =~ /(mandatory|requi|oblig|necess)/i); push @frameworklist, { @@ -439,7 +446,7 @@ sub set_version_syspref { my $error = $installer->load_sql($filename); -Runs a the specified SQL file using a sql loader DBIx::RunSQL +Runs the specified input file using a sql loader DBIx::RunSQL, or a yaml loader Returns any strings sent to STDERR # FIXME This should be improved: sometimes the caller and load_sql warn the same @@ -459,12 +466,32 @@ sub load_sql { local *STDERR; open STDERR, ">>", \$dup_stderr; - eval { - DBIx::RunSQL->run_sql_file( - dbh => $dbh, - sql => $filename, - ); - }; + if ( $filename =~ /sql$/ ) { # SQL files + eval { + DBIx::RunSQL->run_sql_file( + dbh => $dbh, + sql => $filename, + ); + }; + } + else { # YAML files + eval { + my $yaml = LoadFile( $filename ); # Load YAML + for my $table ( @{ $yaml->{'tables'} } ) { + my $table_name = ( keys %$table )[0]; # table name + my @rows = @{ $table->{$table_name}->{rows} }; # + my @columns = ( sort keys %{$rows[0]} ); # column names + my $fields = join ",", @columns; # idem, joined + my $placeholders = join ",", map { "?" } @columns; # '?,..,?' string + my $query = "INSERT INTO $table_name ( $fields ) VALUES ( $placeholders )"; + my $sth = $dbh->prepare($query); + foreach my $row ( @rows ) { + my @values = map { $row->{$_} } @columns; + $sth->execute( @values ); + } + } + }; + } }; # errors thrown while loading installer data should be logged if( $dup_stderr ) { --- a/installer/data/mysql/en/optional/auth_val.sql +++ a/installer/data/mysql/en/optional/auth_val.sql @@ -1,86 +0,0 @@ --- Reasons for acceptance or rejection of suggestions in acquisitions -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SUGGEST','BSELL','Bestseller'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SUGGEST','SCD','Shelf Copy Damaged'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SUGGEST','LCL','Library Copy Lost'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SUGGEST','AVILL','Available via ILL'); - --- Desired formats for requesting new materials -INSERT INTO authorised_values (category, authorised_value, lib, lib_opac) VALUES ('SUGGEST_FORMAT', 'BOOK', 'Book', 'Book'); -INSERT INTO authorised_values (category, authorised_value, lib, lib_opac) VALUES ('SUGGEST_FORMAT', 'LP', 'Large print', 'Large print'); -INSERT INTO authorised_values (category, authorised_value, lib, lib_opac) VALUES ('SUGGEST_FORMAT', 'EBOOK', 'EBook', 'Ebook'); -INSERT INTO authorised_values (category, authorised_value, lib, lib_opac) VALUES ('SUGGEST_FORMAT', 'AUDIOBOOK', 'Audiobook', 'Audiobook'); -INSERT INTO authorised_values (category, authorised_value, lib, lib_opac) VALUES ('SUGGEST_FORMAT', 'DVD', 'DVD', 'DVD'); - --- availability statuses -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOST','2','Long Overdue (Lost)'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOST','1','Lost'); -INSERT INTO `authorised_values` (category, authorised_value, lib ) VALUES ('LOST','3','Lost and Paid For'); -INSERT INTO `authorised_values` (category, authorised_value, lib )VALUES ('LOST','4','Missing'); - --- damaged status of an item -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('DAMAGED','1','Damaged'); - --- location qualification for an item, departments are linked by default to items.location -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','FIC','Fiction'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','CHILD','Children\'s Area'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','DISPLAY','On Display'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','NEW','New Materials Shelf'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','STAFF','Staff Office'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','GEN','General Stacks'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','AV','Audio Visual'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','REF','Reference'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','CART','Book Cart'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('LOC','PROC','Processing Center'); - --- collection codes for an item -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('CCODE','FIC','Fiction'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('CCODE','REF','Reference'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('CCODE','NFIC','Non-fiction'); - --- withdrawn status of an item, linked to items.withdrawn -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('WITHDRAWN','1','Withdrawn'); - --- loanability status of an item, linked to items.notforloan -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('NOT_LOAN','-1','Ordered'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('NOT_LOAN','1','Not For Loan'); -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('NOT_LOAN','2','Staff Collection'); - --- restricted status of an item, linked to items.restricted -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('RESTRICTED','1','Restricted Access'); - --- custom borrower notes -INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('BOR_NOTES','ADDR','Address Notes'); - --- OPAC Suggestions reasons -INSERT INTO authorised_values (category,authorised_value,lib,lib_opac) VALUES ('OPAC_SUG','damaged','The copy on the shelf is damaged','The copy on the shelf is damaged'); -INSERT INTO authorised_values (category,authorised_value,lib,lib_opac) VALUES ('OPAC_SUG','bestseller','Upcoming title by popular author','Upcoming title by popular author'); - --- Report groups -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('REPORT_GROUP', 'CIRC', 'Circulation'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('REPORT_GROUP', 'CAT', 'Catalog'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('REPORT_GROUP', 'PAT', 'Patrons'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('REPORT_GROUP', 'ACQ', 'Acquisitions'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('REPORT_GROUP', 'ACC', 'Accounts'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('REPORT_GROUP', 'SER', 'Serials'); - --- SIP2 media types -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '000', 'Other'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '001', 'Book'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '002', 'Magazine'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '003', 'Bound journal'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '004', 'Audio tape'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '005', 'Video tape'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '006', 'CD/CDROM'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '007', 'Diskette'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '008', 'Book with diskette'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '009', 'Book with CD'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('SIP_MEDIA_TYPE', '010', 'Book with audio tape'); - --- order cancellation reasons -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('ORDER_CANCELLATION_REASON', 0, 'No reason provided'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('ORDER_CANCELLATION_REASON', 1, 'Out of stock'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('ORDER_CANCELLATION_REASON', 2, 'Restocking'); - --- return claims -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('RETURN_CLAIM_RESOLUTION', 'RET_BY_PATRON', 'Returned by patron'); -INSERT INTO authorised_values (category, authorised_value, lib) VALUES ('RETURN_CLAIM_RESOLUTION', 'FOUND_IN_LIB', 'Found in library'); --- a/installer/data/mysql/en/optional/auth_val.txt +++ a/installer/data/mysql/en/optional/auth_val.txt @@ -1, +0,0 @@ -Some basic default authorised values for library locations, item lost status, etc. You can change these at any time after installation. --- a/installer/data/mysql/en/optional/auth_val.yml +++ a/installer/data/mysql/en/optional/auth_val.yml @@ -0,0 +1,289 @@ +--- +# +# Copyright 2019 Koha Development Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +description: + - "Some basic default authorised values for library locations, item lost status, etc." + - "You can change these at any time after installation." + +tables: + - authorised_values: + translatable: [ lib ] + rows: + # Reasons for acceptance or rejection of suggestions in acquisitions + - category: "SUGGEST" + authorised_value: "BSELL" + lib: "Bestseller" + + - category: "SUGGEST" + authorised_value: "SCD" + lib: "Shelf Copy Damaged" + + - category: "SUGGEST" + authorised_value: "LCL" + lib: "Library Copy Lost" + + - category: "SUGGEST" + authorised_value: "AVILL" + lib: "Available via ILL" + + - authorised_values: + translatable: [ lib, lib_opac ] + rows: + # Desired formats for requesting new materials + - category: "SUGGEST_FORMAT" + authorised_value: "BOOK" + lib: "Book" + lib_opac: "Book" + + - category: "SUGGEST_FORMAT" + authorised_value: "LP" + lib: "Large print" + lib_opac: "Large print" + + - category: "SUGGEST_FORMAT" + authorised_value: "EBOOK" + lib: "EBook" + lib_opac: "Ebook" + + - category: "SUGGEST_FORMAT" + authorised_value: "AUDIOBOOK" + lib: "Audiobook" + lib_opac: "Audiobook" + + - category: "SUGGEST_FORMAT" + authorised_value: "DVD" + lib: "DVD" + lib_opac: "DVD" + + - authorised_values : + translatable: [ lib ] + rows: + # availability statuses + - category: "LOST" + authorised_value: "2" + lib: "Long Overdue (Lost)" + + - category: "LOST" + authorised_value: "1" + lib: "Lost" + + - category: "LOST" + authorised_value: "3" + lib : "Lost and Paid For" + + - category: "LOST" + authorised_value: "4" + lib : "Missing" + + # damaged status of an item + - category: "DAMAGED" + authorised_value: "1" + lib: "Damaged" + + # location qualification for an item,departments are linked by default to items.location + - category: "LOC" + authorised_value: "FIC" + lib: "Fiction" + + - category: "LOC" + authorised_value: "CHILD" + lib: "Children's Area" + + - category: "LOC" + authorised_value: "DISPLAY" + lib: "On Display" + + - category: "LOC" + authorised_value: "NEW" + lib: "New Materials Shelf" + + - category: "LOC" + authorised_value: "STAFF" + lib: "Staff Office" + + - category: "LOC" + authorised_value: "GEN" + lib: "General Stacks" + + - category: "LOC" + authorised_value: "AV" + lib: "Audio Visual" + + - category: "LOC" + authorised_value: "REF" + lib: "Reference" + + - category: "LOC" + authorised_value: "CART" + lib: "Book Cart" + + - category: "LOC" + authorised_value: "PROC" + lib: "Processing Center" + + # collection codes for an item + - category: "CCODE" + authorised_value: "FIC" + lib: "Fiction" + + - category: "CCODE" + authorised_value: "REF" + lib: "Reference" + + - category: "CCODE" + authorised_value: "NFIC" + lib: "Non-fiction" + + # withdrawn status of an item,linked to items.withdrawn + - category: "WITHDRAWN" + authorised_value: "1" + lib: "Withdrawn" + + # loanability status of an item,linked to items.notforloan + - category: "NOT_LOAN" + authorised_value: "-1" + lib: "Ordered" + + - category: "NOT_LOAN" + authorised_value: "1" + lib: "Not For Loan" + + - category: "NOT_LOAN" + authorised_value: "2" + lib: "Staff Collection" + + # restricted status of an item,linked to items.restricted + - category: "RESTRICTED" + authorised_value: "1" + lib: "Restricted Access" + + # custom borrower notes + - category: "BOR_NOTES" + authorised_value: "ADDR" + lib: "Address Notes" + + - authorised_values: + translatable: [ lib, lib_opac ] + rows: + # OPAC Suggestions reasons + - category: "OPAC_SUG" + authorised_value: "damaged" + lib: "The copy on the shelf is damaged" + lib_opac: "The copy on the shelf is damaged" + + - category: "OPAC_SUG" + authorised_value: "bestseller" + lib: "Upcoming title by popular author" + lib_opac: "Upcoming title by popular author" + + - authorised_values: + translatable: [ lib ] + rows: + # Report groups + - category: "REPORT_GROUP" + authorised_value: "CIRC" + lib: "Circulation" + + - category: "REPORT_GROUP" + authorised_value: "CAT" + lib: "Catalog" + + - category: "REPORT_GROUP" + authorised_value: "PAT" + lib: "Patrons" + + - category: "REPORT_GROUP" + authorised_value: "ACQ" + lib: "Acquisitions" + + - category: "REPORT_GROUP" + authorised_value: "ACC" + lib: "Accounts" + + - category: "REPORT_GROUP" + authorised_value: "SER" + lib: "Serials" + + # SIP2 media types + - category: "SIP_MEDIA_TYPE" + authorised_value: "000" + lib: "Other" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "001" + lib: "Book" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "002" + lib: "Magazine" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "003" + lib: "Bound journal" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "004" + lib: "Audio tape" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "005" + lib: "Video tape" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "006" + lib: "CD/CDROM" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "007" + lib: "Diskette" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "008" + lib: "Book with diskette" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "009" + lib: "Book with CD" + + - category: "SIP_MEDIA_TYPE" + authorised_value: "010" + lib: "Book with audio tape" + + # order cancellation reasons + - category: "ORDER_CANCELLATION_REASON" + authorised_value: 0 + lib: "No reason provided" + + - category: "ORDER_CANCELLATION_REASON" + authorised_value: 1 + lib: "Out of stock" + + - category: "ORDER_CANCELLATION_REASON" + authorised_value: 2 + lib: "Restocking" + + # return claims + - category: "RETURN_CLAIM_RESOLUTION" + authorised_value: "RET_BY_PATRON" + lib: "Returned by patron" + + - category: "RETURN_CLAIM_RESOLUTION" + authorised_value: "FOUND_IN_LIB" + lib: "Found in library" --