[NUUG fiksgatami] [patch] Fix broken import.cgi (do not work without EvEl) (Was: fiksgatami-dev.nuug.no/import broken)

Petter Reinholdtsen pere at hungry.com
Sat Mar 19 18:15:21 CET 2011


[Petter Reinholdtsen]
> Have not had time to rewrite this myself, but welcome patches.

Found some time to fix it.  Forwarding to mySociety too.

The problem at hand is that import.cgi do not work for us as we do not
use the EvEl subsystem.  The attached patch solve the problem, by
using Page::send_email() instead, and adjust send_email() to work with
import.cgi.  Is this a good approach, or should another one be used?

Happy hacking,
-- 
Petter Reinholdtsen
-------------- next part --------------
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 130b5b3..b9ad8f6 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -395,8 +395,11 @@ sub send_email {
     my ($q, $recipient_email_address, $name, $thing, %h) = @_;
     my $file_thing = $thing;
     $file_thing = 'empty property' if $q->{site} eq 'emptyhomes' && $thing eq 'problem'; # Needs to be in English
-    my $template = "$file_thing-confirm";
-    $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/$template");
+    my $templatepath = "$FindBin::Bin/../templates/emails/$file_thing";
+    if ( -f "$templatepath-confirm" ) {
+        $templatepath = "$FindBin::Bin/../templates/emails/$file_thing-confirm";
+    }
+    my $template = File::Slurp::read_file($templatepath);
     my $to = $name ? [[$recipient_email_address, $name]] : $recipient_email_address;
     my $cobrand = get_cobrand($q);
     my $sender = Cobrand::contact_email($cobrand);
@@ -444,7 +447,7 @@ sub send_email {
     }
     
     my ($action, $worry);
-    if ($thing eq 'problem') {
+    if ($thing eq 'problem' || $thing eq 'partial') {
         $action = _('your problem will not be posted');
         $worry = _("we'll hang on to your problem report while you're checking your email.");
     } elsif ($thing eq 'update') {
diff --git a/web/import.cgi b/web/import.cgi
index ac36b2e..065f2ba 100755
--- a/web/import.cgi
+++ b/web/import.cgi
@@ -112,23 +112,19 @@ sub main {
         $id, $latitude, $longitude, $input{subject},
         $input{detail}, $input{name}, $input{service}, $input{email}, $input{phone}, $photo);
 
-    # Send checking email
-    my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/partial");
     my $token = mySociety::AuthToken::store('partial', $id);
-    my %h = (
-        name => $input{name} ? ' ' . $input{name} : '',
-        url => mySociety::Config::get('BASE_URL') . '/L/' . $token,
-        service => $input{service},
-    );
-
-    my $sender = mySociety::Config::get('CONTACT_EMAIL');
-    $sender =~ s/team/fms-DO-NOT-REPLY/;
-    mySociety::EvEl::send({
-        _template_ => $template,
-        _parameters_ => \%h,
-        To => $input{name} ? [ [ $input{email}, $input{name} ] ] : $input{email},
-        From => [ $sender, 'FixMyStreet' ],
-    }, $input{email});
+
+    my %h = ();
+    $h{title} = $input{title};
+    $h{detail} = $input{detail};
+    $h{name} = $input{name} ? ' ' . $input{name} : '';
+    $h{service} = $input{service};
+
+    my $base = Page::base_url_with_lang($q, undef, 1);
+    $h{url} = $base . '/L/' . $token;
+
+    # Send checking email
+    my $out = Page::send_email($q, $input{email}, $input{name}, 'partial', %h);
 
     dbh()->commit();
     print 'SUCCESS';


More information about the fiksgatami mailing list