Opac po file updates
[koha.git] / C4 / Installer.pm
index a497b43..2e1fe1a 100644 (file)
@@ -79,11 +79,37 @@ sub new {
                                   $self->{'user'}, $self->{'password'});
     $self->{'language'} = undef;
     $self->{'marcflavour'} = undef;
+       $self->{'dbh'}->do('set NAMES "utf8"');
+    $self->{'dbh'}->{'mysql_enable_utf8'}=1; 
 
     bless $self, $class;
     return $self;
 }
 
+=head2 marcflavour_list
+
+=over 4
+
+my ($marcflavours) = $installer->marcflavour_list($lang);
+
+=back
+
+Return a arrayref of the MARC flavour sets available for the
+specified language C<$lang>.  Returns 'undef' if a directory
+for the language does not exist.
+
+=cut
+
+sub marcflavour_list {
+    my $self = shift;
+    my $lang = shift;
+
+    my $dir = C4::Context->config('intranetdir') . "/installer/data/$self->{dbms}/$lang/marcflavour";
+    opendir(MYDIR, $dir) or return;
+    my @list = grep { !/^\.|CVS/ && -d "$dir/$_" } readdir(MYDIR);
+    closedir MYDIR;
+    return \@list;
+}
 
 =head2 marc_framework_sql_list
 
@@ -493,6 +519,7 @@ sub set_version_syspref {
         my $finish=$self->{'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);
     }
+    C4::Context->clear_syspref_cache();
 }
 
 =head2 load_sql
@@ -532,7 +559,7 @@ sub load_sql {
             . ( $self->{user}     ? " -u $self->{user} "     : "" )
             . ( $self->{password} ? " -p'$self->{password}'"   : "" )
             . " $self->{dbname} ";
-        $error = qx($strcmd <$filename 2>&1 1>/dev/null);
+        $error = qx($strcmd --default-character-set=utf8 <$filename 2>&1 1>/dev/null);
     } elsif ( $self->{dbms} eq 'Pg' ) {
         $strcmd = "psql "
             . ( $self->{hostname} ? " -h $self->{hostname} " : "" )
@@ -548,6 +575,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