Bugzilla – Attachment 79149 Details for
Bug 18606
Move rotating collections code to Koha::Object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18606: Get rid of TransferCollection
Bug-18606-Get-rid-of-TransferCollection.patch (text/plain), 8.79 KB, created by
Josef Moravec
on 2018-09-20 11:18:29 UTC
(
hide
)
Description:
Bug 18606: Get rid of TransferCollection
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2018-09-20 11:18:29 UTC
Size:
8.79 KB
patch
obsolete
>From 1a5dc4639c1d98fff79247fdcfb1bb452d99a610 Mon Sep 17 00:00:00 2001 >From: Josef Moravec <josef.moravec@gmail.com> >Date: Wed, 17 May 2017 12:32:10 +0000 >Subject: [PATCH] Bug 18606: Get rid of TransferCollection > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > C4/RotatingCollections.pm | 59 ---------------------- > Koha/RotatingCollection.pm | 48 +++++++++++++++++- > .../rotating_collections/transferCollection.tt | 6 +-- > rotating_collections/transferCollection.pl | 29 ++++------- > 4 files changed, 60 insertions(+), 82 deletions(-) > >diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm >index 466eca5..cc45eb7 100644 >--- a/C4/RotatingCollections.pm >+++ b/C4/RotatingCollections.pm >@@ -48,68 +48,9 @@ BEGIN { > require Exporter; > @ISA = qw( Exporter ); > @EXPORT = qw( >- TransferCollection > ); > } > >-=head2 TransferCollection >- >- ( $success, $errorcode, $errormessage ) = TransferCollection( $colId, $colBranchcode ); >- >-Transfers a collection to another branch >- >- Input: >- $colId: id of the collection to be updated >- $colBranchcode: branch where collection is moving to >- >- Output: >- $success: 1 if all database operations were successful, 0 otherwise >- $errorCode: Code for reason of failure, good for translating errors in templates >- $errorMessage: English description of error >- >-=cut >- >-sub TransferCollection { >- my ( $colId, $colBranchcode ) = @_; >- >- ## Check for all necessary parameters >- if ( !$colId ) { >- return ( 0, 1, "NO_ID" ); >- } >- if ( !$colBranchcode ) { >- return ( 0, 2, "NO_BRANCHCODE" ); >- } >- >- my $dbh = C4::Context->dbh; >- >- my $sth; >- $sth = $dbh->prepare( >- "UPDATE collections >- SET >- colBranchcode = ? >- WHERE colId = ?" >- ); >- $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() ); >- >- $sth = $dbh->prepare(q{ >- SELECT items.itemnumber, items.barcode FROM collections_tracking >- LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber >- LEFT JOIN issues ON items.itemnumber = issues.itemnumber >- WHERE issues.borrowernumber IS NULL >- AND collections_tracking.colId = ? >- }); >- $sth->execute($colId) or return ( 0, 4, $sth->errstr ); >- my @results; >- while ( my $item = $sth->fetchrow_hashref ) { >- my ($status) = CheckReserves( $item->{itemnumber} ); >- my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} ); >- C4::Circulation::transferbook( $colBranchcode, $item->{barcode}, my $ignore_reserves = 1 ) unless ( $status eq 'Waiting' || @transfers ); >- } >- >- return 1; >- >-} >- > =head2 isItemInThisCollection > > $inCollection = isItemInThisCollection( $itemnumber, $colId ); >diff --git a/Koha/RotatingCollection.pm b/Koha/RotatingCollection.pm >index c00f80e..7e4c2ef 100644 >--- a/Koha/RotatingCollection.pm >+++ b/Koha/RotatingCollection.pm >@@ -1,6 +1,6 @@ > package Koha::RotatingCollection; > >-# Copyright Josef Moravec 2016 >+# Copyright Josef Moravec 2017 > # > # This file is part of Koha. > # >@@ -22,7 +22,9 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use Koha::DateUtils; > use Koha::Exceptions; >+use Koha::Holds; > use Koha::Items; > use Koha::RotatingCollection::Trackings; > >@@ -115,6 +117,50 @@ sub remove_item { > return $collection_tracking->delete; > } > >+=head3 transfer >+ >+$collection->transfer( $library_object ) >+ >+throws >+ Koha::Exceptions::MissingParameter >+ Koha::Exceptions::ObjectNotFound >+ >+=cut >+ >+sub transfer { >+ my ( $self, $library ) = @_; >+ >+ Koha::Exceptions::MissingParameter->throw if not defined $library; >+ >+ Koha::Exceptions::ObjectNotFound->throw if ref($library) ne 'Koha::Library'; >+ >+ $self->colBranchcode( $library->branchcode )->store; >+ >+ my $from = C4::Context->userenv->{'branch'} if C4::Context->userenv; >+ >+ my $items = $self->items; >+ while ( my $item = $items->next ) { >+ my $holds = Koha::Holds->search( { >+ itemnumber => $item->itemnumber, >+ found => 'W', >+ } ); >+ >+ >+ # If no user context is defined the default from library for transfer will be the 'holding' one >+ $from = $item->holdingbranch if not defined $from; >+ unless ($holds->count || $item->get_transfer) { >+ my $transfer = Koha::Item::Transfer->new( { >+ frombranch => $from, >+ tobranch => $library->branchcode, >+ itemnumber => $item->itemnumber, >+ datesent => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), >+ comments => $self->colTitle, >+ } )->store; >+ $item->holdingbranch( $library->branchcode )->store; >+ } >+ } >+} >+ > =head3 type > > =cut >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tt >index f91ac72..8eac2dc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tt >@@ -10,14 +10,14 @@ > [% INCLUDE 'header.inc' %] > [% INCLUDE 'cat-search.inc' %] > >-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › <a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a> › <a href="/cgi-bin/koha/rotating_collections/addItems.pl?colId=[% colId | html %]">Collection <i>[% colTitle | html %]</i></a> › Transfer collection</div> >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › <a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a> › <a href="/cgi-bin/koha/rotating_collections/addItems.pl?colId=[% collection.colId | html %]">Collection <i>[% collection.colTitle | html %]</i></a> › Transfer collection</div> > > <div id="doc3" class="yui-t2"> > <div id="bd"> > <div id="yui-main"> > <div class="yui-b"> > >- <h1>Transfer collection <i>[% colTitle | html %]</i></h1> >+ <h1>Transfer collection <i>[% collection.colTitle | html %]</i></h1> > > [% IF ( transferSuccess ) %] > <div class="dialog message"> >@@ -35,7 +35,7 @@ > [% ELSE %] > <div> > <form action="transferCollection.pl" method="post"> >- <input type="hidden" name="colId" value="[% colId | html %]" /> >+ <input type="hidden" name="colId" value="[% collection.colId | html %]" /> > <fieldset class="rows"> > <ol> > <li> >diff --git a/rotating_collections/transferCollection.pl b/rotating_collections/transferCollection.pl >index 8c48ed9..c7795bd 100755 >--- a/rotating_collections/transferCollection.pl >+++ b/rotating_collections/transferCollection.pl >@@ -21,8 +21,8 @@ use Modern::Perl; > use C4::Output; > use C4::Auth; > use C4::Context; >-use C4::RotatingCollections; > >+use Koha::Libraries; > use Koha::RotatingCollections; > > use CGI qw ( -utf8 ); >@@ -32,6 +32,8 @@ my $query = new CGI; > my $colId = $query->param('colId'); > my $toBranch = $query->param('toBranch'); > >+my $collection = Koha::RotatingCollections->find( $colId ); >+ > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { > template_name => "rotating_collections/transferCollection.tt", >@@ -44,31 +46,20 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > ); > > ## Transfer collection >-my ( $success, $errorCode, $errorMessage ); > if ($toBranch) { >- ( $success, $errorCode, $errorMessage ) = >- TransferCollection( $colId, $toBranch ); >+ my $branch = Koha::Libraries->find( $toBranch ); >+ >+ my $transferred = eval ( $collection->transfer( $branch ) ); > >- if ($success) { >+ if ( $@ and not $transferred ) { >+ $template->param( transferFailure => 1 ); >+ } else { > $template->param( transferSuccess => 1 ); > } >- else { >- $template->param( >- transferFailure => 1, >- errorCode => $errorCode, >- errorMessage => $errorMessage >- ); >- } > } > >-## Get data about collection >-my $collection = Koha::RotatingCollections->find($colId); >- > $template->param( >- colId => $collection->colId, >- colTitle => $collection->colTitle, >- colDesc => $collection->colDesc, >- colBranchcode => $collection->colBranchcode, >+ collection => $collection, > ); > > output_html_with_http_headers $query, $cookie, $template->output; >-- >2.1.4
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 18606
:
63508
|
63509
|
63510
|
63511
|
63512
|
63513
|
63514
|
63515
|
63516
|
63517
|
63518
|
63519
|
63520
|
63521
|
63522
|
63523
|
63524
|
63525
|
63526
|
63527
|
63528
|
66227
|
66228
|
66229
|
66230
|
66231
|
66232
|
66233
|
66234
|
66235
|
66236
|
66237
|
66238
|
66239
|
66240
|
66241
|
66286
|
66287
|
66288
|
66289
|
66290
|
66291
|
66292
|
66293
|
66294
|
66295
|
66296
|
66297
|
66298
|
66299
|
66300
|
67734
|
67735
|
67736
|
67737
|
67738
|
67739
|
67740
|
67741
|
67742
|
67743
|
67744
|
67745
|
67746
|
67747
|
67748
|
67749
|
68428
|
68429
|
68430
|
68431
|
68432
|
68433
|
68434
|
68435
|
68436
|
68437
|
68438
|
68439
|
68440
|
68441
|
68442
|
68443
|
69709
|
69710
|
69711
|
69712
|
69713
|
69714
|
69715
|
69716
|
69717
|
69718
|
69719
|
69720
|
69721
|
69722
|
69723
|
69759
|
72416
|
72417
|
72418
|
72419
|
72420
|
72421
|
72422
|
72423
|
72424
|
72425
|
72426
|
72427
|
72428
|
72429
|
72430
|
72431
|
72572
|
72573
|
72574
|
72575
|
72576
|
72577
|
72578
|
72579
|
72580
|
72581
|
72582
|
72583
|
72584
|
72585
|
72586
|
72587
|
72816
|
79141
|
79142
|
79143
|
79144
|
79145
|
79146
|
79147
|
79148
| 79149 |
79150
|
79151
|
79152
|
79153
|
79154
|
79155
|
79156
|
79157
|
79158
|
79161