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::SupportDataCollector::Plugin::OTRS::Ticket::StaticDBOrphanedRecords;
10
11use strict;
12use warnings;
13
14use parent qw(Kernel::System::SupportDataCollector::PluginBase);
15
16use Kernel::Language qw(Translatable);
17
18our @ObjectDependencies = (
19    'Kernel::Config',
20    'Kernel::System::DB',
21);
22
23sub GetDisplayPath {
24    return Translatable('OTRS');
25}
26
27sub Run {
28    my $Self = shift;
29
30    my $Module = $Kernel::OM->Get('Kernel::Config')->Get('Ticket::IndexModule');
31
32    # get database object
33    my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
34
35    if ( $Module !~ /StaticDB/ ) {
36
37        my ( $OrphanedTicketLockIndex, $OrphanedTicketIndex );
38
39        $DBObject->Prepare( SQL => 'SELECT count(*) from ticket_lock_index' );
40        while ( my @Row = $DBObject->FetchrowArray() ) {
41            $OrphanedTicketLockIndex = $Row[0];
42        }
43
44        if ($OrphanedTicketLockIndex) {
45            $Self->AddResultWarning(
46                Identifier => 'TicketLockIndex',
47                Label      => Translatable('Orphaned Records In ticket_lock_index Table'),
48                Value      => $OrphanedTicketLockIndex,
49                Message =>
50                    Translatable(
51                    'Table ticket_lock_index contains orphaned records. Please run bin/otrs.Console.pl "Maint::Ticket::QueueIndexCleanup" to clean the StaticDB index.'
52                    ),
53            );
54        }
55        else {
56            $Self->AddResultOk(
57                Identifier => 'TicketLockIndex',
58                Label      => Translatable('Orphaned Records In ticket_lock_index Table'),
59                Value      => $OrphanedTicketLockIndex || '0',
60            );
61        }
62
63        $DBObject->Prepare( SQL => 'SELECT count(*) from ticket_index' );
64        while ( my @Row = $DBObject->FetchrowArray() ) {
65            $OrphanedTicketIndex = $Row[0];
66        }
67
68        if ($OrphanedTicketLockIndex) {
69            $Self->AddResultWarning(
70                Identifier => 'TicketIndex',
71                Label      => Translatable('Orphaned Records In ticket_index Table'),
72                Value      => $OrphanedTicketIndex,
73                Message =>
74                    Translatable(
75                    'Table ticket_index contains orphaned records. Please run bin/otrs.Console.pl "Maint::Ticket::QueueIndexCleanup" to clean the StaticDB index.'
76                    ),
77            );
78        }
79        else {
80            $Self->AddResultOk(
81                Identifier => 'TicketIndex',
82                Label      => Translatable('Orphaned Records In ticket_index Table'),
83                Value      => $OrphanedTicketIndex || '0',
84            );
85        }
86    }
87
88    return $Self->GetResults();
89}
90
911;
92