[Cpan-forum-commit] rev 246 - in trunk: . lib/CPAN lib/CPAN/Forum/DB lib/CPAN/Forum/RM

svn at pti.co.il svn at pti.co.il
Fri Jul 6 11:00:41 IDT 2007


Author: gabor
Date: 2007-07-06 11:00:41 +0300 (Fri, 06 Jul 2007)
New Revision: 246

Modified:
   trunk/
   trunk/lib/CPAN/Forum.pm
   trunk/lib/CPAN/Forum/DB/Posts.pm
   trunk/lib/CPAN/Forum/RM/Notify.pm
Log:
change the way a post is fetched for the notification e-mail (use plain DBI)



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4117
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
   + 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4130
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752

Modified: trunk/lib/CPAN/Forum/DB/Posts.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Posts.pm	2007-07-06 05:26:31 UTC (rev 245)
+++ trunk/lib/CPAN/Forum/DB/Posts.pm	2007-07-06 08:00:41 UTC (rev 246)
@@ -37,6 +37,18 @@
             });
 my $MORE_SQL = 'groups.name group_name, users.fname user_fname, users.lname user_lname, users.username user_username';
 
+sub get_post {
+    my ($self, $post_id) = @_;
+    return if not $post_id;
+    #Carp::croak("No post_id given") if not $post_id;
+
+    my $sql = "SELECT posts.id, gid, uid, parent, thread, hidden, subject, text, date,
+                groups.name group_name, groups.pauseid
+                FROM posts, groups
+                WHERE posts.id=? AND posts.gid=groups.id";
+    return $self->_fetch_single_hashref($sql, $post_id);
+}
+
 sub retrieve_latest { 
     my ($self, $limit) = @_;
 
@@ -112,7 +124,19 @@
     }
     return \@values;
 }
+sub _fetch_single_hashref {
+    my ($self, $sql, @args) = @_;
 
+    my $dbh = CPAN::Forum::DBI::db_Main();
+    my $sth = $dbh->prepare($sql);
+    $sth->execute(@args);
+    my @values;
+    my $hr = $sth->fetchrow_hashref;
+    $sth->finish;
+    return $hr;
+    
+}
+
 sub mysearch {
     my ($self, $params) = @_;
 

Modified: trunk/lib/CPAN/Forum/RM/Notify.pm
===================================================================
--- trunk/lib/CPAN/Forum/RM/Notify.pm	2007-07-06 05:26:31 UTC (rev 245)
+++ trunk/lib/CPAN/Forum/RM/Notify.pm	2007-07-06 08:00:41 UTC (rev 246)
@@ -11,16 +11,18 @@
 sub notify {
     my ($self, $post_id) = @_;
     
-    my $post = CPAN::Forum::DB::Posts->retrieve($post_id);
+    my $post = CPAN::Forum::DB::Posts->get_post($post_id);
+    return if not $post;
+    # TODO what if it does not find it?
 
     my $message = 
-        $self->_text2mail ($post->text) .
+        $self->_text2mail ($post->{text}) .
         "\n\n" .
         "To write a respons, access\n".
-        "http://$ENV{HTTP_HOST}/response_form/" . $post->id .
+        "http://$ENV{HTTP_HOST}/response_form/" . $post->{id} .
         "\n\n" .
         "To see the full thread, access\n" .
-        "http://$ENV{HTTP_HOST}/threads/" . $post->thread .
+        "http://$ENV{HTTP_HOST}/threads/" . $post->{thread} .
         "\n\n" .
         "--\n" .
         "You are getting this messages from $ENV{HTTP_HOST}\n" .
@@ -28,7 +30,7 @@
     # disclaimer ?
     # X-lits: field ?
 
-    my $subject = sprintf ("[%s] %s",  $post->gid->name, $post->subject); # TODO _subject_escape ?
+    my $subject = sprintf ("[%s] %s",  $post->{group_name}, $post->{subject}); # TODO _subject_escape ?
 
     my $FROM = $self->config("from");
     $self->log->debug("FROM field set to be $FROM");
@@ -37,9 +39,11 @@
         Subject  => $subject,
         Message  => $message,
     );
+    $self->log->debug(Data::Dumper->Dump([\%mail], ['mail']));
 
 
     $self->fetch_subscriptions(\%mail, $post);
+    return;
 }
 
 =head2 notify_admin
@@ -193,7 +197,7 @@
     if ($params[0] eq 'dist') {
         my $dist = $params[1] || '';
         $self->log->debug("rss of dist: '$dist'");
-        return CPAN::Forum::DB::Posts->search_post_by_groupname($dist, $limit); #gid => $group->id, {order_by => 'date DESC'});
+        return CPAN::Forum::DB::Posts->search_post_by_groupname($dist, $limit);
     }
 
     if ($params[0] eq 'author') {

Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm	2007-07-06 05:26:31 UTC (rev 245)
+++ trunk/lib/CPAN/Forum.pm	2007-07-06 08:00:41 UTC (rev 246)
@@ -1413,14 +1413,14 @@
     $self->_sendmail($it, $mail, \%to);
 
     # People who asked for all the posts in this group
-    $it = CPAN::Forum::DB::Subscriptions->search(allposts => 1, gid => $post->gid);
+    $it = CPAN::Forum::DB::Subscriptions->search(allposts => 1, gid => $post->{gid});
     $self->_sendmail($it, $mail, \%to);
 
     # People who asked for all the posts in this PAUSEID
-    $it = CPAN::Forum::DB::Subscriptions_pauseid->search(allposts => 1, pauseid => $post->gid->pauseid);
+    $it = CPAN::Forum::DB::Subscriptions_pauseid->search(allposts => 1, pauseid => $post->{pauseid});
     $self->_sendmail($it, $mail, \%to);
 
-    if ($post->thread == $post->id) { 
+    if ($post->{thread} == $post->{id}) { 
         $self->log->debug("Processing messages for thread starter");
 
         # People who are subscribed to all thread starters
@@ -1428,11 +1428,11 @@
         $self->_sendmail($it, $mail, \%to);
 
         # People who are subscribed to the thread startes in this group
-        $it = CPAN::Forum::DB::Subscriptions->search(starters => 1, gid => $post->gid->id);
+        $it = CPAN::Forum::DB::Subscriptions->search(starters => 1, gid => $post->{gid});
         $self->_sendmail($it, $mail, \%to);
 
         # People who are subscribed to the thread startes of this PAUSEID
-        $it = CPAN::Forum::DB::Subscriptions_pauseid->search(starters => 1, pauseid => $post->gid->pauseid);
+        $it = CPAN::Forum::DB::Subscriptions_pauseid->search(starters => 1, pauseid => $post->{pauseid});
         $self->_sendmail($it, $mail, \%to);
     }
     else {
@@ -1440,7 +1440,7 @@
 
         # Collect the users who posted in this thread
         my %uids;
-        my $pit = CPAN::Forum::DB::Posts->search(thread => $post->thread);
+        my $pit = CPAN::Forum::DB::Posts->search(thread => $post->{thread});
         while (my $p = $pit->next) {
             $uids{$p->uid}=1;
             $self->log->debug("Ids: " . $p->uid);
@@ -1449,12 +1449,14 @@
         $it = CPAN::Forum::DB::Subscriptions_all->search(followups => 1);
         $self->_sendmail($it, $mail, \%to, \%uids);
 
-        $it = CPAN::Forum::DB::Subscriptions->search(followups => 1, gid => $post->gid->id);
+        $it = CPAN::Forum::DB::Subscriptions->search(followups => 1, gid => $post->{gid});
         $self->_sendmail($it, $mail, \%to, \%uids);
         
-        $it = CPAN::Forum::DB::Subscriptions_pauseid->search(followups => 1, pauseid => $post->gid->pauseid);
+        $it = CPAN::Forum::DB::Subscriptions_pauseid->search(followups => 1, pauseid => $post->{pauseid});
         $self->_sendmail($it, $mail, \%to);
     }
+    
+    $self->log->debug("Number of e-mails sent: ", scalar keys %to);
 }
 
 sub _sendmail {
@@ -1532,8 +1534,9 @@
 }
 
 sub _my_sendmail {
-    my ($self, @args) = @_;
-    #$self->log->debug(Data::Dumper->Dump([\@args], ['_my_sendmail']));
+    my ($self, %args) = @_;
+    #$self->log->debug(Data::Dumper->Dump([\%args], ['_my_sendmail']));
+    #$self->log->debug("_my_sendmail to '$args{To}'");
 
     return if $ENV{NO_CPAN_FORUM_MAIL};
     # for testing
@@ -1544,7 +1547,7 @@
         return;
     }
     else {
-        return sendmail(@args);
+        return sendmail(%args);
     }
 }
 



More information about the Cpan-forum-commit mailing list