protected function execute($arguments = array(), $options = array())
 {
     parent::execute($arguments, $options);
     $this->mailLog('starting openpne:send-birthday-mail-lite task');
     // load templates
     list($pcTitleTpl, $pcTpl) = $this->getTwigTemplate('pc', 'birthday_lite');
     $birthday = $this->fetchRow('SELECT id, is_edit_public_flag, default_public_flag FROM ' . $this->getTableName('Profile') . ' WHERE name = ?', array('op_preset_birthday'));
     if (!$birthday) {
         throw new sfException('This project doesn\'t have the op_preset_birthday profile item.');
     }
     if (!$birthday['is_edit_public_flag'] && ProfileTable::PUBLIC_FLAG_PRIVATE == $birthday['default_public_flag']) {
         throw new sfException('all user\'s op_preset_birthday public_flag is hidden from backend');
     }
     $birthDatetime = new DateTime();
     $birthDatetime->modify('+ 1 week');
     $query = 'SELECT member_id FROM ' . $this->getTableName('MemberProfile') . ' WHERE profile_id = ? AND DATE_FORMAT(value_datetime, ?) = ?';
     $params = array($birthday['id'], '%m-%d', $birthDatetime->format('m-d'));
     if ($birthday['is_edit_public_flag']) {
         $query .= ' AND public_flag <> ?';
         $params[] = ProfileTable::PUBLIC_FLAG_PRIVATE;
     }
     if (null !== $options['start-member-id'] && is_numeric($options['start-member-id'])) {
         $query .= ' AND member_id >= ?';
         $params[] = $options['start-member-id'];
     }
     if (null !== $options['end-member-id'] && is_numeric($options['end-member-id'])) {
         $query .= ' AND member_id <= ?';
         $params[] = $options['end-member-id'];
     }
     $memberProfilesStmt = $this->executeQuery($query, $params);
     if ($memberProfilesStmt instanceof PDOStatement) {
         $sf_config = sfConfig::getAll();
         $op_config = new opConfig();
         while ($memberProfile = $memberProfilesStmt->fetch(Doctrine::FETCH_NUM)) {
             $birthMember = $this->getMember($memberProfile[0]);
             $birthMember['birthday'] = $birthDatetime->format('U');
             $ids = $this->getFriendIds($memberProfile[0]);
             foreach ($ids as $id) {
                 $member = $this->getMember($id);
                 $pcAddress = $this->getMemberPcEmailAddress($id);
                 if (!$pcAddress) {
                     continue;
                 }
                 $params = array('member' => $member, 'birthMember' => $birthMember, 'op_config' => $op_config, 'sf_config' => $sf_config);
                 $subject = $pcTitleTpl->render($params);
                 $body = $pcTpl->render($params);
                 try {
                     $this->sendMail($subject, $pcAddress, $this->adminMailAddress, $body);
                     $this->mailLog(sprintf("sent member %d birthday notification mail to member %d (usage memory:%s bytes)", $birthMember['id'], $member['id'], number_format(memory_get_usage())));
                 } catch (Zend_Mail_Transport_Exception $e) {
                     $this->mailLog(sprintf("%s (about member %d birthday to member %d)", $e->getMessage(), $birthMember['id'], $member['id']));
                 }
             }
         }
     }
     $this->mailLog('end openpne:send-birthday-mail-lite task');
 }
 protected function execute($arguments = array(), $options = array())
 {
     parent::execute($arguments, $options);
     $this->mailLog('starting openpne:send-daily-news-lite task');
     $this->dailyNewsDays = opConfig::get('daily_news_day');
     $today = time();
     // load templates
     list($titleTpl, $tpl) = $this->getTwigTemplate('pc', 'dailyNews_lite');
     $query = 'SELECT id, name FROM ' . $this->getTableName('Member') . ' WHERE (is_active = 1 OR is_active IS NULL)';
     $params = array();
     if (null !== $options['start-member-id'] && is_numeric($options['start-member-id'])) {
         $query .= ' AND id >= ?';
         $params[] = $options['start-member-id'];
     }
     if (null !== $options['end-member-id'] && is_numeric($options['end-member-id'])) {
         $query .= ' AND id <= ?';
         $params[] = $options['end-member-id'];
     }
     $stmtMember = $this->executeQuery($query, $params);
     if ($stmtMember instanceof PDOStatement) {
         $sf_config = sfConfig::getAll();
         $op_config = new opConfig();
         $isDailyNewsDay = $this->isDailyNewsDay();
         while ($member = $stmtMember->fetch(Doctrine::FETCH_ASSOC)) {
             $config = $this->getDailyNewsConfig($member['id']);
             if (1 == $config && !$isDailyNewsDay) {
                 continue;
             }
             if (false !== $config && !$config) {
                 continue;
             }
             $address = $this->getMemberPcEmailAddress($member['id']);
             if (!$address) {
                 continue;
             }
             $params = array('member' => $member, 'subject' => $template['title'], 'diaries' => $this->getFriendDiaryList($member['id']), 'communityTopics' => $this->getCommunityTopicList($member['id']), 'unreadMessages' => $this->getUnreadMessageList($member['id']), 'today' => $today, 'op_config' => $op_config, 'sf_config' => $sf_config);
             $subject = $titleTpl->render($params);
             $body = $tpl->render($params);
             try {
                 $this->sendMail($subject, $address, $this->adminMailAddress, $body);
                 $this->mailLog(sprintf("sent daily news to member %d (usage memory:%s bytes)", $member['id'], number_format(memory_get_usage())));
             } catch (Zend_Mail_Transport_Exception $e) {
                 $this->mailLog(sprintf("%s (member %d)", $e->getMessage(), $member['id']), sfLogger::ERR);
             }
         }
     }
     $this->mailLog('end openpne:send-daily-news-lite task');
 }