1# -- 2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/ 3# -- 4# This software comes with ABSOLUTELY NO WARRANTY. For details, see 5# the enclosed file COPYING for license information (GPL). If you 6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. 7# -- 8 9package Kernel::System::NotificationEvent; 10 11use strict; 12use warnings; 13 14use Kernel::Language qw(Translatable); 15use Kernel::System::VariableCheck qw(:all); 16 17our @ObjectDependencies = ( 18 'Kernel::System::DB', 19 'Kernel::System::Log', 20 'Kernel::System::Valid', 21 'Kernel::System::YAML', 22 'Kernel::System::Cache' 23); 24 25=head1 NAME 26 27Kernel::System::NotificationEvent - to manage the notifications 28 29=head1 DESCRIPTION 30 31All functions to manage the notification and the notification jobs. 32 33=head1 PUBLIC INTERFACE 34 35=head2 new() 36 37Don't use the constructor directly, use the ObjectManager instead: 38 39 my $NotificationEventObject = $Kernel::OM->Get('Kernel::System::NotificationEvent'); 40 41=cut 42 43sub new { 44 my ( $Type, %Param ) = @_; 45 46 # allocate new hash for object 47 my $Self = {}; 48 bless( $Self, $Type ); 49 50 $Self->{CacheType} = 'NotificationEvent'; 51 $Self->{CacheTTL} = 60 * 60 * 24 * 20; 52 return $Self; 53} 54 55=head2 NotificationList() 56 57returns a hash of all notifications 58 59 my %List = $NotificationEventObject->NotificationList( 60 Type => 'Ticket', # type of notifications; default: 'Ticket' 61 Details => 1, # include notification detailed data. possible (0|1) # ; default: 0 62 All => 1, # optional: if given all notification types will be returned, even if type is given (possible: 0|1) 63 ); 64 65=cut 66 67sub NotificationList { 68 my ( $Self, %Param ) = @_; 69 70 $Param{Type} ||= 'Ticket'; 71 $Param{Details} = $Param{Details} ? 1 : 0; 72 $Param{All} = $Param{All} ? 1 : 0; 73 74 my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache'); 75 76 my $CacheKey = $Self->{CacheType} . '::' . $Param{Type} . '::' . $Param{Details} . '::' . $Param{All}; 77 my $CacheResult = $CacheObject->Get( 78 Type => $Self->{CacheType}, 79 Key => $CacheKey, 80 ); 81 82 if ( ref $CacheResult eq 'HASH' ) { 83 return %{$CacheResult}; 84 } 85 86 # get database object 87 my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); 88 89 $DBObject->Prepare( SQL => 'SELECT id FROM notification_event' ); 90 91 my @NotificationList; 92 while ( my @Row = $DBObject->FetchrowArray() ) { 93 push @NotificationList, $Row[0]; 94 } 95 96 my %Result; 97 98 ITEMID: 99 for my $ItemID ( sort @NotificationList ) { 100 101 my %NotificationData = $Self->NotificationGet( 102 ID => $ItemID, 103 UserID => 1, 104 ); 105 106 $NotificationData{Data}->{NotificationType} ||= ['Ticket']; 107 108 if ( !$Param{All} ) { 109 next ITEMID if $NotificationData{Data}->{NotificationType}->[0] ne $Param{Type}; 110 } 111 112 if ( $Param{Details} ) { 113 $Result{$ItemID} = \%NotificationData; 114 } 115 else { 116 $Result{$ItemID} = $NotificationData{Name}; 117 } 118 } 119 120 $CacheObject->Set( 121 Type => $Self->{CacheType}, 122 Key => $CacheKey, 123 Value => \%Result, 124 TTL => $Self->{CacheTTL}, 125 ); 126 127 return %Result; 128} 129 130=head2 NotificationGet() 131 132returns a hash of the notification data 133 134 my %Notification = $NotificationEventObject->NotificationGet( 135 Name => 'NotificationName', 136 ); 137 138 my %Notification = $NotificationEventObject->NotificationGet( 139 ID => 1, 140 ); 141 142Returns: 143 144 %Notification = ( 145 ID => 123, 146 Name => 'Agent::Move', 147 Data => { 148 Events => [ 'TicketQueueUpdate' ], 149 ... 150 Queue => [ 'SomeQueue' ], 151 }, 152 Message => { 153 en => { 154 Subject => 'Hello', 155 Body => 'Hello World', 156 ContentType => 'text/plain', 157 }, 158 de => { 159 Subject => 'Hallo', 160 Body => 'Hallo Welt', 161 ContentType => 'text/plain', 162 }, 163 }, 164 Comment => 'An optional comment', 165 ValidID => 1, 166 CreateTime => '2010-10-27 20:15:00', 167 CreateBy => 2, 168 ChangeTime => '2010-10-27 20:15:00', 169 ChangeBy => 1, 170 UserID => 3, 171 ); 172 173=cut 174 175sub NotificationGet { 176 my ( $Self, %Param ) = @_; 177 178 # check needed stuff 179 if ( !$Param{Name} && !$Param{ID} ) { 180 $Kernel::OM->Get('Kernel::System::Log')->Log( 181 Priority => 'error', 182 Message => 'Need Name or ID!', 183 ); 184 return; 185 } 186 187 # get database object 188 my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); 189 190 # general query structure 191 my $SQL = ' 192 SELECT id, name, valid_id, comments, create_time, create_by, change_time, change_by 193 FROM notification_event 194 WHERE '; 195 196 if ( $Param{Name} ) { 197 198 $DBObject->Prepare( 199 SQL => $SQL . 'name = ?', 200 Bind => [ \$Param{Name} ], 201 ); 202 } 203 else { 204 $DBObject->Prepare( 205 SQL => $SQL . 'id = ?', 206 Bind => [ \$Param{ID} ], 207 ); 208 } 209 210 # get notification event data 211 my %Data; 212 while ( my @Row = $DBObject->FetchrowArray() ) { 213 $Data{ID} = $Row[0]; 214 $Data{Name} = $Row[1]; 215 $Data{ValidID} = $Row[2]; 216 $Data{Comment} = $Row[3]; 217 $Data{CreateTime} = $Row[4]; 218 $Data{CreateBy} = $Row[5]; 219 $Data{ChangeTime} = $Row[6]; 220 $Data{ChangeBy} = $Row[7]; 221 } 222 223 return if !%Data; 224 225 # get notification event item data 226 $DBObject->Prepare( 227 SQL => ' 228 SELECT event_key, event_value 229 FROM notification_event_item 230 WHERE notification_id = ? 231 ORDER BY event_key, event_value ASC', 232 Bind => [ \$Data{ID} ], 233 ); 234 235 while ( my @Row = $DBObject->FetchrowArray() ) { 236 push @{ $Data{Data}->{ $Row[0] } }, $Row[1]; 237 } 238 239 # get notification event message data 240 $DBObject->Prepare( 241 SQL => ' 242 SELECT subject, text, content_type, language 243 FROM notification_event_message 244 WHERE notification_id = ?', 245 Bind => [ \$Data{ID} ], 246 ); 247 248 while ( my @Row = $DBObject->FetchrowArray() ) { 249 250 # add to message hash with the language as key 251 $Data{Message}->{ $Row[3] } = { 252 Subject => $Row[0], 253 Body => $Row[1], 254 ContentType => $Row[2], 255 }; 256 } 257 258 return %Data; 259} 260 261=head2 NotificationAdd() 262 263adds a new notification to the database 264 265 my $ID = $NotificationEventObject->NotificationAdd( 266 Name => 'Agent::OwnerUpdate', 267 Data => { 268 Events => [ 'TicketQueueUpdate' ], 269 ... 270 Queue => [ 'SomeQueue' ], 271 }, 272 Message => { 273 en => { 274 Subject => 'Hello', 275 Body => 'Hello World', 276 ContentType => 'text/plain', 277 }, 278 de => { 279 Subject => 'Hallo', 280 Body => 'Hallo Welt', 281 ContentType => 'text/plain', 282 }, 283 }, 284 Comment => 'An optional comment', # (optional) 285 ValidID => 1, 286 UserID => 123, 287 ); 288 289=cut 290 291sub NotificationAdd { 292 my ( $Self, %Param ) = @_; 293 294 # check needed stuff 295 for my $Argument (qw(Name Data Message ValidID UserID)) { 296 if ( !$Param{$Argument} ) { 297 $Kernel::OM->Get('Kernel::System::Log')->Log( 298 Priority => 'error', 299 Message => "Need $Argument!", 300 ); 301 return; 302 } 303 } 304 305 # check if job name already exists 306 my %Check = $Self->NotificationGet( 307 Name => $Param{Name}, 308 ); 309 if (%Check) { 310 $Kernel::OM->Get('Kernel::System::Log')->Log( 311 Priority => 'error', 312 Message => "A notification with the name '$Param{Name}' already exists.", 313 ); 314 return; 315 } 316 317 # check message parameter 318 if ( !IsHashRefWithData( $Param{Message} ) ) { 319 $Kernel::OM->Get('Kernel::System::Log')->Log( 320 Priority => 'error', 321 Message => "Need Message!", 322 ); 323 return; 324 } 325 326 # check each argument for each message language 327 for my $Language ( sort keys %{ $Param{Message} } ) { 328 329 for my $Argument (qw(Subject Body ContentType)) { 330 331 # error if message data is incomplete 332 if ( !$Param{Message}->{$Language}->{$Argument} ) { 333 $Kernel::OM->Get('Kernel::System::Log')->Log( 334 Priority => 'error', 335 Message => "Need Message argument '$Argument' for language '$Language'!", 336 ); 337 return; 338 } 339 340 # fix some bad stuff from some browsers (Opera)! 341 $Param{Message}->{$Language}->{Body} =~ s/(\n\r|\r\r\n|\r\n|\r)/\n/g; 342 } 343 } 344 345 # get database object 346 my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); 347 348 # insert data into db 349 return if !$DBObject->Do( 350 SQL => ' 351 INSERT INTO notification_event 352 (name, valid_id, comments, create_time, create_by, change_time, change_by) 353 VALUES (?, ?, ?, current_timestamp, ?, current_timestamp, ?)', 354 Bind => [ 355 \$Param{Name}, \$Param{ValidID}, \$Param{Comment}, 356 \$Param{UserID}, \$Param{UserID}, 357 ], 358 ); 359 360 # get id 361 $DBObject->Prepare( 362 SQL => 'SELECT id FROM notification_event WHERE name = ?', 363 Bind => [ \$Param{Name} ], 364 ); 365 366 my $ID; 367 while ( my @Row = $DBObject->FetchrowArray() ) { 368 $ID = $Row[0]; 369 } 370 371 # error handling 372 if ( !$ID ) { 373 $Kernel::OM->Get('Kernel::System::Log')->Log( 374 Priority => 'error', 375 Message => "Could not get ID for just added notification '$Param{Name}'!", 376 ); 377 return; 378 } 379 380 # insert notification event item data 381 for my $Key ( sort keys %{ $Param{Data} } ) { 382 383 ITEM: 384 for my $Item ( @{ $Param{Data}->{$Key} } ) { 385 386 next ITEM if !defined $Item; 387 next ITEM if $Item eq ''; 388 389 return if !$DBObject->Do( 390 SQL => ' 391 INSERT INTO notification_event_item 392 (notification_id, event_key, event_value) 393 VALUES (?, ?, ?)', 394 Bind => [ \$ID, \$Key, \$Item ], 395 ); 396 } 397 } 398 399 # insert notification event message data 400 for my $Language ( sort keys %{ $Param{Message} } ) { 401 402 my %Message = %{ $Param{Message}->{$Language} }; 403 404 return if !$DBObject->Do( 405 SQL => ' 406 INSERT INTO notification_event_message 407 (notification_id, subject, text, content_type, language) 408 VALUES (?, ?, ?, ?, ?)', 409 Bind => [ 410 \$ID, 411 \$Message{Subject}, 412 \$Message{Body}, 413 \$Message{ContentType}, 414 \$Language, 415 ], 416 ); 417 } 418 419 $Kernel::OM->Get('Kernel::System::Cache')->CleanUp( 420 Type => $Self->{CacheType}, 421 ); 422 423 return $ID; 424} 425 426=head2 NotificationUpdate() 427 428update a notification in database 429 430 my $Ok = $NotificationEventObject->NotificationUpdate( 431 ID => 123, 432 Name => 'Agent::OwnerUpdate', 433 Data => { 434 Events => [ 'TicketQueueUpdate' ], 435 ... 436 Queue => [ 'SomeQueue' ], 437 }, 438 Message => { 439 en => { 440 Subject => 'Hello', 441 Body => 'Hello World', 442 ContentType => 'text/plain', 443 }, 444 de => { 445 Subject => 'Hallo', 446 Body => 'Hallo Welt', 447 ContentType => 'text/plain', 448 }, 449 }, 450 Comment => 'An optional comment', # (optional) 451 ValidID => 1, 452 UserID => 123, 453 ); 454 455=cut 456 457sub NotificationUpdate { 458 my ( $Self, %Param ) = @_; 459 460 # Check needed stuff. 461 for my $Argument (qw(ID Name Data ValidID UserID)) { 462 463 if ( !$Param{$Argument} ) { 464 $Kernel::OM->Get('Kernel::System::Log')->Log( 465 Priority => 'error', 466 Message => "Need $Argument!", 467 ); 468 return; 469 } 470 } 471 472 # Check message parameter. 473 if ( 474 !$Param{PossibleEmptyMessage} 475 && !IsHashRefWithData( $Param{Message} ) 476 ) 477 { 478 479 $Kernel::OM->Get('Kernel::System::Log')->Log( 480 Priority => 'error', 481 Message => "Need Message!", 482 ); 483 return; 484 } 485 486 # Check each argument for each message language. 487 for my $Language ( sort keys %{ $Param{Message} // {} } ) { 488 489 for my $Argument (qw(Subject Body ContentType)) { 490 491 # Error if message data is incomplete. 492 if ( !$Param{Message}->{$Language}->{$Argument} ) { 493 $Kernel::OM->Get('Kernel::System::Log')->Log( 494 Priority => 'error', 495 Message => "Need Message argument '$Argument' for language '$Language'!", 496 ); 497 return; 498 } 499 500 # Fix some bad stuff from some browsers (Opera)! 501 $Param{Message}->{$Language}->{Body} =~ s/(\n\r|\r\r\n|\r\n|\r)/\n/g; 502 } 503 } 504 505 my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); 506 507 # Update data in db/ 508 return if !$DBObject->Do( 509 SQL => ' 510 UPDATE notification_event 511 SET name = ?, valid_id = ?, comments = ?, change_time = current_timestamp, change_by = ? 512 WHERE id = ?', 513 Bind => [ 514 \$Param{Name}, \$Param{ValidID}, 515 \$Param{Comment}, \$Param{UserID}, 516 \$Param{ID}, 517 ], 518 ); 519 520 # Delete existing notification event item data. 521 $DBObject->Do( 522 SQL => 'DELETE FROM notification_event_item WHERE notification_id = ?', 523 Bind => [ \$Param{ID} ], 524 ); 525 526 # Add new notification event item data. 527 for my $Key ( sort keys %{ $Param{Data} } ) { 528 529 ITEM: 530 for my $Item ( @{ $Param{Data}->{$Key} } ) { 531 532 next ITEM if !defined $Item; 533 next ITEM if $Item eq ''; 534 535 $DBObject->Do( 536 SQL => ' 537 INSERT INTO notification_event_item 538 (notification_id, event_key, event_value) 539 VALUES (?, ?, ?)', 540 Bind => [ 541 \$Param{ID}, 542 \$Key, 543 \$Item, 544 ], 545 ); 546 } 547 } 548 549 # Delete existing notification event message data. 550 $DBObject->Do( 551 SQL => 'DELETE FROM notification_event_message WHERE notification_id = ?', 552 Bind => [ \$Param{ID} ], 553 ); 554 555 # Insert new notification event message data. 556 for my $Language ( sort keys %{ $Param{Message} // {} } ) { 557 558 my %Message = %{ $Param{Message}->{$Language} }; 559 560 $DBObject->Do( 561 SQL => ' 562 INSERT INTO notification_event_message 563 (notification_id, subject, text, content_type, language) 564 VALUES (?, ?, ?, ?, ?)', 565 Bind => [ 566 \$Param{ID}, 567 \$Message{Subject}, 568 \$Message{Body}, 569 \$Message{ContentType}, 570 \$Language, 571 ], 572 ); 573 } 574 575 $Kernel::OM->Get('Kernel::System::Cache')->CleanUp( 576 Type => $Self->{CacheType}, 577 ); 578 579 return 1; 580} 581 582=head2 NotificationDelete() 583 584deletes an notification from the database 585 586 $NotificationEventObject->NotificationDelete( 587 ID => 1, 588 UserID => 123, 589 ); 590 591=cut 592 593sub NotificationDelete { 594 my ( $Self, %Param ) = @_; 595 596 # check needed stuff 597 for my $Argument (qw(ID UserID)) { 598 if ( !$Param{$Argument} ) { 599 $Kernel::OM->Get('Kernel::System::Log')->Log( 600 Priority => 'error', 601 Message => "Need $Argument!", 602 ); 603 return; 604 } 605 } 606 607 # check if job name exists 608 my %Check = $Self->NotificationGet( 609 ID => $Param{ID}, 610 ); 611 if ( !%Check ) { 612 $Kernel::OM->Get('Kernel::System::Log')->Log( 613 Priority => 'error', 614 Message => "Can't delete notification with ID '$Param{ID}'. Notification does not exist!", 615 ); 616 return; 617 } 618 619 # get database object 620 my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); 621 622 # delete notification event item 623 my $DeleteOK = $DBObject->Do( 624 SQL => 'DELETE FROM notification_event_item WHERE notification_id = ?', 625 Bind => [ \$Param{ID} ], 626 ); 627 628 # error handling 629 if ( !$DeleteOK ) { 630 $Kernel::OM->Get('Kernel::System::Log')->Log( 631 Priority => 'error', 632 Message => "Can't delete notification_event_item with ID '$Param{ID}'!", 633 ); 634 return; 635 } 636 637 # delete notification event message 638 $DeleteOK = $DBObject->Do( 639 SQL => 'DELETE FROM notification_event_message WHERE notification_id = ?', 640 Bind => [ \$Param{ID} ], 641 ); 642 643 # error handling 644 if ( !$DeleteOK ) { 645 $Kernel::OM->Get('Kernel::System::Log')->Log( 646 Priority => 'error', 647 Message => "Can't delete notification_event_message with ID '$Param{ID}'!", 648 ); 649 return; 650 } 651 652 # delete notification event 653 $DeleteOK = $DBObject->Do( 654 SQL => 'DELETE FROM notification_event WHERE id = ?', 655 Bind => [ \$Param{ID} ], 656 ); 657 658 # error handling 659 if ( !$DeleteOK ) { 660 $Kernel::OM->Get('Kernel::System::Log')->Log( 661 Priority => 'error', 662 Message => "Can't delete notification_event with ID '$Param{ID}'!", 663 ); 664 return; 665 } 666 667 $Kernel::OM->Get('Kernel::System::Cache')->CleanUp( 668 Type => $Self->{CacheType}, 669 ); 670 671 # success 672 $Kernel::OM->Get('Kernel::System::Log')->Log( 673 Priority => 'notice', 674 Message => "NotificationEvent notification '$Check{Name}' deleted (UserID=$Param{UserID}).", 675 ); 676 677 return 1; 678} 679 680=head2 NotificationEventCheck() 681 682returns array of notification affected by event 683 684 my @IDs = $NotificationEventObject->NotificationEventCheck( 685 Event => 'ArticleCreate', 686 ); 687 688=cut 689 690sub NotificationEventCheck { 691 my ( $Self, %Param ) = @_; 692 693 # check needed stuff 694 if ( !$Param{Event} ) { 695 $Kernel::OM->Get('Kernel::System::Log')->Log( 696 Priority => 'error', 697 Message => 'Need Name!', 698 ); 699 return; 700 } 701 702 # get needed objects 703 my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); 704 my $ValidObject = $Kernel::OM->Get('Kernel::System::Valid'); 705 706 my @ValidIDs = $ValidObject->ValidIDsGet(); 707 my $ValidIDString = join ', ', @ValidIDs; 708 709 $DBObject->Prepare( 710 SQL => " 711 SELECT DISTINCT(nei.notification_id) 712 FROM notification_event ne, notification_event_item nei 713 WHERE ne.id = nei.notification_id 714 AND ne.valid_id IN ( $ValidIDString ) 715 AND nei.event_key = 'Events' 716 AND nei.event_value = ? 717 ORDER BY nei.notification_id ASC", 718 Bind => [ \$Param{Event} ], 719 ); 720 721 my @IDs; 722 while ( my @Row = $DBObject->FetchrowArray() ) { 723 push @IDs, $Row[0]; 724 } 725 726 return @IDs; 727} 728 729=head2 NotificationImport() 730 731import an Notification YAML file/content 732 733 my $NotificationImport = $NotificationEventObject->NotificationImport( 734 Content => $YAMLContent, # mandatory, YAML format 735 OverwriteExistingNotifications => 0, # 0 || 1 736 UserID => 1, # mandatory 737 ); 738 739Returns: 740 741 $NotificationImport = { 742 Success => 1, # 1 if success or undef if operation could not 743 # be performed 744 Message => 'The Message to show.', # error message 745 AddedNotifications => 'Notification1, Notification2', # list of Notifications correctly added 746 UpdatedNotifications => 'Notification3, Notification4', # list of Notifications correctly updated 747 NotificationErrors => 'Notification5', # list of Notifications that could not be added or updated 748 }; 749 750=cut 751 752sub NotificationImport { 753 my ( $Self, %Param ) = @_; 754 755 for my $Needed (qw(Content UserID)) { 756 757 # check needed stuff 758 if ( !$Param{$Needed} ) { 759 $Kernel::OM->Get('Kernel::System::Log')->Log( 760 Priority => 'error', 761 Message => "Need $Needed!", 762 ); 763 return { 764 Success => 0, 765 Message => "$Needed is missing can not continue.", 766 }; 767 } 768 } 769 770 my $NotificationData = $Kernel::OM->Get('Kernel::System::YAML')->Load( 771 Data => $Param{Content}, 772 ); 773 774 if ( ref $NotificationData ne 'ARRAY' ) { 775 return { 776 Success => 0, 777 Message => 778 Translatable("Couldn't read Notification configuration file. Please make sure the file is valid."), 779 }; 780 } 781 782 # Check notification message length for every language. 783 for my $Language ( sort keys %{ $NotificationData->[0]->{Message} } ) { 784 my $Check = $Self->NotificationBodyCheck( 785 Content => $NotificationData->[0]->{Message}->{$Language}->{Body}, 786 UserID => $Param{UserID}, 787 ); 788 789 if ( !$Check ) { 790 return { 791 Success => 0, 792 Message => 793 Translatable('Imported notification has body text with more than 4000 characters.'), 794 }; 795 } 796 } 797 798 my @UpdatedNotifications; 799 my @AddedNotifications; 800 my @NotificationErrors; 801 802 my %CurrentNotifications = $Self->NotificationList( 803 %Param, 804 UserID => $Param{UserID}, 805 ); 806 my %ReverseCurrentNotifications = reverse %CurrentNotifications; 807 808 Notification: 809 for my $Notification ( @{$NotificationData} ) { 810 811 next Notification if !$Notification; 812 next Notification if ref $Notification ne 'HASH'; 813 814 if ( $Param{OverwriteExistingNotifications} && $ReverseCurrentNotifications{ $Notification->{Name} } ) { 815 my $Success = $Self->NotificationUpdate( 816 %{$Notification}, 817 ID => $ReverseCurrentNotifications{ $Notification->{Name} }, 818 UserID => $Param{UserID}, 819 ); 820 821 if ($Success) { 822 push @UpdatedNotifications, $Notification->{Name}; 823 } 824 else { 825 push @NotificationErrors, $Notification->{Name}; 826 } 827 } 828 else { 829 830 # now add the Notification 831 my $Success = $Self->NotificationAdd( 832 %{$Notification}, 833 UserID => $Param{UserID}, 834 ); 835 836 if ($Success) { 837 push @AddedNotifications, $Notification->{Name}; 838 } 839 else { 840 push @NotificationErrors, $Notification->{Name}; 841 } 842 } 843 } 844 845 return { 846 Success => 1, 847 AddedNotifications => join( ', ', @AddedNotifications ) || '', 848 UpdatedNotifications => join( ', ', @UpdatedNotifications ) || '', 849 NotificationErrors => join( ', ', @NotificationErrors ) || '', 850 }; 851} 852 853=head2 NotificationBodyCheck() 854 855Check if body has a proper length depending on DB type. 856 857 my $Ok = $NotificationEventObject->NotificationBodyCheck( 858 Content => $BodyContent, # mandatory 859 UserID => 1, # mandatory 860 ); 861 862=cut 863 864sub NotificationBodyCheck { 865 my ( $Self, %Param ) = @_; 866 867 # Check needed stuff. 868 if ( !$Param{Content} ) { 869 $Kernel::OM->Get('Kernel::System::Log')->Log( 870 Priority => 'error', 871 Message => "Need Content!", 872 ); 873 return; 874 } 875 876 my $DBType = $Kernel::OM->Get('Kernel::System::DB')->{'DB::Type'}; 877 878 # Body field length in the database is strictly set to 4000 characters for both PostgreSQL and Oracle backends. 879 # Since this restriction was not enforced for MySQL previously, it was possible to enter longer texts in the 880 # table. Because of this, we must now for reasons on backwards compatibility limit the body size only for those 881 # backends, at least until the next major version and planned field size change. 882 # Please see both bug#12843 (original semi-reverted fix) and bug#13281 for more information. 883 if ( 884 ( 885 $DBType eq 'postgresql' 886 || $DBType eq 'oracle' 887 ) 888 && length $Param{Content} > 4000 889 ) 890 { 891 return 0; 892 } 893 894 return 1; 895} 896 8971; 898 899=head1 TERMS AND CONDITIONS 900 901This software is part of the OTRS project (L<https://otrs.org/>). 902 903This software comes with ABSOLUTELY NO WARRANTY. For details, see 904the enclosed file COPYING for license information (GPL). If you 905did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>. 906 907=cut 908