@@ -, +, @@ or procure a stopwatch (stopwatch will be simpler but less accurate). the bug page or organise your own csv's with data for 1000 or more patrons to import. (http://demo-intra.mykoha.co.nz/cgi-bin/koha/tools/import_borrowers.pl) start counting seconds from the point you click the button in the next step. start your stopwatch if using one) and check the time or navigate to the folder you have set NYTProf to output. PatronDataCSV2.csv this time around. This will yield the post-optimisation time. post-optimisation time should be faster. --- C4/Members.pm | 87 +++++++++++++++++++++++++++++++-------------- tools/import_borrowers.pl | 10 +++--- 2 files changed, 67 insertions(+), 30 deletions(-) --- a/C4/Members.pm +++ a/C4/Members.pm @@ -448,14 +448,12 @@ sub GetMember { $debug && warn $select, " ",values %information; my $sth = $dbh->prepare("$select"); $sth->execute(map{$information{$_}} keys %information); - my $data = $sth->fetchall_arrayref({}); - #FIXME interface to this routine now allows generation of a result set - #so whole array should be returned but bowhere in the current code expects this - if (@{$data} ) { - return $data->[0]; - } - - return; + my $data = $sth->fetchrow_hashref; + return $data if $data + # FIXME this routine can now support generation of a resultset + # but until that is needed only what is expected by current + # routines will be generated and returned for the sake of + # perfomance. } =head2 GetMemberRelatives @@ -738,12 +736,13 @@ sub AddMember { $data{'dateenrolled'} = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ); } - my $patron_category = $schema->resultset('Category')->find( $data{'categorycode'} ); + # Check the member category privacy level + my $patron_privacy = GetCategoryPrivacy( $data{'categorycode'} ); $data{'privacy'} = - $patron_category->default_privacy() eq 'default' ? 1 - : $patron_category->default_privacy() eq 'never' ? 2 - : $patron_category->default_privacy() eq 'forever' ? 0 - : undef; + $patron_privacy eq 'default' ? 1 + : $patron_privacy eq 'never' ? 2 + : $patron_privacy eq 'forever' ? 0 + : undef; # Make a copy of the plain text password for later use my $plain_text_password = $data{'password'}; @@ -801,17 +800,18 @@ sub Check_Userid { return 0 unless ($uid); # userid is a unique column, we should assume NULL is not unique - return 0 if ( $uid eq C4::Context->config('user') ); - - my $rs = Koha::Database->new()->schema()->resultset('Borrower'); - - my $params; - $params->{userid} = $uid; - $params->{borrowernumber} = { '!=' => $borrowernumber } if ($borrowernumber); - - my $count = $rs->count( $params ); - - return $count ? 0 : 1; + my $sql = 'SELECT borrowernumber FROM borrowers WHERE userid=?'; + $sql .= ' AND borrowernumber != ?' if $borrowernumber; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($sql); + if ($borrowernumber) { + $sth->execute( $uid, $borrowernumber ); + } + else { + $sth->execute($uid); + } + my $data = $sth->fetchrow; + return $data ? 0 : 1; } =head2 Generate_Userid @@ -1308,7 +1308,7 @@ sub checkcardnumber { return 0 unless defined $cardnumber; my $dbh = C4::Context->dbh; - my $query = "SELECT * FROM borrowers WHERE cardnumber=?"; + my $query = "SELECT borrowernumber FROM borrowers WHERE cardnumber=?"; $query .= " AND borrowernumber <> ?" if ($borrowernumber); my $sth = $dbh->prepare($query); $sth->execute( @@ -1316,7 +1316,7 @@ sub checkcardnumber { ( $borrowernumber ? $borrowernumber : () ) ); - return 1 if $sth->fetchrow_hashref; + return 1 if $sth->fetchrow; my ( $min_length, $max_length ) = get_cardnumber_length(); return 2 @@ -2559,6 +2559,41 @@ WHERE categorycode = ? AND DATEDIFF( NOW(), dateenrolled ) > ? |; return $cnt; } +=head2 GetBorrowecategoryHash + + $arrayref_hashref = &GetBorrowercateforyHash; + + This function returns a hash of borrower categories where the keys are category + codes and values are category descriptions. + +=cut + +sub GetBorrowercategoryHash { + my $categories_list = GetBorrowercategoryList(); + my %categories_hash = map { $_->{categorycode} => $_->{description} } @{$categories_list}; + return %categories_hash; +} + +=head2 GetCategoryPrivacyHash + + $hashref = &GetCategoryPrivacyHash + Returns the default privacy description of a patron's category given the category code. + +=cut + +sub GetCategoryPrivacy { + my ($categorycode) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare( + qq{ + SELECT default_privacy + FROM categories + WHERE categorycode = ? + }); + $sth->execute($categorycode); + return $sth->fetchrow; +} + =head2 DeleteUnverifiedOpacRegistrations Delete all unverified self registrations in borrower_modifications, --- a/tools/import_borrowers.pl +++ a/tools/import_borrowers.pl @@ -40,7 +40,7 @@ use warnings; use C4::Auth; use C4::Output; use C4::Context; -use C4::Branch qw/GetBranchesLoop GetBranchName/; +use C4::Branch qw/GetBranchesLoop GetBranches/; use C4::Members; use C4::Members::Attributes qw(:all); use C4::Members::AttributeTypes; @@ -144,6 +144,8 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { my $today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); my @criticals = qw(surname branchcode categorycode); # there probably should be others my @bad_dates; # I've had a few. + my $all_branches = GetBranches(); + my %all_categories = C4::Members::GetBorrowercategoryHash(); LINE: while ( my $borrowerline = <$handle> ) { my %borrower; my @missing_criticals; @@ -178,13 +180,13 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { #warn join(':',%borrower); if ($borrower{categorycode}) { push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline, value=>$borrower{categorycode}, category_map=>1} - unless GetBorrowercategory($borrower{categorycode}); + unless $all_categories{ $borrower{categorycode} } } else { push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline}; } if ($borrower{branchcode}) { push @missing_criticals, {key=>'branchcode', line=>$. , lineraw=>$borrowerline, value=>$borrower{branchcode}, branch_map=>1} - unless GetBranchName($borrower{branchcode}); + unless $all_branches->{ $borrower{branchcode} }->{branchname}; } else { push @missing_criticals, {key=>'branchcode', line=>$. , lineraw=>$borrowerline}; } @@ -314,7 +316,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { $template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber); } else { # FIXME: fixup_cardnumber says to lock table, but the web interface doesn't so this doesn't either. - # At least this is closer to AddMember than in members/memberentry.pl + # At least this is closer to AddMembes $all_categories{ $borrower{categorycode} } than in members/memberentry.pl if (!$borrower{'cardnumber'}) { $borrower{'cardnumber'} = fixup_cardnumber(undef); } --