Bugzilla – Attachment 66292 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 AddItemToCollection
Bug-18606-Get-rid-of-AddItemToCollection.patch (text/plain), 5.48 KB, created by
Josef Moravec
on 2017-08-21 20:25:41 UTC
(
hide
)
Description:
Bug 18606: Get rid of AddItemToCollection
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2017-08-21 20:25:41 UTC
Size:
5.48 KB
patch
obsolete
>From 1c30c12c68d77a5b44d1e3c0e1979c68af410917 Mon Sep 17 00:00:00 2001 >From: Josef Moravec <josef.moravec@gmail.com> >Date: Wed, 17 May 2017 11:36:05 +0000 >Subject: [PATCH] Bug 18606: Get rid of AddItemToCollection > >--- > C4/RotatingCollections.pm | 50 ---------------------------------------- > Koha/RotatingCollection.pm | 33 ++++++++++++++++++++++++++ > rotating_collections/addItems.pl | 31 +++++++++++++------------ > 3 files changed, 49 insertions(+), 65 deletions(-) > >diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm >index 521a4e9..b5aebd8 100644 >--- a/C4/RotatingCollections.pm >+++ b/C4/RotatingCollections.pm >@@ -48,61 +48,11 @@ BEGIN { > require Exporter; > @ISA = qw( Exporter ); > @EXPORT = qw( >- AddItemToCollection > RemoveItemFromCollection > TransferCollection > ); > } > >-=head2 AddItemToCollection >- >- ( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber ); >- >-Adds an item to a rotating collection. >- >- Input: >- $colId: Collection to add the item to. >- $itemnumber: Item to be added to the collection >- 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 AddItemToCollection { >- my ( $colId, $itemnumber ) = @_; >- >- ## Check for all necessary parameters >- if ( !$colId ) { >- return ( 0, 1, "NO_ID" ); >- } >- if ( !$itemnumber ) { >- return ( 0, 2, "NO_ITEM" ); >- } >- >- if ( isItemInThisCollection( $itemnumber, $colId ) ) { >- return ( 0, 2, "IN_COLLECTION" ); >- } >- elsif ( isItemInAnyCollection($itemnumber) ) { >- return ( 0, 3, "IN_COLLECTION_OTHER" ); >- } >- >- my $dbh = C4::Context->dbh; >- >- my $sth; >- $sth = $dbh->prepare(" >- INSERT INTO collections_tracking ( >- colId, >- itemnumber >- ) VALUES ( ?, ? ) >- "); >- $sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() ); >- >- return 1; >- >-} >- > =head2 RemoveItemFromCollection > > ( $success, $errorcode, $errormessage ) = RemoveItemFromCollection( $colId, $itemnumber ); >diff --git a/Koha/RotatingCollection.pm b/Koha/RotatingCollection.pm >index ba90192..dbc97ba 100644 >--- a/Koha/RotatingCollection.pm >+++ b/Koha/RotatingCollection.pm >@@ -22,7 +22,9 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use Koha::Exceptions; > use Koha::Items; >+use Koha::RotatingCollection::Trackings; > > use base qw(Koha::Object); > >@@ -54,6 +56,37 @@ sub items { > return $items; > } > >+=head3 add_item >+ >+$collection->add_item( $item_object ); >+ >+throws >+ Koha::Exceptions::MissingParameter >+ Koha::Exceptions::DuplicateObject >+ Koha::Exceptions::ObjectNotFound >+ >+=cut >+ >+sub add_item { >+ my ( $self, $item ) = @_; >+ >+ Koha::Exceptions::MissingParameter->throw if not defined $item; >+ >+ Koha::Exceptions::ObjectNotFound->throw if ref($item) ne 'Koha::Item'; >+ >+ Koha::Exceptions::DuplicateObject->throw >+ if Koha::RotatingCollection::Trackings->search( { itemnumber => $item->itemnumber } )->count; >+ >+ my $col_tracking = Koha::RotatingCollection::Tracking->new( >+ { >+ colId => $self->colId, >+ itemnumber => $item->itemnumber, >+ } >+ )->store; >+ >+ return $col_tracking; >+} >+ > =head3 type > > =cut >diff --git a/rotating_collections/addItems.pl b/rotating_collections/addItems.pl >index 8ef4645..c0ef9a7 100755 >--- a/rotating_collections/addItems.pl >+++ b/rotating_collections/addItems.pl >@@ -24,6 +24,7 @@ use C4::Context; > use C4::RotatingCollections; > use C4::Items; > >+use Koha::Items; > use Koha::RotatingCollections; > > use CGI qw ( -utf8 ); >@@ -41,32 +42,33 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >+my @errors; >+my @messages; >+my $colId = $query->param('colId'); >+my $collection = Koha::RotatingCollections->find($colId); >+ > if ( $query->param('action') eq 'addItem' ) { > ## Add the given item to the collection >- my $colId = $query->param('colId'); > my $barcode = $query->param('barcode'); > my $removeItem = $query->param('removeItem'); >- my $itemnumber = GetItemnumberFromBarcode($barcode); >+ my $item = Koha::Items->search( { barcode => $barcode } )->next; > > my ( $success, $errorCode, $errorMessage ); > > $template->param( barcode => $barcode ); > > if ( !$removeItem ) { >- ( $success, $errorCode, $errorMessage ) = >- AddItemToCollection( $colId, $itemnumber ); >+ my $added = eval { $collection->add_item( $item ) }; >+ >+ if ( $@ or not $added ) { >+ push @errors, { code => 'error_adding_item' }; >+ } else { >+ push @messages, { code => 'success_adding_item' }; >+ } > > $template->param( > previousActionAdd => 1, > ); >- >- if ($success) { >- $template->param( addSuccess => 1 ); >- } >- else { >- $template->param( addFailure => 1 ); >- $template->param( failureMessage => $errorMessage ); >- } > } > else { > ## Remove the given item from the collection >@@ -89,11 +91,10 @@ if ( $query->param('action') eq 'addItem' ) { > } > } > >-my $colId = $query->param('colId'); >-my $collection = Koha::RotatingCollections->find($colId); >- > $template->param( > collection => $collection, >+ messages => \@messages, >+ errors => \@errors, > ); > > 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