From 8f07fac1fa6772d354d2766a060b01244624a0a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 3 Feb 2021 12:30:04 +0100 Subject: [PATCH] =?utf8?q?DBUtils:=20Pr=C3=BCfung=20auf=20Trigram-Erweiter?= =?utf8?q?ung=20aus=20S/D/ShopOrder=20in=20DBUtils=20verschoben?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/ShopOrder.pm | 17 +---------------- SL/DBUtils.pm | 15 ++++++++++++++- t/shop/shop_order.t | 3 ++- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/SL/DB/ShopOrder.pm b/SL/DB/ShopOrder.pm index 4e125fbc9..684c49b28 100644 --- a/SL/DB/ShopOrder.pm +++ b/SL/DB/ShopOrder.pm @@ -122,7 +122,7 @@ sub check_for_existing_customers { my $zipcode = $self->billing_street ne '' ? $self->billing_zipcode : ''; my $email = $self->billing_street ne '' ? $self->billing_email : ''; - if($self->check_trgm) { + if(check_trgm($::form->get_standard_dbh())) { # Fuzzysearch for street to find e.g. "Dorfstrasse - Dorfstr. - Dorfstraße" my $fs_query = <id <=> $other->id); } -sub check_trgm { - my ( $self ) = @_; - - my $dbh = $::form->get_standard_dbh(); - my $sql = "SELECT installed_version FROM pg_available_extensions WHERE name = 'pg_trgm'"; - my @version = selectall_hashref_query($::form, $dbh, $sql); - - return 1 if($version[0]->{installed_version}); - return 0; -} - sub has_differing_delivery_address { my ($self) = @_; ($self->billing_firstname // '') ne ($self->delivery_firstname // '') || @@ -294,10 +283,6 @@ When it is 0 get customer creates a new customer object of the shop order billin =item C -=item C - -Checks if the postgresextension pg_trgm is installed and return 0 or 1. - =back =head1 TODO diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index 9d1bcace9..f0952440e 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -13,7 +13,7 @@ our @EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_stateme selectall_ids prepare_execute_query prepare_query create_sort_spec does_table_exist - add_token); + add_token check_trgm); use strict; @@ -398,6 +398,14 @@ sub role_is_superuser { return $is_superuser; } +sub check_trgm { + my ($dbh) = @_; + + my $version = $dbh->selectrow_array(qq|SELECT installed_version FROM pg_available_extensions WHERE name = 'pg_trgm'|); + + return !!$version; +} + 1; @@ -684,6 +692,11 @@ application (e.g. if the user clicked on a column header in a report). If it is undefined then the 'default_dir' parameter will be used instead. +=item check_trgm + +Checks if the postgresextension pg_trgm is installed and return trueish +or falsish. + =back =head1 DEBUG FUNCTIONS diff --git a/t/shop/shop_order.t b/t/shop/shop_order.t index f8ea56e09..e40ec2fcf 100644 --- a/t/shop/shop_order.t +++ b/t/shop/shop_order.t @@ -5,6 +5,7 @@ use lib 't'; use Support::TestSetup; use Carp; use Test::Exception; +use SL::DBUtils qw(check_trgm); use SL::Dev::ALL; use SL::Dev::Part qw(new_part); use SL::Dev::Shop qw(new_shop new_shop_part new_shop_order); @@ -71,7 +72,7 @@ Support::TestSetup::login(); reset_state(); -my $trgm = SL::DB::ShopOrder->check_trgm; +my $trgm = check_trgm($::form->get_standard_dbh()); my $shop_trans_id = 1; -- 2.20.1