From: Frank Brehm Date: Sat, 11 Aug 2007 12:13:49 +0000 (+0000) Subject: Vorbereitungsmethoden angefangen X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=80bdf0253ea61188fb6bb1be3eb3c4d791c6de7e;p=cookbook.git Vorbereitungsmethoden angefangen git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@24 191103c4-1d37-0410-b3e5-d8c2315c0aac --- diff --git a/lib/CookBook/Db/Recipes.pm b/lib/CookBook/Db/Recipes.pm index 07576fe..337d195 100644 --- a/lib/CookBook/Db/Recipes.pm +++ b/lib/CookBook/Db/Recipes.pm @@ -39,13 +39,15 @@ __PACKAGE__->add_columns( 'is_auto_increment' => 1, 'extras' => { 'unsigned' => 1 }, }, - "rid" => { 'data_type' => "CHAR", 'default_value' => "", 'is_nullable' => 0, 'size' => 32, }, - "title" => { 'data_type' => "VARCHAR", 'default_value' => "", 'is_nullable' => 0, 'size' => 250, }, - "published" => { 'data_type' => "ENUM", 'default_value' => "n", 'is_nullable' => 0, 'size' => 1, }, - "deleted" => { 'data_type' => "ENUM", 'default_value' => "n", 'is_nullable' => 0, 'size' => 1, }, - "locked" => { 'data_type' => "ENUM", 'default_value' => "n", 'is_nullable' => 0, 'size' => 1, }, - "preface" => { 'data_type' => "TEXT", 'default_value' => "", 'is_nullable' => 1, 'size' => 65535, }, - "instructions" => { 'data_type' => "TEXT", 'default_value' => "", 'is_nullable' => 0, 'size' => 65535, }, + "rid" => { 'data_type' => "CHAR", 'default_value' => "", 'is_nullable' => 0, 'size' => 32, }, + "title" => { 'data_type' => "VARCHAR", 'default_value' => "", 'is_nullable' => 0, 'size' => 250, }, + "published" => { 'data_type' => "ENUM", 'default_value' => "n", 'is_nullable' => 0, 'size' => 1, }, + "deleted" => { 'data_type' => "ENUM", 'default_value' => "n", 'is_nullable' => 0, 'size' => 1, }, + "locked" => { 'data_type' => "ENUM", 'default_value' => "n", 'is_nullable' => 0, 'size' => 1, }, + "edit_session_id" => { 'data_type' => "VARCHAR", 'default_value' => undef, 'is_nullable' => 1, 'size' => 72, }, + "last_edit_action" => { 'data_type' => "DATETIME", 'default_value' => undef, 'is_nullable' => 1, 'size' => 19, }, + "preface" => { 'data_type' => "TEXT", 'default_value' => "", 'is_nullable' => 1, 'size' => 65535, }, + "instructions" => { 'data_type' => "TEXT", 'default_value' => "", 'is_nullable' => 0, 'size' => 65535, }, "yield_amount" => { 'data_type' => "FLOAT", 'default_value' => 0, 'is_nullable' => 0, 'size' => 32, 'extras' => { 'unsigned' => 1 }, }, "yield_amount_offset" => { 'data_type' => "FLOAT", 'default_value' => undef, 'is_nullable' => 1, 'size' => 32, 'extras' => { 'unsigned' => 1 }, }, diff --git a/sbin/initial_import.pl b/sbin/initial_import.pl index 6715e7a..7c94a87 100755 --- a/sbin/initial_import.pl +++ b/sbin/initial_import.pl @@ -37,6 +37,7 @@ my @target_tables = qw( unit_types units properties + prep_methods categories ingredients ingredient_groups @@ -45,25 +46,28 @@ my @target_tables = qw( recipe_authors recipe_categories recipe_ingredients + ingredient_prep_methods ); my %create_method = ( - 'users' => \&create_user_table, - 'authors' => \&create_author_table, - 'session' => \&create_session_table, - 'session_log' => \&create_session_log_table, - 'recipes' => \&create_recipes_table, - 'yield_types' => \&create_yield_types_table, - 'recipe_authors' => \&create_recipe_authors_table, - 'ingredients' => \&create_ingredients_table, - 'ingredient_groups' => \&create_ingredient_groups_table, - 'recipe_ingredients' => \&create_recipe_ingredients_table, - 'unit_types' => \&create_unit_types_table, - 'units' => \&create_units_table, - 'categories' => \&create_categories_table, - 'recipe_categories' => \&create_recipe_categories_table, - 'properties' => \&create_properties_table, - 'ingredient_properties' => \&create_ingredient_properties_table, + 'users' => \&create_user_table, + 'authors' => \&create_author_table, + 'session' => \&create_session_table, + 'session_log' => \&create_session_log_table, + 'recipes' => \&create_recipes_table, + 'yield_types' => \&create_yield_types_table, + 'recipe_authors' => \&create_recipe_authors_table, + 'ingredients' => \&create_ingredients_table, + 'ingredient_groups' => \&create_ingredient_groups_table, + 'recipe_ingredients' => \&create_recipe_ingredients_table, + 'unit_types' => \&create_unit_types_table, + 'units' => \&create_units_table, + 'categories' => \&create_categories_table, + 'recipe_categories' => \&create_recipe_categories_table, + 'properties' => \&create_properties_table, + 'ingredient_properties' => \&create_ingredient_properties_table, + 'prep_methods' => \&create_prep_methods_table, + 'ingredient_prep_methods' => \&create_ingredient_prep_methods_table, ); my @import_tables = qw( @@ -72,6 +76,7 @@ my @import_tables = qw( units categories properties + prep_methods ingredients ingredient_groups ingredient_properties @@ -79,21 +84,24 @@ my @import_tables = qw( recipe_authors recipe_categories recipe_ingredients + ingredient_prep_methods ); my %import_method = ( - 'authors' => \&import_author_table, - 'categories' => \&import_categories_table, - 'recipe_categories' => \&import_recipe_categories_table, - 'yield_types' => \&import_yield_types_table, - 'units' => \&import_units_table, - 'ingredients' => \&import_ingredients_table, - 'ingredient_groups' => \&import_ingredient_groups_table, - 'ingredient_properties' => \&import_ingredient_properties_table, - 'recipes' => \&import_recipes_table, - 'recipe_authors' => \&import_recipe_authors_table, - 'recipe_ingredients' => \&import_recipe_ingredients_table, - 'properties' => \&import_properties_table, + 'authors' => \&import_author_table, + 'categories' => \&import_categories_table, + 'recipe_categories' => \&import_recipe_categories_table, + 'yield_types' => \&import_yield_types_table, + 'units' => \&import_units_table, + 'ingredients' => \&import_ingredients_table, + 'ingredient_groups' => \&import_ingredient_groups_table, + 'ingredient_properties' => \&import_ingredient_properties_table, + 'recipes' => \&import_recipes_table, + 'recipe_authors' => \&import_recipe_authors_table, + 'recipe_ingredients' => \&import_recipe_ingredients_table, + 'properties' => \&import_properties_table, + 'prep_methods' => \&import_prep_methods_table, + 'ingredient_prep_methods' => \&import_ingredient_prep_methods_table, ); my $admin_data = { @@ -488,13 +496,11 @@ sub create_author_table { CREATE TABLE `authors` ( `author_id` int(10) unsigned NOT NULL auto_increment, `user_id` int(10) unsigned, - `old_author_id` int(11) COMMENT 'alte ID aus Kreceipes', `author_name` varchar(100) NOT NULL COMMENT 'Name des Autors', `date_created` datetime NOT NULL, PRIMARY KEY (`author_id`), UNIQUE KEY `author_name` (`author_name`), KEY `user_id` (`user_id`), - KEY `old_author_id` (`old_author_id`), FULLTEXT KEY `author_name_ft` (`author_name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Kochrezept-Autoren' END_SQL @@ -503,9 +509,9 @@ END_SQL $sql = <quote( $admin_data->{'vorname'} . " " . $admin_data->{'nachname'} ) ); @@ -524,7 +530,7 @@ END_SQL sub import_author_table { my $sql = 'SELECT `id`, `name` FROM `authors` order by `name`'; - my ( $source_sth, $target_sth, $author, $row, $count, $qparams, $do_insert ); + my ( $source_sth, $target_sth, $author, $row, $count, $qparams ); unless ( $source_sth = $source_dbh->prepare($sql) ) { return undef; @@ -533,6 +539,7 @@ sub import_author_table { return undef unless $source_sth->execute(); while ( $author = $source_sth->fetchrow_hashref() ) { + $sql = 'SELECT count(*) AS `count` FROM `authors` WHERE `author_name` = ?'; $target_sth = $target_dbh->prepare($sql); unless ($target_sth) { @@ -546,25 +553,20 @@ sub import_author_table { $row = $target_sth->fetchrow_hashref(); $count = $row->{'count'}; $target_sth->finish(); - $qparams = [ $author->{'id'}, $author->{'name'} ]; - $do_insert = 0; + if ($count) { - $sql = 'UPDATE `authors` SET `old_author_id` = ? WHERE `author_name` = ?'; + $map_author_id{ $author->{'id'} } = 1; } else { - $sql = 'INSERT INTO `authors` ( `old_author_id`, `author_name`, `date_created` ) VALUES ( ?, ?, now() )'; - $do_insert = 1; - } - unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { - $source_sth->finish(); - return undef; - } - if ($do_insert) { + $qparams = [ $author->{'name'} ]; + $sql = 'INSERT INTO `authors` ( `author_name`, `date_created` ) VALUES ( ?, now() )'; + unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { + $source_sth->finish(); + return undef; + } $map_author_id{ $author->{'id'} } = $target_dbh->{'mysql_insertid'}; } - else { - $map_author_id{ $author->{'id'} } = 1; - } + } ## end while ( $author = $source_sth->fetchrow_hashref... return 1; @@ -891,6 +893,163 @@ END_SQL #------------------------------------------------------------- +=head2 create_ingredient_prep_methods_table( ) + +=cut + +sub create_ingredient_prep_methods_table { + + my $sql = <do($sql); + return 1; + +} ## end sub create_ingredient_prep_methods_table + +#------------------------------------------------------------- + +=head2 import_ingredient_prep_methods_table( ) + +=cut + +sub import_ingredient_prep_methods_table { + + my $sql = <prepare($sql) ) { + return undef; + } + + return undef unless $source_sth->execute(); + + $sql = <prepare($sql); + unless ($target_sth) { + $source_sth->finish(); + return undef; + } + + my $i = 0; + + while ( $row = $source_sth->fetchrow_hashref() ) { + + next unless $row->{'ingredient_list_id'}; + next unless $row->{'prep_method_id'}; + + $i++; + + $qparams = []; + push @$qparams, $row->{'ingredient_list_id'}; + push @$qparams, $row->{'prep_method_id'}; + push @$qparams, $row->{'order_index'}; + + unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { + $source_sth->finish(); + return undef; + } + + print "." unless $i % 100; + + } ## end while ( $row = $source_sth->fetchrow_hashref(... + + return 1; + +} ## end sub import_ingredient_prep_methods_table + +#------------------------------------------------------------- + +=head2 create_prep_methods_table( ) + +=cut + +sub create_prep_methods_table { + + my $sql = <do($sql); + return 1; + +} ## end sub create_prep_methods_table + +#------------------------------------------------------------- + +=head2 import_prep_methods_table( ) + +=cut + +sub import_prep_methods_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 ( $type = $source_sth->fetchrow_hashref() ) { + + $qparams = [ $type->{'id'}, $type->{'name'}, ]; + + unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { + $source_sth->finish(); + return undef; + } + } + + return 1; + +} ## end sub import_prep_methods_table + +#------------------------------------------------------------- + =head2 create_properties_table( ) =cut @@ -1032,12 +1191,13 @@ sub create_recipes_table { my $sql = <{'id'}, $digest, $recipe->{'title'}, $recipe->{'instructions'}, @@ -1304,13 +1462,13 @@ sub create_recipe_ingredients_table { my $sql = <prepare($sql) ) { return undef; @@ -1361,6 +1519,7 @@ END_SQL $old_rid = 0; $i = 0; + $j = 0; while ( $row = $source_sth->fetchrow_hashref() ) { @@ -1371,6 +1530,7 @@ END_SQL else { $i++; } + $j++; $qparams = []; push @$qparams, $row->{'id'}; @@ -1389,6 +1549,8 @@ END_SQL return undef; } + print "." unless $j % 100; + } ## end while ( $row = $source_sth->fetchrow_hashref(... return 1;