This subroutine was only used in tests to add/update a library.
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
&GetBranch
&GetBranches
&GetBranchesLoop
- &ModBranch
&GetBranchInfo
&mybranch
);
return ($branchname);
}
-=head2 ModBranch
-
-$error = &ModBranch($newvalue);
-
-This function modifies an existing branch
-
-C<$newvalue> is a ref to an array which contains all the columns from branches table.
-
-=cut
-
-sub ModBranch {
- my ($data) = @_;
-
- my $dbh = C4::Context->dbh;
- if ($data->{add}) {
- my $query = "
- INSERT INTO branches
- (branchcode,branchname,branchaddress1,
- branchaddress2,branchaddress3,branchzip,branchcity,branchstate,
- branchcountry,branchphone,branchfax,branchemail,
- branchurl,branchip,branchprinter,branchnotes,opac_info,
- branchreplyto, branchreturnpath)
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
- ";
- my $sth = $dbh->prepare($query);
- $sth->execute(
- $data->{'branchcode'}, $data->{'branchname'},
- $data->{'branchaddress1'}, $data->{'branchaddress2'},
- $data->{'branchaddress3'}, $data->{'branchzip'},
- $data->{'branchcity'}, $data->{'branchstate'},
- $data->{'branchcountry'},
- $data->{'branchphone'}, $data->{'branchfax'},
- $data->{'branchemail'}, $data->{'branchurl'},
- $data->{'branchip'}, $data->{'branchprinter'},
- $data->{'branchnotes'}, $data->{opac_info},
- $data->{'branchreplyto'}, $data->{'branchreturnpath'}
- );
- return 1 if $dbh->err;
- } else {
- my $query = "
- UPDATE branches
- SET branchname=?,branchaddress1=?,
- branchaddress2=?,branchaddress3=?,branchzip=?,
- branchcity=?,branchstate=?,branchcountry=?,branchphone=?,
- branchfax=?,branchemail=?,branchurl=?,branchip=?,
- branchprinter=?,branchnotes=?,opac_info=?,
- branchreplyto=?, branchreturnpath=?
- WHERE branchcode=?
- ";
- my $sth = $dbh->prepare($query);
- $sth->execute(
- $data->{'branchname'},
- $data->{'branchaddress1'}, $data->{'branchaddress2'},
- $data->{'branchaddress3'}, $data->{'branchzip'},
- $data->{'branchcity'}, $data->{'branchstate'},
- $data->{'branchcountry'},
- $data->{'branchphone'}, $data->{'branchfax'},
- $data->{'branchemail'}, $data->{'branchurl'},
- $data->{'branchip'}, $data->{'branchprinter'},
- $data->{'branchnotes'}, $data->{opac_info},
- $data->{'branchreplyto'}, $data->{'branchreturnpath'},
- $data->{'branchcode'},
- );
- }
- # sort out the categories....
- my @checkedcats;
- my @cats = Koha::LibraryCategories->search;
- foreach my $cat (@cats) {
- my $code = $cat->categorycode;
- if ( $data->{$code} ) {
- push( @checkedcats, $code );
- }
- }
- my $branchcode = uc( $data->{'branchcode'} );
- my $branch = GetBranchInfo($branchcode);
- $branch = $branch->[0];
- my $branchcats = $branch->{'categories'};
- my @addcats;
- my @removecats;
- foreach my $bcat (@$branchcats) {
-
- unless ( grep { /^$bcat$/ } @checkedcats ) {
- push( @removecats, $bcat );
- }
- }
- foreach my $ccat (@checkedcats) {
- unless ( grep { /^$ccat$/ } @$branchcats ) {
- push( @addcats, $ccat );
- }
- }
- foreach my $cat (@addcats) {
- my $sth =
- $dbh->prepare(
-"insert into branchrelations (branchcode, categorycode) values(?, ?)"
- );
- $sth->execute( $branchcode, $cat );
- }
- foreach my $cat (@removecats) {
- my $sth =
- $dbh->prepare(
- "delete from branchrelations where branchcode=? and categorycode=?"
- );
- $sth->execute( $branchcode, $cat );
- }
-}
-
=head2 GetBranch
$branch = GetBranch( $query, $branches );
use C4::Context;
use Data::Dumper;
-use Test::More tests => 19;
+use Test::More tests => 17;
use C4::Branch;
+use Koha::Database;
+use Koha::Library;
use Koha::Libraries;
use Koha::LibraryCategories;
GetBranch
GetBranches
GetBranchesLoop
- ModBranch
GetBranchInfo
mybranch
)
);
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
-# Start transaction
my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
# clear the slate
$dbh->do('DELETE FROM branchcategories');
#add 2 branches
my $b1 = {
- add => 1,
branchcode => 'BRA',
branchname => 'BranchA',
branchaddress1 => 'adr1A',
opac_info => 'opacB',
issuing => undef,
};
-ModBranch($b1);
-is( ModBranch($b2), undef, 'the field add is missing' );
+Koha::Library->new($b1)->store;
+Koha::Library->new($b2)->store;
-$b2->{add} = 1;
-ModBranch($b2);
is( Koha::Libraries->search->count, $count + 2, "two branches added" );
is( Koha::Libraries->find( $b2->{branchcode} )->delete, 1, "One row affected" );
is( scalar( keys %$branches ),
Koha::Libraries->search->count, "GetBranches returns the right number of branches" );
-#Test ModBranch
+#Test modify a library
$b1 = {
branchcode => 'BRA',
issuing => undef,
};
-ModBranch($b1);
+Koha::Libraries->find($b1->{branchcode})->set($b1)->store;
is( Koha::Libraries->search->count, $count + 1,
"A branch has been modified, no new branch added" );
is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 deleted" );
-$b2->{CAT1} = 1;
-ModBranch($b2);
+my $b2_stored = Koha::Library->new($b2)->store;
+my $CAT1 = Koha::LibraryCategories->find('CAT1');
+$b2_stored->add_to_categories([$CAT1]);
is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
#Test GetBranchInfo
Koha::LibraryCategory->new($cat2)->store;
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );
-$b2 = {
- branchcode => 'BRB',
- branchname => 'BranchB',
- branchaddress1 => 'adr1B',
- branchaddress2 => 'adr2B',
- branchaddress3 => 'adr3B',
- branchzip => 'zipB',
- branchcity => 'cityB',
- branchstate => 'stateB',
- branchcountry => 'countryB',
- branchphone => 'phoneB',
- branchfax => 'faxB',
- branchemail => 'emailB',
- branchreplyto => 'emailreply',
- branchreturnpath => 'branchreturn',
- branchurl => 'urlB',
- branchip => 'ipB',
- branchprinter => undef,
- branchnotes => 'noteB',
- opac_info => 'opacB',
- issuing => undef,
- CAT1 => 1,
- CAT2 => 1
-};
-ModBranch($b2);
-$b2info = GetBranchInfo( $b2->{branchcode} );
-push( @cat, $cat2->{categorycode} );
-delete $b2->{CAT1};
-delete $b2->{CAT2};
-$b2->{categories} = \@cat;
-is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' );
#TODO later: test mybranchine and onlymine
# Actually we cannot mock C4::Context->userenv in unit tests
my $loop = GetBranchesLoop;
is( scalar(@$loop), Koha::Libraries->search->count, 'There is the right number of branches' );
-# End transaction
-$dbh->rollback;
-
+$schema->storage->txn_rollback;
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Branch;
use C4::Category;
+use Koha::Library;
use MARC::Record;
BEGIN {
my $branchcode = 'B';
-ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
+Koha::Library->new( {branchcode => $branchcode, branchname => 'Branch' } )->store;
my $categorycode = 'C';
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
use C4::Circulation;
use C4::Biblio;
use C4::Items;
-use C4::Branch;
+use Koha::Library;
BEGIN {
my $branchcode = 'B';
-ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
+Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
my $categorycode = 'C';
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
use C4::Branch;
use C4::Category;
use C4::Circulation;
+use Koha::Library;
use MARC::Record;
my $dbh = C4::Context->dbh;
$branchcode = $branches[0];
} else {
$branchcode = 'B';
- ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
+ Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
$branch_created = 1;
}
use Test::More tests => 2;
use Test::Warn;
-use C4::Branch;
use C4::Circulation;
use C4::Members;
+use Koha::Library;
use t::lib::Mocks;
my $dbh = C4::Context->dbh;
t::lib::Mocks::mock_preference('AnonymousPatron', '');
my $branchcode = 'B';
-ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
+Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
my $categorycode = 'C';
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
use Modern::Perl;
use C4::Biblio;
use C4::Members;
-use C4::Branch;
use C4::Circulation;
use C4::Items;
use C4::Context;
+use Koha::Library;
use Test::More tests => 14;
#Add branch and category
my $samplebranch1 = {
- add => 1,
branchcode => 'SAB1',
branchname => 'Sample Branch',
branchaddress1 => 'sample adr1',
opac_info => 'sample opac',
};
my $samplebranch2 = {
- add => 1,
branchcode => 'SAB2',
branchname => 'Sample Branch2',
branchaddress1 => 'sample adr1_2',
branchprinter => undef,
opac_info => 'sample opac2',
};
-ModBranch($samplebranch1);
-ModBranch($samplebranch2);
+Koha::Library->new($samplebranch1)->store;
+Koha::Library->new($samplebranch2)->store;
my $samplecat = {
categorycode => 'CAT1',
use Modern::Perl;
use C4::Context;
-use C4::Branch;
use DateTime;
use Koha::DateUtils;
+use Koha::Library;
use Test::More tests => 9;
#Add branch and category
my $samplebranch1 = {
- add => 1,
branchcode => 'SAB1',
branchname => 'Sample Branch',
branchaddress1 => 'sample adr1',
opac_info => 'sample opac',
};
my $samplebranch2 = {
- add => 1,
branchcode => 'SAB2',
branchname => 'Sample Branch2',
branchaddress1 => 'sample adr1_2',
branchprinter => undef,
opac_info => 'sample opac2',
};
-ModBranch($samplebranch1);
-ModBranch($samplebranch2);
+Koha::Library->new($samplebranch1)->store;
+Koha::Library->new($samplebranch2)->store;
my $samplecat = {
categorycode => 'CAT1',
#!/usr/bin/perl
use Modern::Perl;
-use C4::Branch;
use C4::Circulation;
+use Koha::Library;
use Test::More tests => 7;
#Add branch
my $samplebranch1 = {
- add => 1,
branchcode => 'SAB1',
branchname => 'Sample Branch',
branchaddress1 => 'sample adr1',
branchprinter => undef,
opac_info => 'sample opac',
};
-ModBranch($samplebranch1);
+Koha::Library->new($samplebranch1)->store;
#Begin Tests
#Test AddOfflineOperation
use DateTime::Duration;
use C4::Biblio;
use C4::Members;
-use C4::Branch;
use C4::Circulation;
use C4::Items;
use C4::Context;
use C4::Reserves;
+use Koha::Library;
use Test::More tests => 32;
#Add branch and category
my $samplebranch1 = {
- add => 1,
branchcode => 'CPL',
branchname => 'Sample Branch',
branchaddress1 => 'sample adr1',
opac_info => 'sample opac',
};
my $samplebranch2 = {
- add => 1,
branchcode => 'MPL',
branchname => 'Sample Branch2',
branchaddress1 => 'sample adr1_2',
branchprinter => undef,
opac_info => 'sample opac2',
};
-ModBranch($samplebranch1);
-ModBranch($samplebranch2);
+Koha::Library->new($samplebranch1)->store;
+Koha::Library->new($samplebranch2)->store;
my $samplecat = {
categorycode => 'CAT1',
use MARC::Record;
use C4::Biblio;
-use C4::Branch;
use Koha::Database;
+use Koha::Library;
use t::lib::Mocks;
use t::lib::TestBuilder;
holdingbranch => $library2->{branchcode},
}, $biblionumber );
- my $library = Koha::Libraries->find( $library1->{branchcode} )->unblessed;
- $library->{ opac_info }= "homebranch OPAC info";
- ModBranch($library);
+ my $library = Koha::Libraries->find( $library1->{branchcode} );
+ $library->opac_info("homebranch OPAC info");
+ $library->store;
- $library = Koha::Libraries->find( $library2->{branchcode} )->unblessed;
- $library->{ opac_info } = "holdingbranch OPAC info";
- ModBranch($library);
+ $library = Koha::Libraries->find( $library2->{branchcode} );
+ $library->opac_info("holdingbranch OPAC info");
+ $library->store;
my @results = GetItemsInfo( $biblionumber );
ok( @results, 'GetItemsInfo returns results');
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Branch;
use C4::Category;
use C4::Circulation;
+use Koha::Libraries;
use MARC::Record;
my $dbh = C4::Context->dbh;
$dbh->do(q|DELETE FROM categories|);
my $branchcode = 'B';
-ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
+Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
my $categorycode = 'C';
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Branch;
use C4::Category;
use C4::Circulation;
+use Koha::Libraries;
use MARC::Record;
my $dbh = C4::Context->dbh;
$dbh->do(q|DELETE FROM categories|);
my $branchcode = 'B';
-ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
+Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
my $categorycode = 'C';
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Branch;
use C4::Category;
use C4::Circulation;
+use Koha::Library;
use MARC::Record;
my $dbh = C4::Context->dbh;
$dbh->do(q|DELETE FROM categories|);
my $branchcode = 'B';
-ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
+Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
my $categorycode = 'C';
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Branch;
use C4::Category;
use C4::Circulation;
use Koha::DateUtils qw( dt_from_string output_pref );
+use Koha::Library;
use DateTime::Duration;
use MARC::Record;
$dbh->do(q|DELETE FROM letter|);
my $branchcode = 'B';
-ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
+Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
my $categorycode = 'C';
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
use Test::More tests => 52;
use C4::Context;
-use C4::Branch;
use C4::Biblio;
+use Koha::Library;
BEGIN {
use_ok('C4::RotatingCollections');
#Test TransferCollection
my $samplebranch = {
- add => 1,
branchcode => 'SAB',
branchname => 'Sample Branch',
branchaddress1 => 'sample adr1',
branchnotes => 'sample note',
opac_info => 'sample opac',
};
-ModBranch($samplebranch);
+Koha::Library->new($samplebranch)->store;
is( TransferCollection( $collection_id1, $samplebranch->{branchcode} ),
1, "Collection1 has been transfered in the branch SAB" );
@collection1 = GetCollection($collection_id1);
use C4::Context;
use C4::Members;
use C4::Letters;
-use C4::Branch;
use C4::Budgets qw( AddBudgetPeriod AddBudget );
use Koha::DateUtils qw( dt_from_string );
+use Koha::Library;
use Koha::Libraries;
use DateTime::Duration;
# Add CPL if missing.
if (not defined Koha::Libraries->find('CPL')) {
- ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'});
+ Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store;
}
my $sth = $dbh->prepare("SELECT * FROM categories WHERE categorycode='S';");
use Test::More tests => 5;
use C4::Context;
-use C4::Branch;
+use Koha::Library;
use Koha::Template::Plugin::Branches;
my $dbh = C4::Context->dbh;
$dbh->{RaiseError} = 1;
for my $i ( 1 .. 5 ) {
- C4::Branch::ModBranch(
+ Koha::Library->new(
{
branchcode => "test_br_$i",
branchname => "test_br_$i",
- add => 1,
}
- );
+ )->store;
}
use Test::More tests => 19;
use C4::Context;
-use C4::Branch;
use C4::Members;
use C4::Members::Attributes;
use C4::Members::AttributeTypes;
+use Koha::Library;
+
use t::lib::Mocks;
use_ok( "C4::Utils::DataTables::Members" );
# Add a new branch so we control what borrowers it has
my $branchcode = "UNC";
my $branch_data = {
- add => 1,
branchcode => $branchcode,
branchname => 'Universidad Nacional de Cordoba',
branchaddress1 => 'Haya de la Torre',
branchstate => 'Cordoba',
branchcountry => 'Argentina'
};
-ModBranch( $branch_data );
+Koha::Library->new( $branch_data )->store;
my %john_doe = (
cardnumber => '123456',
use C4::Biblio;
use C4::Context;
-use C4::Branch;
use C4::Members;
+use Koha::Library;
use Koha::Virtualshelf;
use Koha::Virtualshelves;
my $categorycode = $categories[0]->categorycode;
my $branchcode = "ABC";
my $branch_data = {
- add => 1,
branchcode => $branchcode,
branchname => 'my branchname',
};
-ModBranch( $branch_data );
+Koha::Library->new( $branch_data )->store;
my %john_doe = (
cardnumber => '123456',