#!/usr/bin/perl use strict; use warnings; use DBI; use Data::Dumper; use Env qw( HOME MYSQL_HOST MYSQL_TCP_PORT MYSQL_USER MYSQL_DATABASE MYSQL_PW MIGSCHEMA MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR ); use open ':encoding(utf8)'; use Cwd 'abs_path'; use Cwd qw(getcwd); use FindBin; my $mig_bin = "$FindBin::Bin/"; use lib "$FindBin::Bin/"; use XML::Writer; use open ':std', ':encoding(UTF-8)'; use Encode qw( decode_utf8 ); use KMig; my $dbh = KMig::db_connect(); $dbh->{mysql_enable_utf8mb4} = 1; #to do check for array passed and if not present then use tags my @taglist = @ARGV; my $arg_list_length = scalar @taglist; if($arg_list_length < 1) { @taglist = ("authorisedvalues","booksellers","budgets","borrowerattributes","calendar","circrules","itemtypes","letters","libraries","messages","patrontypes","preferences","reports","smsproviders"); } $MIGGITDIR =~ s/\/\//\//; my $timestamp = create_timestamp(); foreach my $backup (@taglist) { my $backupfile; if ($backup eq 'authorisedvalues') { $backupfile = $MIGGITDIR . 'authorisedvalues' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_authorisedvalues($dbh,$backupfile); } if ($backup eq 'booksellers') { $backupfile = $MIGGITDIR . 'booksellers' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_booksellers($dbh,$backupfile); } if ($backup eq 'borrowerattributes') { $backupfile = $MIGGITDIR . 'borrowerattributes' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_borrower_attributes($dbh,$backupfile); } if ($backup eq 'budgets') { $backupfile = $MIGGITDIR . 'budgets' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_budgets($dbh,$backupfile); } if ($backup eq 'calendar') { $backupfile = $MIGGITDIR . 'calendar' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_calendar($dbh,$backupfile); } if ($backup eq 'circrules') { $backupfile = $MIGGITDIR . 'circrules' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_circrules($dbh,$backupfile); } if ($backup eq 'itemtypes') { $backupfile = $MIGGITDIR . 'itemtypes' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_itemtypes($dbh,$backupfile); } if ($backup eq 'letters') { $backupfile = $MIGGITDIR . 'letters' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_letters($dbh,$backupfile); } if ($backup eq 'libraries') { $backupfile = $MIGGITDIR . 'libraries' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_libraries($dbh,$backupfile); } if ($backup eq 'messages') { $backupfile = $MIGGITDIR . 'messages' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_messages($dbh,$backupfile); } if ($backup eq 'patrontypes') { $backupfile = $MIGGITDIR . 'patrontypes' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_patrontypes($dbh,$backupfile); } if ($backup eq 'preferences') { $backupfile = $MIGGITDIR . 'systempreferences' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_preferences($dbh,$backupfile); } if ($backup eq 'reports') { $backupfile = $MIGGITDIR . 'reports' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_reports($dbh,$backupfile); } if ($backup eq 'smsproviders') { $backupfile = $MIGGITDIR . 'smsproviders' . '.' . $timestamp . '.xml'; print "Backing up $backupfile ... \n"; backup_smsproviders($dbh,$backupfile); } } sub backup_authorisedvalues { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('document'); $xml->startTag('authorisedvalues'); my $sth = sql_giveback($dbh,"SELECT category,authorised_value,lib,lib_opac,imageurl FROM authorised_values WHERE category != 'ITEMTYPECAT'"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('category', $row[0]); $xml->dataElement('authorised_value', $row[1]); $xml->dataElement('lib', $row[2]); $xml->dataElement('lib_opac', $row[3]); $xml->dataElement('imageurl', $row[4]); $xml->endTag('value'); } $xml->endTag('authorisedvalues'); $xml->startTag('categories'); $sth = sql_giveback($dbh,"SELECT category_name FROM authorised_value_categories WHERE category_name != 'ITEMTYPECAT'"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('name', $row[0]); $xml->endTag('value'); } $xml->endTag('categories'); $xml->endTag('document'); $xml->end(); close $fh; return; } sub backup_booksellers { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('booksellers'); my $sth = sql_giveback($dbh,"SELECT name,address1,address2,address3,address4,phone,accountnumber,othersupplier,currency,booksellerfax,notes,bookselleremail,booksellerurl,postal,url,active,listprice,invoiceprice,gstreg,listincgst,invoiceincgst,tax_rate,discount,fax,deliverytime FROM aqbooksellers"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('name', $row[1]); $xml->dataElement('address1', $row[2]); $xml->dataElement('address2', $row[3]); $xml->dataElement('address3', $row[4]); $xml->dataElement('address4', $row[5]); $xml->dataElement('phone', $row[6]); $xml->dataElement('accountnumber', $row[7]); $xml->dataElement('othersupplier', $row[8]); $xml->dataElement('currency', $row[9]); $xml->dataElement('booksellerfax', $row[10]); $xml->dataElement('notes', $row[11]); $xml->dataElement('bookselleremail', $row[12]); $xml->dataElement('booksellerurl', $row[13]); $xml->dataElement('postal', $row[14]); $xml->dataElement('url', $row[15]); $xml->dataElement('active', $row[16]); $xml->dataElement('listprice', $row[17]); $xml->dataElement('invoiceprice ', $row[18]); $xml->dataElement('gstreg', $row[19]); $xml->dataElement('listincgst', $row[20]); $xml->dataElement('invoiceincgst', $row[21]); $xml->dataElement('tax_rate', $row[22]); $xml->dataElement('discount', $row[23]); $xml->dataElement('fax ', $row[24]); $xml->dataElement('deliverytime', $row[25]); $xml->endTag('value'); } $xml->endTag('booksellers'); $xml->end(); close $fh; return; } sub backup_borrower_attributes { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('document'); $xml->startTag('borrower_attribute_types'); my $sth = sql_giveback($dbh,"SELECT code,description,repeatable,opac_display,opac_editable,staff_searchable,authorised_value_category,display_checkout,category_code,class FROM borrower_attribute_types"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('code', $row[0]); $xml->dataElement('description', $row[1]); $xml->dataElement('repeat', $row[2]); $xml->dataElement('opac_display', $row[3]); $xml->dataElement('staff_searchable', $row[4]); $xml->dataElement('auth_value_cat', $row[5]); $xml->dataElement('display_checkout', $row[6]); $xml->dataElement('category_code', $row[7]); $xml->dataElement('class', $row[8]); $xml->endTag('value'); } $xml->endTag('borrower_attribute_types'); $xml->startTag('authorised_value_categories'); $sth = sql_giveback($dbh,"SELECT category_name FROM authorised_value_categories WHERE category_name IN (select category_name from borrower_attribute_types)"); while (my @row = $sth->fetchrow_array) { $xml->dataElement('value', $row[0]); } $xml->endTag('authorised_value_categories'); $xml->startTag('authorised_values'); $sth = sql_giveback($dbh,"SELECT category,authorised_value,lib,lib_opac,imageurl FROM authorised_values where category in (select category_code from borrower_attribute_types);"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('category', $row[0]); $xml->dataElement('authvalue', $row[1]); $xml->dataElement('lib', $row[2]); $xml->dataElement('lib_opac', $row[3]); $xml->dataElement('image_url', $row[4]); $xml->endTag('value'); } $xml->endTag('authorised_values'); $xml->endTag('document'); $xml->end(); close $fh; return; } sub backup_budgets { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('document'); $xml->startTag('budgets'); my $sth = sql_giveback($dbh,'SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = "aqbudgets"'); my @ai = $sth->fetchrow_array; $xml->dataElement('autoincrement', $ai[0]); $sth = sql_giveback($dbh,"SELECT budget_id,budget_parent_id,budget_code,budget_name,budget_branchcode,budget_amount,budget_encumb,budget_expend,budget_notes,timestamp,budget_period_id,sort1_authcat,sort2_authcat,budget_owner_id,budget_permission FROM aqbudgets"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('budget_id', $row[0]); $xml->dataElement('budget_parent_id', $row[1]); $xml->dataElement('budget_code', $row[2]); $xml->dataElement('budget_name', $row[3]); $xml->dataElement('budget_branchcode', $row[4]); $xml->dataElement('budget_amount', $row[5]); $xml->dataElement('budget_encumb', $row[6]); $xml->dataElement('budget_expend', $row[7]); $xml->dataElement('budget_notes', $row[8]); $xml->dataElement('timestamp', $row[9]); $xml->dataElement('budget_period_id', $row[10]); $xml->dataElement('sort1_authcat', $row[11]); $xml->dataElement('sort2_authcat', $row[12]); $xml->dataElement('budget_owner_id', $row[13]); $xml->dataElement('budget_permission', $row[14]); $xml->endTag('value'); } $xml->endTag('budgets'); $xml->startTag('budgetperiods'); $sth = sql_giveback($dbh,'SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = "aqbudgetperiods"'); @ai = $sth->fetchrow_array; $xml->dataElement('autoincrement', $ai[0]); $sth = sql_giveback($dbh,"SELECT budget_period_id,budget_period_startdate,budget_period_enddate,budget_period_active,budget_period_description,budget_period_total,budget_period_locked,sort1_authcat,sort2_authcat FROM aqbudgetperiods"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('budget_period_id', $row[0]); $xml->dataElement('budget_period_startdate', $row[1]); $xml->dataElement('budget_period_enddate', $row[2]); $xml->dataElement('budget_period_active', $row[3]); $xml->dataElement('budget_period_description', $row[4]); $xml->dataElement('budget_period_total', $row[5]); $xml->dataElement('budget_period_locked', $row[6]); $xml->dataElement('sort1_authcat', $row[7]); $xml->dataElement('sort2_authcat', $row[8]); $xml->endTag('value'); } $xml->endTag('budgetperiods'); $xml->endTag('document'); $xml->end(); close $fh; return; } sub backup_calendar { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('holidays'); my $sth = sql_giveback($dbh,"SELECT branchcode,weekday,day,month,title,description FROM repeatable_holidays"); while (my @row = $sth->fetchrow_array) { $xml->startTag('repeatable'); $xml->dataElement('branchcode',$row[0]); $xml->dataElement('weekday',$row[1]); $xml->dataElement('day',$row[2]); $xml->dataElement('month',$row[3]); $xml->dataElement('title',$row[4]); $xml->dataElement('description',$row[5]); $xml->endTag('repeatable'); } $sth = sql_giveback($dbh,"SELECT branchcode,day,month,year,isexception,title,description FROM special_holidays"); while (my @row = $sth->fetchrow_array) { $xml->startTag('special'); $xml->dataElement('branchcode',$row[0]); $xml->dataElement('day',$row[1]); $xml->dataElement('month',$row[2]); $xml->dataElement('year',$row[3]); $xml->dataElement('isexception',$row[4]); $xml->dataElement('title',$row[5]); $xml->dataElement('description',$row[6]); $xml->endTag('special'); } $xml->endTag('holidays'); $xml->end(); close $fh; return; } sub backup_circrules { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('document'); $xml->startTag('circ'); my $sth = sql_giveback($dbh,"SELECT branchcode, categorycode, itemtype, rule_name, rule_value FROM circulation_rules"); while (my @row = $sth->fetchrow_array) { $xml->startTag('rule'); $xml->dataElement('branchcode', $row[0]); $xml->dataElement('categorycode', $row[1]); $xml->dataElement('itemtype', $row[2]); $xml->dataElement('rule_name', $row[3]); $xml->dataElement('rule_value', $row[4]); $xml->endTag('rule'); } $xml->endTag('circ'); $xml->startTag('issuing'); $sth = sql_giveback($dbh,"SELECT 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 FROM issuingrules"); while (my @row = $sth->fetchrow_array) { $xml->startTag('rule'); $xml->dataElement('categorycode', $row[0]); $xml->dataElement('itemtype', $row[1]); $xml->dataElement('restrictedtype', $row[2]); $xml->dataElement('rentaldiscount', $row[3]); $xml->dataElement('reservecharge', $row[4]); $xml->dataElement('fine', $row[5]); $xml->dataElement('finedays', $row[6]); $xml->dataElement('maxsuspensiondays', $row[7]); $xml->dataElement('suspension_chargeperiod', $row[8]); $xml->dataElement('firstremind', $row[9]); $xml->dataElement('chargeperiod', $row[10]); $xml->dataElement('chargeperiod_charge_at', $row[11]); $xml->dataElement('accountsent', $row[12]); $xml->dataElement('issuelength', $row[13]); $xml->dataElement('lengthunit', $row[14]); $xml->dataElement('hardduedate', $row[15]); $xml->dataElement('hardduedatecompare', $row[16]); $xml->dataElement('renewalsallowed', $row[17]); $xml->dataElement('renewalperiod', $row[18]); $xml->dataElement('norenewalbefore', $row[19]); $xml->dataElement('auto_renew', $row[20]); $xml->dataElement('no_auto_renewal_after', $row[21]); $xml->dataElement('no_auto_renewal_after_hard_limit', $row[22]); $xml->dataElement('reservesallowed', $row[23]); $xml->dataElement('holds_per_record', $row[24]); $xml->dataElement('holds_per_day', $row[25]); $xml->dataElement('branchcode', $row[26]); $xml->dataElement('overduefinescap', $row[27]); $xml->dataElement('cap_fine_to_replacement_price', $row[28]); $xml->dataElement('onshelfholds', $row[29]); $xml->dataElement('opacitemholds', $row[30]); $xml->dataElement('article_requests', $row[31]); $xml->dataElement('note', $row[32]); $xml->endTag('rule'); } $xml->endTag('issuing'); $xml->endTag('document'); $xml->end(); close $fh; return; } sub backup_itemtypes { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('document'); $xml->startTag('itemtypes'); my $sth = sql_giveback($dbh,"SELECT itemtype, description, rentalcharge, rentalcharge_daily, rentalcharge_hourly, defaultreplacecost, processfee, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type, hideinopac, searchcategory FROM itemtypes"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('itemtype', $row[0]); $xml->dataElement('description', $row[1]); $xml->dataElement('rentalcharge', $row[2]); $xml->dataElement('rentalcharge_daily', $row[3]); $xml->dataElement('rentalcharge_hourly', $row[4]); $xml->dataElement('defaultreplacecost', $row[5]); $xml->dataElement('processfee', $row[6]); $xml->dataElement('notforloan', $row[7]); $xml->dataElement('imageurl', $row[8]); $xml->dataElement('summary', $row[9]); $xml->dataElement('checkinmsg', $row[10]); $xml->dataElement('checkinmsgtype', $row[11]); $xml->dataElement('sip_media_type', $row[12]); $xml->dataElement('hideinopac', $row[13]); $xml->dataElement('searchcategory', $row[14]); $xml->endTag('value'); } $xml->endTag('itemtypes'); $xml->startTag('authorised_values'); $sth = sql_giveback($dbh,"SELECT category,authorised_value,lib,lib_opac,imageurl FROM authorised_values where category = 'ITEMTYPECAT';"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('category', $row[0]); $xml->dataElement('authvalue', $row[1]); $xml->dataElement('lib', $row[2]); $xml->dataElement('lib_opac', $row[3]); $xml->dataElement('image_url', $row[4]); $xml->endTag('value'); } $xml->endTag('authorised_values'); $xml->startTag('localizations'); $sth = sql_giveback($dbh,"SELECT entity, code, lang, translation FROM localization WHERE entity = 'itemtypes';"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('entity', $row[0]); $xml->dataElement('code', $row[1]); $xml->dataElement('lang', $row[2]); $xml->dataElement('translation', $row[3]); $xml->endTag('value'); } $xml->endTag('localizations'); $xml->endTag('document'); $xml->end(); close $fh; return; } sub backup_letters { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('letters'); my $sth = sql_giveback($dbh,"SELECT module,code,branchcode,name,is_html,title,content,message_transport_type,lang FROM letter"); while (my @row = $sth->fetchrow_array) { $xml->startTag('letter'); $xml->dataElement('module',$row[0]); $xml->dataElement('code',$row[1]); $xml->dataElement('branchcode',$row[2]); $xml->dataElement('name',$row[3]); $xml->dataElement('is_html',$row[4]); $xml->dataElement('title',$row[5]); $xml->dataElement('content',$row[6]); $xml->dataElement('message_transport_type',$row[7]); $xml->dataElement('lang',$row[8]); $xml->endTag('letter'); } $xml->endTag('letters'); $xml->end(); close $fh; return; } sub backup_libraries { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('libraries'); my $sth = sql_giveback($dbh,"SELECT id,parent_id,branchcode,title,description,ft_hide_patron_info,ft_search_groups_opac,ft_search_groups_staff FROM library_groups"); while (my @row = $sth->fetchrow_array) { $xml->startTag('library_group'); $xml->dataElement('id',$row[0]); $xml->dataElement('parent_id',$row[1]); $xml->dataElement('branchcode',$row[2]); $xml->dataElement('title',$row[3]); $xml->dataElement('description',$row[4]); $xml->dataElement('ft_hide_patron_info',$row[5]); $xml->dataElement('ft_search_groups_opac',$row[6]); $xml->dataElement('ft_search_groups_staff',$row[7]); $xml->endTag('library_group'); } $sth = sql_giveback($dbh,"SELECT 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 FROM branches"); while (my @row = $sth->fetchrow_array) { $xml->startTag('library'); $xml->dataElement('branchcode',$row[0]); $xml->dataElement('branchname',$row[1]); $xml->dataElement('branchaddress1',$row[2]); $xml->dataElement('branchaddress2',$row[3]); $xml->dataElement('branchaddress3',$row[4]); $xml->dataElement('branchzip',$row[5]); $xml->dataElement('branchcity',$row[6]); $xml->dataElement('branchstate',$row[7]); $xml->dataElement('branchcountry',$row[8]); $xml->dataElement('branchphone',$row[9]); $xml->dataElement('branchfax',$row[10]); $xml->dataElement('branchemail',$row[11]); $xml->dataElement('branchreplyto',$row[12]); $xml->dataElement('branchreturnpath',$row[13]); $xml->dataElement('branchurl',$row[14]); $xml->dataElement('issuing',$row[15]); $xml->dataElement('branchip',$row[16]); $xml->dataElement('branchprinter',$row[17]); $xml->dataElement('branchnotes',$row[18]); $xml->dataElement('opac_info',$row[19]); $xml->dataElement('geolocation',$row[20]); $xml->dataElement('marcorgcode',$row[21]); $xml->dataElement('pickup_location',$row[22]); $xml->endTag('library'); } $xml->endTag('libraries'); $xml->end(); close $fh; return; } sub backup_messages { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('document'); $xml->startTag('message_attributes'); my $sth = sql_giveback($dbh,'SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = "message_attributes"'); my @ai = $sth->fetchrow_array; $xml->dataElement('autoincrement', $ai[0]); $sth = sql_giveback($dbh,"SELECT message_attribute_id, message_name, takes_days FROM message_attributes"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('message_attribute_id', $row[0]); $xml->dataElement('message_name', $row[1]); $xml->dataElement('takes_days', $row[2]); $xml->endTag('value'); } $xml->endTag('message_attributes'); $xml->startTag('message_transport_types'); $sth = sql_giveback($dbh,"SELECT message_transport_type FROM message_transport_types"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('message_transport_type', $row[0]); $xml->endTag('value'); } $xml->endTag('message_transport_types'); $xml->startTag('message_transports'); $sth = sql_giveback($dbh,"SELECT message_attribute_id, message_transport_type, is_digest, letter_module, letter_code, branchcode FROM message_transports"); while (my @row = $sth->fetchrow_array) { $xml->startTag('value'); $xml->dataElement('message_attribute_id', $row[0]); $xml->dataElement('message_transport_type', $row[1]); $xml->dataElement('is_digest', $row[2]); $xml->dataElement('letter_module', $row[3]); $xml->dataElement('letter_code', $row[4]); $xml->dataElement('branchcode', $row[5]); $xml->endTag('value'); } $xml->endTag('message_transports'); $xml->endTag('document'); $xml->end(); close $fh; return; } sub backup_patrontypes { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('patron'); my $sth = sql_giveback($dbh,"SELECT categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit,reservefee,hidelostitems,category_type,BlockExpiredPatronOpacActions,default_privacy,checkprevcheckout,reset_password,change_password FROM categories"); while (my @row = $sth->fetchrow_array) { $xml->startTag('category'); $xml->dataElement('categorycode',$row[0]); $xml->dataElement('description',$row[1]); $xml->dataElement('enrolmentperiod',$row[2]); $xml->dataElement('enrolmentperioddate',$row[3]); $xml->dataElement('upperagelimit',$row[4]); $xml->dataElement('dateofbirthrequired',$row[5]); $xml->dataElement('finetype',$row[6]); $xml->dataElement('bulk',$row[7]); $xml->dataElement('enrolmentfee',$row[8]); $xml->dataElement('overduenoticerequired',$row[9]); $xml->dataElement('issuelimit',$row[10]); $xml->dataElement('reservefee',$row[11]); $xml->dataElement('hidelostitems',$row[12]); $xml->dataElement('category_type',$row[13]); $xml->dataElement('BlockExpiredPatronOpacActions',$row[14]); $xml->dataElement('default_privacy',$row[15]); $xml->dataElement('checkprevcheckout',$row[16]); $xml->dataElement('reset_password',$row[17]); $xml->dataElement('change_password',$row[18]); $xml->endTag('category'); } $xml->endTag('patron'); $xml->end(); close $fh; return; } sub backup_preferences { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('preferences'); my $sth = sql_giveback($dbh,"SELECT variable,value FROM systempreferences WHERE value != '' AND value IS NOT NULL"); while (my @row = $sth->fetchrow_array) { $xml->startTag('pref'); $xml->dataElement('variable',$row[0]); $xml->dataElement('value',$row[1]); $xml->endTag('pref'); } $xml->endTag('preferences'); $xml->end(); close $fh; return; } sub backup_reports { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('reports'); my $sth = sql_giveback($dbh,"SELECT s.date_created, s.last_modified, s.savedsql, s.report_name, s.type, s.notes, s.cache_expiry, s.public, s.report_area, s.report_group, s.report_subgroup, b.userid FROM saved_sql s LEFT JOIN borrowers b ON b.borrowernumber = s.borrowernumber"); while (my @row = $sth->fetchrow_array) { $xml->startTag('sqlreport'); $xml->dataElement('date_created',$row[0]); $xml->dataElement('last_modified',$row[1]); $xml->dataElement('savedsql',$row[2]); $xml->dataElement('report_name',$row[3]); $xml->dataElement('type',$row[4]); $xml->dataElement('notes',$row[5]); $xml->dataElement('cache_expiry',$row[6]); $xml->dataElement('public',$row[7]); $xml->dataElement('report_area',$row[8]); $xml->dataElement('report_group',$row[9]); $xml->dataElement('report_subgroup',$row[10]); $xml->dataElement('userid',$row[11]); $xml->endTag('sqlreport'); } $xml->endTag('reports'); $xml->end(); close $fh; return; } sub backup_smsproviders { my $dbh = shift; my $backupfile = shift; open(my $fh, '>', $backupfile) or die "Could not open $backupfile!"; my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2, ); $xml->xmlDecl('UTF-8'); $xml->startTag('sms'); my $sth = sql_giveback($dbh,"SELECT name,domain FROM sms_providers"); while (my @row = $sth->fetchrow_array) { $xml->startTag('provider'); $xml->dataElement('name',$row[0]); $xml->dataElement('domain',$row[1]); $xml->endTag('provider'); } $xml->endTag('sms'); $xml->end(); close $fh; return; } sub create_timestamp { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; $mon = sprintf("%02s",$mon); $mday = sprintf("%02s",$mday); $hour = sprintf("%02s",$hour); $min = sprintf("%02s",$min); $sec = sprintf("%02s",$sec); my $str = "$year$mon$mday$hour$min$sec"; return $str; } sub sql_noresult { my $dbh = shift; my $statement = shift; my $sth = $dbh->prepare($statement); $sth->execute(); return; } sub sql_giveback { my $dbh = shift; my $query = shift; my $sth = $dbh->prepare($query); $sth->execute(); return $sth; } sub abort { my $msg = shift; print STDERR "$0: $msg", "\n"; print_usage(); exit 1; } sub print_usage { print <<_USAGE_; mig export foo_a foo_b foo_c _USAGE_ }