Beispiel #1
0
 /**
  * 执行图度规则过滤
  *
  * 遍历所有接收人所有可用规则,并执行过滤
  * @param $params
  */
 public function filterTudu($params)
 {
     if (empty($params['tuduid']) || empty($params['tsid'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     /** @var $daoRule Dao_Td_Rule_Rule */
     $daoRule = Tudu_Dao_Manager::getDao('Dao_Td_Rule_Rule', Tudu_Dao_Manager::DB_TS);
     $users = $manager->getTuduUsers($tuduId);
     if (!$users) {
         $this->getLogger()->warn("Tudu id:{$tuduId} Users are not exists");
         return;
     }
     $tudu = $manager->getTuduById($tuduId, $users[0]['uniqueid']);
     if (null === $tudu) {
         $this->getLogger()->warn("Tudu id: {$tuduId} is not exists");
         return;
     }
     $tudu = $tudu->toArray();
     $expire = 3600 * 24;
     //定义Memcache过期时间: 一天
     // 获取接收用户规则过滤
     foreach ($users as $user) {
         $unId = $user['uniqueid'];
         $rules = $this->_memcache->loadCache(array($daoRule, 'getRulesByUniqueId'), array($unId, array('isvalid' => true)), $expire);
         if ($rules->count() <= 0) {
             continue;
         }
         foreach ($rules as $rule) {
             $filters = $rule->getFilters();
             $filterCount = $filters->count();
             $matchCount = 0;
             if ($filterCount <= 0) {
                 continue;
             }
             foreach ($filters as $filter) {
                 $contain = false;
                 switch ($filter->what) {
                     // 发起人
                     case 'from':
                         if (is_array($filter->value)) {
                             foreach ($filter->value as $item) {
                                 $item = str_replace(array('oray.com', 'tudu.com'), array('oray', ''), $item);
                                 if ($item == $tudu['from'][3]) {
                                     $contain = true;
                                     break;
                                 }
                             }
                         }
                         break;
                         // 接收人,抄送人
                     // 接收人,抄送人
                     case 'to':
                     case 'cc':
                         if (is_array($filter->value)) {
                             $count = 0;
                             $match = 0;
                             foreach ($filter->value as $item) {
                                 $count++;
                                 $item = str_replace(array('oray.com', 'tudu.com'), array('oray', ''), $item);
                                 if (isset($tudu[$filter->what][$item])) {
                                     $match++;
                                 }
                             }
                             if ($count == $match) {
                                 $contain = true;
                             }
                         }
                         break;
                     case 'subject':
                         $contain = false !== strpos($tudu['subject'], $filter->value);
                         break;
                 }
                 if ($filter->type == 'contain' && $contain || $filter->type == 'exclusive' && !$contain) {
                     $matchCount++;
                 }
             }
             // 匹配过滤条件,执行规则操作
             if ($matchCount == $filterCount) {
                 // 标签
                 if ($rule->operation == 'label') {
                     $manager->addLabel($tuduId, $unId, $rule->value);
                     // 忽略
                 } elseif ($rule->operation == 'ignore') {
                     $manager->deleteLabel($tuduId, $unId, '^i');
                     $manager->addLabel($tuduId, $unId, '^g');
                     // 星标
                 } elseif ($rule->operation == 'starred') {
                     $manager->addLabel($tuduId, $unId, '^t');
                 }
                 // 是否需要邮件提醒
                 if (!empty($rule->mailRemind)) {
                     $mailRemind = $rule->mailRemind;
                     // 邮件提醒可用且图度在指定的板块的
                     if ($mailRemind['isvalid'] && !empty($mailRemind['boards']) && !empty($mailRemind['mailbox']) && is_array($mailRemind['boards']) && in_array($tudu['boardid'], $mailRemind['boards'])) {
                         $emails = array();
                         foreach ($mailRemind['mailbox'] as $email) {
                             // 必须是邮箱
                             if (Oray_Function::isEmail($email)) {
                                 $emails[] = $email;
                             }
                         }
                         if (!empty($emails)) {
                             $remind = array('tuduid' => $tudu['tuduid'], 'tsid' => $params['tsid'], 'emails' => $emails, 'subject' => $tudu['subject'], 'sender' => $tudu['from'][0], 'lastupdate' => date('Y-m-d H:i:s', $tudu['lastposttime']), 'content' => mb_substr(strip_tags($tudu['content']), 0, 20, 'utf-8'), 'type' => $this->_typeNames[$tudu['type']], 'url' => 'http://' . $tudu['orgid'] . '.tudu.com/tudu/view?tid=' . $tudu['tuduid']);
                             $this->getLogger()->warn("Send Email notify to:" . implode(',', $emails));
                             // 发送邮件提醒请求
                             $data = implode(' ', array('send', 'email', '', http_build_query($remind)));
                             $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['send']);
                         }
                     }
                 }
             }
         }
     }
     $this->getLogger()->debug("Tudu id:{$tuduId} done");
 }
Beispiel #2
0
 /**
  * (non-PHPdoc)
  * @see OpenApi_OAuth_Storage_Interface::getRefreshToken()
  */
 public function getRefreshToken($refreshToken)
 {
     return $this->_memcache->get($this->_makeRefreshTokenKey($refreshToken));
 }
Beispiel #3
0
 /**
  * 刷新im服务器缓存
  *
  * @param string $orgId
  */
 protected function _refreshCastCache($orgId)
 {
     /* @var $db Zend_Db_Adapter_Abstract */
     $db = Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_MD);
     // 读取所有用户列表
     $userSql = "SELECT * FROM ((" . "SELECT u.org_id, u.`status`, u.dept_id, u.user_id, u.unique_id, ui.true_name, ui.pinyin, ui.update_time, 0 AS usertype " . "FROM md_user AS u " . "LEFT JOIN md_user_info AS ui ON u.org_id = ui.org_id AND u.user_id = ui.user_id " . "WHERE u.org_id = :orgid) UNION ALL (" . "SELECT org_id, 1 AS `status`, '' AS dept_id, user_id, unique_id, true_name, pinyin, update_time, 1 AS usertype FROM v_cast_common_user)) AS T";
     $users = $db->fetchAll($userSql, array('orgid' => $orgId));
     /*
             // 读取所有部门
             $deptSql = "SELECT org_id, dept_id, dept_name, IF(parent_dept_id = '^root', NULL, parent_dept_id) AS parent_dept_id, order_num "
                      . "FROM md_department WHERE org_id = :orgid AND dept_id <> '^root'";
     
             $depts = $db->fetchAll($deptSql, array('orgid' => $orgId));
     
             // 读取组织所有匹配规则
             $castUserSql = "SELECT org_id, owner_id, user_id FROM md_cast_disable_user WHERE org_id = :orgid";
             $castDeptSql = "SELECT org_id, owner_id, dept_id FROM md_cast_disable_dept WHERE org_id = :orgid";
     
             $res = $db->query($castUserSql, array('orgid' => $orgId));
             $castUsers = array();
             while (($row = $res->fetch())) {
                 $castUsers[$row['owner_id']][] = $row['user_id'];
             }
             $res->closeCursor();
     
             $res = $db->query($castDeptSql, array('orgid' => $orgId));
             $castDepts = array();
             while (($row = $res->fetch())) {
                 $castDepts[$row['owner_id']][] = $row['dept_id'];
             }
             $res->closeCursor();
     
             unset($res);
     */
     // 更新各用户好友列表
     foreach ($users as $user) {
         // 跳过公共用户
         if (1 == $user['usertype']) {
             continue;
         }
         /*
                     $d = isset($castDepts[$user['user_id']]) ? $castDepts[$user['user_id']] : array();
                     $u = isset($castUsers[$user['user_id']]) ? $castUsers[$user['user_id']] : array();
         
                     // 更新当前用户部门列表缓存
                     $contentDepts = array();
         
                     foreach ($depts as $dept) {
                         if (in_array($dept['dept_id'], $d)) {
                             continue ;
                         }
         
                         $str = "<item id='{$dept['dept_id']}' name='{$dept['dept_name']}' orgid='{$dept['org_id']}'";
                         if (!empty($dept['parent_dept_id'])) {
                             $str .= " parentid='{$dept['parent_dept_id']}'";
                         }
                         $str .= ' />';
         
                         $contentDepts[] = $str;
                     }
         
                     $contentDepts = '<dept>' . implode('', $contentDepts) . '</dept>';
                     $this->_memcache->set('im_' . $orgId . '_' . $user['user_id'] . '_depts', $contentDepts, null, null, true);
         
                     // 更新用户列表缓存
                     $contentUsers = array();
                     foreach ($users as $du) {
                         if (in_array($du['user_id'], $u) && 0 == $du['usertype']) {
                             continue ;
                         }
         
                         $contentUsers[] = "<user userid='{$du['user_id']}' usertype='{$du['usertype']}' orgid='{$du['org_id']}' deptid='{$du['dept_id']}' "
                                         . "name='{$du['true_name']}' host='{$du['org_id']}' updatetime='{$du['update_time']}' satus='{$du['status']}' />";
                     }
                     $contentUsers = '<Roster>' . implode('', $contentUsers) . '</Roster>';
         
                     $this->_memcache->set('im_' . $orgId . '_' . $user['user_id'] . '_roster', $contentUsers, null, null, true);
         
                     $this->_memcache->delete('TUDU-APP-ROLES-' . $user['user_id'] . '@' . $orgId);
         */
         $this->_memcache->delete('im_' . $user['org_id'] . '_' . $user['user_id'] . '_depts');
         $this->_memcache->delete('im_' . $user['org_id'] . '_' . $user['user_id'] . '_roster');
         $this->getLogger()->debug("refresh cache of {$user['user_id']}@{$orgId}");
         //unset($conentDepts, $contentUsers, $d, $u);
     }
     //unset($users, $castUsers, $castDepts, $depts);
 }
Beispiel #4
0
 /**
  * Delete item from the storage
  * 
  * @param string $key
  */
 public function delete($key)
 {
     return $this->_storage->delete($key);
 }
Beispiel #5
0
 /**
  *
  * 更新用户设置缓存
  */
 public function updateSetting()
 {
     $key = self::CACHE_KEY_USER . strtolower($this->_attrs['username']);
     self::$_memcache->delete($key);
 }
Beispiel #6
0
 /**
  * 连接资源监控
  */
 public function checkConfigAction()
 {
     //
     $message = array();
     $ts = time();
     $count = array('warning' => 0, 'error' => 0);
     $queueName = 'check';
     $memcacheKey = 'TUDU-CHECK-MARK';
     if (defined('WWW_ROOT')) {
         $sites = array('www.tudu.com', 'api.tudu.com', 'admin.tudu.com', 'web.tudu.com');
         // 先写入数据,遍历各站点时读取
         // memcache
         $ret = $this->cache->set($memcacheKey, $ts, null);
         if (!$ret) {
             $message[] = "[ERROR] Memcache prepare failure";
             $count['error']++;
         } else {
             $message[] = "[SUCCESS] Memcache prepare success";
         }
         $this->cache->close();
         // httpsqs
         $cfg = $this->options['httpsqs'];
         $httpsqs = new Oray_Httpsqs($cfg['host'], $cfg['port'], $cfg['chartset'], $queueName);
         $ret = $httpsqs->put($ts, $queueName);
         if (!$ret) {
             $count['error']++;
             $message[] = "[ERROR] Httpsqs prepare failure";
         } else {
             $message[] = "[SUCCESS] Httpsqs prepare success";
         }
         $queueStatus = $httpsqs->status($queueName);
         if ($count['error'] <= 0) {
             foreach ($sites as $site) {
                 $configFile = WWW_ROOT . '/htdocs/' . $site . '/application/configs/application.ini';
                 $message[] = '-=' . $site . '=-';
                 try {
                     $config = new Zend_Config_Ini($configFile, 'production');
                 } catch (Zend_Config_Exception $e) {
                     $message[] = '[ERROR] Config read failure';
                     continue;
                 }
                 $config = $config->toArray();
                 if (!empty($config['resources']['multidb'])) {
                     // 遍历数据库配置
                     foreach ($config['resources']['multidb'] as $k => $opt) {
                         $dbParams = array();
                         $adapterName = '';
                         foreach ($opt as $n => $v) {
                             if ($n == 'adapter') {
                                 $adapterName = $v;
                             } else {
                                 $dbParams[$n] = $v;
                             }
                         }
                         try {
                             $db = Zend_Db::factory($adapterName, $dbParams);
                             if (false !== strpos($adapterName, 'oci')) {
                                 $db->query("SELECT 1 FROM TUDU_LOG");
                             } else {
                                 $db->query("SELECT 1");
                             }
                             $message[] = "[SUCCESS] Database \"{$k}\" success";
                         } catch (Zend_Db_Exception $e) {
                             $message[] = "[ERROR] Database \"{$k}\" failure: " . $e->getMessage();
                             $count['error']++;
                         }
                     }
                 }
                 // 匹配memcache,获取指定key,匹配当前检测插入的值
                 if (!empty($config['resources']['memcache'])) {
                     $memcache = new Oray_Memcache($config['resources']['memcache']);
                     $mv = $memcache->get($memcacheKey);
                     if ($mv != $ts) {
                         $message[] = "[WARNING] memcache get failure or value not match:{$mv}";
                         $count['warning']++;
                     } else {
                         $message[] = "[SUCCESS] memcache match success";
                     }
                     $memcache->close();
                 }
                 // 匹配httpsqs
                 if (!empty($config['httpsqs'])) {
                     $cfg = $config['httpsqs'];
                     $charset = isset($cfg['chartset']) ? $cfg['chartset'] : $cfg['charset'];
                     $httpsqs = new Oray_Httpsqs($cfg['host'], $cfg['port'], $charset, $queueName);
                     $status = $httpsqs->status($queueName);
                     if (!$status || $status['put'] != $queueStatus['put'] || $status['get'] != $queueStatus['get'] || $status['unread'] != $queueStatus['unread']) {
                         $message[] = "[WARNING] httpsqs status not match";
                         $count['warning']++;
                     } else {
                         $message[] = "[SUCCESS] httpsqs status match success";
                     }
                 }
             }
             // 检测脚本配置
             $scriptConfig = WWW_ROOT . '/scripts/task/configs/config.ini';
             $message[] = "-=task=-";
             $config = null;
             try {
                 $config = new Zend_Config_Ini($scriptConfig, 'production');
             } catch (Zend_Config_Exception $e) {
                 $message[] = '[ERROR] Config read failure';
             }
             if ($config) {
                 $config = $config->toArray();
                 if (!empty($config['multidb'])) {
                     foreach ($config['multidb'] as $k => $opt) {
                         try {
                             $db = Zend_Db::factory($opt['adapter'], $opt['params']);
                             if (false !== strpos($opt['adapter'], 'oci')) {
                                 $db->query("SELECT 1 FROM TUDU_LOG");
                             } else {
                                 $db->query("SELECT 1");
                             }
                             $message[] = "[SUCCESS] Database \"{$k}\" success";
                         } catch (Zend_Db_Exception $e) {
                             $message[] = "[WARNING] Database \"{$k}\" failure: " . $e->getMessage();
                             $count['warning']++;
                         }
                     }
                 }
                 if (!empty($config['memcache'])) {
                     $cfg = $config['memcache'];
                     $cfg['servers'] = array('host' => $cfg['host'], 'port' => $cfg['port'], 'timeout' => $cfg['timeout']);
                     $memcache = new Oray_Memcache($cfg);
                     $mv = $memcache->get($memcacheKey);
                     if ($mv != $ts) {
                         $message[] = "[WARNING] memcache get failure or value not match: {$mv}";
                         $count['warning']++;
                     } else {
                         $message[] = "[SUCCESS] memcache match success";
                     }
                 }
                 // 匹配httpsqs
                 if (!empty($config['httpsqs'])) {
                     $cfg = $config['httpsqs'];
                     $charset = isset($cfg['chartset']) ? $cfg['chartset'] : $cfg['charset'];
                     $httpsqs = new Oray_Httpsqs($cfg['host'], $cfg['port'], $charset, $queueName);
                     $status = $httpsqs->status($queueName);
                     if (!$status || $status['put'] != $queueStatus['put'] || $status['get'] != $queueStatus['get'] || $status['unread'] != $queueStatus['unread']) {
                         $message[] = "[WARNING] httpsqs status not match";
                         $count['warning']++;
                     } else {
                         $message[] = "[SUCCESS] httpsqs status match success";
                     }
                     $memcache->close();
                 }
             }
         } else {
             $message[] = "[ERROR] Undefined \"WWW_ROOT\"";
             $count['error']++;
         }
     }
     $message[] = '';
     $message[] = "Check complete, {$count['warning']} warnings, {$count['error']} errors";
     $message = implode("\n", $message);
     header('Accept-Ranges: bytes');
     header('Content-Type', 'text/plain; charset=utf-8');
     //header('Content-Length', strlen($message));
     echo $message;
     exit;
 }
Beispiel #7
0
 /**
  * 获取系统提示数据
  */
 public function getTips()
 {
     if ($this->_tips) {
         return $this->_tips;
     }
     $lang = !empty($this->_user->option['language']) ? $this->_user->option['language'] : 'zh_CN';
     $this->_tips = $this->cache->get('TUDU-TIPS-' . $lang);
     if (!$this->_tips) {
         $dataFile = $this->options['data']['path'] . '/' . 'tudu_tips-' . $lang . '.xml';
         if (!file_exists($dataFile) || !is_readable($dataFile)) {
             return null;
         }
         $xml = @simplexml_load_file($dataFile);
         if (!$xml) {
             return null;
         }
         foreach ($xml as $tip) {
             if (!isset($tip->id)) {
                 continue;
             }
             if (isset($tip->expiretime) && strtotime($tip->expiretime) < time()) {
                 continue;
             }
             $item = array();
             foreach ($tip as $k => $val) {
                 $item[$k] = (string) $val;
             }
             $this->_tips[$item['id']] = $item;
         }
         $this->cache->set('TUDU-TIPS-' . $lang, $this->_tips, null, 86400);
     }
     return $this->_tips;
 }