From 07999bac4371450a6aecf9f0e51358d7be471717 Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Wed, 26 Jun 2013 20:40:56 +0200 Subject: [PATCH] DBIx::Class tests: replacing GetBranchName by it's DBIx::Class equivalent In this patch, I choose to overload the C4/Branch.pm/GetBranchName by it's DBIx::Class equivalent It's just a POC, no need to commit this patch. the question behind the patch is: should we * REMOVE GetBranchName by replacing all the calls by Koha::BusinessLogic::Branch->read({'branchcode' => $branchcode})->first->branchname; * overload the sub and make it die later I think the 1st will require more effort, but better, while the second requires less effort, but result in much less code cleaning My preference would go to the 1st option. http://bugs.koha-community.org/show_bug.cgi?id=8798 --- C4/Branch.pm | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/C4/Branch.pm b/C4/Branch.pm index 5770f7b..34f7532 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -21,6 +21,8 @@ use strict; require Exporter; use C4::Context; +use Koha::BusinessLogic::Branch; + use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); BEGIN { @@ -177,13 +179,8 @@ sub GetBranchesLoop { # since this is what most pages want anyway sub GetBranchName { my ($branchcode) = @_; - my $dbh = C4::Context->dbh; - my $sth; - $sth = $dbh->prepare("Select branchname from branches where branchcode=?"); - $sth->execute($branchcode); - my $branchname = $sth->fetchrow_array; - $sth->finish; - return ($branchname); + return "" unless $branchcode; #FIXME ? sometimes GetBranchName is called without branchcode, we must return immediatly to avoid an arror in ->first->branchname + return Koha::BusinessLogic::Branch->read({'branchcode' => $branchcode})->first->branchname; } =head2 ModBranch -- 1.7.9.5