diff --git a/fotostore.pl b/fotostore.pl index db56d2f..55c47e8 100755 --- a/fotostore.pl +++ b/fotostore.pl @@ -377,14 +377,11 @@ sub save_tags { my $image = shift; my $db_file_id = shift; -# $log->debug(Dumper($image->tags())); my @tags = $image->tags(); -# $log->debug(Dumper(\@tags)); - for my $tag (@tags) { - $log->debug(sprintf("tag: [%s] [%s]", $tag->[0], $tag->[1])); - my $row = $db->save_tag($db_file_id, $tag->[0], $tag->[1]); -# $log->debug(Dumper($row)); - } + + my %tags_data = map { $_->[0] => $_->[1]} @tags; + $db->save_tags($db_file_id, \%tags_data); + } Mojo::IOLoop->start; diff --git a/lib/FotoStore/DB.pm b/lib/FotoStore/DB.pm index 0ae60c1..77d8229 100644 --- a/lib/FotoStore/DB.pm +++ b/lib/FotoStore/DB.pm @@ -8,7 +8,7 @@ use feature qw(signatures say); no warnings qw(experimental::signatures); use Data::Dumper; -use DBIx::Struct; +use DBIx::Struct qw(connector); @@ -93,10 +93,8 @@ sub add_album($self, $user_id, $album_name, $album_desc) { } sub save_tag($self, $db_file_id, $tag_name, $tag_value) { - say STDERR ("[$db_file_id][$tag_name][$tag_value]"); eval { my $row = new_row('exif_data', 'exif_tag' => $tag_name, 'tag_data' => $tag_value,'image_id' => $db_file_id, deleted => 0) || die "error!"; - say STDERR (Dumper($row)); return $row; }; if ($@) { @@ -104,5 +102,19 @@ sub save_tag($self, $db_file_id, $tag_name, $tag_value) { } } +sub save_tags($self, $db_file_id, $tag_data) { + eval { + connector->txn(sub { + for my $key (keys %$tag_data) { + $self->save_tag($db_file_id, $key, $tag_data->{$key}); + } + }); + }; + if ($@) { + say STDERR ("Error! $@"); + } + +} + 1; \ No newline at end of file