blib/lib/oEdtk/lib/index_Run_lot.pl untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 78 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5  
6 use oEdtk::Config qw(config_read);
7 use oEdtk::DBAdmin qw(db_connect);
8 use oEdtk::Messenger qw(oe_send_mail);
9 use oEdtk::Outmngr qw(omgr_stats);
10 use oEdtk::Run qw(oe_outmngr_output_run_tex);
11  
12 my $cfg = config_read( 'EDTK_DB', 'MAIL' );
13  
14 if ( @ARGV % 2 != 0 or $ARGV[0] =~ /-h/i ) {
15 warn "Odd number of parameters.\n" if ( $ARGV[0] !~ /-h/i );
16 warn "usage: $0 [<column> <value>]...\n";
17 warn "\n\tthis run outmanagement from index table and doclibs\n";
18 exit 1;
19 }
20  
21 my @lots = oe_outmngr_output_run_tex( {@ARGV}, 'Mass' );
22  
23 if ( @lots == 0 ) {
24 my $sujet = "INFO: No lot pending processing\n";
25 my @body = (
26 "lot management processing done on ",
27 $cfg->{'EDTK_TYPE_ENV'},
28 " ($0), no lot pending."
29 );
30 oe_send_mail( $cfg->{'EDTK_MAIL_SENDER'}, $sujet, @body );
31 warn $sujet;
32 exit;
33 }
34  
35 # Now, run statistics and send the output by mail.
36 my $dbh = db_connect( $cfg, 'EDTK_DBI_DSN', { AutoCommit => 1, RaiseError => 1 } );
37 my $pdbh = db_connect( $cfg, 'EDTK_DBI_PARAM' );
38  
39 my $rows = omgr_stats( $dbh, $pdbh, 'day', 'idlot' );
40 my $fmt = shift(@$rows);
41 my $head = shift(@$rows);
42  
43 my $mailfile = $cfg->{'EDTK_MAIL_OMGR'};
44 open( my $fh, '<', $mailfile ) or die "ERROR: Cannot open \"$mailfile\": $!\n";
45 my @body = <$fh>;
46 close($fh);
47  
48 push( @body, "\n\n\n" );
49 push( @body, sprintf( $$fmt, @$head ) );
50 foreach my $row (@$rows) {
51 push( @body, sprintf( $$fmt, @$row ) );
52 }
53  
54 my ( $sec, $min, $hour, $day, $month, $year ) = localtime();
55 my $date = sprintf( "%02d/%02d/%d", $day, $month + 1, $year + 1900 );
56 my $time = sprintf( "%02d:%02d:%02d", $hour, $min, $sec );
57  
58 my $subject .= $cfg->{'EDTK_MAIL_SUBJ'};
59 $subject =~ s/%date/$date/;
60 $subject =~ s/%time/$time/;
61  
62 oe_send_mail( $cfg->{'EDTK_MAIL_TO'}, $subject, @body );