Bugzilla – Attachment 19249 Details for
Bug 8798
Add the use of DBIx::Class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
DBIx::Class Branch.pm implementation
DBIxClass-Branchpm-implementation.patch (text/plain), 6.99 KB, created by
Paul Poulain
on 2013-06-26 19:00:25 UTC
(
hide
)
Description:
DBIx::Class Branch.pm implementation
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2013-06-26 19:00:25 UTC
Size:
6.99 KB
patch
obsolete
>From 1525ee9aff8465b61ccea4462ed28359191a1f2c Mon Sep 17 00:00:00 2001 >From: Paul Poulain <paul.poulain@biblibre.com> >Date: Wed, 26 Jun 2013 20:18:51 +0200 >Subject: [PATCH] DBIx::Class Branch.pm implementation > >This package, and the test implement CRUD for Branches table. >Very basic, but proves we can do many things in a few lines ! > >http://bugs.koha-community.org/show_bug.cgi?id=8798 >--- > Koha/BusinessLogic/Branch.pm | 9 ++++ > Koha/DB/Branch.pm | 49 ++++++++++++++++++++ > Koha/DataObject/Branch.pm | 8 ++++ > .../lib/KohaTest/Koha/BusinessLogic/Branch.t | 24 ++++++++++ > t/db_dependent/lib/KohaTest/Koha/DB/Branch.t | 24 ++++++++++ > .../lib/KohaTest/Koha/DataObject/Branch.t | 24 ++++++++++ > 6 files changed, 138 insertions(+) > create mode 100644 Koha/BusinessLogic/Branch.pm > create mode 100644 Koha/DB/Branch.pm > create mode 100644 Koha/DataObject/Branch.pm > create mode 100644 t/db_dependent/lib/KohaTest/Koha/BusinessLogic/Branch.t > create mode 100644 t/db_dependent/lib/KohaTest/Koha/DB/Branch.t > create mode 100644 t/db_dependent/lib/KohaTest/Koha/DataObject/Branch.t > >diff --git a/Koha/BusinessLogic/Branch.pm b/Koha/BusinessLogic/Branch.pm >new file mode 100644 >index 0000000..fcdcea2 >--- /dev/null >+++ b/Koha/BusinessLogic/Branch.pm >@@ -0,0 +1,9 @@ >+package Koha::BusinessLogic::Branch; >+ >+use Modern::Perl; >+use Koha::DataObject::Branch; >+ >+use Class::Accessor "antlers"; >+ >+extends (qw(Koha::DataObject::Branch)); >+ >diff --git a/Koha/DB/Branch.pm b/Koha/DB/Branch.pm >new file mode 100644 >index 0000000..658da64 >--- /dev/null >+++ b/Koha/DB/Branch.pm >@@ -0,0 +1,49 @@ >+package Koha::DB::Branch; >+ >+use Modern::Perl; >+use C4::Context; #FIXME = create a Koha package for KOHA_CONF reading >+ >+use Koha::Database; >+use Class::Accessor "antlers"; >+ >+has 'branchcode' => (is => 'rw', required => 1, isa => 'Str'); >+has 'branchname' => (is => 'rw', required => 1, isa => 'Str'); >+has 'branchaddress1' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchaddress2' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchaddress3' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchzip' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchcity' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchstate' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchcountry' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchphone' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchfax' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchemail' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchurl' => (is => 'rw', required => 0, isa => 'Str'); >+has 'issuing' => (is => 'rw', required => 0, isa => 'Int'); >+has 'branchip' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchprinter' => (is => 'rw', required => 0, isa => 'Str'); >+has 'branchnotes' => (is => 'rw', required => 0, isa => 'Str'); >+has 'opac_info' => (is => 'rw', required => 0, isa => 'Str'); >+ >+my $database = Koha::Database->new(); >+my $schema = $database->schema(); >+ >+sub create { >+ my ($self) = @_; >+ $schema->resultset('Branch')->create({ map { $_ => $self->$_ } $schema->source('Branch')->columns }); >+} >+ >+sub read { >+ my ($self, $branch) = @_; >+ return $schema->resultset('Branch')->search($branch); >+} >+ >+sub update { >+ my ($self, $branch) = @_; >+ return $schema->resultset('Branch')->search({branchcode => $branch->{branchcode}})->update($branch); >+} >+ >+sub delete { >+ my ($self,$branch) = @_; >+ $schema->resultset('Branch')->search($branch)->delete; >+} >diff --git a/Koha/DataObject/Branch.pm b/Koha/DataObject/Branch.pm >new file mode 100644 >index 0000000..d561fbc >--- /dev/null >+++ b/Koha/DataObject/Branch.pm >@@ -0,0 +1,8 @@ >+package Koha::DataObject::Branch; >+ >+use Modern::Perl; >+use Koha::DB::Branch; >+ >+use Class::Accessor "antlers"; >+ >+extends (qw(Koha::DB::Branch)); >diff --git a/t/db_dependent/lib/KohaTest/Koha/BusinessLogic/Branch.t b/t/db_dependent/lib/KohaTest/Koha/BusinessLogic/Branch.t >new file mode 100644 >index 0000000..3909a2d >--- /dev/null >+++ b/t/db_dependent/lib/KohaTest/Koha/BusinessLogic/Branch.t >@@ -0,0 +1,24 @@ >+#!/usr/bin/perl >+ >+use v5.10.0; >+use Modern::Perl; >+ >+use Test::More tests => 5; >+ >+BEGIN { >+ use_ok('Koha::BusinessLogic::Branch', 'Loading Koha::BusinessLogic::Branch OK'); >+} >+ >+# CREATE >+my $branch = Koha::BusinessLogic::Branch->new({'branchcode' => 'TEST_T','branchname' => 'TEST NAME'}); >+ok($branch->create->id eq 'TEST_T','Creating a branch OK'); >+ >+# READ >+ok(Koha::BusinessLogic::Branch->read({'branchcode' => 'TEST_T'})->first->branchname eq 'TEST NAME','Reading a branch OK'); >+ >+# UPDATE >+Koha::BusinessLogic::Branch->update({'branchcode' => 'TEST_T','branchname' => 'TEST UPDATED'}); >+ok(Koha::BusinessLogic::Branch->read({'branchcode' => 'TEST_T'})->first->branchname eq 'TEST UPDATED','Updating a branch OK'); >+ >+# DELETE >+ok(Koha::BusinessLogic::Branch->delete({'branchcode' => 'TEST_T'}),'Deleting a branch OK'); >diff --git a/t/db_dependent/lib/KohaTest/Koha/DB/Branch.t b/t/db_dependent/lib/KohaTest/Koha/DB/Branch.t >new file mode 100644 >index 0000000..3f60b15 >--- /dev/null >+++ b/t/db_dependent/lib/KohaTest/Koha/DB/Branch.t >@@ -0,0 +1,24 @@ >+#!/usr/bin/perl >+ >+use v5.10.0; >+use Modern::Perl; >+ >+use Test::More tests => 5; >+ >+BEGIN { >+ use_ok('Koha::DB::Branch', 'Loading Koha::DB::Branch OK'); >+} >+ >+# CREATE >+my $branch = Koha::DB::Branch->new({'branchcode' => 'TEST','branchname' => 'TEST NAME'}); >+ok($branch->create->id eq 'TEST','Creating a branch OK'); >+ >+# READ >+ok(Koha::DB::Branch->read({'branchcode' => 'TEST'})->first->branchname eq 'TEST NAME','Reading a branch OK'); >+ >+# UPDATE >+Koha::DB::Branch->update({'branchcode' => 'TEST','branchname' => 'TEST UPDATED'}); >+ok(Koha::DB::Branch->read({'branchcode' => 'TEST'})->first->branchname eq 'TEST UPDATED','Updating a branch OK'); >+ >+# DELETE >+ok(Koha::DB::Branch->delete({'branchcode' => 'TEST'}),'Deleting a branch OK'); >diff --git a/t/db_dependent/lib/KohaTest/Koha/DataObject/Branch.t b/t/db_dependent/lib/KohaTest/Koha/DataObject/Branch.t >new file mode 100644 >index 0000000..3f1cfb0 >--- /dev/null >+++ b/t/db_dependent/lib/KohaTest/Koha/DataObject/Branch.t >@@ -0,0 +1,24 @@ >+#!/usr/bin/perl >+ >+use v5.10.0; >+use Modern::Perl; >+ >+use Test::More tests => 5; >+ >+BEGIN { >+ use_ok('Koha::DataObject::Branch', 'Loading Koha::DataObject::Branch OK'); >+} >+ >+# CREATE >+my $branch = Koha::DataObject::Branch->new({'branchcode' => 'TEST','branchname' => 'TEST NAME'}); >+ok($branch->create->id eq 'TEST','Creating a branch OK'); >+ >+# READ >+ok(Koha::DataObject::Branch->read({'branchcode' => 'TEST'})->first->branchname eq 'TEST NAME','Reading a branch OK'); >+ >+# UPDATE >+Koha::DataObject::Branch->update({'branchcode' => 'TEST','branchname' => 'TEST UPDATED'}); >+ok(Koha::DataObject::Branch->read({'branchcode' => 'TEST'})->first->branchname eq 'TEST UPDATED','Updating a branch OK'); >+ >+# DELETE >+ok(Koha::DataObject::Branch->delete({'branchcode' => 'TEST'}),'Deleting a branch OK'); >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8798
:
12403
|
12405
|
12429
|
12439
|
12442
|
12443
|
12453
|
12477
|
12478
|
12480
|
12481
|
12506
|
12520
|
12521
|
12538
|
17581
|
17582
|
17583
|
17584
|
17585
|
17586
|
19134
|
19137
|
19138
|
19139
|
19140
|
19141
|
19248
|
19249
|
19250
|
19251