recipe_categories
recipe_ingredients
ingredient_prep_methods
+ ingredient_weights
);
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(
recipe_categories
recipe_ingredients
ingredient_prep_methods
+ ingredient_weights
);
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 = {
my %map_unit_id;
my %map_ingredient_id;
+my %valid_prep_methods;
+
my $port;
$target_dsn = 'dbi:mysql:host=%s;database=%s';
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();
#-------------------------------------------------------------
+=head2 create_ingredient_weights_table( )
+
+=cut
+
+sub create_ingredient_weights_table {
+
+ my $sql = <<END_SQL;
+CREATE TABLE IF NOT EXISTS `ingredient_weights` (
+ `ingredient_weight_id` int(10) unsigned NOT NULL auto_increment,
+ `ingredient_id` int(10) unsigned NOT NULL,
+ `amount` float unsigned default NULL,
+ `unit_id` int(10) unsigned default NULL,
+ `weight` float unsigned default NULL,
+ `weight_unit_id` int(10) unsigned default NULL,
+ `prep_method_id` int(10) unsigned default NULL,
+ `date_created` datetime NOT NULL,
+ `date_changed` datetime NOT NULL,
+ PRIMARY KEY (`ingredient_weight_id`),
+ KEY `ingredient_id` (`ingredient_id`),
+ KEY `unit_id` (`unit_id`),
+ KEY `weight_unit_id` (`weight_unit_id`),
+ KEY `prep_method_id` (`prep_method_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Spezielle Gewichtsumrechnungen einzelner Zutaten';
+END_SQL
+
+ return undef unless $target_dbh->do($sql);
+ return 1;
+
+} ## end sub create_yield_types_table
+
+#-------------------------------------------------------------
+
+=head2 import_ingredient_weights_table( )
+
+=cut
+
+sub import_ingredient_weights_table {
+
+ my $sql = <<END_SQL;
+SELECT `ingredient_id`, `amount`, `unit_id`, `weight`, `weight_unit_id`, `prep_method_id`
+ FROM `ingredient_weights`
+ ORDER BY `ingredient_id`
+END_SQL
+
+ my ( $source_sth, $target_sth, $weight, $qparams );
+
+ unless ( $source_sth = $source_dbh->prepare($sql) ) {
+ return undef;
+ }
+
+ return undef unless $source_sth->execute();
+
+ $sql = <<END_SQL;
+INSERT INTO `ingredient_weights` (
+ `ingredient_id`, `amount`, `unit_id`, `weight`, `weight_unit_id`, `prep_method_id`, `date_created`, `date_changed`
+ ) VALUES (
+ ?, ?, ?, ?, ?, ?, now(), now() )
+END_SQL
+ $target_sth = $target_dbh->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