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

(-)a/misc/maintenance/batchSanitizeEntity.pl (-43 / +43 lines)
Lines 18-24 Link Here
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
20
21
use warnings;
21
use Modern::Perl;
22
use C4::Charset;
22
use C4::Charset;
23
use C4::Context;
23
use C4::Context;
24
use DBI;
24
use DBI;
Lines 26-41 use C4::Biblio; Link Here
26
use Getopt::Long;
26
use Getopt::Long;
27
use Pod::Usage;
27
use Pod::Usage;
28
28
29
my ($biblios,$run,$want_help);
29
my ( $biblios, $run, $want_help, $batch );
30
my $result = GetOptions(
30
my $result = GetOptions(
31
    'where=s'      => \$biblios,
31
    'where=s' => \$biblios,
32
    '--run'        => \$run,
32
    '--run'   => \$run,
33
    'help|h'       => \$want_help,
33
    'help|h'  => \$want_help,
34
    'batch|b'      => \$batch,
34
    'batch|b' => \$batch,
35
);
35
);
36
36
37
# We check if required entries are given :
37
# We check if required entries are given :
38
if ( not $result or $want_help or not $biblios or not $run) {
38
if ( not $result or $want_help or not $biblios or not $run ) {
39
    print_usage();
39
    print_usage();
40
    exit 0;
40
    exit 0;
41
}
41
}
Lines 50-86 my $record; Link Here
50
my $cleanrecord;
50
my $cleanrecord;
51
51
52
# We first detect if we have a file or biblos directly entered by command line or if we want to use findAmp() sub :
52
# We first detect if we have a file or biblos directly entered by command line or if we want to use findAmp() sub :
53
if ($biblios eq "search"){
53
if ( $biblios eq "search" ) {
54
    @biblios = findAmp();
54
    @biblios = findAmp();
55
}
55
}
56
else {
56
else {
57
    if ($biblios =~ /\//) {
57
    if ( $biblios =~ m|/| ) {
58
        open (FILE, "$biblios") || die ("Can't open $biblios");
58
        open( FILE, "$biblios" ) || die("Can't open $biblios");
59
        @bibliofile = <FILE>;
59
        @bibliofile = <FILE>;
60
        close (FILE);
60
        close(FILE);
61
    }
61
    }
62
    else {
62
    else {
63
        @biblionum = split ',', $biblios;
63
        @biblionum = split ',', $biblios;
64
    }
64
    }
65
65
    # We take the biblios
66
    # We take the biblios
66
    @biblios = @bibliofile?@bibliofile:@biblionum;
67
    @biblios = @bibliofile ? @bibliofile : @biblionum;
67
}
68
}
68
69
69
# We remove spaces
70
# We remove spaces
70
my @biblio;
71
s/(^\s*|\s*$)//g for @biblios;
71
foreach my $bib(@biblios) {
72
# Remove empty lines
72
    $bib =~ s/(^\s*|\s*$)//g;
73
@biblios = grep {!/^$/} @biblios;
73
    next if $bib eq "";
74
    push @biblio, $bib;
75
}
76
@biblios = @biblio;
77
74
78
# We valid the input
75
# We valid the input
79
foreach my $biblio (@biblios) {
76
foreach my $biblio (@biblios) {
80
    if ($biblio !~ /^\d+$/){
77
    if ( $biblio !~ /^\d+$/ ) {
81
        print "=============== \"$biblio\" is not a biblionumber !!! ===============\n";
78
        print
79
"=============== \"$biblio\" is not a biblionumber !!! ===============\n";
82
        print "=============== please verify \"$biblio\" !!! ===============\n";
80
        print "=============== please verify \"$biblio\" !!! ===============\n";
83
        $count += 1;
81
        $count++;
84
    }
82
    }
85
    exit(1) if $count;
83
    exit(1) if $count;
86
}
84
}
Lines 88-117 foreach my $biblio (@biblios) { Link Here
88
$bibliocount = scalar @biblios;
86
$bibliocount = scalar @biblios;
89
my $confirm = 0;
87
my $confirm = 0;
90
88
91
print "=============== $bibliocount Biblio(s) ready to be cleaned ===============\n";
89
print
92
if (!$batch) {
90
"=============== $bibliocount Biblio(s) ready to be cleaned ===============\n";
91
if ( !$batch ) {
93
    print "=============== You are ok ? Types yes/no :\n";
92
    print "=============== You are ok ? Types yes/no :\n";
94
    while ($confirm == 0){
93
    while ( $confirm == 0 ) {
95
                my $prout = <STDIN>;
94
        my $prout = <STDIN>;
96
                if ($prout eq "yes\n") {
95
        if ( $prout eq "yes\n" ) {
97
                        $confirm = 1;
96
            $confirm = 1;
98
                }
97
        }
99
                elsif ($prout eq "no\n") {
98
        elsif ( $prout eq "no\n" ) {
100
                    print "=============== Ok, bye ===============\n";
99
            print "=============== Ok, bye ===============\n";
101
                    exit(0);
100
            exit(0);
102
                    }
101
        }
103
                else {
102
        else {
104
                    print "======= Bad answer please types 'yes' or 'no' !!!!!!!!!!! ===============\n";
103
            print
105
                }
104
"======= Bad answer please types 'yes' or 'no' !!!!!!!!!!! ===============\n";
106
            }
105
        }
106
    }
107
}
107
}
108
108
109
foreach my $biblio (@biblios){
109
foreach my $biblio (@biblios) {
110
    print "=============== N° $biblio selected ===============\n";
110
    print "=============== N° $biblio selected ===============\n";
111
    $record = GetMarcBiblio($biblio);
111
    $record      = GetMarcBiblio($biblio);
112
    $cleanrecord = SanitizeEntity($record);
112
    $cleanrecord = SanitizeEntity($record);
113
    my $frameworkcode = GetFrameworkCode($biblio);
113
    my $frameworkcode = GetFrameworkCode($biblio);
114
    ModBiblio($cleanrecord, $biblio, $frameworkcode);
114
    ModBiblio( $cleanrecord, $biblio, $frameworkcode );
115
    print "=============== Biblio n° $biblio done ===============\n";
115
    print "=============== Biblio n° $biblio done ===============\n";
116
}
116
}
117
117
Lines 135-144 _USAGE_ Link Here
135
sub findAmp {
135
sub findAmp {
136
    my @bibliosearch;
136
    my @bibliosearch;
137
    my $dbh = C4::Context->dbh;
137
    my $dbh = C4::Context->dbh;
138
    my $strsth = qq{SELECT biblionumber FROM biblioitems WHERE marcxml LIKE "%amp;amp;%"};
138
    my $strsth =
139
      qq{SELECT biblionumber FROM biblioitems WHERE marcxml LIKE "%amp;amp;%"};
139
    my $sth = $dbh->prepare($strsth);
140
    my $sth = $dbh->prepare($strsth);
140
    $sth->execute();
141
    $sth->execute();
141
    while (my $bib = $sth-> fetchrow_array()){
142
    while ( my $bib = $sth->fetchrow_array() ) {
142
        push @bibliosearch, $bib;
143
        push @bibliosearch, $bib;
143
    }
144
    }
144
    return @bibliosearch;
145
    return @bibliosearch;
145
- 

Return to bug 8218