Bug 17170: DB Updates
This patch adds the new table, permission, and a syspref to enable the feature Sponsored-by: Sponsored by: Round Rock Public Library [https://www.roundrocktexas.gov/departments/library/] Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
e0d992eb06
commit
47228046ee
|
|
@ -0,0 +1,92 @@
|
|||
package Koha::SearchFilter;
|
||||
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
|
||||
use Koha::Database;
|
||||
|
||||
use base qw(Koha::Object);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::SearchFilter - Koha Search filter object class
|
||||
|
||||
=head1 API
|
||||
|
||||
=head2 Class methods
|
||||
|
||||
=head3 to_api_mapping
|
||||
|
||||
=cut
|
||||
|
||||
sub to_api_mapping {
|
||||
return {
|
||||
id => 'search_filter_id',
|
||||
query => 'filter_query',
|
||||
limits => 'filter_limits',
|
||||
};
|
||||
}
|
||||
|
||||
=head3 expand_filter
|
||||
|
||||
my $expanded_filter = $filter->expand_filter;
|
||||
|
||||
Returns the filter as an arrayref of limit queries suitable to
|
||||
be passed to QueryBuilder
|
||||
|
||||
=cut
|
||||
|
||||
sub expand_filter {
|
||||
my $self = shift;
|
||||
|
||||
my $query_part = $self->query;
|
||||
my $limits_part = $self->limits;
|
||||
|
||||
my $limits = decode_json($limits_part)->{limits};
|
||||
|
||||
my $query = decode_json($query_part);
|
||||
my $operators = $query->{operators};
|
||||
my $operands = $query->{operands};
|
||||
my $indexes = $query->{indexes};
|
||||
|
||||
my $query_limit;
|
||||
for( my $i = 0; $i < scalar @$operands; $i++ ){
|
||||
next unless @$operands[$i];
|
||||
my $index = @$indexes[$i] ? @$indexes[$i] . "=" : "";
|
||||
my $query = "(" . @$operands[$i] . ")";
|
||||
my $operator = "";
|
||||
$operator = @$operators[$i-1] ? " " . @$operators[$i-1] . " " : scalar @$operands > $i ? " AND " : "" if $i > 0;
|
||||
my $limit = $operator . $index . $query;
|
||||
$query_limit .= $limit;
|
||||
}
|
||||
|
||||
push @$limits, "(".$query_limit.")" if $query_limit;
|
||||
|
||||
return $limits;
|
||||
}
|
||||
|
||||
=head2 Internal methods
|
||||
|
||||
=head3 _type
|
||||
|
||||
=cut
|
||||
|
||||
sub _type {
|
||||
return 'SearchFilter';
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package Koha::SearchFilters;
|
||||
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
|
||||
use Koha::Database;
|
||||
|
||||
use Koha::SearchFilter;
|
||||
|
||||
use base qw(Koha::Objects);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::SearchFilters - Koha Search filters object set class
|
||||
|
||||
=head1 API
|
||||
|
||||
=head2 Class Methods
|
||||
|
||||
=cut
|
||||
|
||||
=head3 type
|
||||
|
||||
=cut
|
||||
|
||||
sub _type {
|
||||
return 'SearchFilter';
|
||||
}
|
||||
|
||||
=head3 object_class
|
||||
|
||||
=cut
|
||||
|
||||
sub object_class {
|
||||
return 'Koha::SearchFilter';
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
use Modern::Perl;
|
||||
|
||||
return {
|
||||
bug_number => "17170",
|
||||
description => "Add permission for creating saved search filters",
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
||||
$dbh->do(q{
|
||||
INSERT IGNORE INTO permissions (module_bit, code, description) VALUES
|
||||
(3, 'manage_search_filters', 'Manage custom search filters');
|
||||
});
|
||||
say $out "Added manage_search_filters permission";
|
||||
unless( TableExists( 'search_filters' ) ){
|
||||
$dbh->do(q{
|
||||
CREATE TABLE `search_filters` (
|
||||
id int(11) NOT NULL auto_increment, -- unique identifier for each search filter
|
||||
name varchar(255) NOT NULL, -- display name for this filter
|
||||
query mediumtext DEFAULT NULL, -- query part of the filter, can be blank
|
||||
limits mediumtext DEFAULT NULL, -- limits part of the filter, can be blank
|
||||
opac tinyint(1) NOT NULL DEFAULT 0, -- whether this filter is shown on OPAC
|
||||
staff_client tinyint(1) NOT NULL DEFAULT 0, -- whether this filter is shown in staff client
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
|
||||
});
|
||||
say $out "Added search_filters table";
|
||||
} else {
|
||||
say $out "search_filters table already created";
|
||||
}
|
||||
$dbh->do(q{
|
||||
INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
|
||||
('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo')
|
||||
});
|
||||
say $out "Added SavedSearchFilters system preference";
|
||||
},
|
||||
}
|
||||
|
|
@ -4723,6 +4723,24 @@ CREATE TABLE `search_field` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `search_filters`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `search_filters`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `search_filters` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`query` mediumtext COLLATE utf8mb4_unicode_ci,
|
||||
`limits` mediumtext COLLATE utf8mb4_unicode_ci,
|
||||
`opac` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'whether this filter is shown on OPAC',
|
||||
`staff_client` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'whether this filter is shown in staff client',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `search_history`
|
||||
--
|
||||
|
|
|
|||
|
|
@ -623,6 +623,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
|
|||
('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
|
||||
('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> system preference.','70|10','Define a note to be shown on all routing lists','Textarea'),
|
||||
('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'),
|
||||
('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo'),
|
||||
('SCOAllowCheckin','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
|
||||
('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea'),
|
||||
('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded <style> tag.','free'),
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES
|
|||
( 3, 'manage_smtp_servers', 'Manage SMTP servers configuration'),
|
||||
( 3, 'manage_background_jobs', 'Manage background jobs'),
|
||||
( 3, 'manage_curbside_pickups', 'Manage curbside pickups'),
|
||||
( 3, 'manage_search_filters', 'Manage custom search filters'),
|
||||
( 4, 'delete_borrowers', 'Delete patrons'),
|
||||
( 4, 'edit_borrowers', 'Add, modify and view patron information'),
|
||||
( 4, 'view_borrower_infos_from_any_libraries', 'View patron infos from any libraries'),
|
||||
|
|
|
|||
|
|
@ -213,6 +213,11 @@
|
|||
Manage item search fields
|
||||
</span>
|
||||
<span class="permissioncode">([% name | html %])</span>
|
||||
[%- CASE 'manage_search_filters' -%]
|
||||
<span class="sub_permission manage_search_filters_subpermission">
|
||||
Manage saved search filters
|
||||
</span>
|
||||
<span class="permissioncode">([% name | html %])</span>
|
||||
[%- CASE 'manage_search_engine_config' -%]
|
||||
<span class="sub_permission manage_search_engine_config_subpermission">
|
||||
Manage search engine configuration
|
||||
|
|
|
|||
|
|
@ -87,6 +87,13 @@ Searching:
|
|||
0: Disable
|
||||
- "the cross_fields option for Elasticsearch searches, supported in Elasticsearch 6.X and above."
|
||||
- "See documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-cross-fields"
|
||||
-
|
||||
- pref: SavedSearchFilters
|
||||
default: 0
|
||||
choices:
|
||||
1: Enable
|
||||
0: Disable
|
||||
- "the option for staff with permission to create/edit custom saved search filters."
|
||||
Search form:
|
||||
-
|
||||
- pref : LoadSearchHistoryToTheFirstLoggedUser
|
||||
|
|
|
|||
Loading…
Reference in New Issue