« blib/lib/oEdtk/lib/index_Check_tracked_docs.pl
↑ Summary
blib/lib/oEdtk/lib/index_Purge_DCLIB.pl »
| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use oEdtk::DBAdmin qw(db_connect); | ||
| 7 | use oEdtk::Config qw(config_read); | ||
| 8 | use oEdtk::Outmngr qw(omgr_stats_referent); | ||
| 9 | use oEdtk::Messenger qw(oe_send_mail); | ||
| 10 | |||
| 11 | if ( $ARGV[0] =~ /-h/i ) { | ||
| 12 | warn "Usage: $0\n\n"; | ||
| 13 | warn "\tThis runs statistics and sends mail to referent for approval request.\n"; | ||
| 14 | exit 1; | ||
| 15 | } | ||
| 16 | |||
| 17 | # run statistics and send the notification by mail. | ||
| 18 | my $cfg = config_read( 'EDTK_DB', 'MAIL' ); | ||
| 19 | my $dbh = db_connect( $cfg, 'EDTK_DBI_DSN', { AutoCommit => 1, RaiseError => 1 } ); | ||
| 20 | my $pdbh = db_connect( $cfg, 'EDTK_DBI_PARAM' ); | ||
| 21 | |||
| 22 | my $rows = omgr_stats_referent( $dbh, $pdbh ); | ||
| 23 | |||
| 24 | if ( !scalar @{$rows} ) { | ||
| 25 | my $subject = "INFO: no lot validation planned in the lot management database.\n"; | ||
| 26 | oe_send_mail( $cfg->{'EDTK_MAIL_SENDER'}, $subject, $subject ); | ||
| 27 | warn $subject; | ||
| 28 | exit; | ||
| 29 | } | ||
| 30 | |||
| 31 | my %hMail; | ||
| 32 | foreach my $mail (@$rows) { | ||
| 33 | my $corp = @$mail[2] || " "; | ||
| 34 | $hMail{ @$mail[0] } .= @$mail[1] . "\t" . $corp . "\n "; | ||
| 35 | warn "INFO: edition(s) pending \n " . $hMail{ @$mail[0] } . "\n"; | ||
| 36 | } | ||
| 37 | |||
| 38 | foreach my $MAIL_TO ( keys %hMail ) { | ||
| 39 | my $mailfile = $cfg->{'EDTK_MAIL_REFER'}; | ||
| 40 | open( my $fh, '<', $mailfile ) or die "ERROR: Cannot open \"$mailfile\": $!\n"; | ||
| 41 | my @body = <$fh>; | ||
| 42 | close($fh); | ||
| 43 | |||
| 44 | push( @body, $hMail{$MAIL_TO} ); | ||
| 45 | |||
| 46 | if ( $MAIL_TO !~ /\@/ ) { | ||
| 47 | $MAIL_TO = $cfg->{$MAIL_TO}; | ||
| 48 | } | ||
| 49 | |||
| 50 | my ( $sec, $min, $hour, $day, $month, $year ) = localtime(); | ||
| 51 | my $date = sprintf( "%02d/%02d/%d", $day, $month + 1, $year + 1900 ); | ||
| 52 | my $time = sprintf( "%02d:%02d:%02d", $hour, $min, $sec ); | ||
| 53 | |||
| 54 | my $subject = $cfg->{'EDTK_MAIL_SUBJ'}; | ||
| 55 | $subject =~ s/%date/$date/; | ||
| 56 | $subject =~ s/%time/$time/; | ||
| 57 | |||
| 58 | oe_send_mail( $MAIL_TO, $subject, @body ); | ||
| 59 | } |