예제 #1
0
파일: cron.php 프로젝트: hardikamutech/loov
 /**
  * Send new matches to users by email
  */
 public function sendNewMatches()
 {
     $config = OW::getConfig();
     if (!$config->configExists('matchmaking', 'cron_busy')) {
         $config->addConfig('matchmaking', 'cron_busy', 0, 'Mass mailing queue is busy');
     }
     if (!$config->configExists('matchmaking', 'cron_mailing_user_first')) {
         $config->addConfig('matchmaking', 'cron_mailing_user_first', 0, 'Already mailed users count');
     }
     // check if cron queue is not busy
     if ($config->getValue('matchmaking', 'cron_busy')) {
         $cronBusyTime = (int) $config->getValue('matchmaking', 'cron_busy_timestamp');
         if (time() - $cronBusyTime > 60 * 30) {
             $config->saveConfig('matchmaking', 'cron_busy', 0);
         }
         return;
     }
     if ($this->send_new_matches_interval == 0) {
         return;
     }
     if (time() - $this->last_matches_sent_timestamp < $this->send_new_matches_interval) {
         return;
     }
     $config->saveConfig('matchmaking', 'cron_busy', 1);
     if (!$config->configExists('matchmaking', 'cron_busy_timestamp')) {
         $config->addConfig('matchmaking', 'cron_busy_timestamp', time(), '');
     } else {
         $config->saveConfig('matchmaking', 'cron_busy_timestamp', time());
     }
     $userService = BOL_UserService::getInstance();
     $first = $config->getValue('matchmaking', 'cron_mailing_user_first');
     $count = $userService->count(true);
     if ($first < $count) {
         $users = $userService->findList($first, self::CRON_USER_COUNT, true);
         $counter = 0;
         /**
          * @var BOL_User $user
          */
         foreach ($users as $id => $user) {
             if ($user->emailVerify == 0) {
                 $counter++;
                 continue;
             }
             try {
                 $this->service->sendNewMatchesForUser($user->getId());
                 $counter++;
             } catch (Exception $e) {
                 $config->saveConfig('matchmaking', 'cron_mailing_user_first', $first + $counter);
                 $config->saveConfig('matchmaking', 'cron_busy', 0);
                 return;
             }
         }
         $config->saveConfig('matchmaking', 'cron_mailing_user_first', $first + $counter);
     } else {
         OW::getConfig()->saveConfig('matchmaking', 'cron_mailing_user_first', 0);
         OW::getConfig()->saveConfig('matchmaking', 'last_matches_sent_timestamp', time());
     }
     $config->saveConfig('matchmaking', 'cron_busy', 0);
 }