← Back to team overview

mvhub-dev team mailing list archive

[Merge] lp:~pulaparti/mvhub/create_email_send_library into lp:mvhub

 

pulaparti has proposed merging lp:~pulaparti/mvhub/create_email_send_library into lp:mvhub.

Requested reviews:
  mvhub-dev (mvhub-dev)


Started refactoring project with e-mails.
-- 
https://code.launchpad.net/~pulaparti/mvhub/create_email_send_library/+merge/22236
Your team mvhub-dev is subscribed to branch lp:mvhub.
=== modified file 'app-mvhub/DocumentRoot/cgi-bin/mvhub/agency_form.pl'
--- app-mvhub/DocumentRoot/cgi-bin/mvhub/agency_form.pl	2009-12-29 17:26:17 +0000
+++ app-mvhub/DocumentRoot/cgi-bin/mvhub/agency_form.pl	2010-03-26 16:01:24 +0000
@@ -104,8 +104,8 @@
             if ( $agency_id == $MVHub::Common::NO_AGENCY_ID ) {
                 $agency_id = insert_agency_record($values_href);
                 if ( !$is_admin ) {    # an agency submitted a new record
-                    send_admin_notification($values_href);
-                    send_confirmation_email( $cfg, $values_href );
+                    send_agency_admin_notification($values_href);
+                    send_agency_confirmation_email( $cfg, $values_href );
 
                     # Log them in, and display the First Program wizard page
                     my $tmpl
@@ -147,10 +147,10 @@
     }    # else form is submitted
 }    # main
 
-sub send_confirmation_email {
+sub send_agency_confirmation_email {
     my ( $cfg, $values_href ) = @_;
 
-    my %params = build_confirmation_email_params( $cfg, $values_href );
+    my %params = build_agency_confirmation_email_params( $cfg, $values_href );
     my $top = MIME::Entity->build(
         Type    => "text/plain",
         From    => $params{from},
@@ -162,7 +162,7 @@
     MVHub::Common::sendmail($top);
 }
 
-sub build_confirmation_email_params {
+sub build_agency_confirmation_email_params {
     my ( $cfg, $values_href ) = @_;
 
     my $from = $cfg->param('NOTIFICATION.team_name')
@@ -177,14 +177,14 @@
     my $subject = "$values_href->{agency_name} added to: ";
     $subject .= $cfg->param('SITE.website_name');
 
-    my $body = build_confirmation_email_body( $cfg, $values_href );
+    my $body = build_agency_confirmation_email_body( $cfg, $values_href );
     my %params
         = ( from => $from, to => $to, subject => $subject, body => $body, );
     return %params;
 
 }
 
-sub build_confirmation_email_body {
+sub build_agency_confirmation_email_body {
     my ( $cfg, $values_href ) = @_;
 
     my $website_name = $cfg->param('SITE.website_name');
@@ -431,7 +431,7 @@
     return $return_val;
 }
 
-sub send_admin_notification {
+sub send_agency_admin_notification {
     my $values_href = shift;
     my $body;
 

=== modified file 'app-mvhub/DocumentRoot/cgi-bin/mvhub/program.pl'
--- app-mvhub/DocumentRoot/cgi-bin/mvhub/program.pl	2010-03-17 14:33:14 +0000
+++ app-mvhub/DocumentRoot/cgi-bin/mvhub/program.pl	2010-03-26 16:01:24 +0000
@@ -19,6 +19,7 @@
 use MVHub::HTML;
 use MVHub::Page;
 use MVHub::ProgramFieldDefs;
+use MVHub::Utils::Email::Send qw/send_program_admin_notification/;
 
 my $MODE_PARAM = 'mode';
 
@@ -305,11 +306,13 @@
                 $program_id = insert_program_record($values_href);
 
                 if ( !$is_admin ) {    # an agency submitted a new record
-                    send_admin_notification(
+
+                    MVHub::Utils::Email::Send::send_program_admin_notification(
                         mode       => $MODE_PROGRAM_FORM,
                         program_id => $program_id,
                         agency_id  => $values_href->{agency_id},
                     );
+
                 }
 
             # Redirect to the program category selection page.
@@ -861,11 +864,13 @@
     $dbh->do($sql);
 
     if ( !$is_admin ) {
-        send_admin_notification(
+
+        MVHub::Utils::Email::Send::send_program_admin_notification(
             mode       => $MODE_HIDE_PROGRAM,
             program_id => $program_id,
             agency_id  => $agency_id
         );
+
     }
 
     MVHub::Common::display_agency_home_page_and_exit(
@@ -888,11 +893,13 @@
 
 # Send the e-mail before executing the db query, so we can get the hidden_reason
     if ( !$is_admin ) {
-        send_admin_notification(
+
+        MVHub::Utils::Email::Send::send_program_admin_notification(
             mode       => $MODE_UNHIDE_PROGRAM,
             program_id => $program_id,
             agency_id  => $agency_id
         );
+
     }
 
     $dbh->do($sql);
@@ -928,11 +935,13 @@
 
  # We send the notification before doing the deletion since the following call
  # queries the database for that record.
-            send_admin_notification(
+
+            MVHub::Utils::Email::Send::send_program_admin_notification(
                 mode       => $MODE_REMOVE_PROGRAM,
                 program_id => $program_id,
                 agency_id  => $agency_id,
             );
+
         }
 
         my $rows_affected
@@ -950,99 +959,7 @@
     );
 }
 
-sub send_admin_notification {
-    my %args       = @_;
-    my $mode       = delete $args{'mode'};
-    my $program_id = delete $args{'program_id'};
-    my $agency_id  = delete $args{'agency_id'};
-    MVHub::Utils::assert( ( scalar keys %args ) == 0,
-        "Unknown arguments: @{[%args]}" );
-
-    my $dbh = MVHub::Utils::DB::get_dbh( $ENV{MV_CONFIG_FILE} );
-
-    # Regardless of mode, get the program info and prepare it for display
-    my $result_aref = $dbh->selectall_arrayref(
-        "SELECT a.agency_name, p.* FROM agency a, program p "
-            . "WHERE p.program_id = "
-            . $dbh->quote($program_id)
-            . "AND a.agency_id = "
-            . $dbh->quote($agency_id),
-        { Slice => {} }
-    );
-
-    MVHub::Utils::assert( ( @$result_aref == 1 ),
-        "Expected 1 result, got " . scalar @$result_aref );
-
-    my $values_href = $$result_aref[0];
-
-    my $program_name = $values_href->{program_name};
-    my $agency_name  = $values_href->{agency_name};
-
-    my $subject = "Program [ $program_name ]";
-
-    my $body = '';
-
-    # Mode-specific actions
-    if ( $mode eq $MODE_REMOVE_PROGRAM ) {
-        $subject .= " removed";
-        $body = "$subject by the agency\n\n";
-    }
-    elsif ( $mode eq $MODE_HIDE_PROGRAM ) {
-        $subject .= " hidden";
-        $body = "$subject by the agency\n\n";
-        $body
-            .= "Reason for hiding program: $values_href->{hidden_reason}\n\n";
-    }
-    elsif ( $mode eq $MODE_UNHIDE_PROGRAM ) {
-        $subject .= " unhidden";
-        $body = "$subject by the agency\n\n";
-        $body
-            .= "Original reason program was hidden: $values_href->{hidden_reason}\n\n";
-    }
-    elsif ( $mode eq $MODE_PROGRAM_FORM ) {
-        $subject .= " added";
-        $body = "$subject by ";
-        $body .= "the agency \n\n";
-    }
-    else {
-        MVHub::Utils::assert( 0,
-            "Unknown mode ($mode) passed to send_admin_notification." );
-    }
-
-    $body .= "\n-------------------------------------\n\n";
-
-    $body .= "Agency Name: $agency_name\n\n";
-
-    # Prepare the fields for display
-    foreach my $field (@MVHub::ProgramFieldDefs::FIELDS) {
-
-        if ( defined $values_href->{$field} ) {
-            $values_href->{$field} =~ s/$MVHub::Common::FIELD_DELIMITER/, /g;
-        }
-
-        if ( exists $values_href->{$field} )
-        {    # Since we deleted the _verification fields
-            $body 
-                .= uc($field) . ": "
-                . (
-                ( defined $values_href->{$field} )
-                ? $values_href->{$field}
-                : ''
-                ) . "\n\n";
-        }
-
-    }
-    my $cfg = MVHub::Utils::ConfigSimple::create_config_from(
-        $ENV{MV_CONFIG_FILE} );
-    my $to = $cfg->param('NOTIFICATION.admin_email');
-
-    # Send the e-mail
-    MVHub::Common::notification_email(
-        to      => $to,
-        subject => $subject,
-        message => $body
-    );
-}
+# moved subroutine send_program_admin_notification to MVHub::Utils::Email::Send.pm
 
 # Take the area_type and $AREAS_SERVED_CBOX_PREFIX<area_type-value> fields
 # and put them into the record (values_href) that is being prepared for entry
@@ -1343,7 +1260,7 @@
     return ( $row[0] != 0 );
 }
 
-sub send_confirmation_email {
+sub send_program_confirmation_email {
     my $values_href = shift;
     my $agency_name
         = MVHub::Utils::DB::get_full_name( $values_href->{agency_id} );

=== modified file 'app-mvhub/t/html_lint.t'
--- app-mvhub/t/html_lint.t	2010-03-25 15:49:52 +0000
+++ app-mvhub/t/html_lint.t	2010-03-26 16:01:24 +0000
@@ -18,7 +18,6 @@
 my @files = get_files(qw/*.inc *.tmpl *.shtml/);
 
 # we use HTML::Template for more than html files
-
 @files = grep { !m#conf/templates/text# } @files;
 
 eval ' use Test::HTML::Lint; ';

=== modified file 'lib-mvhub/lib/MVHub/Common.pm'
--- lib-mvhub/lib/MVHub/Common.pm	2010-03-12 15:34:38 +0000
+++ lib-mvhub/lib/MVHub/Common.pm	2010-03-26 16:01:24 +0000
@@ -33,6 +33,7 @@
     prepare_form
     print_page_and_exit
     undelimit_field
+    notification_email
 );
 
 our ($VERSION) = '$Revision: 1729 $' =~ /([.\d]+)/;
@@ -296,7 +297,8 @@
     my $cfg = MVHub::Utils::ConfigSimple::create_config_from(
         $ENV{MV_CONFIG_FILE} );
 
-    my $notice = $cfg->param('SITE.website_name') . " /($ENV{HTTP_HOST})";
+    my $host = $ENV{HTTP_HOST} || `/bin/hostname`;
+    my $notice = $cfg->param('SITE.website_name') . "/$host";
 
     my $installation = $ENV{SERVER_NAME} || $ENV{USER} . ' site';
 

=== added directory 'lib-mvhub/lib/MVHub/Utils/Email'
=== added file 'lib-mvhub/lib/MVHub/Utils/Email/Send.pm'
--- lib-mvhub/lib/MVHub/Utils/Email/Send.pm	1970-01-01 00:00:00 +0000
+++ lib-mvhub/lib/MVHub/Utils/Email/Send.pm	2010-03-26 16:01:24 +0000
@@ -0,0 +1,204 @@
+package MVHub::Utils::Email::Send;
+use strict;
+use warnings;
+
+our ($VERSION) = '$Revision: 1740 $' =~ /([.\d]+)/xm;
+
+use Carp;
+use DBI;
+use MVHub::Utils qw/assert/;
+use MVHub::Utils::DB qw/get_dbh/;
+use MVHub::Utils::ConfigSimple qw/create_config_from/;
+use MVHub::Common qw/notification_email/;
+use MVHub::ProgramFieldDefs;
+use base 'Exporter';
+
+our @EXPORT_OK = qw(send_program_admin_notification
+);
+
+# TODO KLUDGE duplicate of the constants program.pl
+my $MODE_REMOVE_PROGRAM = 'remove';
+my $MODE_HIDE_PROGRAM   = 'hide';
+my $MODE_UNHIDE_PROGRAM = 'unhide';
+my $MODE_PROGRAM_FORM   = 'program_form';
+
+sub send_program_admin_notification {
+    my %args       = @_;
+    my $mode       = delete $args{'mode'};
+    my $program_id = delete $args{'program_id'};
+    my $agency_id  = delete $args{'agency_id'};
+    MVHub::Utils::assert( ( scalar keys %args ) == 0,
+        "Unknown arguments: @{[%args]}" );
+
+    my $dbh = MVHub::Utils::DB::get_dbh( $ENV{MV_CONFIG_FILE} );
+
+    # Regardless of mode, get the program info and prepare it for display
+    my $result_aref = $dbh->selectall_arrayref(
+        "SELECT a.agency_name, p.* FROM agency a, program p "
+            . "WHERE p.program_id = "
+            . $dbh->quote($program_id)
+            . "AND a.agency_id = "
+            . $dbh->quote($agency_id),
+        { Slice => {} }
+    );
+
+    MVHub::Utils::assert( ( @$result_aref == 1 ),
+        "Expected 1 result, got " . scalar @$result_aref );
+
+    my $values_href = $$result_aref[0];
+
+    my $program_name = $values_href->{program_name};
+    my $agency_name  = $values_href->{agency_name};
+
+    my $subject = "Program [ $program_name ]";
+
+    my $body = '';
+
+    # Mode-specific actions
+    if ( $mode eq $MODE_REMOVE_PROGRAM ) {
+        $subject .= " removed";
+        $body = "$subject by the agency\n\n";
+    }
+    elsif ( $mode eq $MODE_HIDE_PROGRAM ) {
+        $subject .= " hidden";
+        $body = "$subject by the agency\n\n";
+        $body
+            .= "Reason for hiding program: $values_href->{hidden_reason}\n\n";
+    }
+    elsif ( $mode eq $MODE_UNHIDE_PROGRAM ) {
+        $subject .= " unhidden";
+        $body = "$subject by the agency\n\n";
+        $body
+            .= "Original reason program was hidden: $values_href->{hidden_reason}\n\n";
+    }
+    elsif ( $mode eq $MODE_PROGRAM_FORM ) {
+        $subject .= " added";
+        $body = "$subject by ";
+        $body .= "the agency \n\n";
+    }
+    else {
+        MVHub::Utils::assert( 0,
+            "Unknown mode ($mode) passed to send_program_admin_notification."
+        );
+    }
+
+    $body .= "\n-------------------------------------\n\n";
+
+    $body .= "Agency Name: $agency_name\n\n";
+
+    # Prepare the fields for display
+    foreach my $field (@MVHub::ProgramFieldDefs::FIELDS) {
+
+        if ( defined $values_href->{$field} ) {
+            $values_href->{$field} =~ s/$MVHub::Common::FIELD_DELIMITER/, /g;
+        }
+
+        if ( exists $values_href->{$field} )
+        {    # Since we deleted the _verification fields
+            $body 
+                .= uc($field) . ": "
+                . (
+                ( defined $values_href->{$field} )
+                ? $values_href->{$field}
+                : ''
+                ) . "\n\n";
+        }
+
+    }
+    my $cfg = MVHub::Utils::ConfigSimple::create_config_from(
+        $ENV{MV_CONFIG_FILE} );
+    my $to = $cfg->param('NOTIFICATION.admin_email');
+
+    # Send the e-mail
+    MVHub::Common::notification_email(
+        to      => $to,
+        subject => $subject,
+        message => $body
+    );
+
+}
+
+#return true like all good modules should
+1;
+
+__END__
+
+=head1 NAME
+
+MVHub::Utils::DB -functions to return info from database
+
+=head1 VERSION
+
+This documentation refers to MVHub::Utils::DB version $Revision: 1740 $
+
+=head1 SYNOPSIS
+
+    use MVHub::Utils::DB;
+
+=head1 DESCRIPTION
+
+subs that return a datbase handle ($dbh) or take a database handle and return 
+data from the Database
+
+=head1 SEE ALSO
+
+ MVHub::Common MVHub::Utils
+
+=head1 LAST MODIFIED
+
+Last modified on $Date: 2009-02-27 19:01:34 -0500 (Fri, 27 Feb 2009) $ by $Author: omacneil $
+
+=head1 BUGS
+
+none known 
+
+=head1 LICENSE AND COPYRIGHT
+
+The GNU Affero General Public License, version 3.0 or later
+
+Copyright (c) 2004-2008 Community Software Lab, Inc ( http://thecsl.org )
+
+=cut
+
+=head1 SUBROUTINES/METHODS 
+
+=head2 get_data_source($config_file)
+
+  Given a configuration file return the right DBI
+  data source , depending on what database_type
+  is in the config file
+      
+     "dbi:SQLite:dbname=$db_name"
+   
+   or:
+      "dbi:Pg:dbname=$db_name;host=$host";
+                
+   croak if the database_type in the config file is neither
+   SQLite or Pg
+                    
+=head1 DIAGNOSTICS
+
+Error messages are listed with documentation for sub routines.
+
+=head1 CONFIGURATION AND ENVIRONMENT
+
+MVHub::Utils does not require configuration beyond that used by MVHub itself
+
+=head1 DEPENDENCIES
+
+Carp, DBI, HTML::Strip
+
+=head1 BUGS AND LIMITATIONS
+
+There are no known bugs in this module.
+Please report problems to help@xxxxxxxxxx
+Patches are welcome.
+
+=head1 AUTHOR
+
+Community Software Lab help@xxxxxxxxxx
+=head1 INCOMPATIBILITIES
+
+No known incompatibilities
+
+

=== modified file 'lib-mvhub/t/01-load.t'
--- lib-mvhub/t/01-load.t	2009-09-15 01:12:17 +0000
+++ lib-mvhub/t/01-load.t	2010-03-26 16:01:24 +0000
@@ -50,6 +50,11 @@
             $module = join '::', ( split '/', $file )[ -3 .. -1 ];
             $module = ( split '\.', $module )[0];
             push @modules, $module;
+        }    # lib/Bar/Baz/Boo/Foo.pm ==> Bar::Baz::Boo::Foo
+        elsif ( $file =~ m|lib/\w+/\w+/\w+/\w+\.pm$| ) {
+            $module = join '::', ( split '/', $file )[ -4 .. -1 ];
+            $module = ( split '\.', $module )[0];
+            push @modules, $module;
         }
         else {
             warn "\n'$file'\n not matched \n";