From 365cff8988e3a16568104cdf2a1b0cf035a375e2 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 21 Feb 2017 12:07:18 +0000 Subject: [PATCH] Bug 16735 - Don't use objects for database update --- installer/data/mysql/updatedatabase.pl | 40 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index bf78262..7c6e45f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -14599,29 +14599,41 @@ $DBversion = "XXX"; if ( CheckVersion($DBversion) ) { require Koha::Library::Group; - my $search_groups_staff_root = Koha::Library::Group->new( { title => '__SEARCH_GROUPS__', description => "Library search groups - Staff only" } )->store(); - my $search_groups_opac_root = Koha::Library::Group->new( { title => '__SEARCH_GROUPS_OPAC__', description => "Library search groups - OPAC & Staff" } )->store(); + $dbh->do(q{ + INSERT INTO library_groups ( title, description, created_on ) VALUES ( '__SEARCH_GROUPS__', 'Library search groups - Staff only', NOW() ) + }); + my $search_groups_staff_root_id = $dbh->last_insert_id(undef, undef, 'library_groups', undef); + + $dbh->do(q{ + INSERT INTO library_groups ( title, description, created_on ) VALUE ( '__SEARCH_GROUPS_OPAC__', 'Library search groups - Staff only', NOW() ) + }); + my $search_groups_opac_root_id = $dbh->last_insert_id(undef, undef, 'library_groups', undef); my $sth = $dbh->prepare("SELECT * FROM branchcategories"); - $sth->execute(); + my $sth2 = $dbh->prepare("INSERT INTO library_groups ( parent_id, title, description, created_on ) VALUES ( ?, ?, ?, NOW() )"); + + my $sth3 = $dbh->prepare("SELECT * FROM branchrelations WHERE categorycode = ?"); + + my $sth4 = $dbh->prepare("INSERT INTO library_groups ( parent_id, branchcode, created_on ) VALUES ( ?, ?, NOW() )"); + + $sth->execute(); while ( my $lc = $sth->fetchrow_hashref ) { my $description = $lc->{categorycode}; $description .= " - " . $lc->{codedescription} if $lc->{codedescription}; - my $subgroup = Koha::Library::Group->new( - { - parent_id => $lc->{show_in_pulldown} ? $search_groups_opac_root->id : $search_groups_staff_root->id, - title => $lc->{categoryname}, - description => $description, - } - )->store(); + $sth2->execute( + $lc->{show_in_pulldown} ? $search_groups_opac_root_id : $search_groups_staff_root_id, + $lc->{categoryname}, + $description, + ); + + my $subgroup_id = $dbh->last_insert_id(undef, undef, 'library_groups', undef); - my $sth2 = $dbh->prepare("SELECT * FROM branchrelations WHERE categorycode = ?"); - $sth2->execute( $lc->{categorycode} ); + $sth3->execute( $lc->{categorycode} ); - while ( my $l = $sth2->fetchrow_hashref ) { - Koha::Library::Group->new( { parent_id => $subgroup->id, branchcode => $l->{branchcode} } )->store(); + while ( my $l = $sth3->fetchrow_hashref ) { + $sth4->execute( $subgroup_id, $l->{branchcode} ); } } -- 2.10.2