9 HOME MYSQL_HOST MYSQL_TCP_PORT MYSQL_USER MYSQL_DATABASE MYSQL_PW
10 MIGSCHEMA MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
12 use open ':encoding(utf8)';
17 use open ':std', ':encoding(UTF-8)';
18 use Encode qw( decode_utf8 );
19 use List::Util qw( min max );
20 my $mig_bin = "$FindBin::Bin/";
21 use lib "$FindBin::Bin/";
24 my $dbh = KMig::db_connect();
25 #$dbh->{mysql_enable_utf8mb4} = 1;
26 $dbh->do('SET NAMES utf8mb4');
28 #to do check for array passed and if not present then use tags
31 my $arg_list_length = scalar @taglist;
32 if($arg_list_length < 1) { @taglist = ("authorisedvalues","calendar","circrules","itemtypes","libraries","patrontypes","preferences","reports","smsproviders"); }
33 $MIGGITDIR =~ s/\/\//\//;
35 foreach my $restore (@taglist) {
37 if ($restore eq 'authorisedvalues') {
38 my $timestamp = most_recent_single($MIGGITDIR,'authorisedvalues');
39 if ($timestamp) { $restorefile = $MIGGITDIR . 'authorisedvalues' . '.' . $timestamp . '.xml'; }
40 print "Restoring from $restorefile ... \n";
41 if ($restorefile) { restore_authorisedvalues($dbh,$restorefile); }
43 if ($restore eq 'calendar') {
44 my $timestamp = most_recent_single($MIGGITDIR,'calendar');
45 if ($timestamp) { $restorefile = $MIGGITDIR . 'calendar' . '.' . $timestamp . '.xml'; }
46 print "Restoring from $restorefile ... \n";
47 if ($restorefile) { restore_calendar($dbh,$restorefile); }
49 if ($restore eq 'circrules') {
50 my $timestamp = most_recent_single($MIGGITDIR,'circrules');
51 if ($timestamp) { $restorefile = $MIGGITDIR . 'circrules' . '.' . $timestamp . '.xml'; }
52 print "Restoring from $restorefile ... \n";
53 if ($restorefile) { restore_circrules($dbh,$restorefile); }
55 if ($restore eq 'itemtypes') {
56 my $timestamp = most_recent_single($MIGGITDIR,'itemtypes');
57 if ($timestamp) { $restorefile = $MIGGITDIR . 'itemtypes' . '.' . $timestamp . '.xml'; }
58 print "Restoring from $restorefile ... \n";
59 if ($restorefile) { restore_itemtypes($dbh,$restorefile); }
61 if ($restore eq 'libraries') {
62 my $timestamp = most_recent_single($MIGGITDIR,'libraries');
63 if ($timestamp) { $restorefile = $MIGGITDIR . 'libraries' . '.' . $timestamp . '.xml'; }
64 print "Restoring from $restorefile ... \n";
65 if ($restorefile) { restore_libraries($dbh,$restorefile); }
67 if ($restore eq 'patrontypes') {
68 my $timestamp = most_recent_single($MIGGITDIR,'patrontypes');
69 if ($timestamp) { $restorefile = $MIGGITDIR . 'patrontypes' . '.' . $timestamp . '.xml'; }
70 print "Restoring from $restorefile ... \n";
71 if ($restorefile) { restore_patrontypes($dbh,$restorefile); }
73 if ($restore eq 'preferences') {
74 my $timestamp = most_recent_single($MIGGITDIR,'systempreferences');
75 if ($timestamp) { $restorefile = $MIGGITDIR . 'systempreferences' . '.' . $timestamp . '.xml'; }
76 print "Restoring from $restorefile ... \n";
77 if ($restorefile) { restore_preferences($dbh,$restorefile); }
78 print "IMPORTANT : if you are changing system preferences you may need to run 'sudo systemctl restart apache2 memcached'\n\n";
80 if ($restore eq 'reports') {
81 my $timestamp = most_recent_single($MIGGITDIR,'reports');
82 if ($timestamp) { $restorefile = $MIGGITDIR . 'reports' . '.' . $timestamp . '.xml'; }
83 print "Restoring from $restorefile ... \n";
84 if ($restorefile) { restore_reports($dbh,$restorefile); }
86 if ($restore eq 'smsproviders') {
87 my $timestamp = most_recent_single($MIGGITDIR,'smsproviders');
88 if ($timestamp) { $restorefile = $MIGGITDIR . 'smsproviders' . '.' . $timestamp . '.xml'; }
89 print "Restoring from $restorefile ... \n";
90 if ($restorefile) { restore_smsproviders($dbh,$restorefile); }
97 sub most_recent_single {
98 my $MGIGITDIR = shift;
102 opendir (DIR, $MIGGITDIR) or abort("could not open $MIGGITDIR");;
103 while (my $file = readdir(DIR)) {
104 if ($file =~ m/$str/) { push @files, $file; }
106 foreach my $file (@files) {
107 my @f = split /\./, $file;
111 my $max = max @times;
115 sub restore_authorisedvalues {
117 my $restore_file = shift;
118 my $parser = XML::LibXML->new();
119 my $dom = $parser->parse_file($restore_file);
121 my $query = "DELETE FROM authorised_values WHERE category != 'ITEMTYPECAT'";
122 my $sth = $dbh->prepare($query);
125 foreach my $node ($dom->findnodes('//value')) {
126 my $category = sql_str($node->findvalue('./category'));
127 my $authorised_value = sql_str($node->findvalue('./authorised_value'));
128 my $lib = sql_str($node->findvalue('./lib'));
129 my $lib_opac = sql_str($node->findvalue('./lib_opac'));
130 my $imageurl = sql_str($node->findvalue('./imageurl'));
131 $query = "INSERT INTO authorised_values (category,authorised_value,lib,lib_opac,imageurl) VALUES ($category,$authorised_value,$lib,$lib_opac,$imageurl)";
132 $sth = $dbh->prepare($query);
138 sub restore_calendar {
140 my $restore_file = shift;
141 my $parser = XML::LibXML->new();
142 my $dom = $parser->parse_file($restore_file);
144 my $query = "DELETE FROM repeatable_holidays WHERE 1 = 1";
145 my $sth = $dbh->prepare($query);
148 $query = "DELETE FROM special_holidays WHERE 1 = 1";
149 $sth = $dbh->prepare($query);
152 foreach my $node ($dom->findnodes('/holidays/repeatable')) {
153 my $branchcode = sql_str($node->findvalue('./branchcode'));
154 my $weekday = sql_num($node->findvalue('./weekday'));
155 my $day = sql_num($node->findvalue('./day'));
156 my $month = sql_num($node->findvalue('./month'));
157 my $title = sql_str($node->findvalue('./title'));
158 my $description = sql_str($node->findvalue('./description'));
159 $query = "INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description) VALUES ($branchcode,$weekday,$day,$month,$title,$description)";
160 $sth = $dbh->prepare($query);
164 foreach my $node ($dom->findnodes('/holidays/special')) {
165 my $branchcode = sql_str($node->findvalue('./branchcode'));
166 my $day = sql_num($node->findvalue('./day'));
167 my $month = sql_num($node->findvalue('./month'));
168 my $year = sql_num($node->findvalue('./year'));
169 my $isexception = sql_num($node->findvalue('./isexception'));
170 my $title = sql_str($node->findvalue('./title'));
171 my $description = sql_str($node->findvalue('./description'));
172 $query = "INSERT INTO special_holidays (branchcode,day,month,year,isexception,title,description) VALUES ($branchcode,$day,$month,$year,$isexception,$title,$description)";
173 $sth = $dbh->prepare($query);
180 sub restore_circrules {
182 my $restore_file = shift;
183 my $parser = XML::LibXML->new();
184 my $dom = $parser->parse_file($restore_file);
186 #order of operations - clean out circ_rules, then issuingrules; restore issuingrules then circ_rules
188 my $query = "DELETE FROM circulation_rules WHERE 1 = 1";
189 my $sth = $dbh->prepare($query);
192 $query = "DELETE FROM issuingrules WHERE 1 = 1";
193 $sth = $dbh->prepare($query);
196 foreach my $node ($dom->findnodes('//issuing/rule')) {
197 my $categorycode = sql_str($node->findvalue('./categorycode'));
198 my $itemtype = sql_str($node->findvalue('./itemtype'));
199 my $restrictedtype = sql_num($node->findvalue('./restrictedtype'));
200 my $rentaldiscount = sql_num($node->findvalue('./rentaldiscount'));
201 my $reservecharge = sql_num($node->findvalue('./reservecharge'));
202 my $fine = sql_num($node->findvalue('./fine'));
203 my $finedays = sql_num($node->findvalue('./finedays'));
204 my $maxsuspensiondays = sql_num($node->findvalue('./maxsuspensiondays'));
205 my $suspension_chargeperiod = sql_num($node->findvalue('./suspension_chargeperiod'));
206 my $firstremind = sql_num($node->findvalue('./firstremind'));
207 my $chargeperiod = sql_num($node->findvalue('./chargeperiod'));
208 my $chargeperiod_charge_at = sql_num($node->findvalue('./chargeperiod_charge_at'));
209 my $accountsent = sql_num($node->findvalue('./accountsent'));
210 my $issuelength = sql_num($node->findvalue('./issuelength'));
211 my $lengthunit = sql_str($node->findvalue('./lengthunit'));
212 my $hardduedate = sql_str($node->findvalue('./hardduedate'));
213 my $hardduedatecompare = sql_num($node->findvalue('./hardduedatecompare'));
214 my $renewalsallowed = sql_num($node->findvalue('./renewalsallowed'));
215 my $renewalperiod = sql_num($node->findvalue('./renewalperiod'));
216 my $norenewalbefore = sql_num($node->findvalue('./norenewalbefore'));
217 my $auto_renew = sql_num($node->findvalue('./auto_renew'));
218 my $no_auto_renewal_after = sql_num($node->findvalue('./no_auto_renewal_after'));
219 my $no_auto_renewal_after_hard_limit = sql_str($node->findvalue('./no_auto_renewal_after_hard_limit'));
220 my $reservesallowed = sql_num($node->findvalue('./reservesallowed'));
221 my $holds_per_record = sql_num($node->findvalue('./holds_per_record'));
222 my $holds_per_day = sql_num($node->findvalue('./holds_per_day'));
223 my $branchcode = sql_str($node->findvalue('./branchcode'));
224 my $overduefinescap = sql_num($node->findvalue('./overduefinescap'));
225 my $cap_fine_to_replacement_price = sql_num($node->findvalue('./cap_fine_to_replacement_price'));
226 my $onshelfholds = sql_num($node->findvalue('./onshelfholds'));
227 my $opacitemholds = sql_str($node->findvalue('./opacitemholds'));
228 my $article_requests = sql_str($node->findvalue('./article_requests'));
229 my $note = sql_str($node->findvalue('./note'));
230 $query = "INSERT INTO issuingrules (categorycode,itemtype,restrictedtype,rentaldiscount,reservecharge,fine,finedays,maxsuspensiondays,suspension_chargeperiod,firstremind,chargeperiod,chargeperiod_charge_at,accountsent,issuelength,lengthunit,hardduedate,hardduedatecompare,renewalsallowed,renewalperiod,norenewalbefore,auto_renew,no_auto_renewal_after,no_auto_renewal_after_hard_limit,reservesallowed,holds_per_record,holds_per_day,branchcode,overduefinescap,cap_fine_to_replacement_price,onshelfholds,opacitemholds,article_requests,note) VALUES ($categorycode,$itemtype,$restrictedtype,$rentaldiscount,$reservecharge,$fine,$finedays,$maxsuspensiondays,$suspension_chargeperiod,$firstremind,$chargeperiod,$chargeperiod_charge_at,$accountsent,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$renewalsallowed,$renewalperiod,$norenewalbefore,$auto_renew,$no_auto_renewal_after,$no_auto_renewal_after_hard_limit,$reservesallowed,$holds_per_record,$holds_per_day,$branchcode,$overduefinescap,$cap_fine_to_replacement_price,$onshelfholds,$opacitemholds,$article_requests,$note)";
231 $sth = $dbh->prepare($query);
235 foreach my $node ($dom->findnodes('//circ/rule')) {
236 my $branchcode = sql_str($node->findvalue('./branchcode'));
237 my $categorycode = sql_str($node->findvalue('./categorycode'));
238 my $itemtype = sql_str($node->findvalue('./itemtype'));
239 my $rule_name = sql_str($node->findvalue('./rule_name'));
240 my $rule_value = sql_str($node->findvalue('./rule_value'));
241 $query = "INSERT INTO circulation_rules (branchcode,categorycode,itemtype,rule_name,rule_value) VALUES ($branchcode,$categorycode,$itemtype,$rule_name,$rule_value)";
242 $sth = $dbh->prepare($query);
249 sub restore_itemtypes {
251 my $restorefile = shift;
252 my $parser = XML::LibXML->new();
253 my $dom = $parser->parse_file($restorefile);
255 my $query = "UPDATE itemtypes SET searchcategory = NULL";
256 my $sth = $dbh->prepare($query);
259 $query = "DELETE FROM authorised_values WHERE category = 'ITEMTYPECAT'";
260 $sth = $dbh->prepare($query);
263 $query = "DELETE FROM localization WHERE entity = 'itemtypes'";
264 $sth = $dbh->prepare($query);
267 foreach my $node ($dom->findnodes('/authorised_values/value')) {
268 my $category = sql_str($node->findvalue('./category'));
269 my $authvalue = sql_str($node->findvalue('./authvalue'));
270 my $lib = sql_str($node->findvalue('./lib'));
271 my $lib_opac = sql_str($node->findvalue('./lib_opac'));
272 my $image_url = sql_str($node->findvalue('./image_url'));
273 my $query = "INSERT INTO authorised_values (category,authvalue,lib,lib_opac,image_url) VALUES ($category,$authvalue,$lib,$lib_opac,$image_url)";
274 $sth = $dbh->prepare($query);
278 foreach my $node ($dom->findnodes('/itemtypes/value')) {
279 my $itemtype = sql_str($node->findvalue('./itemtype'));
280 my $description = sql_str($node->findvalue('./description'));
281 my $rentalcharge = sql_str($node->findvalue('./rentalcharge'));
282 my $rentalcharge_daily = sql_str($node->findvalue('./rentalcharge_daily'));
283 my $rentalcharge_hourly = sql_str($node->findvalue('./rentalcharge_hourly'));
284 my $defaultreplacecost = sql_str($node->findvalue('./defaultreplacecost'));
285 my $processfee = sql_str($node->findvalue('./processfee'));
286 my $notforloan = sql_str($node->findvalue('./notforloan'));
287 my $imageurl = sql_str($node->findvalue('./imageurl'));
288 my $summary = sql_str($node->findvalue('./summary'));
289 my $checkinmsg = sql_str($node->findvalue('./checkinmsg'));
290 my $checkinmsgtype = sql_str($node->findvalue('./checkinmsgtype'));
291 my $sip_media_type = sql_str($node->findvalue('./sip_media_type'));
292 my $hideinopac = sql_str($node->findvalue('./hideinopac'));
293 my $searchcategory = sql_str($node->findvalue('./searchcategory'));
294 $query = "SELECT itemtype FROM itemtypes WHERE itemtype = $itemtype";
295 $sth = $dbh->prepare($query);
298 while (my @row = $sth->fetchrow_array) { $answer = sql_str($row[0]); }
299 if (!defined $answer or $answer ne $itemtype) {
300 $query = "INSERT INTO itemtypes (itemtype,description,rentalcharge,rentalcharge_daily,rentalcharge_hourly,defaultreplacecost,processfee,notforloan,imageurl,summary,checkinmsg,sip_media_type,hideinopac,searchcategory)
301 VALUES ($itemtype,$description,$rentalcharge,$rentalcharge_daily,$rentalcharge_hourly,$defaultreplacecost,$processfee,$notforloan,$imageurl,$summary,$checkinmsg,$sip_media_type,$hideinopac,$searchcategory)";
302 $sth = $dbh->prepare($query);
305 $query = "UPDATE itemtypes SET description = $description,rentalcharge = $rentalcharge,rentalcharge_daily = $rentalcharge_daily,rentalcharge_hourly = $rentalcharge_hourly,defaultreplacecost = $defaultreplacecost,processfee = $processfee,notforloan = $notforloan,imageurl = $imageurl,summary = $summary,checkinmsg = $checkinmsg,sip_media_type = $sip_media_type,hideinopac = $hideinopac,searchcategory = $searchcategory
306 WHERE itemtype = $itemtype";
307 $sth = $dbh->prepare($query);
312 foreach my $node ($dom->findnodes('//localizations/value')) {
313 my $entity = sql_str($node->findvalue('./entity'));
314 my $code = sql_str($node->findvalue('./code'));
315 my $lang = sql_str($node->findvalue('./lang'));
316 my $translation = sql_str($node->findvalue('./translation'));
317 my $query = "INSERT INTO localization (entity,code,lang,translation) VALUES ($entity,$code,$lang,$translation)";
318 $sth = $dbh->prepare($query);
326 sub restore_libraries {
328 my $restorefile = shift;
329 my $parser = XML::LibXML->new();
330 my $dom = $parser->parse_file($restorefile);
332 my $query = "TRUNCATE library_groups";
333 my $sth = $dbh->prepare($query);
336 foreach my $node ($dom->findnodes('//library')) {
337 my $branchcode = sql_str($node->findvalue('./branchcode'));
338 my $branchname = sql_str($node->findvalue('./branchname'));
339 my $branchaddress1 = sql_str($node->findvalue('./branchaddress1'));
340 my $branchaddress2 = sql_str($node->findvalue('./branchaddress2'));
341 my $branchaddress3 = sql_str($node->findvalue('./branchaddress3'));
342 my $branchzip = sql_str($node->findvalue('./branchzip'));
343 my $branchcity = sql_str($node->findvalue('./branchcity'));
344 my $branchstate = sql_str($node->findvalue('./branchstate'));
345 my $branchcountry = sql_str($node->findvalue('./branchcountry'));
346 my $branchphone = sql_str($node->findvalue('./branchphone'));
347 my $branchfax = sql_str($node->findvalue('./branchfax'));
348 my $branchemail = sql_str($node->findvalue('./branchemail'));
349 my $branchreplyto = sql_str($node->findvalue('./branchreplyto'));
350 my $branchreturnpath = sql_str($node->findvalue('./branchreturnpath'));
351 my $branchurl = sql_str($node->findvalue('./branchurl'));
352 my $issuing = sql_str($node->findvalue('./issuing'));
353 my $branchip = sql_str($node->findvalue('./branchip'));
354 my $branchprinter = sql_str($node->findvalue('./branchprinter'));
355 my $branchnotes = sql_str($node->findvalue('./branchnotes'));
356 my $opac_info = sql_str($node->findvalue('./opac_info'));
357 my $geolocation = sql_str($node->findvalue('./geolocation'));
358 my $marcorgcode = sql_str($node->findvalue('./marcorgcode'));
359 my $pickup_location = $node->findvalue('./pickup_location');
360 $query = "SELECT branchcode FROM branches WHERE branchcode = $branchcode";
361 $sth = $dbh->prepare($query);
364 while (my @row = $sth->fetchrow_array) { $answer = sql_str($row[0]); }
365 if (!defined $answer or $answer ne $branchcode) {
366 $query = "INSERT INTO branches (branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchzip,branchcity,branchstate,branchcountry,branchphone,branchfax,branchemail,branchreplyto,branchreturnpath,branchurl,issuing,branchip,branchprinter,branchnotes,opac_info,geolocation,marcorgcode,pickup_location) VALUES ($branchcode,$branchname,$branchaddress1,$branchaddress2,$branchaddress3,$branchzip,$branchcity,$branchstate,$branchcountry,$branchphone,$branchfax,$branchemail,$branchreplyto,$branchreturnpath,$branchurl,$issuing,$branchip,$branchprinter,$branchnotes,$opac_info,$geolocation,$marcorgcode,$pickup_location)";
367 $sth = $dbh->prepare($query);
370 $query = "UPDATE branches SET branchname = $branchname,branchaddress1 = $branchaddress1,branchaddress2 = $branchaddress2,branchaddress3 = $branchaddress3,branchzip = $branchzip,branchcity = $branchcity,branchstate = $branchstate,branchcountry = $branchcountry,branchphone = $branchphone,branchfax = $branchfax,branchemail = $branchemail,branchreplyto = $branchreplyto,branchreturnpath = $branchreturnpath,branchurl = $branchurl,issuing = $issuing,branchip = $branchip,branchprinter = $branchprinter,branchnotes = $branchnotes,opac_info = $opac_info,geolocation = $geolocation,marcorgcode = $marcorgcode,pickup_location = $pickup_location WHERE branchcode = $branchcode";
371 $sth = $dbh->prepare($query);
376 #haven't taken into account them needing to go in, in a specific order so I could check parent ids first
377 foreach my $node ($dom->findnodes('//library_group')) {
378 my $id = $node->findvalue('./id');
379 my $parent_id = sql_num($node->findvalue('./parent_id'));
380 my $branchcode = sql_str($node->findvalue('./branchcode'));
381 my $title = sql_str($node->findvalue('./title'));
382 my $descr = sql_str($node->findvalue('./description'));
383 my $ft1 = sql_num($node->findvalue('./ft_hide_patron_info'));
384 my $ft2 = sql_num($node->findvalue('./ft_search_groups_opac'));
385 my $ft3 = sql_num($node->findvalue('./ft_search_groups_staff'));
386 $query = "INSERT INTO library_groups (id,parent_id,branchcode,title,description,ft_hide_patron_info,ft_search_groups_opac,ft_search_groups_staff) VALUES ($id,$parent_id,$branchcode,$title,$descr,$ft1,$ft2,$ft3)";
387 $sth = $dbh->prepare($query);
393 sub restore_patrontypes {
395 my $restorefile = shift;
396 my $parser = XML::LibXML->new();
397 my $dom = $parser->parse_file($restorefile);
402 foreach my $node ($dom->findnodes('//category')) {
403 my $categorycode = sql_str($node->findvalue('./categorycode'));
404 my $description = sql_str($node->findvalue('./description'));
405 my $enrolmentperiod = sql_num($node->findvalue('./enrolmentperiod'));
406 my $enrolmentperioddate = sql_str($node->findvalue('./enrolmentperioddate'));
407 my $upperagelimit = sql_num($node->findvalue('./upperagelimit'));
408 my $dateofbirthrequired = sql_num($node->findvalue('./dateofbirthrequired'));
409 my $finetype = sql_str($node->findvalue('./finetype'));
410 my $bulk = sql_num($node->findvalue('./bulk'));
411 my $enrolmentfee = sql_num($node->findvalue('./enrolmentfee'));
412 my $overduenoticerequired = sql_num($node->findvalue('./overduenoticerequired'));
413 my $issuelimit = sql_num($node->findvalue('./issuelimit'));
414 my $reservefee = sql_num($node->findvalue('./reservefee'));
415 my $hidelostitems = sql_num($node->findvalue('./hidelostitems'));
416 my $category_type = sql_str($node->findvalue('./category_type'));
417 my $BlockExpiredPatronOpacActions = sql_num($node->findvalue('./BlockExpiredPatronOpacActions'));
418 my $default_privacy = sql_str($node->findvalue('./default_privacy'));
419 my $checkprevcheckout = sql_str($node->findvalue('./checkprevcheckout'));
420 my $reset_password = sql_num($node->findvalue('./reset_password'));
421 my $change_password = sql_num($node->findvalue('./change_password'));
422 $query = "SELECT categorycode FROM categories WHERE categorycode = $categorycode";
423 $sth = $dbh->prepare($query);
426 while (my @row = $sth->fetchrow_array) { $answer = sql_str($row[0]); }
427 if (!defined $answer or $answer ne $categorycode) {
428 $query = "INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit,reservefee,hidelostitems,category_type,BlockExpiredPatronOpacActions,default_privacy,checkprevcheckout,reset_password,change_password) VALUES ($categorycode,$description,$enrolmentperiod,$enrolmentperioddate,$upperagelimit,$dateofbirthrequired,$finetype,$bulk,$enrolmentfee,$overduenoticerequired,$issuelimit,$reservefee,$hidelostitems,$category_type,$BlockExpiredPatronOpacActions,$default_privacy,$checkprevcheckout,$reset_password,$change_password)";
429 $sth = $dbh->prepare($query);
432 $query = "UPDATE categories SET description = $description,enrolmentperiod = $enrolmentperiod,enrolmentperioddate = $enrolmentperioddate,upperagelimit = $upperagelimit,dateofbirthrequired = $dateofbirthrequired,finetype = $finetype,bulk = $bulk,enrolmentfee = $enrolmentfee,overduenoticerequired = $overduenoticerequired,issuelimit = $issuelimit,reservefee = $reservefee,hidelostitems = $hidelostitems,category_type = $category_type,BlockExpiredPatronOpacActions = $BlockExpiredPatronOpacActions,default_privacy = $default_privacy,checkprevcheckout = $checkprevcheckout,reset_password = $reset_password,change_password = $change_password WHERE categorycode = $categorycode";
433 $sth = $dbh->prepare($query);
440 sub restore_preferences {
442 my $restore_file = shift;
443 my $parser = XML::LibXML->new();
444 my $dom = $parser->parse_file($restore_file);
446 foreach my $node ($dom->findnodes('//pref')) {
447 my $variable = domain_shift(sql_str($node->findvalue('./variable')));
448 my $value = domain_shift(sql_str($node->findvalue('./value')));
449 my $query = "UPDATE systempreferences SET value = $value WHERE variable = $variable";
450 my $sth = $dbh->prepare($query);
456 sub restore_reports {
458 my $restore_file = shift;
459 my $parser = XML::LibXML->new();
460 my $dom = $parser->parse_file($restore_file);
462 my $query = "DELETE FROM saved_sql WHERE 1 = 1";
463 my $sth = $dbh->prepare($query);
466 foreach my $node ($dom->findnodes('//sqlreport')) {
467 my $date_created = sql_str($node->findvalue('./date_created'));
468 my $last_modified = sql_str($node->findvalue('./last_modified'));
469 my $savedsql = domain_shift(sql_str($node->findvalue('./savedsql')));
470 my $report_name = sql_str($node->findvalue('./report_name'));
471 my $type = sql_str($node->findvalue('./type'));
472 my $notes = sql_str($node->findvalue('./notes'));
473 my $cache_expiry = sql_num($node->findvalue('./cache_expiry'));
474 my $public = sql_str($node->findvalue('./public'));
475 my $report_area = sql_str($node->findvalue('./report_area'));
476 my $report_group = sql_str($node->findvalue('./report_group'));
477 my $report_subgroup = sql_str($node->findvalue('./report_subgroup'));
478 my $userid = sql_str($node->findvalue('./userid'));
480 $query = "SELECT borrowernumber FROM borrowers WHERE userid = $userid";
481 $sth = $dbh->prepare($query);
483 my @row = $sth->fetchrow_array;
484 my $borrowernumber = sql_num($row[0]);
486 $query = "INSERT INTO saved_sql (date_created,last_modified,savedsql,report_name,type,notes,cache_expiry,public,report_area,report_group,report_subgroup,borrowernumber) VALUES ($date_created,$last_modified,$savedsql,$report_name,$type,$notes,$cache_expiry,$public,$report_area,$report_group,$report_subgroup,$borrowernumber)";
487 $sth = $dbh->prepare($query);
493 sub restore_smsproviders {
495 my $restore_file = shift;
496 my $parser = XML::LibXML->new();
497 my $dom = $parser->parse_file($restore_file);
499 my $query = "DELETE FROM sms_providers WHERE 1 = 1";
500 my $sth = $dbh->prepare($query);
503 foreach my $node ($dom->findnodes('//provider')) {
504 my $name = sql_str($node->findvalue('./name'));
505 my $domain = sql_str($node->findvalue('./domain'));
506 $query = "INSERT INTO sms_providers (name,domain) VALUES ($name,$domain)";
507 $sth = $dbh->prepare($query);
515 $str =~ s/-test.kohacatalog.com/.kohacatalog.com/g;
516 $str =~ s/-test-staff.kohacatalog.com/-staff.kohacatalog.com/g;
522 if (!defined $str or $str eq '') { return 'NULL'; }
524 $str = '\'' . $str . '\'';
530 if (!defined $str or $str eq '') { return 'NULL'; } else { return $str; }
535 print STDERR "$0: $msg", "\n";
543 mig import foo_a foo_b foo_c