From c96cea16fe01716c1f70ab9dda1041df6f3db555 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Fri, 26 Jul 2024 15:37:00 +0200 Subject: [PATCH] fix(gorgone): Do not log errors when checking if we need to create/update db schema --- gorgone/gorgone/class/db.pm | 15 +++++++++++---- gorgone/gorgone/standard/library.pm | 6 ++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gorgone/gorgone/class/db.pm b/gorgone/gorgone/class/db.pm index 847678411fd..cd98953fbdb 100644 --- a/gorgone/gorgone/class/db.pm +++ b/gorgone/gorgone/class/db.pm @@ -311,14 +311,18 @@ sub do { } sub error { - my ($self, $error, $query) = @_; + my ($self, $error, $query, %options) = @_; my ($package, $filename, $line) = caller 1; + %options = () if (ref(\%options) ne 'HASH'); + chomp($query); $self->{lastError} = "SQL error: $error (caller: $package:$filename:$line) Query: $query "; - $self->{logger}->writeLogError($error); + unless ($options{no_log}) { + $self->{logger}->writeLogError($error); + } if ($self->{transaction_begin} == 1) { $self->rollback(); } @@ -336,6 +340,9 @@ sub query { my ($self) = shift; my ($status, $count) = (0, -1); my $statement_handle; + my %error_options = (); + + $error_options{no_log} = 1 if ($_[0]->{no_error_log}); while (1) { if (!defined($self->{instance})) { @@ -348,7 +355,7 @@ sub query { $count++; $statement_handle = $self->{instance}->prepare($_[0]->{query}); if (!defined($statement_handle)) { - $self->error($self->{instance}->errstr, $_[0]->{query}); + $self->error($self->{instance}->errstr, $_[0]->{query}, %error_options); $status = -1; last if ($self->{force} == 0 || ($self->{force} == 2 && $count == 1)); sleep(1); @@ -367,7 +374,7 @@ sub query { $rv = $statement_handle->execute(); } if (!$rv) { - $self->error($statement_handle->errstr, $_[0]->{query}); + $self->error($statement_handle->errstr, $_[0]->{query}, %error_options); $status = -1; last if ($self->{force} == 0 || ($self->{force} == 2 && $count == 1)); sleep(1); diff --git a/gorgone/gorgone/standard/library.pm b/gorgone/gorgone/standard/library.pm index 8a6426e6b9c..7f77215e0b6 100644 --- a/gorgone/gorgone/standard/library.pm +++ b/gorgone/gorgone/standard/library.pm @@ -952,9 +952,11 @@ sub init_database { return if (!defined($options{autocreate_schema}) || $options{autocreate_schema} != 1); my $db_version = '1.0'; - my ($status, $sth) = $options{gorgone}->{db_gorgone}->query({ query => q{SELECT `value` FROM gorgone_information WHERE `key` = 'version'} }); + # don't log errors for this query as we know the tables may not exist, and + # that's the info we're looking for + my ($status, $sth) = $options{gorgone}->{db_gorgone}->query({ query => q{SELECT `value` FROM gorgone_information WHERE `key` = 'version'}, no_error_log => 1 }); if ($status == -1) { - ($status, $sth) = $options{gorgone}->{db_gorgone}->query({ query => q{SELECT 1 FROM gorgone_identity LIMIT 1} }); + ($status, $sth) = $options{gorgone}->{db_gorgone}->query({ query => q{SELECT 1 FROM gorgone_identity LIMIT 1}, no_error_log => 1 }); if ($status == -1) { create_schema(gorgone => $options{gorgone}, logger => $options{logger}, version => $options{version}); return ;