Bug 21395: Make perlcritic happy
[koha.git] / misc / migration_tools / buildLANG.pl
blobb1174ab8d3bd529ce82bef41aaa4d06db00bda8d
1 #!/usr/bin/perl
2 # script that rebuild thesaurus from biblio table.
4 # delete FROM `marc_subfield_table` WHERE tag = "606" AND subfieldcode = 9;
5 use strict;
6 #use warnings; FIXME - Bug 2505
8 # Koha modules used
9 use Koha::Script;
10 use C4::Context;
11 use C4::Biblio;
12 use C4::AuthoritiesMarc;
13 use Time::HiRes qw(gettimeofday);
15 use Getopt::Long;
16 my ( $fields, $number,$language) = ('',0);
17 my ($version, $verbose, $test_parameter, $delete);
18 GetOptions(
19 'h' => \$version,
20 'd' => \$delete,
21 't' => \$test_parameter,
22 's:s' => \$fields,
23 'v' => \$verbose,
24 'l:s' => \$language,
27 if ($version or !$fields) {
28 print <<EOF
29 Small script to recreate the LANG list in authorised values from existing langs in the catalogue.
30 This script is useful when you migrate your datas with bulkmarcimport.pl as it populates parameters tables that are not modified by bulkmarcimport.
32 parameters :
33 \th : this version/help screen
34 \ts : the field or field list where the lang codes are stored.
35 \td : delete every entry of LANG category before doing work.
36 \tl : the language of the language list (fr or en for instance)
38 The table is populated with iso codes and meaning (in french).
39 If the complete language name is unknown, the code is used instead and you will be warned by the script
41 SAMPLES :
42 ./buildLANG -d -s "('101a','101b')"
43 EOF
44 ;#/
45 exit;
48 my %codesiso;
50 %codesiso = (
51 'eng' => 'english',
52 'fre' => 'french'
55 %codesiso = (
56 'mis' => 'diverses',
57 'und' => 'inconnue',
58 'mul' => 'multilingue',
59 'ger' => 'allemand',
60 'eng' => 'anglais',
61 'afr' => 'afrikaans',
62 'akk' => 'akkadien',
63 'amh' => 'amharique',
64 'ang' => 'anglo-saxon (ca. 450-1100)',
65 'arc' => 'araméen',
66 'ara' => 'arabe',
67 'arm' => 'arménien',
68 'baq' => 'basque',
69 'ber' => 'berbere',
70 'bre' => 'breton',
71 'bul' => 'bulgare',
72 'cat' => 'catalan',
73 'chi' => 'chinois',
74 'cop' => 'copte',
75 'cro' => 'croate',
76 'cze' => 'tchèque',
77 'dan' => 'danois',
78 'dum' => 'néerlandais moyen (ca. 1050-1350)',
79 'dut' => 'néerlandais',
80 'spa' => 'espagnol',
81 'egy' => 'egyptien',
82 'esp' => 'espéranto',
83 'fin' => 'finnois',
84 'fra' => 'français ancien',
85 'fre' => 'français',
86 'frm' => 'français moyen (ca. 1400-1600)',
87 'fro' => 'français ancien (842-ca. 1400)',
88 'gmh' => 'allemand, moyen haut (ca. 1050-1500)',
89 'got' => 'gothique',
90 'grc' => 'grec classique',
91 'gre' => 'grec moderne',
92 'heb' => 'hébreu',
93 'hin' => 'hindi',
94 'hun' => 'hongrois',
95 'ind' => 'indonésien',
96 'ine' => 'indo-européennes, autres',
97 'ita' => 'italien',
98 'jap' => 'japonais',
99 'jpn' => 'japonais',
100 'kor' => 'coréen',
101 'lan' => 'occitan (post 1500)',
102 'lat' => 'latin',
103 'map' => 'malayo-polynésiennes, autres',
104 'mla' => 'malgache',
105 'nic' => 'nigéro-congolaises, autres',
106 'nor' => 'norvégien',
107 'per' => 'persan',
108 'pro' => 'provencal ancien (jusqu\'à 1500)',
109 'pol' => 'polonais',
110 'por' => 'portugais',
111 'rom' => 'tzigane',
112 'rum' => 'roumain',
113 'rus' => 'russe',
114 'sam' => 'samaritain',
115 'san' => 'sanskrit',
116 'scr' => 'serbo-croate',
117 'sem' => 'sémitique, autres langues',
118 'ser' => 'serbe',
119 'sla' => 'slave, autres langues',
120 'slo' => 'slovène',
121 'syr' => 'syriaque',
122 'swe' => 'suedois',
123 'tib' => 'tibétain',
124 'tur' => 'turc',
125 'uga' => 'ougaritique',
126 'ukr' => 'ukraine',
127 'wel' => 'gallois',
128 'yid' => 'yiddish',
129 ) if $language eq 'fr';
131 my $dbh = C4::Context->dbh;
132 if ($delete) {
133 print "deleting lang list\n";
134 $dbh->do("delete from authorised_values where category='LANG'");
137 if ($test_parameter) {
138 print "TESTING MODE ONLY\n DOING NOTHING\n===============\n";
140 my $starttime = gettimeofday;
142 my $sth = $dbh->prepare("SELECT DISTINCT subfieldvalue FROM marc_subfield_table WHERE tag + subfieldcode IN $fields order by subfieldvalue");
144 $sth->execute;
145 my $i=1;
147 print "=========================\n";
148 my $sth2 = $dbh->prepare("insert into authorised_values (category, authorised_value, lib) values (?,?,?)");
149 while (my ($langue) = $sth->fetchrow) {
150 $sth2->execute('LANG',$langue,$langue?$codesiso{$langue}:$langue);
151 print "lang : $langue is unknown is iso list\n" unless $codesiso{$langue};
153 print "=========================\n";