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