[freeside-commits] branch master updated. b307e9044cc1fded25280ea5d9e105daaba89d43

Jonathan Prykop jonathan at 420.am
Tue Jul 26 12:38:02 PDT 2016


The branch, master has been updated
       via  b307e9044cc1fded25280ea5d9e105daaba89d43 (commit)
       via  5f563d5ac7e6e1e93cca382baa42ee106f3db5a0 (commit)
      from  0b08a87698a2278f3806a66dd6c93b24b18d4767 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b307e9044cc1fded25280ea5d9e105daaba89d43
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Jul 26 14:36:09 2016 -0500

    Bug fix for RT#71623 or RT#13971, discovered during RT#38217, needs backport to v4

diff --git a/FS/FS/cust_pkg_reason.pm b/FS/FS/cust_pkg_reason.pm
index 29b4b0a..a632ab4 100644
--- a/FS/FS/cust_pkg_reason.pm
+++ b/FS/FS/cust_pkg_reason.pm
@@ -3,7 +3,7 @@ use base qw( FS::otaker_Mixin FS::Record );
 
 use strict;
 use vars qw( $ignore_empty_action );
-use FS::Record qw( qsearch ); #qsearchs );
+use FS::Record qw( qsearch qsearchs );
 use FS::upgrade_journal;
 
 $ignore_empty_action = 0;

commit 5f563d5ac7e6e1e93cca382baa42ee106f3db5a0
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Jul 26 14:27:53 2016 -0500

    RT#38217: Send email when logging conditions are met

diff --git a/FS/FS/Log.pm b/FS/FS/Log.pm
index 2fd0020..9d6ce6a 100644
--- a/FS/FS/Log.pm
+++ b/FS/FS/Log.pm
@@ -9,7 +9,7 @@ use vars qw(@STACK @LEVELS);
 
 # override the stringification of @_ with something more sensible.
 BEGIN {
-  @LEVELS = qw(debug info notice warning error critical alert emergency);
+  @LEVELS = qw(debug info warning error critical);
 
   foreach my $l (@LEVELS) {
     my $sub = sub {
diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index 65b83bd..3faf47e 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -352,6 +352,9 @@ sub upgrade_data {
 
   tie my %hash, 'Tie::IxHash', 
 
+    #remap log levels
+	'log' => [],
+
     #cust_main (remove paycvv from history, locations, cust_payby, etc)
     'cust_main' => [],
 
diff --git a/FS/FS/log.pm b/FS/FS/log.pm
index 1d4df73..b8f51cd 100644
--- a/FS/FS/log.pm
+++ b/FS/FS/log.pm
@@ -6,6 +6,7 @@ use FS::Record qw( qsearch qsearchs dbdef );
 use FS::UID qw( dbh driver_name );
 use FS::log_context;
 use FS::log_email;
+use FS::upgrade_journal;
 
 =head1 NAME
 
@@ -383,6 +384,52 @@ sub search {
   };
 }
 
+sub _upgrade_data {
+  my ($class, %opts) = @_;
+
+  return if FS::upgrade_journal->is_done('log__remap_levels');
+
+  tie my %levelmap, 'Tie::IxHash', 
+#    0 => 0, #debug
+#    1 => 1, #info
+    2 => 1, #notice -> info
+    3 => 2, #warning
+    4 => 3, #error
+    5 => 4, #critical
+    6 => 4, #alert -> critical
+    7 => 4, #emergency -> critical
+  ;
+
+  # this method should never autocommit
+  # should have been set in upgrade, but just in case...
+  local $FS::UID::AutoCommit = 0;
+
+  # FS::log has no replace method
+  # in practice, only debug/info/warning/error were used,
+  #   so this should only hit warning/error
+  foreach my $old (keys %levelmap) {
+    my $sql = 'UPDATE log SET level=' . dbh->quote($levelmap{$old}) . ' WHERE level=' . dbh->quote($old);
+    warn $sql unless $opts{'quiet'};
+    my $sth = dbh->prepare($sql) or die dbh->errstr;
+    $sth->execute() or die $sth->errstr;
+    $sth->finish();
+  }
+
+  foreach my $log_email (
+    qsearch('log_email',{ 'min_level' => { 'op' => '>=', 'value' => '2' } })
+  ) {
+    $log_email->min_level($levelmap{$log_email->min_level});
+    my $error = $log_email->replace;
+    if ($error) {
+      dbh->rollback;
+      die $error;
+    }
+  }
+
+  FS::upgrade_journal->set_done('log__remap_levels');
+
+}
+
 =back
 
 =head1 BUGS
diff --git a/httemplate/edit/log_email.html b/httemplate/edit/log_email.html
index 0c98046..4b7d09f 100644
--- a/httemplate/edit/log_email.html
+++ b/httemplate/edit/log_email.html
@@ -16,8 +16,8 @@
                             },
                             { 'field' => 'min_level',
                               'type'  => 'select',
-                              'options' => [ 0..7 ],
-                              'labels' => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 },
+                              'options' => [ 0..4 ],
+                              'labels' => { map {$_ => $FS::Log::LEVELS[$_]} 0..4 },
                               'curr_value' => scalar($cgi->param('min_level')),
                             },
                             'to_addr',
diff --git a/httemplate/search/log.html b/httemplate/search/log.html
index 111200f..cefa399 100644
--- a/httemplate/search/log.html
+++ b/httemplate/search/log.html
@@ -81,15 +81,15 @@ a:visited {text-decoration: none}
   <TD>Level
     <& /elements/select.html,
       field => 'min_level',
-      options => [ 0..7 ],
-      labels => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 },
+      options => [ 0..4 ],
+      labels => { map {$_ => $FS::Log::LEVELS[$_]} 0..4 },
       curr_value => $cgi->param('min_level'),
     &>
      to
     <& /elements/select.html,
       field => 'max_level',
-      options => [ 0..7 ],
-      labels => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 },
+      options => [ 0..4 ],
+      labels => { map {$_ => $FS::Log::LEVELS[$_]} 0..4 },
       curr_value => $cgi->param('max_level'),
     &>
   </TD>
@@ -192,14 +192,11 @@ my $object_link_sub = sub {
 };
 
 my @colors = (
-  '404040', #debug
-  '0000aa', #info
-  '00aa00', #notice
-  'aa0066', #warning
-  '000000', #error
-  'aa0000', #critical
-  'ff0000', #alert
-  'ff0000', #emergency
+  '404040', #debug, gray
+  '000000', #info, black
+  '0000aa', #warning, blue
+  'aa0066', #error, purple
+  'ff0000', #critical, red
 );
 
 my $color_sub = sub { $colors[ $_[0]->level ]; };

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Log.pm                   |    2 +-
 FS/FS/Upgrade.pm               |    3 +++
 FS/FS/cust_pkg_reason.pm       |    2 +-
 FS/FS/log.pm                   |   47 ++++++++++++++++++++++++++++++++++++++++
 httemplate/edit/log_email.html |    4 ++--
 httemplate/search/log.html     |   21 ++++++++----------
 6 files changed, 63 insertions(+), 16 deletions(-)




More information about the freeside-commits mailing list