Fix massmailer memory usage
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 1 Feb 2007 10:28:45 +0000 (10:28 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 1 Feb 2007 10:28:45 +0000 (10:28 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/branches/platal-0.9.13@1455 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/plmailer.php
include/massmailer.inc.php

index 9468fa3..5d38bb2 100644 (file)
@@ -28,11 +28,10 @@ class PlMail extends Smarty
     private $tpl;
     private $mailer = null;
 
-    function __construct(&$mailer, $tpl)
+    function __construct($tpl)
     {
         global $globals;
         $this->tpl           = $tpl;
-        $this->mailer       =& $mailer;
         $this->caching       = false;
         $this->compile_check = true;
 
@@ -50,6 +49,16 @@ class PlMail extends Smarty
         $this->register_function('add_header', Array($this, 'addHeader'));
     }
 
+    public static function &get(&$mailer, $tpl)
+    {
+        static $plmail;
+        if (!isset($plmail) || $plmail->tpl != $tpl) {
+            $plmail = new PlMail($tpl);
+        }
+        $plmail->mailer =& $mailer;
+        return $plmail;
+    }
+
     public function run($html)
     {
         $this->assign('html_version', $html);
@@ -146,7 +155,7 @@ class PlMailer extends Mail_Mime {
         $this->Mail_Mime("\n");
         $this->mail = @Mail::factory('sendmail', Array('sendmail_args' => '-oi'));
         if (!is_null($tpl)) {
-            $this->page = new PlMail($this, $tpl);
+            $this->page =& PlMail::get($this, $tpl);
         }
     }
 
index 79b0fa0..77a38b2 100644 (file)
@@ -121,7 +121,8 @@ abstract class MassMailer
 
     protected function getAllRecipients()
     {
-        return  "SELECT  u.user_id, a.alias,
+        global $globals;
+        return  "SELECT  u.user_id, CONCAT(a.alias, '@{$globals->mail->domain}'),
                          u.prenom, IF(u.nom_usage='', u.nom, u.nom_usage),
                          FIND_IN_SET('femme', u.flags),
                          q.core_mail_fmt AS pref, 0 AS hash
@@ -151,6 +152,7 @@ abstract class MassMailer
             XDB::execute("UPDATE  {$this->subscriptionTable()}
                              SET  last = {?}
                            WHERE " . implode(' OR ', $sent), $this->_id);
+            
             sleep(60);
         }
     }