This patch calls the new optional database SQL scripts to that sensible data is
isntalled.
---
C4/Installer.pm | 43 ++++++++++++++++++++
installer/data/mysql/updatedatabase.pl | 25 +++++++++++
.../KohaTest/Installer/get_file_path_from_name.pm | 36 ++++++++++++++++
3 files changed, 104 insertions(+), 0 deletions(-)
create mode 100644 t/lib/KohaTest/Installer/get_file_path_from_name.pm
diff --git a/C4/Installer.pm b/C4/Installer.pm
index 25918c0..1dc13aa 100644
--- a/C4/Installer.pm
+++ b/C4/Installer.pm
@@ -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( [ [EMAIL PROTECTED] ], [ '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
diff --git a/installer/data/mysql/updatedatabase.pl
b/installer/data/mysql/updatedatabase.pl
index 8fff5cd..352507d 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -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);
}
diff --git a/t/lib/KohaTest/Installer/get_file_path_from_name.pm
b/t/lib/KohaTest/Installer/get_file_path_from_name.pm
new file mode 100644
index 0000000..40962a7
--- /dev/null
+++ b/t/lib/KohaTest/Installer/get_file_path_from_name.pm
@@ -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;
--
1.5.5.GIT
_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches