try to fix encoding issues in Directory name trawl
Tara L Andrews [Tue, 28 Feb 2012 22:07:33 +0000 (23:07 +0100)]
lib/Text/Tradition/Collation/RelationshipStore.pm
lib/Text/Tradition/Directory.pm
stemmaweb/lib/stemmaweb/Controller/Root.pm

index 47d384e..2f8784c 100644 (file)
@@ -271,7 +271,6 @@ sub add_relationship {
                my $rel = $self->get_relationship( @$v );
        if( $rel && $rel ne $relationship ) {
                if( $rel->nonlocal ) {
-                       $DB::single = 1;
                        throw( "Found conflicting relationship at @$v" );
                } else {
                        warn "Not overriding local relationship set at @$v";
index 8783b96..2fa8fc5 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 use Moose;
 use DBI;
+use Encode qw/ decode_utf8 /;
 use KiokuDB::GC::Naive;
 use KiokuDB::TypeMap;
 use KiokuDB::TypeMap::Entry::Naive;
@@ -231,18 +232,20 @@ sub traditionlist {
        # If we are using DBI, we can do it the easy way; if not, the hard way.
        # Easy way still involves making a separate DBI connection. Ew.
        my @tlist;
-       if( $self->dsn =~ /^dbi/ ) {
-               $DB::single = 1;
+       if( $self->dsn =~ /^dbi:(\w+):/ ) {
+               my $dbtype = $1;
                my @connection = @{$self->directory->backend->connect_info};
                # Get rid of KiokuDB-specific arg
                pop @connection if scalar @connection > 4;
-               $connection[3]->{'sqlite_unicode'} = 1 if $connection[0] =~ /^dbi:SQLite/;
-               $connection[3]->{'mysql_enable_utf8'} = 1 if $connection[0] =~ /^dbi:mysql/;
-               $connection[3]->{'pg_enable_utf8'} = 1 if $connection[0] =~ /^dbi:Pg/;
+               $connection[3]->{'sqlite_unicode'} = 1 if $dbtype eq 'SQLite';
+               $connection[3]->{'pg_enable_utf8'} = 1 if $dbtype eq 'Pg';
                my $dbh = DBI->connect( @connection );
                my $q = $dbh->prepare( 'SELECT id, name from entries WHERE class = "Text::Tradition"' );
                $q->execute();
                while( my @row = $q->fetchrow_array ) {
+                       my( $id, $name ) = @row;
+                       # Horrible horrible hack
+                       $name = decode_utf8( $name ) if $dbtype eq 'mysql';
                        push( @tlist, { 'id' => $row[0], 'name' => $row[1] } );
                }
        } else {
index c33b9f0..6610705 100644 (file)
@@ -69,7 +69,7 @@ sub variantgraph :Local :Args(1) {
        my $collation = $tradition->collation;
        my $needsave = !$collation->has_cached_svg;
        $c->stash->{'result'} = $collation->as_svg;
-       $m->save( $tradition );
+       $m->save( $tradition );  # to save generate SVG in the cache
        $c->forward('View::SVG');
 }
        
@@ -96,7 +96,6 @@ sub alignment :Local :Args(1) {
                        @{$alignment->{'alignment'}};
                push( @$rows, { 'rank' => $i+1, 'readings' => \@rankrdgs } );
        }
-       $c->log->debug( Dumper( $rows ) );
        $c->stash->{'witnesses'} = $wits;
        $c->stash->{'table'} = $rows;
        $c->stash->{'template'} = 'alignment.tt';