From 5c4452dac84a1dae8fa74ebcde235efd8896f04c Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 9 Aug 2007 12:20:06 +0000 Subject: [PATCH] Rezepte erstmals importiert git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@12 191103c4-1d37-0410-b3e5-d8c2315c0aac --- sbin/initial_import.pl | 199 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 196 insertions(+), 3 deletions(-) diff --git a/sbin/initial_import.pl b/sbin/initial_import.pl index 55ba817..17740d1 100755 --- a/sbin/initial_import.pl +++ b/sbin/initial_import.pl @@ -13,6 +13,7 @@ use Data::Dumper; use DBI; use Term::ANSIColor; use Crypt::SaltedHash; +use Digest::MD5 qw(md5_hex); $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1; @@ -29,7 +30,10 @@ $| = 1; my @target_tables = qw( users + session + session_log authors + recipes ); my $admin_data = { @@ -355,8 +359,11 @@ Erstellt alle notwendigen Ziel-Tabellen ... sub create_target_tables { my %create_method = ( - 'users' => \&create_user_table, - 'authors' => \&create_author_table, + 'users' => \&create_user_table, + 'authors' => \&create_author_table, + 'session' => \&create_session_table, + 'session_log' => \&create_session_log_table, + 'recipes' => \&create_recipes_table, ); print green_star() . " Erstelle Ziel-Tabellen ...\n"; @@ -440,6 +447,15 @@ sub import_data { } print ok() . "\n"; + print " - recipes ... "; + eval { die "Tabelle 'recipes' wurde nicht importiert.\n" unless import_receipes_table(); }; + if ($@) { + print not_ok() . "\n"; + warn $@ . "\n"; + return undef; + } + print ok() . "\n"; + print "\n"; return 1; @@ -495,6 +511,183 @@ sub import_author_table { #------------------------------------------------------------- +=head2 create_session_table( ) + +=cut + +sub create_session_table { + + my $sql = <do($sql); + return 1; + +} + +#------------------------------------------------------------- + +=head2 create_session_log_table( ) + +=cut + +sub create_session_log_table { + + my $sql = <do($sql); + return 1; + +} + +#------------------------------------------------------------- + +=head2 create_recipes_table( ) + +=cut + +sub create_recipes_table { + + my $sql = <do($sql); + return 1; + +} + +#------------------------------------------------------------- + +=head2 import_receipes_table( ) + +=cut + +sub import_receipes_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 ( $recipe = $source_sth->fetchrow_hashref() ) { + + $i++; + my $digest_source = sprintf( '%07d-%s-%s', $i, time(), $recipe->{'title'} ); + my $digest = md5_hex($digest_source); + + $qparams = [ + $recipe->{'id'}, + $digest, + $recipe->{'title'}, + $recipe->{'instructions'}, + $recipe->{'yield_amount'} || 0, + $recipe->{'yield_amount_offset'} || undef, + ( $recipe->{'yield_type_id'} and $recipe->{'yield_type_id'} > 0 ? $recipe->{'yield_type_id'} : undef ), + $recipe->{'prep_time'}, + $recipe->{'ctime'}, + $recipe->{'mtime'}, + ]; + + unless ( $target_dbh->do( $sql, {}, @$qparams ) ) { + $source_sth->finish(); + return undef; + } + } + + return 1; + + + +} +#------------------------------------------------------------- + =head2 create_user_table( ) Erstellt die Tabelle 'users' ... @@ -504,7 +697,7 @@ Erstellt die Tabelle 'users' ... sub create_user_table { my $sql = <