#$dbh->{mysql_enable_utf8mb4} = 1;
$dbh->do('SET NAMES utf8mb4');
-#to do check for array passed and if not present then use tags
+my $mig_path = abs_path($0);
+$mig_path =~ s|[^/]+$||;
my @taglist = @ARGV;
my $arg_list_length = scalar @taglist;
-if($arg_list_length < 1) { @taglist = ("authorisedvalues","booksellers","borrowerattributes","budgets","calendar","circrules","itemtypes","letters","libraries","patrontypes","preferences","reports","smsproviders"); }
+if($arg_list_length < 1) { @taglist = ("libraries","patrontypes","itemtypes","authorisedvalues","booksellers","borrowerattributes","budgets","calendar","circrules","letters","preferences","reports","smsproviders"); }
$MIGGITDIR =~ s/\/\//\//;
+my @errors;
+
foreach my $restore (@taglist) {
my $restorefile;
if ($restore eq 'authorisedvalues') {
my $timestamp = most_recent_single($MIGGITDIR,'circrules');
if ($timestamp) { $restorefile = $MIGGITDIR . 'circrules' . '.' . $timestamp . '.xml'; }
print "Restoring from $restorefile ... \n";
- if ($restorefile) { restore_circrules($dbh,$restorefile); }
+ if ($restorefile) { @errors = restore_circrules($dbh,$restorefile,@errors); }
}
if ($restore eq 'itemtypes') {
my $timestamp = most_recent_single($MIGGITDIR,'itemtypes');
if ($timestamp) { $restorefile = $MIGGITDIR . 'itemtypes' . '.' . $timestamp . '.xml'; }
print "Restoring from $restorefile ... \n";
- if ($restorefile) { restore_itemtypes($dbh,$restorefile); }
+ if ($restorefile) { @errors = restore_itemtypes($dbh,$restorefile,@errors); }
}
if ($restore eq 'letters') {
my $timestamp = most_recent_single($MIGGITDIR,'letters');
my $timestamp = most_recent_single($MIGGITDIR,'smsproviders');
if ($timestamp) { $restorefile = $MIGGITDIR . 'smsproviders' . '.' . $timestamp . '.xml'; }
print "Restoring from $restorefile ... \n";
- if ($restorefile) { restore_smsproviders($dbh,$restorefile); }
+ if ($restorefile) { restore_smsproviders($dbh,$restorefile,$mig_path); }
}
}
print "Done.\n";
+foreach my $e (@errors) { print "$e\n"; }
+
+# ---------------------------
+
+sub check_branchcode {
+ my $dbh = shift;
+ my $value = shift;
+ my $query;
+
+ if ($value and $value ne 'NULL') {
+ $query = "SELECT EXISTS(SELECT 1 FROM branches WHERE branchcode = $value)";
+ } else {
+ return 1;
+ }
+ print "$query\n";
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ my @sqlresult = $sth->fetchrow_array;
+ my $result = pop @sqlresult;
+ return $result;
+}
+
+sub check_category {
+ my $dbh = shift;
+ my $value = shift;
+ my $query;
+
+ if ($value and $value ne 'NULL') {
+ $query = "SELECT EXISTS(SELECT 1 FROM categories WHERE categorycode = $value)";
+ } else {
+ return 1;
+ }
+ print "$query\n";
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ my @sqlresult = $sth->fetchrow_array;
+ my $result = pop @sqlresult;
+ return $result;
+}
+
+sub check_itemtype {
+ my $dbh = shift;
+ my $value = shift;
+ my $query;
+ if ($value and $value ne 'NULL') {
+ $query = "SELECT EXISTS(SELECT 1 FROM itemtypes WHERE itemtype = $value)";
+ } else {
+ return 1;
+ }
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ my @sqlresult = $sth->fetchrow_array;
+ my $result = pop @sqlresult;
+ return $result;
+}
sub most_recent_single {
my $MGIGITDIR = shift;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
- my $query = "DELETE FROM authorised_values WHERE category != 'ITEMTYPECAT'";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM authorised_values WHERE category != 'ITEMTYPECAT'");
- $query = "DELETE FROM authorised_value_categories WHERE category_name != 'ITEMTYPECAT'";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM authorised_value_categories WHERE category_name != 'ITEMTYPECAT'");
foreach my $node ($dom->findnodes('/document/categories/value')) {
my $name = sql_str_not_null($node->findvalue('./name'));
- $query = "INSERT INTO authorised_value_categories (category_name) VALUES ($name)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO authorised_value_categories (category_name) VALUES ($name)");
}
foreach my $node ($dom->findnodes('/document/authorisedvalues/value')) {
my $lib = sql_str($node->findvalue('./lib'));
my $lib_opac = sql_str($node->findvalue('./lib_opac'));
my $imageurl = sql_str($node->findvalue('./imageurl'));
- $query = "INSERT INTO authorised_values (category,authorised_value,lib,lib_opac,imageurl) VALUES ($category,$authorised_value,$lib,$lib_opac,$imageurl)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO authorised_values (category,authorised_value,lib,lib_opac,imageurl) VALUES ($category,$authorised_value,$lib,$lib_opac,$imageurl)");
}
return;
}
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
- my $query = "DELETE FROM aqbooksellers WHERE 1 = 1";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM aqbooksellers WHERE 1 = 1");
foreach my $node ($dom->findnodes('/booksellers/value')) {
my $name = sql_str($node->findvalue('./name'));
my $discount = sql_num($node->findvalue('./discount'));
my $fax = sql_str($node->findvalue('./fax'));
my $deliverytime = sql_num($node->findvalue('./deliverytime'));
- $query = "INSERT INTO aqbooksellers (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) VALUES ($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)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO aqbooksellers (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) VALUES ($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)");
}
return;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
- my $query = "DELETE FROM authorised_values WHERE category IN (select category_code from borrower_attribute_types)";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM authorised_values WHERE category IN (select category_code from borrower_attribute_types)");
- $query = "DELETE FROM authorised_value_categories WHERE category_name IN (select category_name from borrower_attribute_types)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM authorised_value_categories WHERE category_name IN (select category_name from borrower_attribute_types)");
- $query = "DELETE FROM borrower_attribute_types WHERE 1 = 1";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM borrower_attribute_types WHERE 1 = 1");
foreach my $node ($dom->findnodes('/borrower_attribute_types/value')) {
my $code = sql_str($node->findvalue('./code'));
my $display_checkout = sql_num($node->findvalue('./display_checkout'));
my $category_code = sql_str($node->findvalue('./category_code'));
my $class = sql_str($node->findvalue('./class'));
- $query = "INSERT INTO borrower_attribute_types (code,description,repeatable,opac_display,staff_searchable,authorised_value_category,display_checkout,category_code,class) VALUES ($code,$description,$repeatable,$opac_display,$staff_searchable,$authorised_value_category,$display_checkout,$category_code,$class)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO borrower_attribute_types (code,description,repeatable,opac_display,staff_searchable,authorised_value_category,display_checkout,category_code,class) VALUES ($code,$description,$repeatable,$opac_display,$staff_searchable,$authorised_value_category,$display_checkout,$category_code,$class)");
}
foreach my $node ($dom->findnodes('/authorised_value_categories/value')) {
my $category_name = sql_str($node->nodeValue);
- $query = "INSERT INTO authorised_value_categories (category_name) VALUES ($category_name)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO authorised_value_categories (category_name) VALUES ($category_name)");
}
foreach my $node ($dom->findnodes('/authorised_values/value')) {
my $lib = sql_str($node->findvalue('./lib'));
my $lib_opac = sql_str($node->findvalue('./lib_opac'));
my $image_url = sql_str($node->findvalue('./image_url'));
- $query = "INSERT INTO authorised_values (category,authvalue,lib,lib_opac,image_url) VALUES ($category,$authvalue,$lib,$lib_opac,$image_url)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO authorised_values (category,authvalue,lib,lib_opac,image_url) VALUES ($category,$authvalue,$lib,$lib_opac,$image_url)");
}
return;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
- my $query = "DELETE FROM aqbudgets WHERE 1 = 1";
- my $sth = $dbh->prepare($query);
- $sth->execute();
-
- $query = "DELETE FROM aqbudgetperiods WHERE 1 = 1";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM aqbudgets WHERE 1 = 1");
+ sql_noresult($dbh,"DELETE FROM aqbudgetperiods WHERE 1 = 1");
my $budget_ai;
my $budgetperiod_ai;
-
foreach my $node ($dom->findnodes('/document/budgets')) {
$budget_ai = sql_num($node->findvalue('./autoincrement'));
}
-
foreach my $node ($dom->findnodes('/document/budgetperiods')) {
$budgetperiod_ai = sql_num($node->findvalue('./autoincrement'));
}
-
- $query = "ALTER TABLE aqbudgets AUTO_INCREMENT = $budget_ai";
- $sth = $dbh->prepare($query);
- $sth->execute();
-
- $query = "ALTER TABLE aqbudgetperiods AUTO_INCREMENT = $budgetperiod_ai";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"ALTER TABLE aqbudgets AUTO_INCREMENT = $budget_ai");
+ sql_noresult($dbh,"ALTER TABLE aqbudgetperiods AUTO_INCREMENT = $budgetperiod_ai");
foreach my $node ($dom->findnodes('/document/budgetperiods/value')) {
my $budget_period_id = sql_num($node->findvalue('./budget_period_id'));
my $budget_period_locked = sql_num($node->findvalue('./budget_period_locked'));
my $sort1_authcat = sql_str($node->findvalue('./sort1_authcat'));
my $sort2_authcat = sql_str($node->findvalue('./sort2_authcat'));
- $query = "INSERT INTO aqbudgetperiods (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) VALUES ($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)";
- print "$query\n";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO aqbudgetperiods (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) VALUES ($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)");
}
#note that at this point we are not loading the budget owner, it's nullable and not 100% clear that it's the borrower
my $sort1_authcat = sql_str_not_null($node->findvalue('./sort1_authcat'));
my $sort2_authcat = sql_str_not_null($node->findvalue('./sort2_authcat'));
my $budget_permission = sql_num($node->findvalue('./budget_permission'));
- $query = "INSERT INTO aqbudgets (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_permission) VALUES ($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_permission)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO aqbudgets (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_permission) VALUES ($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_permission)");
}
return;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
- my $query = "DELETE FROM repeatable_holidays WHERE 1 = 1";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM repeatable_holidays WHERE 1 = 1");
- $query = "DELETE FROM special_holidays WHERE 1 = 1";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM special_holidays WHERE 1 = 1");
foreach my $node ($dom->findnodes('/holidays/repeatable')) {
my $branchcode = sql_str($node->findvalue('./branchcode'));
my $month = sql_num($node->findvalue('./month'));
my $title = sql_str($node->findvalue('./title'));
my $description = sql_str($node->findvalue('./description'));
- $query = "INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description) VALUES ($branchcode,$weekday,$day,$month,$title,$description)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description) VALUES ($branchcode,$weekday,$day,$month,$title,$description)");
}
foreach my $node ($dom->findnodes('/holidays/special')) {
my $isexception = sql_num($node->findvalue('./isexception'));
my $title = sql_str($node->findvalue('./title'));
my $description = sql_str($node->findvalue('./description'));
- $query = "INSERT INTO special_holidays (branchcode,day,month,year,isexception,title,description) VALUES ($branchcode,$day,$month,$year,$isexception,$title,$description)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO special_holidays (branchcode,day,month,year,isexception,title,description) VALUES ($branchcode,$day,$month,$year,$isexception,$title,$description)");
}
return;
sub restore_circrules {
my $dbh = shift;
my $restore_file = shift;
+ my @errors = shift;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
-
+ my $error;
+ my $check;
#order of operations - clean out circ_rules, then issuingrules; restore issuingrules then circ_rules
- my $query = "DELETE FROM circulation_rules WHERE 1 = 1";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM circulation_rules WHERE 1 = 1");
- $query = "DELETE FROM issuingrules WHERE 1 = 1";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM issuingrules WHERE 1 = 1");
foreach my $node ($dom->findnodes('//issuing/rule')) {
my $categorycode = sql_str($node->findvalue('./categorycode'));
my $opacitemholds = sql_str($node->findvalue('./opacitemholds'));
my $article_requests = sql_str($node->findvalue('./article_requests'));
my $note = sql_str($node->findvalue('./note'));
- $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)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ $check = check_itemtype($dbh,$itemtype);
+ if ($check == 0 ) {
+ $error = "restore_circrules: issing rules rules itemtype $itemtype was not valid";
+ push @errors, $error;
+ next;
+ }
+ $check = check_category($dbh,$categorycode);
+ if ($check == 0 ) {
+ $error = "restore_circrules: issuing rules rules category $categorycode was not valid";
+ push @errors, $error;
+ next;
+ }
+ sql_noresult($dbh,"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)");
}
foreach my $node ($dom->findnodes('//circ/rule')) {
my $itemtype = sql_str($node->findvalue('./itemtype'));
my $rule_name = sql_str($node->findvalue('./rule_name'));
my $rule_value = sql_str($node->findvalue('./rule_value'));
- $query = "INSERT INTO circulation_rules (branchcode,categorycode,itemtype,rule_name,rule_value) VALUES ($branchcode,$categorycode,$itemtype,$rule_name,$rule_value)";
- $sth = $dbh->prepare($query);
- $sth->execute();
- }
- return;
+ $check = check_itemtype($dbh,$itemtype);
+ if ($check == 0 ) {
+ $error = "restore_circrules: circulation rules rules itemtype $itemtype was not valid";
+ push @errors, $error;
+ next;
+ }
+ $check = check_category($dbh,$categorycode);
+ if ($check == 0 ) {
+ $error = "restore_circrules: circulation rules rules category $categorycode was not valid";
+ push @errors, $error;
+ next;
+ }
+
+ sql_noresult($dbh,"INSERT INTO circulation_rules (branchcode,categorycode,itemtype,rule_name,rule_value) VALUES ($branchcode,$categorycode,$itemtype,$rule_name,$rule_value)");
+ }
+
+ return @errors;
}
sub restore_itemtypes {
my $dbh = shift;
my $restorefile = shift;
+ my @errors = shift;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restorefile);
+ my $check;
- my $query = "UPDATE itemtypes SET searchcategory = NULL";
- my $sth = $dbh->prepare($query);
- $sth->execute();
-
- $query = "DELETE FROM authorised_values WHERE category = 'ITEMTYPECAT'";
- $sth = $dbh->prepare($query);
- $sth->execute();
-
- $query = "DELETE FROM localization WHERE entity = 'itemtypes'";
- $sth = $dbh->prepare($query);
- $sth->execute();
-
- $query = "DELETE FROM itemtypes WHERE 1 = 1";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"UPDATE itemtypes SET searchcategory = NULL");
+ sql_noresult($dbh,"DELETE FROM authorised_values WHERE category = 'ITEMTYPECAT'");
+ sql_noresult($dbh,"DELETE FROM localization WHERE entity = 'itemtypes'");
+ sql_noresult($dbh,"DELETE FROM itemtypes WHERE 1 = 1");
foreach my $node ($dom->findnodes('/document/authorised_values/value')) {
my $category = sql_str($node->findvalue('./category'));
my $lib = sql_str($node->findvalue('./lib'));
my $lib_opac = sql_str($node->findvalue('./lib_opac'));
my $image_url = sql_str($node->findvalue('./image_url'));
- my $query = "INSERT INTO authorised_values (category,authvalue,lib,lib_opac,image_url) VALUES ($category,$authvalue,$lib,$lib_opac,$image_url)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO authorised_values (category,authvalue,lib,lib_opac,image_url) VALUES ($category,$authvalue,$lib,$lib_opac,$image_url)");
}
foreach my $node ($dom->findnodes('/document/itemtypes/value')) {
my $sip_media_type = sql_str($node->findvalue('./sip_media_type'));
my $hideinopac = sql_str($node->findvalue('./hideinopac'));
my $searchcategory = sql_str($node->findvalue('./searchcategory'));
- $query = "SELECT itemtype FROM itemtypes WHERE itemtype = $itemtype";
- $sth = $dbh->prepare($query);
- $sth->execute();
- my $answer;
- while (my @row = $sth->fetchrow_array) { $answer = sql_str($row[0]); }
- if (!defined $answer or $answer ne $itemtype) {
- $query = "INSERT INTO itemtypes (itemtype,description,rentalcharge,rentalcharge_daily,rentalcharge_hourly,defaultreplacecost,processfee,notforloan,imageurl,summary,checkinmsg,sip_media_type,hideinopac,searchcategory)
- VALUES ($itemtype,$description,$rentalcharge,$rentalcharge_daily,$rentalcharge_hourly,$defaultreplacecost,$processfee,$notforloan,$imageurl,$summary,$checkinmsg,$sip_media_type,$hideinopac,$searchcategory)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+
+ $check = check_itemtype($dbh,$itemtype);
+ if ($check == 0) {
+ sql_noresult($dbh,"INSERT INTO itemtypes (itemtype,description,rentalcharge,rentalcharge_daily,rentalcharge_hourly,defaultreplacecost,processfee,notforloan,imageurl,summary,checkinmsg,sip_media_type,hideinopac,searchcategory) VALUES ($itemtype,$description,$rentalcharge,$rentalcharge_daily,$rentalcharge_hourly,$defaultreplacecost,$processfee,$notforloan,$imageurl,$summary,$checkinmsg,$sip_media_type,$hideinopac,$searchcategory)");
} else {
- $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
- WHERE itemtype = $itemtype";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"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 WHERE itemtype = $itemtype");
}
}
my $code = sql_str($node->findvalue('./code'));
my $lang = sql_str($node->findvalue('./lang'));
my $translation = sql_str($node->findvalue('./translation'));
- my $query = "INSERT INTO localization (entity,code,lang,translation) VALUES ($entity,$code,$lang,$translation)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO localization (entity,code,lang,translation) VALUES ($entity,$code,$lang,$translation)");
}
return;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
- my $query = "DELETE FROM letter WHERE 1 = 1";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM letter WHERE 1 = 1");
foreach my $node ($dom->findnodes('/letters/letter')) {
my $module = sql_str($node->findvalue('./module'));
my $content = sql_str($node->findvalue('./content'));
my $message_transport_type = sql_str($node->findvalue('./message_transport_type'));
my $lang = sql_str($node->findvalue('./lang'));
- $query = "INSERT INTO letter (module,code,branchcode,name,is_html,title,content,message_transport_type,lang) VALUES ($module,$code,$branchcode,$name,$is_html,$title,$content,$message_transport_type,$lang)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO letter (module,code,branchcode,name,is_html,title,content,message_transport_type,lang) VALUES ($module,$code,$branchcode,$name,$is_html,$title,$content,$message_transport_type,$lang)");
}
return;
my $restorefile = shift;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restorefile);
+ my $check;
my $query = "TRUNCATE library_groups";
my $sth = $dbh->prepare($query);
my $geolocation = sql_str($node->findvalue('./geolocation'));
my $marcorgcode = sql_str($node->findvalue('./marcorgcode'));
my $pickup_location = $node->findvalue('./pickup_location');
- $query = "SELECT branchcode FROM branches WHERE branchcode = $branchcode";
- $sth = $dbh->prepare($query);
- $sth->execute();
- my $answer;
- while (my @row = $sth->fetchrow_array) { $answer = sql_str($row[0]); }
- if (!defined $answer or $answer ne $branchcode) {
- $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)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ $check = check_branchcode($dbh,$branchcode);
+ if ($check == 0) {
+ sql_noresult($dbh,"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)");
} else {
- $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";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"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");
}
}
my $ft1 = sql_num($node->findvalue('./ft_hide_patron_info'));
my $ft2 = sql_num($node->findvalue('./ft_search_groups_opac'));
my $ft3 = sql_num($node->findvalue('./ft_search_groups_staff'));
- $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)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"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)");
}
return;
}
my $restorefile = shift;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restorefile);
-
+ my $check;
my $query;
my $sth;
my $checkprevcheckout = sql_str($node->findvalue('./checkprevcheckout'));
my $reset_password = sql_num($node->findvalue('./reset_password'));
my $change_password = sql_num($node->findvalue('./change_password'));
- $query = "SELECT categorycode FROM categories WHERE categorycode = $categorycode";
- $sth = $dbh->prepare($query);
- $sth->execute();
- my $answer;
- while (my @row = $sth->fetchrow_array) { $answer = sql_str($row[0]); }
- if (!defined $answer or $answer ne $categorycode) {
- $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)";
+ $check = check_category($dbh,$categorycode);
+ if ($check == 0) {
+ sql_noresult($dbh,"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)");
$sth = $dbh->prepare($query);
$sth->execute();
} else {
- $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";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"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");
}
}
return;
my $dom = $parser->parse_file($restore_file);
foreach my $node ($dom->findnodes('//pref')) {
- my $variable = domain_shift(sql_str($node->findvalue('./variable')));
- my $value = domain_shift(sql_str($node->findvalue('./value')));
- my $query = "UPDATE systempreferences SET value = $value WHERE variable = $variable";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ my $variable = domain_shift(sql_str_not_null($node->findvalue('./variable')));
+ my $value = domain_shift(sql_str_not_null($node->findvalue('./value')));
+ sql_noresult($dbh,"UPDATE systempreferences SET value = $value WHERE variable = $variable");
}
return;
}
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
- my $query = "DELETE FROM saved_sql WHERE 1 = 1";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM saved_sql WHERE 1 = 1");
foreach my $node ($dom->findnodes('//sqlreport')) {
my $date_created = sql_str($node->findvalue('./date_created'));
my @row = $sth->fetchrow_array;
my $borrowernumber = sql_num($row[0]);
- $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)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"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)");
}
return;
}
sub restore_smsproviders {
my $dbh = shift;
my $restore_file = shift;
+ my $migpath = shift;
my $parser = XML::LibXML->new();
my $dom = $parser->parse_file($restore_file);
- my $query = "DELETE FROM sms_providers WHERE 1 = 1";
- my $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"DELETE FROM sms_providers WHERE 1 = 1");
+
+ my $p = 0;
+ foreach my $node ($dom->findnodes('//provider')) { $p++; }
+
+ if ($p == 0) {
+ my $failover_file = find_xml('smsproviders.xml',$migpath);
+ $dom = $parser->parse_file($failover_file);
+ }
foreach my $node ($dom->findnodes('//provider')) {
my $name = sql_str($node->findvalue('./name'));
my $domain = sql_str($node->findvalue('./domain'));
- $query = "INSERT INTO sms_providers (name,domain) VALUES ($name,$domain)";
- $sth = $dbh->prepare($query);
- $sth->execute();
+ sql_noresult($dbh,"INSERT INTO sms_providers (name,domain) VALUES ($name,$domain)");
}
return;
}
return $str;
}
+sub sql_giveback {
+ my $dbh = shift;
+ my $query = shift;
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ my @result = $sth->fetchrow_array;
+ return @result;
+}
+
+sub sql_noresult {
+ my $dbh = shift;
+ my $statement = shift;
+ my $sth = $dbh->prepare($statement);
+ $sth->execute();
+ return;
+}
+
sub sql_str {
my $str = shift;
if (!defined $str or $str eq '') { return 'NULL'; }
exit 1;
}
+sub find_xml {
+ my $reports_xml = shift;
+ my $mig_path = shift;
+
+ if ($reports_xml =~ m/\//) { return $reports_xml; }
+
+ my $mig_test_file = $mig_path . '/../xml/' . $reports_xml;
+ my $working_test_dir = getcwd();
+ my $working_test_file = $working_test_dir . '/' . $reports_xml;
+
+ if (-e $mig_test_file) { return $mig_test_file; }
+ if (-e $working_test_file) { return $working_test_file; }
+
+ return undef;
+}
+
sub print_usage {
print <<_USAGE_;