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