From: Bernd Bleßmann Date: Wed, 3 Feb 2021 11:30:04 +0000 (+0100) Subject: DBUtils: Prüfung auf Trigram-Erweiterung aus S/D/ShopOrder in DBUtils verschoben X-Git-Tag: kivitendo-mebil_0.1-0~9^2~479 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=8f07fac1fa6772d354d2766a060b01244624a0a5;p=kivitendo-erp.git DBUtils: Prüfung auf Trigram-Erweiterung aus S/D/ShopOrder in DBUtils verschoben --- 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;