after_sql.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. STDOUT->autoflush(1);
  17. my $upgrade_from = '2.7.9';
  18. my $this_release = '2.8.0';
  19. $dbh=init_db();
  20. init_option($dbh);
  21. if (!$config_ref{version}) {
  22. print "Current version unknown! Skip upgrade!\n";
  23. exit 100;
  24. }
  25. if ($this_release eq $config_ref{version}) { print "Already updated!\n"; exit; }
  26. if ($upgrade_from ne $config_ref{version}) { print "Illegal version. Needed $upgrade_from!\n"; exit; }
  27. print 'Apply patch for version: '.$config_ref{version}.' upgrade to: '.$this_release."\n";
  28. my @authlist_ref = get_records_sql($dbh,"SELECT * FROM User_auth WHERE dns_name>''" );
  29. my $total = scalar @authlist_ref;
  30. print "Stage 1: Fix dns name fields\n";
  31. my $i = 0;
  32. foreach my $row (@authlist_ref) {
  33. my $new;
  34. $i++;
  35. my $dns_name = trim($row->{dns_name});
  36. if ($dns_name and $dns_name =~ /\.\Q$domain_name\E$/i) {
  37. $dns_name =~ s/\.\Q$domain_name\E$//i;
  38. $dns_name =~s/\.$//g;
  39. $dns_name =~s/_/-/g;
  40. $dns_name =~s/ /-/g;
  41. $dns_name =~s/-$//g;
  42. $dns_name = trim($dns_name);
  43. if ($dns_name) { $new->{dns_name}=$dns_name; }
  44. } else {
  45. $dns_name =~s/_/-/g;
  46. $dns_name =~s/ /-/g;
  47. $dns_name =~s/-$//g;
  48. $dns_name = trim($dns_name);
  49. if ($dns_name and $dns_name=~/\./) {
  50. $dns_name = $dns_name.".";
  51. $new->{dns_name}=$dns_name;
  52. }
  53. }
  54. my $percent = int(($i / $total) * 100);
  55. if (exists $new->{dns_name} and $new->{dns_name}) {
  56. update_record($dbh,'User_auth',$new,'id='.$row->{id});
  57. }
  58. print "\r::Progress: [$percent%] ";
  59. }
  60. print "Done!\n";
  61. exit;