Also displays entreprise name on profile, minifiche... when awaiting validation.
[platal.git] / include / massmailer.inc.php
index a9269bd..269a570 100644 (file)
@@ -165,7 +165,7 @@ abstract class MassMailer
         if (is_null($hash)) {
             $hash = XDB::fetchOneCell("SELECT  hash
                                          FROM  {$this->_subscriptionTable}
-                                        WHERE  user_id = {?}", $user->id());
+                                        WHERE  uid = {?}", $user->id());
         }
         if (is_null($hash)) {
             $hash = $this->createHash(array($user->displayName(), $user->fullName(),
@@ -173,7 +173,7 @@ abstract class MassMailer
                                        rand(), "X.org rulez"));
             XDB::execute("UPDATE  {$this->_subscriptionTable} as ni
                              SET  ni.hash = {?}
-                           WHERE  ni.user_id != {?}",
+                           WHERE  ni.uid = {?}",
                          $hash, $user->id());
         }
 
@@ -192,7 +192,7 @@ abstract class MassMailer
         global $globals;
         return  "SELECT  a.uid
                    FROM  {$this->_subscriptionTable}  AS ni
-             INNER JOIN  accounts AS a ON (ni.user_id = a.uid)
+             INNER JOIN  accounts AS a ON (ni.uid = a.uid)
               LEFT JOIN  email_options AS eo ON (eo.uid = a.uid)
               LEFT JOIN  emails   AS e ON (e.uid = a.uid AND e.flags='active')
                   WHERE  ni.last < {?} AND ({$this->subscriptionWhere()}) AND
@@ -203,15 +203,18 @@ abstract class MassMailer
     public function sendToAll()
     {
         $this->setSent();
-        $query = XDB::format($this->getAllRecipients(), $this->id()) . ' LIMIT 60';
+        $query = XDB::format($this->getAllRecipients(), $this->_id) . ' LIMIT 60';
+        $emailsCount = 0;
+
         while (true) {
             $users = User::getBulkUsersWithUIDs(XDB::fetchColumn($query));
             if (count($users) == 0) {
-                return;
+                return $emailsCount;
             }
             foreach ($users as $user) {
-                $sent[] = XDB::format('user_id = {?}', $user->id());
+                $sent[] = XDB::format('uid = {?}', $user->id());
                 $this->sendTo($user, $hash);
+                ++$emailsCount;
             }
             XDB::execute("UPDATE  {$this->_subscriptionTable}
                              SET  last = {?}
@@ -219,6 +222,7 @@ abstract class MassMailer
 
             sleep(60);
         }
+        return $emailsCount;
     }
 
     abstract protected function assignData(&$smarty);