This file is indexed.

/usr/share/otrs/scripts/DBUpdateTo6/MigrateArticleData.pm is in otrs2 6.0.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
# --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package scripts::DBUpdateTo6::MigrateArticleData;    ## no critic

use strict;
use warnings;

use IO::Interactive qw(is_interactive);

use parent qw(scripts::DBUpdateTo6::Base);

our @ObjectDependencies = (
    'Kernel::System::DB',
    'Kernel::System::Log',
);

=head1 NAME

scripts::DBUpdateTo6::MigrateArticleData -  Create entries in new article table for OmniChannel base infrastructure.

=cut

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

    my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
    my $Verbose = $Param{CommandlineOptions}->{Verbose} || 0;

    my $MigrationStatus = $Self->_CheckMigrationIsDone();

    return 1 if $MigrationStatus->{MigrationDone};

    # Check if article_type table exists.
    my $TableExists = $Self->TableExists(
        Table => 'article_type',
    );

    # Skip execution if article_type table is missing.
    if ( !$TableExists ) {
        print "        - Article types table missing, skipping...\n" if $Verbose;
        return 1;
    }

    my $TaskConfig = $Self->GetTaskConfig( Module => 'MigrateArticleData' );

    my %ArticleTypeMapping = %{ $TaskConfig->{ArticleTypeMapping} };

    my %TablesData = %{ $MigrationStatus->{TablesData} };

    # Collect data for further calculation of IsVisibleForCustomer.
    return if !$DBObject->Prepare(
        SQL => 'SELECT id, name FROM article_type',
    );

    my %ArticleTypes;
    while ( my @Row = $DBObject->FetchrowArray() ) {
        $ArticleTypes{ $Row[0] } = $Row[1];
    }

    return if !$DBObject->Prepare(
        SQL => 'SELECT id, name FROM communication_channel',
    );

    my %CommunicationChannels;
    while ( my @Row = $DBObject->FetchrowArray() ) {
        $CommunicationChannels{ $Row[1] } = $Row[0];
    }

    my $MaxVerboseOutputs    = 20;
    my $ArticlesForMigration = $TablesData{article_data_mime}->{Count} - $TablesData{article}->{Count};
    my $VerboseRange         = $ArticlesForMigration / $MaxVerboseOutputs;

    if ($Verbose) {

        print
            "\n        - $ArticlesForMigration articles will be migrated\n";
    }
    my $AlreadyMigratedArticles = 0;
    my $VerboseLoop             = 1;

    # TODO:OCBI: This number might be changed or even configurable
    my $RowsPerLoop = $Param{RowsPerLoop} || 1000;

    my $StartInEntry = $TablesData{article}->{MaxID};

    while ( $StartInEntry < $TablesData{article_data_mime}->{MaxID} ) {

        # Get the complete set of Article entries.
        my $EndInEntry = $StartInEntry + 1 + $RowsPerLoop;

        return if !$DBObject->Prepare(
            SQL => '
                SELECT id, ticket_id, article_sender_type_id, article_type_id,
                    create_by,create_time, change_by, change_time
                FROM article_data_mime
                WHERE id > ' . $StartInEntry . ' AND id < ' . $EndInEntry . '
                ORDER BY id ASC',
        );

        # NOTE: Remaining fields in re-named 'article_data_mime'
        # table will stay there, except for 'ticket_id' and 'valid_id'
        # now they are part of the MIME communication channel data

        my @Data;
        while ( my @Row = $DBObject->FetchrowArray() ) {

            # Map Visible for Customer
            my $IsVisibleForCustomer = $ArticleTypeMapping{ $ArticleTypes{ $Row[3] } }->{Visible};

            # Map Communication Channel.
            my $CommunicationChannel   = $ArticleTypeMapping{ $ArticleTypes{ $Row[3] } }->{Channel};
            my $CommunicationChannelID = $CommunicationChannels{$CommunicationChannel};

            my %CurrentRow = (
                ID                     => $Row[0],
                TicketID               => $Row[1],
                ArticleSenderTypeID    => $Row[2],
                CommunicationChannelID => $CommunicationChannelID,
                IsVisibleForCustomer   => $IsVisibleForCustomer,
                CreateBy               => $Row[4],
                CreateTime             => $Row[5],
                ChangeBy               => $Row[6],
                ChangeTime             => $Row[7],
            );
            push @Data, \%CurrentRow;
        }

        if (@Data) {

            my $MigrationResult = $Self->_MigrateData(
                Data              => \@Data,
                LastArticleDataID => $Data[-1]->{ID},
            );

            if ( !$MigrationResult ) {
                $Kernel::OM->Get('Kernel::System::Log')->Log(
                    Priority => 'error',
                    Message  => "An error occurs during article data migration!",
                );
                print "\n    An error occurs during article data migration!\n";
                return;
            }

            $AlreadyMigratedArticles += scalar @Data;

            # Add some meaningful information
            if ( $Verbose && ( $AlreadyMigratedArticles > $VerboseLoop * $VerboseRange ) ) {

                print
                    "        - $AlreadyMigratedArticles of $ArticlesForMigration articles migrated. \n";
                $VerboseLoop++;
            }
        }

        $StartInEntry += $RowsPerLoop;
    }

    print "\n" if $Verbose;

    return 1;
}

=head2 _MigrateData()

Adds multiple article entries to the article table. Returns 1 on success

    my $Result = $DBUpdateTo6Object->_MigrateData(
        Data => \@OldArticleData, # Old structure content
    );

=cut

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

    # Check needed stuff.
    if ( !$Param{Data} ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Need Data!",
        );
        return;
    }

    # Check needed stuff.
    if ( ref $Param{Data} ne 'ARRAY' ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Data must be an array reference!",
        );
        return;
    }

    # Check needed stuff.
    if ( !@{ $Param{Data} } ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Data array must not be empty!",
        );
        return;
    }

    # Check needed stuff.
    if ( !defined $Param{LastArticleDataID} ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Need LastArticleDataID!",
        );
        return;
    }

    my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

    # Get the database type.
    my $DBType = $DBObject->GetDatabaseFunction('Type');

    # Decide data migration type.
    my $AllowMultiple          = 1;
    my @SupportMultipleInserts = qw(mysql oracle postgresql);

    if ( !grep {m/$DBType/} @SupportMultipleInserts ) {
        $AllowMultiple = 0;
    }

    # Define database specific SQL for the multi-line inserts.
    my %DatabaseSQL;

    if ( $DBType eq 'oracle' && $AllowMultiple ) {

        %DatabaseSQL = (
            Start     => 'INSERT ALL ',
            FirstLine => '
                INTO article (
                    id,ticket_id,article_sender_type_id,communication_channel_id,
                    is_visible_for_customer,create_by,create_time,change_by,change_time
                )
                VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? ) ',
            NextLine => '
                INTO article (
                    id,ticket_id,article_sender_type_id,communication_channel_id,
                    is_visible_for_customer,create_by,create_time,change_by,change_time
                )
                VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? ) ',
            End => 'SELECT * FROM DUAL',
        );
    }
    else {
        %DatabaseSQL = (
            Start => '
                INSERT INTO article (
                    id,ticket_id,article_sender_type_id,communication_channel_id,
                    is_visible_for_customer,create_by,create_time,change_by,change_time
                )',
            FirstLine => 'VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )',
            NextLine  => ', ( ?, ?, ?, ?, ?, ?, ?, ?, ? ) ',
            End       => '',
        );

    }

    my $SQL = '';
    my @Bind;

    ARTICLEENTRY:
    for my $ArticleEntry ( @{ $Param{Data} } ) {

        # Now the article entry is validated and can be added to sql.
        if ( !$SQL ) {
            $SQL = $DatabaseSQL{Start} . $DatabaseSQL{FirstLine};
        }
        else {
            $SQL .= $DatabaseSQL{NextLine};
        }

        push @Bind, (
            \$ArticleEntry->{ID},
            \$ArticleEntry->{TicketID},
            \$ArticleEntry->{ArticleSenderTypeID},
            \$ArticleEntry->{CommunicationChannelID},
            \$ArticleEntry->{IsVisibleForCustomer},
            \$ArticleEntry->{CreateBy},
            \$ArticleEntry->{CreateTime},
            \$ArticleEntry->{ChangeBy},
            \$ArticleEntry->{ChangeTime},
        );

        # Check the length of the SQL string
        # (some databases only accept SQL strings up to 4k,
        # so we want to stay safe here with just 3500 bytes).
        if ( length $SQL > 3500 || !$AllowMultiple || $ArticleEntry->{ID} == $Param{LastArticleDataID} ) {

            # Add the end line to sql string.
            $SQL .= $DatabaseSQL{End};

            # Insert multiple entries.
            return if !$DBObject->Do(
                SQL  => $SQL,
                Bind => \@Bind,
            );

            # Reset the SQL string and the Bind array.
            $SQL  = '';
            @Bind = ();
        }
    }

    return 1;
}

=head2 CheckPreviousRequirement()

Check for initial conditions for running this migration step.

Returns 1 on success:

    my $Result = $DBUpdateTo6Object->CheckPreviousRequirement();

=cut

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

    my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

    my $Verbose = $Param{CommandlineOptions}->{Verbose} || 0;

    # Check for interactive mode.
    my $InteractiveMode = 1;
    if ( $Param{CommandlineOptions}->{NonInteractive} || !is_interactive() ) {
        $InteractiveMode = 0;
    }

    # Check for orphaned articles only if article table was not migrated yet.
    my $OrphanedArticleCheck = !$Self->TableExists(
        Table => 'article_data_mime',
    );

    if ($OrphanedArticleCheck) {

        # Define orphaned entries checks, for now all related to the article table.
        my @OrphanedEntryChecks = (
            {
                Table       => 'article_flag',
                Description => 'Check for orphaned entries in article_flag table',
                CheckSQL    => '
                    SELECT COUNT(article_flag.article_id)
                    FROM article_flag
                    WHERE (article_flag.article_id NOT IN (SELECT article.id FROM article))
                    OR (article_flag.article_id IN (SELECT article.id FROM article WHERE article.ticket_id NOT IN (SELECT ticket.id FROM ticket)))
                ',
                DeleteSQL => [
                    '
                        DELETE
                        FROM article_flag
                        WHERE (article_flag.article_id NOT IN (SELECT article.id FROM article))
                        OR (article_flag.article_id IN (SELECT article.id FROM article WHERE article.ticket_id NOT IN (SELECT ticket.id FROM ticket)))
                    ',
                ],
            },
            {
                Table       => 'article_attachment',
                Description => 'Check for orphaned entries in article_attachment table',
                CheckSQL    => '
                    SELECT COUNT(article_attachment.article_id)
                    FROM article_attachment
                    WHERE (article_attachment.article_id NOT IN (SELECT article.id FROM article))
                    OR (article_attachment.article_id IN (SELECT article.id FROM article WHERE article.ticket_id NOT IN (SELECT ticket.id FROM ticket)))
                ',
                DeleteSQL => [
                    '
                        DELETE
                        FROM article_attachment
                        WHERE (article_attachment.article_id NOT IN (SELECT article.id FROM article))
                        OR (article_attachment.article_id IN (SELECT article.id FROM article WHERE article.ticket_id NOT IN (SELECT ticket.id FROM ticket)))
                    ',
                ],
            },
            {
                Table       => 'time_accounting',
                Description => 'Check for orphaned entries in time_accounting table',
                CheckSQL    => '
                    SELECT COUNT(time_accounting.article_id)
                    FROM time_accounting
                    WHERE (time_accounting.article_id NOT IN (SELECT article.id FROM article))
                    OR (time_accounting.article_id IN (SELECT article.id FROM article WHERE article.ticket_id NOT IN (SELECT ticket.id FROM ticket)))
                ',
                DeleteSQL => [
                    '
                        DELETE
                        FROM time_accounting
                        WHERE (time_accounting.article_id NOT IN (SELECT article.id FROM article))
                        OR (time_accounting.article_id IN (SELECT article.id FROM article WHERE article.ticket_id NOT IN (SELECT ticket.id FROM ticket)))
                    ',
                ],
            },
            {
                Table       => 'article_plain',
                Description => 'Check for orphaned entries in article_plain table',
                CheckSQL    => '
                    SELECT COUNT(article_plain.article_id)
                    FROM article_plain
                    WHERE (article_plain.article_id NOT IN (SELECT article.id FROM article))
                    OR (article_plain.article_id IN (SELECT article.id FROM article WHERE article.ticket_id NOT IN (SELECT ticket.id FROM ticket)))
                ',
                DeleteSQL => [
                    '
                        DELETE
                        FROM article_plain
                        WHERE (article_plain.article_id NOT IN (SELECT article.id FROM article))
                        OR (article_plain.article_id IN (SELECT article.id FROM article WHERE article.ticket_id NOT IN (SELECT ticket.id FROM ticket)))
                    ',
                ],
            },
            {
                Table       => 'ticket_history',
                Description => 'Check for orphaned entries in ticket_history table',
                CheckSQL    => '
                    SELECT COUNT(ticket_history.article_id)
                    FROM ticket_history
                    WHERE (ticket_history.article_id <> 0 AND ticket_history.article_id NOT IN (SELECT article.id FROM article))
                    OR (ticket_history.ticket_id NOT IN (SELECT ticket.id FROM ticket))
                ',
                DeleteSQL => [
                    '
                        DELETE
                        FROM ticket_history
                        WHERE (ticket_history.article_id <> 0 AND ticket_history.article_id NOT IN (SELECT article.id FROM article))
                        OR (ticket_history.ticket_id NOT IN (SELECT ticket.id FROM ticket))
                    ',
                    '
                        UPDATE ticket_history
                        SET ticket_history.article_id = NULL
                        WHERE ticket_history.article_id = 0
                    ',
                ],
            },
            {
                Table       => 'article',
                Description => 'Check for orphaned entries in article table',
                CheckSQL    => '
                    SELECT COUNT(article.id)
                    FROM article
                    WHERE article.ticket_id
                    NOT IN (SELECT ticket.id FROM ticket)
                ',
                DeleteSQL => [
                    '
                        DELETE
                        FROM article
                        WHERE article.ticket_id
                        NOT IN (SELECT ticket.id FROM ticket)
                    ',
                ],
            },
        );

        print "\n" if $Verbose;

        my $Stop;

        ORPHANEDENTRYCHECK:
        for my $Index ( 0 .. $#OrphanedEntryChecks ) {
            my $OrphanedEntryCheck = $OrphanedEntryChecks[$Index];

            print "        $OrphanedEntryCheck->{Description} ...\n" if $Verbose;

            return if !$DBObject->Prepare(
                SQL => $OrphanedEntryCheck->{CheckSQL},
            );

            my $Count = 0;
            while ( my @Row = $DBObject->FetchrowArray() ) {
                $Count = $Row[0];
            }

            # No orphaned entries found.
            next ORPHANEDENTRYCHECK if !$Count;

            print "\n" if !$Verbose && !$Index;

            print "        Found $Count orphaned entries in $OrphanedEntryCheck->{Table} table ...\n";

            # Only in interactive mode or if the CleanupOrphanedArticles parameter is active.
            if ( $InteractiveMode || $Param{CommandlineOptions}->{CleanupOrphanedArticles} ) {

                my $Answer = '';

                # In interactive mode we ask the user what he wants to do.
                if ( !$Param{CommandlineOptions}->{CleanupOrphanedArticles} ) {

                    # Ask the user and get the answer.
                    print '        Do you want to automatically delete the entries from the database now? [Y]es/[N]o: ';
                    $Answer = <>;

                    # Remove white space from input.
                    $Answer =~ s{\s}{}smx;
                }

                # Fix the problem automatically.
                if ( $Answer =~ m{^y}i || $Param{CommandlineOptions}->{CleanupOrphanedArticles} ) {

                    # Delete the orphaned entries.
                    for my $SQL ( @{ $OrphanedEntryCheck->{DeleteSQL} } ) {
                        return if !$DBObject->Do(
                            SQL => $SQL,
                        );
                    }

                    # Now check if no orphaned entries are found anymore.
                    return if !$DBObject->Prepare(
                        SQL => $OrphanedEntryCheck->{CheckSQL},
                    );
                    my $Count;
                    while ( my @Row = $DBObject->FetchrowArray() ) {
                        $Count = $Row[0];
                    }

                    # Everything was deleted automatically.
                    if ( !$Count ) {
                        print "        Fixing... Done.\n\n";
                        next ORPHANEDENTRYCHECK;
                    }

                    # Could not be deleted automatically.
                    print "        It was not possible to automatically delete the orphaned entries.\n";
                }

                print
                    "        Please delete them manually with the following SQL statements and then run the migration script again:\n";
                for my $SQL ( @{ $OrphanedEntryCheck->{DeleteSQL} } ) {
                    print $SQL;
                }
                print "\n";

                return;
            }

            # In non-interactive mode we just remember that there was a problem, and show the output
            #    and in a later step we then stop.
            else {

                # Show manual instructions and remember to stop later.
                print
                    "        Please delete them manually with the following SQL statements and then run the migration script again:\n";
                for my $SQL ( @{ $OrphanedEntryCheck->{DeleteSQL} } ) {
                    print $SQL;
                }
                print "\n";

                $Stop = 1;
            }

        }

        print "\n" if $Verbose;

        return if $Stop;
    }

    # Check if article_type table still exist.
    my $ArticleTypeTableExists = $Self->TableExists(
        Table => 'article_type',
    );

    # Check for unknown article types.
    if ($ArticleTypeTableExists) {

        my $TaskConfig = $Self->GetTaskConfig( Module => 'MigrateArticleData' );

        my @ArticleTypes = sort keys %{ $TaskConfig->{ArticleTypeMapping} };

        my $ArticleTypesString = "'" . ${ \( join "', '", @ArticleTypes ) } . "'";

        $DBObject->Prepare(
            SQL => "
                SELECT id, name
                FROM article_type
                WHERE name NOT IN ( $ArticleTypesString )
            ",
        );

        my @UnknownArticleTypes;

        while ( my @Row = $DBObject->FetchrowArray() ) {
            push @UnknownArticleTypes, $Row[1];
        }

        # If unknown article types are encountered, do not continue with the migration.
        if (@UnknownArticleTypes) {

            print "\n    Error! Unknown article types were found: ${\(join ', ', @UnknownArticleTypes)}.\n"
                . "    Please provide additional migration matrix entries in following file:\n\n"
                . "        scripts/DBUpdateTo6/TaskConfig/MigrateArticleData.yml\n\n"
                . "    Tip: Create a copy of .dist file with the same name and edit it instead,\n"
                . "    before starting migration again.\n\n";

            return;
        }
    }

    return 1;
}

=head2 _CheckMigrationIsDone()

updates the table article_data_mime:

    - adding an article_id column
    - copying id values into article_id column
    - recreating indexes and foreign keys
    - dropping no longer used columns

Returns 1 on success

    my $Result = $DBUpdateTo6Object->_CheckMigrationIsDone();

=cut

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

    my $MigrationDone = 0;
    my $Message;

    my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

    my %TablesData = (
        'article' => {
            MaxID => 0,
            Count => 0,
        },
        'article_data_mime' => {
            MaxID => 0,
            Count => 0,
        },
    );

    for my $TableName ( sort keys %TablesData ) {

        # Get last id.
        return if !$DBObject->Prepare(
            SQL => "SELECT MAX(id) FROM $TableName",
        );
        while ( my @Row = $DBObject->FetchrowArray() ) {
            $TablesData{$TableName}->{MaxID} = $Row[0] || 0;
        }

        # Get amount of entries
        return if !$DBObject->Prepare(
            SQL => "SELECT COUNT(*) FROM $TableName",
        );
        while ( my @Row = $DBObject->FetchrowArray() ) {
            $TablesData{$TableName}->{Count} = $Row[0] || 0;
        }
    }

    # This should never happen.
    if (
        $TablesData{article_data_mime}->{MaxID} < $TablesData{article}->{MaxID}
        || $TablesData{article_data_mime}->{Count} < $TablesData{article}->{Count}
        )
    {
        $Message =
            "Something got wrong, there are more entries in 'article' table than in 'article_data_mime'.";
        $MigrationDone = 0;
    }

    # Have to be the same amount of records in both tables.
    # tables with the sale ids
    elsif (
        $TablesData{article_data_mime}->{MaxID} == $TablesData{article}->{MaxID}
        && $TablesData{article_data_mime}->{Count} == $TablesData{article}->{Count}
        )
    {

        $Message =
            "Article data migration already executed.";
        $MigrationDone = 1;
    }

    return {
        MigrationDone => $MigrationDone,
        Message       => $Message,
        TablesData    => \%TablesData,
    };
}

1;

=head1 TERMS AND CONDITIONS

This software is part of the OTRS project (L<http://otrs.org/>).

This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.

=cut