bug: 2176 improvements to database upgrade path
This patch calls the new optional database SQL scripts to that sensible data is isntalled. Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
parent
556538e101
commit
6bd827e546
3 changed files with 104 additions and 0 deletions
|
@ -572,6 +572,49 @@ sub load_sql {
|
|||
return $error;
|
||||
}
|
||||
|
||||
=head2 get_file_path_from_name
|
||||
|
||||
=over 4
|
||||
|
||||
my $filename = $installer->get_file_path_from_name('script_name');
|
||||
|
||||
=back
|
||||
|
||||
searches through the set of known SQL scripts and finds the fully
|
||||
qualified path name for the script that mathches the input.
|
||||
|
||||
returns undef if no match was found.
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
sub get_file_path_from_name {
|
||||
my $self = shift;
|
||||
my $partialname = shift;
|
||||
|
||||
my $lang = 'en'; # FIXME: how do I know what language I want?
|
||||
|
||||
my ($defaulted_to_en, $list) = $self->sample_data_sql_list($lang);
|
||||
# warn( Data::Dumper->Dump( [ $list ], [ 'list' ] ) );
|
||||
|
||||
my @found;
|
||||
foreach my $frameworklist ( @$list ) {
|
||||
push @found, grep { $_->{'fwkfile'} =~ /$partialname$/ } @{$frameworklist->{'frameworks'}};
|
||||
}
|
||||
|
||||
# warn( Data::Dumper->Dump( [ \@found ], [ 'found' ] ) );
|
||||
if ( 0 == scalar @found ) {
|
||||
return;
|
||||
} elsif ( 1 < scalar @found ) {
|
||||
warn "multiple results found for $partialname";
|
||||
return;
|
||||
} else {
|
||||
return $found[0]->{'fwkfile'};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
C4::Installer is a refactoring of logic originally from installer/installer.pl, which was
|
||||
|
|
|
@ -22,6 +22,7 @@ use DBI;
|
|||
use Getopt::Long;
|
||||
# Koha modules
|
||||
use C4::Context;
|
||||
use C4::Installer;
|
||||
|
||||
use MARC::Record;
|
||||
use MARC::File::XML ( BinaryEncoding => 'utf8' );
|
||||
|
@ -1763,6 +1764,30 @@ VALUES
|
|||
('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo')
|
||||
END_SQL
|
||||
|
||||
$dbh->do( <<'END_SQL');
|
||||
INSERT INTO `letter`
|
||||
(module, code, name, title, content)
|
||||
VALUES
|
||||
('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now due:\r\n\r\n<<biblio.title>> by <<biblio.author>>'),
|
||||
('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You have <<count>> items due'),
|
||||
('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item will be due soon:\r\n\r\n<<biblio.title>> by <<biblio.author>>'),
|
||||
('circulation','PREDUEDGST','Advance Notice of Item Due (Digest)','Advance Notice of Item Due','You have <<count>> items due soon'),
|
||||
('circulation','EVENT','Upcoming Library Event','Upcoming Library Event','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThis is a reminder of an upcoming library event in which you have expressed interest.');
|
||||
END_SQL
|
||||
|
||||
my @sql_scripts = (
|
||||
'installer/data/mysql/en/mandatory/message_transport_types.sql',
|
||||
'installer/data/mysql/en/optional/sample_notices_message_attributes.sql',
|
||||
'installer/data/mysql/en/optional/sample_notices_message_transports.sql',
|
||||
);
|
||||
|
||||
my $installer = C4::Installer->new();
|
||||
foreach my $script ( @sql_scripts ) {
|
||||
my $full_path = $installer->get_file_path_from_name($script);
|
||||
my $error = $installer->load_sql($full_path);
|
||||
warn $error if $error;
|
||||
}
|
||||
|
||||
print "Upgrade to $DBversion done (Table structure for table `message_queue`, `message_transport_types`, `message_attributes`, `message_transports`, `borrower_message_preferences`, and `borrower_message_transport_preferences`. Alter `borrowers` table,\n";
|
||||
SetVersion ($DBversion);
|
||||
}
|
||||
|
|
36
t/lib/KohaTest/Installer/get_file_path_from_name.pm
Normal file
36
t/lib/KohaTest/Installer/get_file_path_from_name.pm
Normal file
|
@ -0,0 +1,36 @@
|
|||
package KohaTest::Installer::get_file_path_from_name;
|
||||
use base qw( KohaTest::Installer );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
use C4::Languages;
|
||||
use C4::Installer;
|
||||
|
||||
sub startup_50_get_installer : Test( startup => 1 ) {
|
||||
my $self = shift;
|
||||
my $installer = C4::Installer->new();
|
||||
is(ref($installer), "C4::Installer", "created installer");
|
||||
$self->{installer} = $installer;
|
||||
}
|
||||
|
||||
sub search_for_known_scripts : Tests( 2 ) {
|
||||
my $self = shift;
|
||||
|
||||
skip "did not create installer" unless ref($self->{installer}) eq 'C4::Installer';
|
||||
|
||||
foreach my $script ( 'installer/data/mysql/en/mandatory/message_transport_types.sql',
|
||||
'installer/data/mysql/en/optional/sample_notices_message_attributes.sql', ) {
|
||||
|
||||
ok( $self->{'installer'}->get_file_path_from_name( $script ), "found $script" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub shutdown_50_clear_installer : Tests( shutdown ) {
|
||||
my $self = shift;
|
||||
delete $self->{installer};
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in a new issue