unit_types
units
properties
+ prep_methods
categories
ingredients
ingredient_groups
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(
units
categories
properties
+ prep_methods
ingredients
ingredient_groups
ingredient_properties
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 = {
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
$sql = <<END_SQL;
INSERT INTO `authors`
- ( `author_id`, `user_id`, `old_author_id`, `author_name`, `date_created` )
+ ( `author_id`, `user_id`, `author_name`, `date_created` )
VALUES
- ( 1, 1, NULL, %s, now() )
+ ( 1, 1, %s, now() )
END_SQL
$sql = sprintf( $sql, $target_dbh->quote( $admin_data->{'vorname'} . " " . $admin_data->{'nachname'} ) );
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;
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) {
$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;
#-------------------------------------------------------------
+=head2 create_ingredient_prep_methods_table( )
+
+=cut
+
+sub create_ingredient_prep_methods_table {
+
+ my $sql = <<END_SQL;
+CREATE TABLE IF NOT EXISTS `ingredient_prep_methods` (
+ `ingredient_prep_method_id` int(10) unsigned NOT NULL auto_increment,
+ `recipe_ingredient_id` int(10) unsigned NOT NULL COMMENT 'Verknüpfung zur Zutat eines Rezepts',
+ `prep_method_id` int(10) unsigned NOT NULL COMMENT 'Verknüpfung zu Vorbereitungsmethoden',
+ `order_index` int(10) unsigned NOT NULL COMMENT 'Sortierreihenfolge',
+ `date_created` datetime NOT NULL,
+ `date_changed` datetime NOT NULL,
+ PRIMARY KEY ( `ingredient_prep_method_id` ),
+ UNIQUE KEY `r_p_id` ( `recipe_ingredient_id`, `prep_method_id` ),
+ KEY `prep_method_id` ( `prep_method_id` )
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Vorbereitungsmethoden einer Zutat eines Rezepts'
+END_SQL
+
+ return undef unless $target_dbh->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 = <<END_SQL;
+SELECT `ingredient_list_id`, `prep_method_id`, `order_index`
+ FROM `prep_method_list`
+ ORDER BY `ingredient_list_id`, `order_index`
+END_SQL
+
+ my ( $source_sth, $target_sth, $row, $qparams );
+
+ unless ( $source_sth = $source_dbh->prepare($sql) ) {
+ return undef;
+ }
+
+ return undef unless $source_sth->execute();
+
+ $sql = <<END_SQL;
+INSERT INTO `ingredient_prep_methods` (
+ `recipe_ingredient_id`, `prep_method_id`, `order_index`, `date_created`, `date_changed`
+ ) VALUES ( ?, ?, ?, now(), now() )
+END_SQL
+ $target_sth = $target_dbh->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 = <<END_SQL;
+CREATE TABLE IF NOT EXISTS `prep_methods` (
+ `prep_method_id` int(10) unsigned NOT NULL auto_increment,
+ `prep_method_name` varchar(30) NOT NULL COMMENT 'Name der Vorbereitungsmethode',
+ `date_created` datetime NOT NULL,
+ `date_changed` datetime NOT NULL,
+ PRIMARY KEY (`prep_method_id`),
+ UNIQUE KEY `prep_method_name` (`prep_method_name`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Vorbereitungsmethoden'
+END_SQL
+
+ return undef unless $target_dbh->do($sql);
+ return 1;
+
+} ## end sub create_prep_methods_table
+
+#-------------------------------------------------------------
+
+=head2 import_prep_methods_table( )
+
+=cut
+
+sub import_prep_methods_table {
+
+ my $sql = <<END_SQL;
+SELECT `id`, `name`
+ FROM `prep_methods`
+ ORDER BY `name`
+END_SQL
+
+ my ( $source_sth, $target_sth, $type, $qparams );
+
+ unless ( $source_sth = $source_dbh->prepare($sql) ) {
+ return undef;
+ }
+
+ return undef unless $source_sth->execute();
+
+ $sql = <<END_SQL;
+INSERT INTO `prep_methods` ( `prep_method_id`, `prep_method_name`, `date_created`, `date_changed` )
+ VALUES ( ?, ?, now(), now() )
+END_SQL
+ $target_sth = $target_dbh->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
my $sql = <<END_SQL;
CREATE TABLE `recipes` (
`recipe_id` int(10) unsigned NOT NULL auto_increment,
- `old_recipe_id` int(11) default NULL COMMENT 'alte ID aus Kreceipes',
`rid` char(32) NOT NULL COMMENT 'MD5-ID des Rezeptes',
`title` varchar(250) NOT NULL COMMENT 'Rezepttitel',
`published` enum('n','y') NOT NULL default 'n' COMMENT 'Ist das Rezept veröffentlicht?',
`deleted` enum('n','y') NOT NULL COMMENT 'Wurde dieses Rezept gelöscht?',
`locked` enum('n','y') NOT NULL default 'n' COMMENT 'Ist das Rezept von einem Administrator gesperrt?',
+ `edit_session_id` varchar(72) default NULL COMMENT 'Sitzungs-Id des aktuell Bearbeitenden',
+ `last_edit_action` datetime default NULL COMMENT 'Zeitpunkt der letzten Editieraktion',
`preface` text COMMENT 'Vorwort zum Rezept',
`instructions` text NOT NULL COMMENT 'Zubereitungsanleitung',
`yield_amount` float unsigned NOT NULL default '0' COMMENT 'Ergebnismenge',
`user_changed` int(10) unsigned NOT NULL COMMENT 'User-Id des letzten Änderers',
PRIMARY KEY (`recipe_id`),
UNIQUE KEY `rid` (`rid`),
- KEY `old_recipe_id` (`old_recipe_id`),
KEY `title` (`title`),
FULLTEXT KEY `title_ft` (`title`),
FULLTEXT KEY `instructions_ft` (`instructions`),
$sql = <<END_SQL;
INSERT INTO `recipes` (
- `old_recipe_id`, `rid`, `title`, `published`, `deleted`, `locked`, `preface`, `instructions`,
+ `rid`, `title`, `published`, `deleted`, `locked`, `preface`, `instructions`,
`yield_amount`, `yield_amount_offset`, `yield_type_id`, `prep_time`,
`date_created`, `user_created`, `date_changed`, `user_changed`
)
VALUES (
- ?, ?, ?, 'y', 'n', 'n', NULL, ?,
+ ?, ?, 'y', 'n', 'n', NULL, ?,
?, ?, ?, ?,
?, 1, ?, 1
)
my $digest = md5_hex($digest_source);
$qparams = [
- $recipe->{'id'},
$digest,
$recipe->{'title'},
$recipe->{'instructions'},
my $sql = <<END_SQL;
CREATE TABLE `recipe_ingredients` (
`recipe_ingredient_id` int(10) unsigned NOT NULL auto_increment,
- `recipe_id` int(10) unsigned NOT NULL COMMENT 'Verknüfung zu recipes',
- `ingredient_id` int(10) unsigned default NULL COMMENT 'Verknüfung zu ingredients',
+ `recipe_id` int(10) unsigned NOT NULL COMMENT 'Verknüfung zu Rezepte',
+ `ingredient_id` int(10) unsigned default NULL COMMENT 'Verknüfung zu Zutaten',
`amount` float unsigned default NULL COMMENT 'Menge der Zutat',
`amount_offset` float unsigned default NULL COMMENT 'Mengen-Spielraum',
`unit_id` int(10) unsigned default NULL COMMENT 'Verknüfung zu units',
`order_index` int(10) unsigned NOT NULL default '0' COMMENT 'Sortierreihenfolge im Rezept',
- `ingredient_group_id` int(10) unsigned default NULL COMMENT 'Verknüfung zu ingredient_groups',
+ `ingredient_group_id` int(10) unsigned default NULL COMMENT 'Verknüfung zu Zutat-Gruppierungen',
`date_created` datetime NOT NULL,
`date_changed` datetime NOT NULL,
PRIMARY KEY ( `recipe_ingredient_id`),
ORDER BY `recipe_id`, `order_index`
END_SQL
- my ( $source_sth, $target_sth, $row, $qparams, $i, $old_rid );
+ my ( $source_sth, $target_sth, $row, $qparams, $i, $old_rid, $j );
unless ( $source_sth = $source_dbh->prepare($sql) ) {
return undef;
$old_rid = 0;
$i = 0;
+ $j = 0;
while ( $row = $source_sth->fetchrow_hashref() ) {
else {
$i++;
}
+ $j++;
$qparams = [];
push @$qparams, $row->{'id'};
return undef;
}
+ print "." unless $j % 100;
+
} ## end while ( $row = $source_sth->fetchrow_hashref(...
return 1;