# PODNAME: koha-rebuild-editors
# ABSTRACT: Populates EDITORS authorities based on biblio records

use 5.010;
use utf8;
use strict;
use warnings;
use Koha::Contrib::Tamil::Koha;
use Koha::Contrib::Tamil::Authority::EditorsBuilder;
use Koha::Contrib::Tamil::Authority::EditorsUpdater;
use Getopt::Long;
use Pod::Usage;
use YAML;

my ($help, $verbose, $doit, $delete, $dump);
$verbose = 1;
    'help|h'   => \$help,
    'verbose!' => \$verbose,
    'doit'     => \$doit,
    'delete|d' => \$delete,
    'dump'     => \$dump,

if ( $help ) {
    pod2usage( -verbose => 2 );

say "** Test mode **" unless $doit;

my $koha = Koha::Contrib::Tamil::Koha->new();
my $builder = Koha::Contrib::Tamil::Authority::EditorsBuilder->new(
    koha    => $koha,
    doit    => $doit,
    verbose => $verbose,
if ( $dump ) {
    binmode(STDOUT, ":utf8");
    print "Editeurs sans ISBN :\n",
          Dump( sort keys %{$builder->editor_without_isbn} ), "\n",
          "Editeurs avec ISBN invalide :\n",
          Dump( sort keys %{$builder->editor_with_invalid_isbn} ), "\n",
          "Editeurs avec ISBN valide :\n", Dump( $builder->editor_from_isbn );

my $updater = Koha::Contrib::Tamil::Authority::EditorsUpdater->new(
    koha             => $koha,
    doit             => $doit,
    verbose          => $verbose,
    editor_from_isbn => $builder->editor_from_isbn,



=encoding UTF-8

=head1 NAME

koha-rebuild-editors - Populates EDITORS authorities based on biblio records

=head1 VERSION

version 0.068


This script add entries in EDITORS authorities list based on what is found in
the current Koha biblio records catalog. EDITORS list is used by unimarc_210c
and unimarc_225a plugins.

Those plugins will work only if you have an EDITORS authority type, with:

  200a being the first 2 parts of an ISBN
  200b being the editor name
  200c (repeatable) being the series title

=head1 USAGE

 koha-rebuild-editors --noverbose --dump
 koha-rebuild-editors --doit
 koha-rebuild-editors --doit --delete



=item --help, -h

Display this help.

=item --verbose, --noverbose

Verbose mode. By default, the script operates in verbose mode.

=item --doit

Effective operations. Without this flag, Koha DB is not updated.

=item --delete, -d

Delete all existing entries in EDITORS before adding new entries found in
biblio records.

=item --dump

After processing all biblio records, dumps a YAML representation of the
isbn-editor-collection found.


=head1 AUTHOR

Frédéric Demians <f.demians@tamil.fr>


This software is Copyright (c) 2022 by Fréderic Démians.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007