From: Frank Brehm Date: Fri, 10 Aug 2007 12:33:18 +0000 (+0000) Subject: Kategorien dazu X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=d8c9ba884a8fc67cf4d371ec5ccae4d1359cf827;p=cookbook.git Kategorien dazu git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@21 191103c4-1d37-0410-b3e5-d8c2315c0aac --- diff --git a/lib/CookBook/Db.pm b/lib/CookBook/Db.pm index 0a12758..e5f5eeb 100644 --- a/lib/CookBook/Db.pm +++ b/lib/CookBook/Db.pm @@ -25,9 +25,11 @@ use base qw/DBIx::Class::Schema/; __PACKAGE__->load_classes( qw/ Authors + Categories Ingredients IngredientGroups RecipeAuthors + RecipeCategories RecipeIngredients Recipes SessionLog diff --git a/lib/CookBook/Db/Categories.pm b/lib/CookBook/Db/Categories.pm new file mode 100644 index 0000000..8791d1f --- /dev/null +++ b/lib/CookBook/Db/Categories.pm @@ -0,0 +1,58 @@ +package CookBook::Db::Categories; + +# $Id$ +# $URL$ + +=head1 NAME + +CookBook::Db::Categories + +=head1 DESCRIPTION + +Module for abstract database access to the table 'categories' + +=cut + +#--------------------------------------------------------------------------- + +use strict; +use warnings; + +use CookBook::Common; +use base qw/DBIx::Class/; + +__PACKAGE__->load_components( + qw/ + PK::Auto + Core + / +); + +__PACKAGE__->table('categories'); + +__PACKAGE__->add_columns( + "category_id" => { + 'data_type' => "INT", + 'default_value' => undef, + 'is_nullable' => 0, + 'size' => 10, + 'is_auto_increment' => 1, + 'extras' => { 'unsigned' => 1 }, + }, + "category_name" => { 'data_type' => "VARCHAR", 'default_value' => "", 'is_nullable' => 0, 'size' => 100 }, + "parent_id" => { 'data_type' => "INT", 'default_value' => undef, 'is_nullable' => 1, 'size' => 10, 'extras' => { 'unsigned' => 1 }, }, + "date_created" => { 'data_type' => "DATETIME", 'default_value' => "", 'is_nullable' => 0, 'size' => 19 }, + "date_changed" => { 'data_type' => "DATETIME", 'default_value' => "", 'is_nullable' => 0, 'size' => 19 }, +); + +__PACKAGE__->set_primary_key("category_id"); +__PACKAGE__->add_unique_constraint( "category_name", ["category_name"] ); + +#---------------------------------------------------------------------------------------- + +1; + +#---------------------------------------------------------------------------------------- + +__END__ + diff --git a/lib/CookBook/Db/RecipeCategories.pm b/lib/CookBook/Db/RecipeCategories.pm new file mode 100644 index 0000000..939be71 --- /dev/null +++ b/lib/CookBook/Db/RecipeCategories.pm @@ -0,0 +1,59 @@ +package CookBook::Db::RecipeCategories; + +# $Id$ +# $URL$ + +=head1 NAME + +CookBook::Db::RecipeCategories + +=head1 DESCRIPTION + +Module for abstract database access to the table 'recipe_categories' + +=cut + +#--------------------------------------------------------------------------- + +use strict; +use warnings; + +use CookBook::Common; +use base qw/DBIx::Class/; + +__PACKAGE__->load_components( + qw/ + PK::Auto + Core + / +); + +__PACKAGE__->table('recipe_categories'); + +__PACKAGE__->add_columns( + "recipe_category_id" => { + 'data_type' => "INT", + 'default_value' => undef, + 'is_nullable' => 0, + 'size' => 10, + 'is_auto_increment' => 1, + 'extras' => { 'unsigned' => 1 }, + }, + "recipe_id" => { 'data_type' => "INT", 'default_value' => 0, 'is_nullable' => 0, 'size' => 10, 'extras' => { 'unsigned' => 1 } }, + "category_id" => { 'data_type' => "INT", 'default_value' => 0, 'is_nullable' => 0, 'size' => 10, 'extras' => { 'unsigned' => 1 } }, + "date_created" => { 'data_type' => "DATETIME", 'default_value' => "", 'is_nullable' => 0, 'size' => 19 }, +); + +__PACKAGE__->set_primary_key("recipe_category_id"); + +__PACKAGE__->belongs_to( 'recipe' => 'CookBook::Db::Recipes', 'recipe_id', ); +__PACKAGE__->belongs_to( 'category' => 'CookBook::Db::Categories', 'category_id', ); + +#---------------------------------------------------------------------------------------- + +1; + +#---------------------------------------------------------------------------------------- + +__END__ + diff --git a/lib/CookBook/Db/UnitTypes.pm b/lib/CookBook/Db/UnitTypes.pm index 6b1e653..921e6e0 100644 --- a/lib/CookBook/Db/UnitTypes.pm +++ b/lib/CookBook/Db/UnitTypes.pm @@ -9,7 +9,7 @@ CookBook::Db::UnitTypes =head1 DESCRIPTION -Module for abstract database access to the table 'yield_types' +Module for abstract database access to the table 'unit_types' =cut diff --git a/sbin/initial_import.pl b/sbin/initial_import.pl index 92a83f3..06db69b 100755 --- a/sbin/initial_import.pl +++ b/sbin/initial_import.pl @@ -36,10 +36,12 @@ my @target_tables = qw( yield_types unit_types units + categories ingredients ingredient_groups recipes recipe_authors + recipe_categories recipe_ingredients ); @@ -56,21 +58,27 @@ my %create_method = ( '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, ); my @import_tables = qw( authors yield_types units + categories ingredients ingredient_groups recipes recipe_authors + recipe_categories recipe_ingredients ); 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, @@ -557,6 +565,82 @@ sub import_author_table { #------------------------------------------------------------- +=head2 create_categories_table( ) + +=cut + +sub create_categories_table { + + my $sql = <do($sql); + return 1; + +} ## end sub create_ingredients_table + +#------------------------------------------------------------- + +=head2 import_categories_table( ) + +=cut + +sub import_categories_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 ( $cat = $source_sth->fetchrow_hashref() ) { + + $qparams = []; + push @$qparams, $cat->{'id'}; + push @$qparams, $cat->{'name'}; + push @$qparams, ( $cat->{'parent_id'} and $cat->{'parent_id'} > 0 ) ? $cat->{'parent_id'} : undef; + + unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { + $source_sth->finish(); + return undef; + } + + } ## end while ( $ingr = $source_sth->fetchrow_hashref... + + return 1; + +} ## end sub import_ingredients_table + +#------------------------------------------------------------- + =head2 create_ingredients_table( ) =cut @@ -955,6 +1039,79 @@ END_SQL #------------------------------------------------------------- +=head2 create_recipe_categories_table( ) + +=cut + +sub create_recipe_categories_table { + + my $sql = <do($sql); + return 1; + +} ## end sub create_recipe_authors_table + +#------------------------------------------------------------- + +=head2 import_recipe_categories_table( ) + +=cut + +sub import_recipe_categories_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 ( $row = $source_sth->fetchrow_hashref() ) { + + next unless $row->{'recipe_id'} and $row->{'recipe_id'} > 0; + next unless $row->{'category_id'} and $row->{'category_id'} > 0; + + $qparams = [ $map_recipe_id{ $row->{'recipe_id'} }, $row->{'category_id'}, ]; + + unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { + $source_sth->finish(); + return undef; + } + } ## end while ( $row = $source_sth->fetchrow_hashref(... + + return 1; + +} ## end sub import_recipe_authors_table + +#------------------------------------------------------------- + =head2 create_recipe_ingredients_table( ) =cut