@@ -, +, @@ statements in YAML files for frameworks, and fixes it's encoding. --- description: - "File description" tables: - table_name: translatable: [ title, content ] multiline: [ content ] rows: - title: "Example title" content: - "Content:" - "" - "This is the content." id: 1 value: ~ sql_statements: - "UPDATE table_name SET value ='empty' WHERE value IS NULL" ... lines. This attribute is expected in all YAML files. translated multiple lines of content, they are joined using '\r\n' before insert into database. This is useful to express fields like 'news' content, and to simplify it's translation. '\r\n' is used for correct display in Windows clients. insertions normally, that are executed in order. --- C4/Installer.pm | 29 ++++++++++++++----- installer/data/mysql/en/optional/auth_val.yml | 5 ++++ 2 files changed, 27 insertions(+), 7 deletions(-) --- a/C4/Installer.pm +++ a/C4/Installer.pm @@ -150,11 +150,17 @@ sub marc_framework_sql_list { my %cell; my @frameworklist; map { - 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) ); - my @lines = split /\n/, $line; + my ( $name, $ext ) = split /\./, $_; + my @lines; + if ( $ext =~ /yml/ ) { + my $yaml = LoadFile("$dir/$requirelevel/$name\.$ext"); + @lines = map { Encode::decode('UTF-8', $_) } @{ $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, { @@ -231,7 +237,7 @@ sub sample_data_sql_list { my @lines; if ( $ext =~ /yml/ ) { my $yaml = LoadFile("$dir/$requirelevel/$name\.$ext"); - @lines = @{ $yaml->{'description'} }; + @lines = map { Encode::decode('UTF-8', $_) } @{ $yaml->{'description'} }; } else { open my $fh, "<:encoding(UTF-8)", "$dir/$requirelevel/$name.txt"; my $line = <$fh>; @@ -484,11 +490,20 @@ sub load_sql { my $placeholders = join ",", map { "?" } @columns; # '?,..,?' string my $query = "INSERT INTO $table_name ( $fields ) VALUES ( $placeholders )"; my $sth = $dbh->prepare($query); + my @multiline = @{ $table->{$table_name}->{'multiline'} }; # to check multiline values; foreach my $row ( @rows ) { - my @values = map { $row->{$_} } @columns; + my @values = map { + my $col = $_; + ( @multiline and grep { $_ eq $col } @multiline ) + ? join "\r\n", @{$row->{$col}} # join multiline values + : $row->{$col}; + } @columns; $sth->execute( @values ); } } + for my $statement ( @{ $yaml->{'sql_statements'} } ) { # extra SQL statements + $dbh->do($statement); + } }; } if ($@){ --- a/installer/data/mysql/en/optional/auth_val.yml +++ a/installer/data/mysql/en/optional/auth_val.yml @@ -25,6 +25,7 @@ description: tables: - authorised_values: translatable: [ lib ] + multiline: [] rows: # Reasons for acceptance or rejection of suggestions in acquisitions - category: "SUGGEST" @@ -45,6 +46,7 @@ tables: - authorised_values: translatable: [ lib, lib_opac ] + multiline: [] rows: # Desired formats for requesting new materials - category: "SUGGEST_FORMAT" @@ -74,6 +76,7 @@ tables: - authorised_values : translatable: [ lib ] + multiline: [] rows: # availability statuses - category: "LOST" @@ -181,6 +184,7 @@ tables: - authorised_values: translatable: [ lib, lib_opac ] + multiline: [] rows: # OPAC Suggestions reasons - category: "OPAC_SUG" @@ -195,6 +199,7 @@ tables: - authorised_values: translatable: [ lib ] + multiline: [] rows: # Report groups - category: "REPORT_GROUP" --