Пример #1
0
 protected function loadDb()
 {
     MySqlDbManager::createInstance($this->config->AuxConfig->host, $this->config->AuxConfig->user, $this->config->AuxConfig->password, $this->config->AuxConfig->name, $this->config->AuxConfig->isPersistent);
     $this->db = MySqlDbManager::getDbObject();
     $this->db->setConnectionEncoding($this->config->AuxConfig->encoding);
     $this->register($this->db);
 }
Пример #2
0
 /**
  * Parse requests log and blacklist flooding IPs.
  * Should be called by cron job every minute.
  */
 public function parseLogForFloodingIps()
 {
     $tablesToLock = array(Tbl::get('TBL_SECURITY_REQUESTS_LOG'), Tbl::get('TBL_SECURITY_FLOODER_IPS'));
     MySqlDbManager::getDbObject()->lockTables($tablesToLock, "w");
     $this->query->exec("INSERT IGNORE INTO `" . Tbl::get('TBL_SECURITY_FLOODER_IPS') . "` (`ip`) \n\t\t\t\t\t\t\tSELECT `ip` \n\t\t\t\t\t\t\t\tFROM `" . Tbl::get('TBL_SECURITY_REQUESTS_LOG') . "` \n\t\t\t\t\t\t\t\tWHERE `count` >= " . $this->config->requestsLimit);
     $this->query->exec("TRUNCATE TABLE `" . Tbl::get('TBL_SECURITY_REQUESTS_LOG') . "`");
     MySqlDbManager::getDbObject()->unlockTables();
 }
Пример #3
0
 /**
  * Parse requests log and blacklist flooding IPs.
  * Should be called by cron job every minute.
  */
 public function parseLogForFloodingIps()
 {
     $tablesToLock = array(Tbl::get('TBL_SECURITY_REQUESTS_LOG'), Tbl::get('TBL_SECURITY_FLOODER_IPS'));
     MySqlDbManager::getDbObject()->startTransaction();
     $qb = new QueryBuilder();
     $qbSelect = new QueryBuilder();
     $qbSelect->select(new Field('ip'))->from(Tbl::get('TBL_SECURITY_REQUESTS_LOG'))->where($qbSelect->expr()->greaterEqual(new Field('count'), $this->config->requestsLimit));
     $qb->insertIgnore(Tbl::get('TBL_SECURITY_FLOODER_IPS'))->fields('ip')->values($qbSelect);
     $this->query->exec($qb->getSQL());
     $this->query->exec("TRUNCATE TABLE `" . Tbl::get('TBL_SECURITY_REQUESTS_LOG') . "`");
     if (!MySqlDbManager::getDbObject()->commit()) {
         MySqlDbManager::getDbObject()->rollBack();
     }
 }
Пример #4
0
 public function init()
 {
     $this->db = MySqlDbManager::getDbObject($this->dbInstanceKey);
     $this->query = MySqlDbManager::getQueryObject($this->dbInstanceKey);
 }
 public function clearGarbage()
 {
     $db = MySqlDbManager::getDbObject();
     $db->lockTables(Tbl::get('TBL_CONVERSATION_ATTACHEMENTS'), "w");
     $qb = new QueryBuilder();
     $qb->select(new Field("system_filename"))->from(Tbl::get('TBL_CONVERSATION_ATTACHEMENTS', 'ConversationAttachmentManager'))->where($qb->expr()->isNull(new Field('message_id')))->andWhere($qb->expr()->greater($qb->expr()->diff(new Func("NOW"), new Field('date')), 60 * 60 * 24 * $this->config->attachmentsClearTimeout));
     $this->query->exec($qb->getSQL());
     while (($row = $this->query->fetchRecord()) != null) {
         try {
             @unlink($this->config->uploadDir . $row['system_filename']);
         } catch (ErrorException $e) {
         }
     }
     $qb = new QueryBuilder();
     $qb->delete(Tbl::get('TBL_CONVERSATION_ATTACHEMENTS', 'ConversationAttachmentManager'))->where($qb->expr()->isNull(new Field('message_id')))->andWhere($qb->expr()->greater($qb->expr()->diff(new Func("NOW"), new Field('date')), 60 * 60 * 24 * $this->config->attachmentsClearTimeout));
     $deletedCount = $this->query->exec($qb->getSQL())->affected();
     $db->unlockTables();
     return $deletedCount;
 }
Пример #6
0
 protected function openConversation($userId1, $userId2, $systemMessage = false)
 {
     if (empty($userId1) or !is_numeric($userId1)) {
         throw new InvalidIntegerArgumentException("\$userId1 have to be non zero integer.");
     }
     if (empty($userId2) or !is_numeric($userId2)) {
         throw new InvalidIntegerArgumentException("\$userId2 have to be non zero integer.");
     }
     $db = MySqlDbManager::getDbObject();
     $db->startTransaction(true);
     $newUUID = $this->getMaxUUID() + 1;
     $qb = new QueryBuilder();
     $qb->insert(Tbl::get('TBL_CONVERSATIONS'))->values(array('uuid' => $newUUID, 'user_id' => $userId1, 'interlocutor_id' => $userId2, 'system' => $systemMessage ? '1' : '0'));
     $this->query->exec($qb->getSQL());
     $qb->insert(Tbl::get('TBL_CONVERSATIONS'))->values(array('uuid' => $newUUID, 'user_id' => $userId2, 'interlocutor_id' => $userId1, 'system' => $systemMessage ? '1' : '0'));
     $this->query->exec($qb->getSQL());
     if (!$db->commit()) {
         $db->rollBack();
         return false;
     }
     return $newUUID;
 }
 protected function openConversation($userId1, $userId2)
 {
     if (empty($userId1) or !is_numeric($userId1)) {
         throw new InvalidIntegerArgumentException("\$userId1 have to be non zero integer.");
     }
     if (empty($userId2) or !is_numeric($userId2)) {
         throw new InvalidIntegerArgumentException("\$userId2 have to be non zero integer.");
     }
     $db = MySqlDbManager::getDbObject();
     $db->lockTables(Tbl::get('TBL_CONVERSATIONS'), "w");
     $newUUID = $this->getMaxUUID() + 1;
     $qb = new QueryBuilder();
     $qb->insert(Tbl::get('TBL_CONVERSATIONS'))->values(array('uuid' => $newUUID, 'user_id' => $userId1, 'interlocutor_id' => $userId2));
     $this->query->exec($qb->getSQL());
     $qb->insert(Tbl::get('TBL_CONVERSATIONS'))->values(array('uuid' => $newUUID, 'user_id' => $userId2, 'interlocutor_id' => $userId1));
     $this->query->exec($qb->getSQL());
     $db->unlockTables();
     return $newUUID;
 }