Bugzilla – Attachment 189225 Details for
Bug 38050
Add REST endpoints for working with "lists"/"virtual shelves"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38050: move sortfield validation to method for reuse
Bug-38050-move-sortfield-validation-to-method-for-.patch (text/plain), 3.20 KB, created by
Jacob O'Mara
on 2025-11-06 19:56:36 UTC
(
hide
)
Description:
Bug 38050: move sortfield validation to method for reuse
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2025-11-06 19:56:36 UTC
Size:
3.20 KB
patch
obsolete
>From 819bcb4abe188e7b061089b3a59e65c9c4764cea Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <Jacob.omara@openfifth.co.uk> >Date: Wed, 5 Nov 2025 21:34:28 +0000 >Subject: [PATCH] Bug 38050: move sortfield validation to method for reuse > >Call method instead of repeating the validation logic >--- > Koha/Virtualshelf.pm | 25 +++++++++++++++++++++++++ > virtualshelves/shelves.pl | 13 ++----------- > 2 files changed, 27 insertions(+), 11 deletions(-) > >diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm >index 339351b6226..9d4665422c0 100644 >--- a/Koha/Virtualshelf.pm >+++ b/Koha/Virtualshelf.pm >@@ -70,6 +70,9 @@ sub store { > $self->created_on(dt_from_string) > unless defined $self->created_on; > >+ $self->sortfield( $self->_validate_sortfield( $self->sortfield ) ) >+ if $self->sortfield; >+ > return $self->SUPER::store($self); > } > >@@ -547,6 +550,28 @@ sub public_read_list { > > =head2 Internal methods > >+=head3 _validate_sortfield >+ >+Validates and normalizes the sortfield value. >+Defaults to 'title' if invalid, and converts 'copyrightdate' to 'publicationyear' for UNIMARC. >+ >+=cut >+ >+sub _validate_sortfield { >+ my ( $self, $sortfield ) = @_; >+ >+ # Default to 'title' if invalid >+ $sortfield = 'title' >+ unless grep { $_ eq $sortfield } qw( title author copyrightdate publicationyear itemcallnumber dateadded ); >+ >+ # Convert copyrightdate to publicationyear for UNIMARC >+ if ( $sortfield eq 'copyrightdate' && C4::Context->preference('marcflavour') eq 'UNIMARC' ) { >+ $sortfield = 'publicationyear'; >+ } >+ >+ return $sortfield; >+} >+ > =head3 _type > > =cut >diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl >index f64caf75428..15770e07ea8 100755 >--- a/virtualshelves/shelves.pl >+++ b/virtualshelves/shelves.pl >@@ -123,11 +123,7 @@ if ( $op eq 'add_form' ) { > if ($shelf) { > $op = $referer; > my $sortfield = $query->param('sortfield'); >- $sortfield = 'title' >- unless grep { $_ eq $sortfield } qw( title author copyrightdate publicationyear itemcallnumber dateadded ); >- if ( $sortfield eq 'copyrightdate' and C4::Context->preference('marcflavour') eq 'UNIMARC' ) { >- $sortfield = 'publicationyear'; >- } >+ $sortfield = $shelf->_validate_sortfield($sortfield); > if ( $shelf->can_be_managed($loggedinuser) ) { > $shelf->shelfname( scalar $query->param('shelfname') ); > $shelf->sortfield($sortfield); >@@ -294,12 +290,7 @@ if ( $op eq 'view' ) { > $query->param('sortfield') > || $shelf->sortfield > || 'title'; # Passed in sorting overrides default sorting >- $sortfield = 'title' >- unless grep { $_ eq $sortfield } >- qw( title author copyrightdate publicationyear itemcallnumber dateadded ); >- if ( $sortfield eq 'copyrightdate' and C4::Context->preference('marcflavour') eq 'UNIMARC' ) { >- $sortfield = 'publicationyear'; >- } >+ $sortfield = $shelf->_validate_sortfield($sortfield); > my $direction = $query->param('direction') || 'asc'; > $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc'; > my $rows; >-- >2.39.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 38050
:
174807
|
174808
|
174809
|
174810
|
176462
|
176463
|
176464
|
176465
|
176466
|
176467
|
176769
|
176770
|
176771
|
176772
|
176773
|
176774
|
180788
|
180789
|
180790
|
180791
|
180792
|
180793
|
180838
|
180839
|
180840
|
180841
|
180842
|
180843
|
180879
|
180880
|
180881
|
180882
|
180883
|
180884
|
189219
|
189220
|
189221
|
189222
|
189223
|
189224
| 189225