summaryrefslogtreecommitdiff
path: root/FS/FS/Cron
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-09-22 01:08:04 -0500
committerMark Wells <mark@freeside.biz>2015-11-09 16:47:31 -0800
commit7133b592b4bd28a9aa887f716cd7dc67a8bbdc7a (patch)
treee51b0120b40a27d7851204ac1f0aa50abf93af92 /FS/FS/Cron
parent9be553c793b473f85bd4061faa6635adb21f2a08 (diff)
RT#37908: Convert existing email-sending code to use common interface [removals and switches to FS::Log]
Diffstat (limited to 'FS/FS/Cron')
-rw-r--r--FS/FS/Cron/agent_email.pm79
-rw-r--r--FS/FS/Cron/backup.pm59
2 files changed, 25 insertions, 113 deletions
diff --git a/FS/FS/Cron/agent_email.pm b/FS/FS/Cron/agent_email.pm
deleted file mode 100644
index 6bc1cc6..0000000
--- a/FS/FS/Cron/agent_email.pm
+++ /dev/null
@@ -1,79 +0,0 @@
-package FS::Cron::agent_email;
-use base qw( Exporter );
-
-use strict;
-use vars qw( @EXPORT_OK $DEBUG );
-use Date::Simple qw(today);
-use URI::Escape;
-use FS::Mason qw( mason_interps );
-use FS::Conf;
-use FS::Misc qw(send_email);
-use FS::Record qw(qsearch);# qsearchs);
-use FS::agent;
-
-@EXPORT_OK = qw ( agent_email );
-$DEBUG = 0;
-
-sub agent_email {
- my %opt = @_;
-
- my $conf = new FS::Conf;
-
- my $day = $conf->config('agent-email_day') or return;
- return unless $day == today->day;
-
- if ( 1 ) { #XXX if ( %%%RT_ENABLED%%% ) {
- require RT;
- RT::LoadConfig();
- RT::Init();
- RT::ConnectToDatabase();
- }
-
- my $from = $conf->invoice_from_full();
-
- my $outbuf = '';;
- my( $fs_interp, $rt_interp ) = mason_interps('standalone', 'outbuf'=>\$outbuf);
-
- my $comp = '/search/cust_main.html';
- my %args = (
- 'cust_fields' => 'Cust# | Cust. Status | Customer | Current Balance',
- '_type' => 'html-print',
- );
- my $query = join('&', map "$_=".uri_escape($args{$_}), keys %args );
-
- my $extra_sql = $opt{a} ? " AND agentnum IN ( $opt{a} ) " : '';
-
- foreach my $agent ( qsearch({
- 'table' => 'agent',
- 'hashref' => {
- 'disabled' => '',
- 'agent_custnum' => { op=>'!=', value=>'' },
- },
- 'extra_sql' => $extra_sql,
- })
- )
- {
-
- $FS::Mason::Request::QUERY_STRING = $query. '&agentnum='. $agent->agentnum;
- $fs_interp->exec($comp);
-
- my @email = $agent->agent_cust_main->invoicing_list or next;
-
- warn "emailing ". join(',',@email). " for agent ". $agent->agent. "\n"
- if $DEBUG;
- send_email(
- 'from' => $from,
- 'to' => \@email,
- 'subject' => 'Customer report',
- 'body' => $outbuf,
- 'content-type' => 'text/html',
- #'content-encoding'
- );
-
- $outbuf = '';
-
- }
-
-}
-
-1;
diff --git a/FS/FS/Cron/backup.pm b/FS/FS/Cron/backup.pm
index cfc8e36..a192ca9 100644
--- a/FS/FS/Cron/backup.pm
+++ b/FS/FS/Cron/backup.pm
@@ -6,7 +6,7 @@ use Exporter;
use File::Copy;
use Date::Format;
use FS::UID qw(driver_name datasrc);
-use FS::Misc qw( send_email );
+use FS::Log
@ISA = qw( Exporter );
@EXPORT_OK = qw( backup );
@@ -20,7 +20,7 @@ sub backup {
my $filename = time2str('%Y%m%d%H%M%S',time);
datasrc =~ /dbname=([\w\.]+)$/
- or backup_email_and_die($conf,$filename,"unparsable datasrc ". datasrc);
+ or backup_log_and_die($filename,"unparsable datasrc ". datasrc);
my $database = $1;
my $ext;
@@ -31,70 +31,61 @@ sub backup {
system("mysqldump $database >/var/tmp/$database.sql");
$ext = 'sql';
} else {
- backup_email_and_die($conf,$filename,"database dumps not yet supported for ". driver_name);
+ backup_log_and_die($filename,"database dumps not yet supported for ". driver_name);
}
chmod 0600, "/var/tmp/$database.$ext";
if ( $conf->config('dump-pgpid') ) {
eval 'use GnuPG;';
- backup_email_and_die($conf,$filename,$@) if $@;
+ backup_log_and_die($filename,$@) if $@;
my $gpg = new GnuPG;
$gpg->encrypt( plaintext => "/var/tmp/$database.$ext",
output => "/var/tmp/$database.gpg",
recipient => $conf->config('dump-pgpid'),
);
unlink "/var/tmp/$database.$ext"
- or backup_email_and_die($conf,$filename,$!);
+ or backup_log_and_die($filename,$!);
chmod 0600, "/var/tmp/$database.gpg";
$ext = 'gpg';
}
if ( $localdest ) {
copy("/var/tmp/$database.$ext", "$localdest/$filename.$ext")
- or backup_email_and_die($conf,$filename,$!);
+ or backup_log_and_die($filename,$!);
chmod 0600, "$localdest/$filename.$ext";
}
if ( $scpdest ) {
eval "use Net::SCP qw(scp);";
- backup_email_and_die($conf,$filename,$@) if $@;
+ backup_log_and_die($filename,$@) if $@;
scp("/var/tmp/$database.$ext", "$scpdest/$filename.$ext");
}
- unlink "/var/tmp/$database.$ext" or backup_email_and_die($conf,$filename,$!); #or just warn?
+ unlink "/var/tmp/$database.$ext" or backup_log_and_die($filename,$!); #or just warn?
- backup_email($conf,$filename);
+ backup_log($filename);
}
-#runs backup_email and dies with same error message
-sub backup_email_and_die {
- my ($conf,$filename,$error) = @_;
- backup_email($conf,$filename,$error);
- warn "backup_email_and_die called without error message" unless $error;
+#runs backup_log and dies with same error message
+sub backup_log_and_die {
+ my ($filename,$error) = @_;
+ $error = "backup_log_and_die called without error message" unless $error;
+ backup_log($filename,$error);
die $error;
}
-#checks if email should be sent, sends it
-sub backup_email {
- my ($conf,$filename,$error) = @_;
- my $to = $conf->config('dump-email_to');
- return unless $to;
- my $result = $error ? 'FAILED' : 'succeeded';
- my $email_error = send_email(
- 'from' => $conf->config('invoice_from'), #or whatever, don't think it matters
- 'to' => $to,
- 'subject' => 'FREESIDE NOTIFICATION: Backup ' . $result,
- 'body' => [
- "This is an automatic message from your Freeside installation.\n",
- "Freeside backup $filename $result",
- ($error ? " with the following error:\n\n" : "\n"),
- ($error || ''),
- "\n",
- ],
- 'msgtype' => 'admin',
- );
- warn $email_error if $email_error;
+#logs result
+sub backup_log {
+ my ($filename,$error) = @_;
+ my $result = $error ? "FAILED: $error" : 'succeeded';
+ my $message = "backup $filename $result\n";
+ my $log = FS::Log->new('Cron::backup');
+ if ($error) {
+ $log->error($message);
+ } else {
+ $log->info($message);
+ }
return;
}