znuny / Znuny

Znuny/Znuny LTS is a fork of the ((OTRS)) Community Edition, one of the most flexible web-based ticketing systems used for Customer Service, Help Desk, IT Service Management.
https://www.znuny.org
GNU General Public License v3.0
355 stars 85 forks source link

Znuny 7 - Ticket notifications not sent #361

Closed cristalink closed 1 year ago

cristalink commented 1 year ago

Environment

Expected behaviour

Agents should receive emails notifications on ticket creation and update.

Actual behaviour

Emails are not sent and the following error is logged:

(in cleanup) Not a HASH reference at /opt/znuny-7.0.2/Kernel/System/TemplateGenerator.pm line 993.

Additional information

The problem seems to be with the newly added code in Kernel/System/Ticket/Event/NotificationEvent/Transport/Base.pm line 81:

sub GetTransportRecipients {
    my ( $Self, %Param ) = @_;
{
    return []; 
# Apparently, the above returns "( [] )" - an array with a single element, and the element is a reference to an empty
# array (I may not be entirely correct here as I am not a Perl expert).
# It should be this instead:
#  return ();
}

The return value from Transport::Activity::GetTransportRecipients() is then used in this loop at Kernel/System/Ticket/Event/NotificationEvent.pm @346:

RECIPIENT:
            for my $Recipient (@TransportRecipients) {
# *** Here, @TransportRecipients is "[ [] ]", $Recipient is "[]"
                # replace all notification tags for each special recipient
                my %ReplacedNotification = $TemplateGeneratorObject->NotificationEvent(
                    TicketData            => \%Ticket,
                    Recipient             => $Recipient,

There seem to be a similar problem in Kernel/System/Calendar/Event/Transport/Base.pm line 79, but it isn't hit in my scenario.

I was able to fix the issue by using "return ()" instead of "return []".

There's a number of places in Znuny that use "return []". Perhaps they need to be reviewed as well.

Thanks.

cristalink commented 1 year ago

Simple test at Online Perl Compiler:

sub ReturnSquare { return []; }
sub ReturnRound { return (); }

my @square = ReturnSquare;
my $square = @square;
my @round = ReturnRound;
my $round = @round;
print "ReturnSquare = " . \@square . ", [0] = " . @square[0] . ", count = " . $square . "\n";
print "ReturnRound = " . \@round . ", count = " . $round . "\n";

Result:

ReturnSquare = ARRAY(0x55bbe9141148), [0] = ARRAY(0x55bbe9118650), count = 1
ReturnRound = ARRAY(0x55bbe9141250), count = 0
dennykorsukewitz commented 1 year ago

Hi @cristalink, thanks for your report.

The analysis is absolutely correct as far as it goes. Many thanks for it. 👍🏼

I will write the code clearly and simply. This should prevent any misunderstandings.

sub GetTransportRecipients {
    my ( $Self, %Param ) = @_;

    my @TransportRecipients;
    return @TransportRecipients;
}

The fix will come with the next release, soon.

Regards :rocket: Denny

dennykorsukewitz commented 1 year ago

Fixed in 7.0.3 https://github.com/znuny/Znuny/commit/33d477adabb2ad711259e8a191191684e2c289aa