Bugzilla – Attachment 16485 Details for
Bug 9869
Add object oriented database access system to Koha.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9869 - Add object oriented database access system to Koha.
Bug-9869---Add-object-oriented-database-access-sys.patch (text/plain), 6.05 KB, created by
Kyle M Hall (khall)
on 2013-03-20 10:36:58 UTC
(
hide
)
Description:
Bug 9869 - Add object oriented database access system to Koha.
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-03-20 10:36:58 UTC
Size:
6.05 KB
patch
obsolete
>From 7ef6952044b4a53ddb32a8ac453728e9ec2a3f4a Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 19 Mar 2013 07:40:35 -0700 >Subject: [PATCH] Bug 9869 - Add object oriented database access system to Koha. > >This patch adds the framework necessary to enable object oriented >database access to Koha via DBIx::SearchBuilder. The advantage to >SearchBuilder over DBIx::Class is the fact that SearchBuilder does >not require Moose as a prerequisite. > >This patch includes only one table class, AuthorisedValues as a >concept test. Each table can be added as neccessary. > >Test Plan: >1) Apply patch >2) Run t/db_dependent/SearchBuilder.t >--- > Koha/DataObject/AuthorisedValue.pm | 29 ++++++++++++++++++++++++++ > Koha/DataObject/AuthorisedValues.pm | 18 ++++++++++++++++ > Koha/SearchBuilder.pm | 19 +++++++++++++++++ > Koha/SearchBuilder/Handle.pm | 37 ++++++++++++++++++++++++++++++++++ > Koha/SearchBuilder/Record.pm | 19 +++++++++++++++++ > t/db_dependent/SearchBuilder.t | 38 +++++++++++++++++++++++++++++++++++ > 6 files changed, 160 insertions(+), 0 deletions(-) > create mode 100644 Koha/DataObject/AuthorisedValue.pm > create mode 100644 Koha/DataObject/AuthorisedValues.pm > create mode 100644 Koha/SearchBuilder.pm > create mode 100644 Koha/SearchBuilder/Handle.pm > create mode 100644 Koha/SearchBuilder/Record.pm > create mode 100755 t/db_dependent/SearchBuilder.t > >diff --git a/Koha/DataObject/AuthorisedValue.pm b/Koha/DataObject/AuthorisedValue.pm >new file mode 100644 >index 0000000..1d15c42 >--- /dev/null >+++ b/Koha/DataObject/AuthorisedValue.pm >@@ -0,0 +1,29 @@ >+package Koha::DataObject::AuthorisedValue; >+ >+use base qw/Koha::SearchBuilder::Record/; >+ >+sub _Init { >+ my $self = shift; >+ >+ $self->Table("authorised_values"); >+ >+ return $self->SUPER::_Init(@_); >+} >+ >+# Tell Record what the primary keys are >+sub _PrimaryKeys { >+ return ['id']; >+} >+ >+sub _ClassAccessible { >+ { >+ id => { 'read' => 1, 'auto' => 1, 'public' => 1, }, >+ category => { 'read' => 1, 'auto' => 1, 'public' => 1, }, >+ authorised_value => { 'read' => 1, 'auto' => 1, 'public' => 1, }, >+ lib => { 'read' => 1, 'auto' => 1, 'public' => 1, }, >+ lib_opac => { 'read' => 1, 'auto' => 1, 'public' => 1, }, >+ mageurl => { 'read' => 1, 'auto' => 1, 'public' => 1, }, >+ }; >+} >+ >+1; >diff --git a/Koha/DataObject/AuthorisedValues.pm b/Koha/DataObject/AuthorisedValues.pm >new file mode 100644 >index 0000000..ad9a297 >--- /dev/null >+++ b/Koha/DataObject/AuthorisedValues.pm >@@ -0,0 +1,18 @@ >+package Koha::DataObject::AuthorisedValues; >+ >+use base qw/Koha::SearchBuilder/; >+ >+sub _Init { >+ my $self = shift; >+ >+ $self->Table("authorised_values"); >+ >+ return $self->SUPER::_Init(@_); >+} >+ >+sub NewItem { >+ my $self = shift; >+ return ( Koha::DataObject::AuthorisedValue->new() ); >+} >+ >+1; >diff --git a/Koha/SearchBuilder.pm b/Koha/SearchBuilder.pm >new file mode 100644 >index 0000000..b4a68cd >--- /dev/null >+++ b/Koha/SearchBuilder.pm >@@ -0,0 +1,19 @@ >+package Koha::SearchBuilder; >+ >+use base qw/DBIx::SearchBuilder/; >+ >+use DBIx::SearchBuilder; >+use C4::Context; >+ >+sub _Init { >+ my $self = shift; >+ >+ $self->SUPER::_Init(@_); >+ >+ my $handle = Koha::SearchBuilder::Handle->new(); >+ $handle->Connect(); >+ $self->_Handle( $handle ); >+} >+ >+1; >+ >diff --git a/Koha/SearchBuilder/Handle.pm b/Koha/SearchBuilder/Handle.pm >new file mode 100644 >index 0000000..458f32e >--- /dev/null >+++ b/Koha/SearchBuilder/Handle.pm >@@ -0,0 +1,37 @@ >+package Koha::SearchBuilder::Handle; >+ >+use base qw/DBIx::SearchBuilder::Handle/; >+ >+use strict; >+use warnings; >+ >+use C4::Context; >+ >+sub Connect { >+ my $self = shift; >+ my %args = (@_); >+ >+ my $driver = C4::Context::db_scheme2dbi( C4::Context->config('db_scheme') ); >+ >+ $self->SUPER::Connect( >+ Driver => $driver, >+ User => C4::Context->config('user'),, >+ Password => C4::Context->config('pass'), >+ Host => C4::Context->config('hostname'), >+ Database => C4::Context->config('database'), >+ %args, >+ ); >+ >+ if ( $driver eq 'mysql' ) { >+ my $version = $self->DatabaseVersion; >+ ($version) = $version =~ /^(\d+\.\d+)/; >+ $self->dbh->do("SET NAMES 'utf8'") if $version >= 4.1; >+ } >+ elsif ( $driver eq 'Pg' ) { >+ my $version = $self->DatabaseVersion; >+ ($version) = $version =~ /^(\d+\.\d+)/; >+ $self->dbh->do("SET bytea_output = 'escape'") if $version >= 9.0; >+ } >+} >+ >+1; >diff --git a/Koha/SearchBuilder/Record.pm b/Koha/SearchBuilder/Record.pm >new file mode 100644 >index 0000000..fc35e18 >--- /dev/null >+++ b/Koha/SearchBuilder/Record.pm >@@ -0,0 +1,19 @@ >+package Koha::SearchBuilder::Record; >+ >+use base qw/DBIx::SearchBuilder::Record/; >+ >+use Koha::SearchBuilder::Handle; >+ >+sub _Init { >+ my $self = shift; >+ >+ $self->SUPER::_Init(@_); >+ >+ my $handle = Koha::SearchBuilder::Handle->new(); >+ $handle->Connect(); >+ >+ $self->_Handle( $handle ); >+} >+ >+1; >+ >diff --git a/t/db_dependent/SearchBuilder.t b/t/db_dependent/SearchBuilder.t >new file mode 100755 >index 0000000..a5f98c0 >--- /dev/null >+++ b/t/db_dependent/SearchBuilder.t >@@ -0,0 +1,38 @@ >+#!/usr/bin/perl >+ >+use strict; >+use warnings; >+ >+use Test::More tests => 8; >+ >+BEGIN { >+ use_ok('Koha::SearchBuilder'); >+ use_ok('Koha::SearchBuilder::Handle'); >+ use_ok('Koha::SearchBuilder::Record'); >+ use_ok('Koha::DataObject::AuthorisedValue'); >+ use_ok('Koha::DataObject::AuthorisedValues'); >+} >+ >+my $av = Koha::DataObject::AuthorisedValue->new(); >+ >+$av->Create( >+ 'category' => 'Foo', >+ 'authorised_value' => 'Bar', >+ 'lib' => 'libFoo', >+ 'lib_opac' => 'opacFoo', >+); >+ >+my $avs = Koha::DataObject::AuthorisedValues->new(); >+$avs->Limit( FIELD => "category", VALUE => "Foo" ); >+my $record = $avs->Next(); >+ok( $record->authorised_value() eq "Bar", "Create, Limit, Next, and field value getter working correctly"); >+ >+my $av_id = $record->id(); >+ >+$av->LoadById($av_id); >+ok( $av->lib_opac() eq 'opacFoo', "LoadById functions correctly" ); >+ >+$record->Delete(); >+ >+$av->LoadById($av_id); >+ok( !defined( $av->lib_opac() ), "Delete functions correctly" ); >-- >1.7.2.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 9869
:
16485
|
16504
|
16507