From: Frank Brehm Date: Sun, 7 Oct 2007 12:58:40 +0000 (+0000) Subject: Tabelle 'ingredient_weights' importiert X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=cce1affdc8c7b80e5baa6ed0157101e5a9b08cbb;p=cookbook.git Tabelle 'ingredient_weights' importiert git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@25 191103c4-1d37-0410-b3e5-d8c2315c0aac --- diff --git a/sbin/initial_import.pl b/sbin/initial_import.pl index 7c94a87..f4f00b0 100755 --- a/sbin/initial_import.pl +++ b/sbin/initial_import.pl @@ -47,6 +47,7 @@ my @target_tables = qw( recipe_categories recipe_ingredients ingredient_prep_methods + ingredient_weights ); my %create_method = ( @@ -68,6 +69,7 @@ my %create_method = ( 'ingredient_properties' => \&create_ingredient_properties_table, 'prep_methods' => \&create_prep_methods_table, 'ingredient_prep_methods' => \&create_ingredient_prep_methods_table, + 'ingredient_weights' => \&create_ingredient_weights_table, ); my @import_tables = qw( @@ -85,6 +87,7 @@ my @import_tables = qw( recipe_categories recipe_ingredients ingredient_prep_methods + ingredient_weights ); my %import_method = ( @@ -102,6 +105,7 @@ my %import_method = ( 'properties' => \&import_properties_table, 'prep_methods' => \&import_prep_methods_table, 'ingredient_prep_methods' => \&import_ingredient_prep_methods_table, + 'ingredient_weights' => \&import_ingredient_weights_table, ); my $admin_data = { @@ -161,6 +165,8 @@ my %map_author_id; my %map_unit_id; my %map_ingredient_id; +my %valid_prep_methods; + my $port; $target_dsn = 'dbi:mysql:host=%s;database=%s'; @@ -1037,6 +1043,7 @@ END_SQL while ( $type = $source_sth->fetchrow_hashref() ) { $qparams = [ $type->{'id'}, $type->{'name'}, ]; + $valid_prep_methods{ $type->{'id'} } = 1; unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { $source_sth->finish(); @@ -1757,6 +1764,92 @@ END_SQL #------------------------------------------------------------- +=head2 create_ingredient_weights_table( ) + +=cut + +sub create_ingredient_weights_table { + + my $sql = <do($sql); + return 1; + +} ## end sub create_yield_types_table + +#------------------------------------------------------------- + +=head2 import_ingredient_weights_table( ) + +=cut + +sub import_ingredient_weights_table { + + my $sql = <prepare($sql) ) { + return undef; + } + + return undef unless $source_sth->execute(); + + $sql = <prepare($sql); + unless ($target_sth) { + $source_sth->finish(); + return undef; + } + + while ( $weight = $source_sth->fetchrow_hashref() ) { + + $qparams = []; + push @$qparams, $map_ingredient_id{ $weight->{'ingredient_id'} }; + push @$qparams, $weight->{'amount'}; + push @$qparams, $map_unit_id{ $weight->{'unit_id'} }; + push @$qparams, $weight->{'weight'}; + push @$qparams, $map_unit_id{ $weight->{'weight_unit_id'} }; + push @$qparams, ( $valid_prep_methods{ $weight->{'prep_method_id'} } ? $weight->{'prep_method_id'} : undef ); + + unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { + $source_sth->finish(); + return undef; + } + } + + return 1; + +} ## end sub import_yield_types_table + +#------------------------------------------------------------- + =head2 create_yield_types_table( ) =cut