View | Details | Raw Unified | Return to bug 35836
Collapse All | Expand All

(-)a/misc/maintenance/search_for_data_inconsistencies.pl (-1 / +91 lines)
Lines 326-331 use C4::Biblio qw( GetMarcFromKohaField ); Link Here
326
    }
326
    }
327
}
327
}
328
328
329
{
330
    my @loop_borrowers_relationships;
331
    my @relationships = Koha::Patron::Relationships->search();
332
    my @patrons_guarantors = Koha::Patron::Relationships::guarantors(@relationships)->as_list;
333
    my @patrons_guarantees = Koha::Patron::Relationships::guarantees(@relationships)->as_list;
334
335
    foreach my $patron_guarantor (@patrons_guarantors) {
336
        foreach my $patron_guarantee (@patrons_guarantees) {
337
            if ($patron_guarantor->borrowernumber == $patron_guarantee->borrowernumber) {
338
339
                my $relationship_id;
340
                my $guarantee_id;
341
                my $size_list;
342
                my $tmp_garantor_id = $patron_guarantor->borrowernumber;
343
                my @relationship_ids;
344
                my @guarantor_to_find;
345
346
                push @guarantor_to_find, $patron_guarantor->borrowernumber;
347
348
                do {
349
                    my @relationship_for_go = Koha::Patron::Relationships->search(
350
                        {
351
                            -or => [
352
                                'guarantor_id' => { '=', $tmp_garantor_id },
353
                            ]
354
                        },
355
                    )->as_list;
356
                    $size_list = scalar @relationship_for_go;
357
358
                    foreach my $relation (@relationship_for_go) {
359
                        $relationship_id = $relation->id;
360
                        unless (grep { $_ == $relationship_id } @relationship_ids) {
361
                            push @relationship_ids, $relationship_id;
362
                        }
363
                        $guarantee_id = $relation->guarantee_id;
364
365
                        if (grep { $_ eq $guarantee_id } @guarantor_to_find) {
366
                            last;
367
                        }
368
369
                        my @relationship_for_go = Koha::Patron::Relationships->search(
370
                            {
371
                                -or => [
372
                                    'guarantor_id' => { '=', $guarantee_id },
373
                                ]
374
                            },
375
                        )->as_list;
376
                        $size_list = scalar @relationship_for_go;
377
378
                        push @guarantor_to_find, $guarantee_id;
379
380
                        foreach my $relation (@relationship_for_go) {
381
                            $relationship_id = $relation->id;
382
                            unless (grep { $_ == $relationship_id } @relationship_ids) {
383
                                push @relationship_ids, $relationship_id;
384
                            }
385
                            $guarantee_id = $relation->guarantee_id;
386
387
                            if (grep { $_ eq $guarantee_id } @guarantor_to_find) {
388
                                last;
389
                            }
390
                        }
391
                        if (grep { $_ eq $guarantee_id } @guarantor_to_find) {
392
                            last;
393
                        }
394
                    }
395
396
                    $tmp_garantor_id = $guarantee_id;
397
                } while ((!grep { $_ eq $guarantee_id } @guarantor_to_find) && $size_list > 0);
398
399
                if ($patron_guarantor->borrowernumber == $guarantee_id) {
400
                    unless (grep {  join("", sort @$_) eq join("", sort @relationship_ids) } @loop_borrowers_relationships) {
401
                        push @loop_borrowers_relationships, \@relationship_ids;
402
                    }
403
                }
404
            }
405
        }
406
    }
407
408
    if (scalar @loop_borrowers_relationships > 0) {
409
        new_section("The list of relationships id with guarantors who are also guarantee.");
410
        foreach my $table (@loop_borrowers_relationships) {
411
            new_item(
412
                sprintf "Relationships connected : %s |",
413
                join(" | ", @$table)
414
            );
415
        }
416
        new_hint("Relationships that form guarantor loops must be deleted");
417
    }
418
}
419
329
sub new_section {
420
sub new_section {
330
    my ( $name ) = @_;
421
    my ( $name ) = @_;
331
    say "\n== $name ==";
422
    say "\n== $name ==";
332
- 

Return to bug 35836