summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-12-23 21:46:53 -0600
committerMitch Jackson <mitch@freeside.biz>2018-10-09 12:22:58 -0400
commit4252e76a77bd4def206cfaa7466ba39bb1f027b6 (patch)
tree636808247b4e7c8b6584e6ddb58947e2e73e9277 /FS
parentec1cb553b60314cadce24d5360de61e43c42e344 (diff)
RT#38217 Send email when logging conditions are met [default template & dump-email_to upgrade]
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/msg_template.pm23
-rw-r--r--FS/FS/msg_template/InitialData.pm14
2 files changed, 37 insertions, 0 deletions
diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm
index 2388aba69..0018a4586 100644
--- a/FS/FS/msg_template.pm
+++ b/FS/FS/msg_template.pm
@@ -879,6 +879,25 @@ sub _upgrade_data {
###
$self->_populate_initial_data;
+ ### Fix dump-email_to (needs to happen after _populate_initial_data)
+ if ($conf->config('dump-email_to')) {
+ # anyone who still uses dump-email_to should have just had this created
+ my ($msg_template) = qsearch('msg_template',{ msgname => 'System log' });
+ if ($msg_template) {
+ eval "use FS::log_email;";
+ die $@ if $@;
+ my $log_email = new FS::log_email {
+ 'context' => 'Cron::backup',
+ 'min_level' => 1,
+ 'msgnum' => $msg_template->msgnum,
+ 'to_addr' => $conf->config('dump-email_to'),
+ };
+ my $error = $log_email->insert;
+ die $error if $error;
+ $conf->delete('dump-email_to');
+ }
+ }
+
}
sub _populate_initial_data { #class method
@@ -887,18 +906,22 @@ sub _populate_initial_data { #class method
eval "use FS::msg_template::InitialData;";
die $@ if $@;
+ eval "use FS::upgrade_journal;";
+ die $@ if $@;
my $initial_data = FS::msg_template::InitialData->_initial_data;
foreach my $hash ( @$initial_data ) {
next if $hash->{_conf} && $conf->config( $hash->{_conf} );
+ next if $hash->{_upgrade_journal} && FS::upgrade_journal->is_done( $hash->{_upgrade_journal} );
my $msg_template = new FS::msg_template($hash);
my $error = $msg_template->insert( @{ $hash->{_insert_args} || [] } );
die $error if $error;
$conf->set( $hash->{_conf}, $msg_template->msgnum ) if $hash->{_conf};
+ FS::upgrade_journal->set_done( $hash->{_upgrade_journal} );
}
diff --git a/FS/FS/msg_template/InitialData.pm b/FS/FS/msg_template/InitialData.pm
index 7cf83d070..cbb9ccd8f 100644
--- a/FS/FS/msg_template/InitialData.pm
+++ b/FS/FS/msg_template/InitialData.pm
@@ -38,6 +38,20 @@ Amount: {$refund}<BR>
END
],
},
+ { msgname => 'System log',
+ msgclass => 'email',
+ mime_type => 'text/html',
+ _upgrade_journal => 'system_log_email_template',
+ _insert_args => [ subject => '{ $company_name } system log',
+ body => <<'END',
+Level: {$loglevel}<BR>
+Context: {$logcontext}<BR>
+<BR>
+{$logmessage}<BR>
+
+END
+ ],
+ },
];
}