Advertisement
chrissharp123

Untitled

Apr 20th, 2023
1,351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.90 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5. use Text::CSV qw/ csv /;
  6.  
  7.  
  8. my $file = 'renewal_policies.csv';
  9.  
  10. my $policies = csv (in => "$file", headers => "skip", empty_is_undef => 1, undef_str => "NULL");
  11.  
  12. # Perm Group,Org Unit,Copy Circ Lib,Renewal?,Circulation Modifier,Reference?,Circulate?,Duration Rule,Recurring Fine Rule,Max Fine Rule,Early Renewal Extends Due Date,Early Renewal Minimum Duration Interval
  13.  
  14. foreach my $policy (@$policies) {
  15.     print "insert into config.circ_matrix_matchpoint (
  16.            grp,
  17.            org_unit,
  18.            copy_circ_lib,
  19.            is_renewal,
  20.            circ_modifier,
  21.            ref_flag,
  22.            circulate,
  23.            duration_rule,
  24.            recurring_fine_rule,
  25.            max_fine_rule,
  26.            renew_extends_due_date,
  27.            renew_extend_min_interval
  28.    ) values (
  29.            (select id from permission.grp_tree where name = '@$policy[0]'),
  30.            (select id from actor.org_unit where shortname = '@$policy[1]'),\n\t\t"
  31.             . (@$policy[2] ? "(select id from actor.org_unit where shortname = '@$policy[2]'),\n\t\t" : "NULL,\n\t\t")
  32.             . (@$policy[3] ? "@$policy[3],\n\t\t" : "NULL,\n\t\t")
  33.             . (@$policy[4] ? "(select code from config.circ_modifier where name = '@$policy[4]'),\n\t\t" : "NULL,\n\t\t")
  34.             . (@$policy[5] ? "@$policy[5],\n\t\t" : "NULL,\n\t\t")
  35.             . (@$policy[6] ? "@$policy[6],\n\t\t" : "NULL,\n\t\t")
  36.             . (@$policy[7] ? "(select id from config.rule_circ_duration where name = '@$policy[7]'),\n\t\t" : "NULL,\n\t\t")
  37.             . (@$policy[8] ? "(select id from config.rule_recurring_fine where name = '@$policy[8]'),\n\t\t" : "NULL,\n\t\t")
  38.             . (@$policy[9] ? "(select id from config.rule_max_fine where name = '@$policy[9]'),\n\t\t" : "NULL,\n\t\t")
  39.             . "@$policy[10],\n\t\t"
  40.             . "'@$policy[11]'"
  41.             . ");\n\n";
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement