Implements the first API handler (/api/1/user/<user>/isRegistered). It
[platal.git] / include / massmailer.inc.php
index a6dc702..8c132a1 100644 (file)
@@ -173,7 +173,7 @@ abstract class MassMailer
                                        rand(), "X.org rulez"));
             XDB::execute("UPDATE  {$this->_subscriptionTable} as ni
                              SET  ni.hash = {?}
-                           WHERE  ni.uid != {?}",
+                           WHERE  ni.uid = {?}",
                          $hash, $user->id());
         }
 
@@ -195,6 +195,8 @@ abstract class MassMailer
              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')
+              LEFT JOIN  account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
+              LEFT JOIN  profile_display AS pd ON (ap.pid = pd.pid)
                   WHERE  ni.last < {?} AND ({$this->subscriptionWhere()}) AND
                          (e.email IS NOT NULL OR FIND_IN_SET('googleapps', eo.storage))
                GROUP BY  a.uid";
@@ -203,22 +205,23 @@ 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) {
+            $sent = array();
             $users = User::getBulkUsersWithUIDs(XDB::fetchColumn($query));
             if (count($users) == 0) {
                 return $emailsCount;
             }
             foreach ($users as $user) {
-                $sent[] = XDB::format('uid = {?}', $user->id());
+                $sent[] = $user->id();
                 $this->sendTo($user, $hash);
                 ++$emailsCount;
             }
             XDB::execute("UPDATE  {$this->_subscriptionTable}
                              SET  last = {?}
-                           WHERE " . implode(' OR ', $sent), $this->_id);
+                           WHERE  uid IN {?}", $this->_id, $sent);
 
             sleep(60);
         }