after_sql.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) Roman Dmitiriev, rnd@rajven.ru
  4. #
  5. use utf8;
  6. use Encode;
  7. no warnings 'utf8';
  8. use open ':encoding(utf-8)';
  9. use FindBin '$Bin';
  10. use lib "/opt/Eye/scripts";
  11. use eyelib::config;
  12. use eyelib::main;
  13. use eyelib::database;
  14. use strict;
  15. use warnings;
  16. my $upgrade_from = '2.7.3';
  17. my $this_release = '2.7.4';
  18. $dbh=init_db();
  19. init_option($dbh);
  20. if (!$config_ref{version}) {
  21. print "Current version unknown! Skip upgrade!\n";
  22. exit 100;
  23. }
  24. if ($this_release eq $config_ref{version}) { print "Already updated!\n"; exit; }
  25. if ($upgrade_from ne $config_ref{version}) { print "Illegal version. Needed $upgrade_from!\n"; exit; }
  26. print 'Apply patch for version: '.$config_ref{version}.' upgrade to: '.$this_release."\n";
  27. my @authlist_ref = get_records_sql($dbh,"SELECT * FROM User_auth WHERE `created_by` IS NULL" );
  28. my $total = scalar @authlist_ref;
  29. print "Stage 1: Fill field created_by\n";
  30. my $i = 0;
  31. foreach my $row (@authlist_ref) {
  32. my $new;
  33. $i++;
  34. if (!$row->{dhcp_action}) { $new->{created_by} = 'manual'; }
  35. if ($row->{dhcp_action}=~/^(add|old|del)$/i) {
  36. $new->{created_by}='dhcp';
  37. } else {
  38. $new->{created_by}=$row->{dhcp_action};
  39. $new->{dhcp_action}='';
  40. }
  41. my $percent = int(($i / $total) * 100);
  42. update_record($dbh,'User_auth',$new,'id='.$row->{id});
  43. print "\r::Progress: [$percent%] ";
  44. }
  45. print "Done!\n";
  46. exit;