public function __construct(Registry $doctrineRegistry)
 {
     $this->doctrineRegistry = $doctrineRegistry;
     $this->qbOroUsers = $this->doctrineRegistry->getManager()->getRepository('OroUserBundle:User')->createQueryBuilder('u');
     $this->qbOroUsers->select('u');
     $this->qbDiamanteUsers = $this->doctrineRegistry->getManager()->getRepository('DiamanteUserBundle:DiamanteUser')->createQueryBuilder('u');
     $this->qbDiamanteUsers->select('u');
 }
Пример #2
0
/**
 * Get Mysql's current datetime by selecting NOW()
 * 
 * @return string
 */
function getDBCurrentDateTime($isTimestamp = false)
{
    $sql = MySqlDbManager::getQueryObject();
    $qb = new QueryBuilder();
    if ($isTimestamp) {
        $qb->select(new Func("UNIX_TIMESTAMP", new Func("NOW"), 'now'));
    } else {
        $qb->select(new Func("NOW", null, 'now'));
    }
    return $sql->exec($qb->getSQL())->fetchField('now');
}
Пример #3
0
 protected static function queryString($lang_id = null, $host_id = null, $module = null, $page = null, $cacheMinutes = null)
 {
     $qb = new QueryBuilder();
     $qb->select(new Field('title'), new Field('meta_keywords'), new Field('meta_description'))->from(Tbl::get('TBL_PAGE_INFO'));
     if ($lang_id === null) {
         $qb->andWhere($qb->expr()->isNull(new Field('lang_id')));
     } else {
         $qb->andWhere($qb->expr()->equal(new Field('lang_id'), $lang_id));
     }
     if ($host_id === null) {
         $qb->andWhere($qb->expr()->isNull(new Field('host_id')));
     } else {
         $qb->andWhere($qb->expr()->equal(new Field('host_id'), $host_id));
     }
     if ($module === null) {
         $qb->andWhere($qb->expr()->isNull(new Field('module')));
     } else {
         $qb->andWhere($qb->expr()->equal(new Field('module'), $module));
     }
     if ($page === null) {
         $qb->andWhere($qb->expr()->isNull(new Field('page')));
     } else {
         $qb->andWhere($qb->expr()->equal(new Field('page'), $page));
     }
     return $qb->getSQL();
 }
Пример #4
0
 /**
  * Check validity of username, password and other auth factors
  * 
  * @param string $username
  * @param string $password
  * @param array $additionalCredentials
  * @param boolean $writeCookie
  * @throws UserAuthFailedException
  * @return User
  */
 public function checkCredentials($username, $password, $additionalCredentials = array(), $writeCookie = false)
 {
     $qb = new QueryBuilder();
     $qb->select(new Field('id'), new Field('password'), new Field('salt'))->from(Tbl::get('TBL_USERS', 'UserManager'))->where($qb->expr()->equal(new Field('login'), $username));
     $this->query->exec($qb->getSQL());
     if ($this->query->countRecords() == 1) {
         $userData = $this->query->fetchRecord();
         $hashToCheck = static::getUserPasswordHash($password, $userData['salt']);
         if ($userData['password'] === $hashToCheck) {
             $usr = $this->doLogin($userData['id'], $additionalCredentials, $writeCookie);
             try {
                 $hookParams = array("user" => $usr, "additionalCredentials" => $additionalCredentials);
                 HookManager::callHook("UserAuthSuccess", $hookParams);
             } catch (UserAuthFailedException $e) {
                 $this->doLogout();
                 throw $e;
             }
             return $usr;
         }
     }
     // Failed login nothing returned from above code
     $hookParams = array("username" => $username, "password" => $password, "additionalCredentials" => $additionalCredentials);
     HookManager::callHook("UserAuthFail", $hookParams);
     throw new UserAuthFailedException("Incorrect login/password combination");
 }
Пример #5
0
 /**
  * Loads user's answers into private $this->profileAnsers field
  *
  */
 private function initUserAnswers($cacheMinutes = 0)
 {
     $qb = new QueryBuilder();
     $qb->select(new Field('profile_id'))->from(Tbl::get('TBL_PROFILE_SAVE'))->where($qb->expr()->equal(new Field('user_id'), $this->userId));
     $this->query->exec($qb->getSQL(), $cacheMinutes);
     $this->profileAnswers = $this->query->fetchFields("profile_id");
 }
Пример #6
0
 public function getLastId()
 {
     $qb = new QueryBuilder();
     $qb->select($qb->expr()->max(new Field('id'), 'lastId'))->from(Tbl::get('TBL_CHAT_MESSAGES'));
     $lastId = $this->query->exec($qb->getSQL())->fetchField('lastId');
     return empty($lastId) ? 0 : $lastId;
 }
 public static function getControllerTemplateByHost(Host $host)
 {
     $sql = MySqlDbManager::getQueryObject();
     $qb = new QueryBuilder();
     $qb->select(new Field('*'))->from(Tbl::get("TBL_HOST_CONTROLLER_TEMPLATE"))->where($qb->expr()->equal(new Field('host_id'), $host->id));
     $sql->exec($qb->getSQL());
     return $sql->fetchRecord();
 }
Пример #8
0
 public function getEventsLastId()
 {
     $qb = new QueryBuilder();
     $qb->select($qb->expr()->max(new Field('id'), 'maxId'))->from(Tbl::get('TBL_COMET_EVENTS'));
     $maxId = $this->query->exec($qb->getSQL())->fetchField('maxId');
     if (empty($maxId)) {
         $maxId = 0;
     }
     return $maxId;
 }
Пример #9
0
 public function getGroupsList($cacheMinutes = null)
 {
     $qb = new QueryBuilder();
     $qb->select(new Field('*'))->from(Tbl::get('TBL_TEXTS_GROUPS'));
     $this->query->exec($qb->getSQL(), $cacheMinutes);
     $groups = array();
     foreach ($this->query->fetchRecords() as $data) {
         array_push($groups, $this->getGroupObjectFromData($data));
     }
     return $groups;
 }
Пример #10
0
 /**
  * Check if given country code is valid
  * 
  * @param string $countryCode
  * @param int $cacheMinutes
  */
 public function isValidCountryCode($countryCode = null, $cacheMinutes = null)
 {
     $qb = new QueryBuilder();
     $qb->select($qb->expr()->count("*", "count"))->from(Tbl::get('TBL_LOCATIONS'))->where($qb->expr(new Field('country'), $countryCode));
     $this->query->exec($qb->getSQL(), $cacheMinutes);
     $count = $this->query->fetchField('count');
     if ($count > 0) {
         return true;
     }
     return false;
 }
Пример #11
0
 public function search($array, $limit = 100)
 {
     $qb = new QueryBuilder();
     $q = $qb->select();
     foreach ($array as $key => $val) {
         $q->where($key, $val);
     }
     $query = $q->getQueryString();
     $rows = $limit == -1 ? 9999999 : (int) $limit;
     $select = Solr::select()->rows($rows)->search($query);
     return $this->solr_client->core($this->collection)->select($select);
 }
Пример #12
0
 /**
  * Constructor
  * 
  * @param Librarian $librarian The librarian interface responsible for the query
  * @param DBAL\Connection $db A Doctrine Connection
  * @param int $limit The maximum number of results to return
  * @param array $orderBy An assoc. array of indexName => direction
  * @param array $indexes An assoc. array of indexName => Index
  */
 public function __construct(LibrarianInterface $librarian, DBAL\Connection $db, $limit, array $orderBy, array $indexes)
 {
     $this->librarian = $librarian;
     $this->indexes = $indexes;
     $this->db = $db;
     $this->limit = $limit;
     $this->queryBuilder = $this->db->createQueryBuilder();
     $this->queryBuilder->setMaxResults($limit);
     foreach ($this->indexes as $index) {
         $index->setQuery($this);
         $index->setQueryBuilder($this->queryBuilder);
     }
     // TODO: make this explicitly defined?
     $this->mainIndex = current($this->indexes);
     foreach (array_slice($this->indexes, 1) as $name => $index) {
         $this->queryBuilder->leftJoin($this->mainIndex->getName(), $index->getTableName(), $index->getName($quote = true), $this->mainIndex->getName() . '.id = ' . $this->db->quoteIdentifier($name) . '.id');
     }
     $this->queryBuilder->select('distinct ' . $this->mainIndex->getName() . '.id')->from($this->mainIndex->getTableName(), $this->mainIndex->getName($quote = true));
     foreach ($orderBy as $name => $direction) {
         $this->indexes[$name]->orderBy($direction);
     }
 }
Пример #13
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();
     }
 }
Пример #14
0
 public function getAliases(TextValue $textValue, $cacheMinutes = null)
 {
     if (!is_numeric($textValue->id)) {
         throw new InvalidArgumentException("TextValue ID have to be numeric");
     }
     $qb = new QueryBuilder();
     $qb->select(new Field('*'))->from(Tbl::get('TBL_TEXTS_ALIASES'))->where($qb->expr()->equal(new Field('value_id'), $textValue->id));
     $this->query->exec($qb->getSQL(), $cacheMinutes);
     $arrayToReturn = array();
     foreach ($this->query->fetchRecords() as $data) {
         array_push($arrayToReturn, $this->getTextAliasObjectFromData($data));
     }
     return $arrayToReturn;
 }
Пример #15
0
 /**
  * Initiates a find by PK query
  *
  * @param $pk
  * @param $select
  * @return QueryBuilder
  */
 public static function findByPk($pk, $select = null)
 {
     $instance = self::createInstance();
     $instance->getFields();
     if ($instance->primaryKey == null) {
         return null;
     }
     $query = new QueryBuilder($instance->getTable(), 'SELECT');
     if ($select != null) {
         $query->select($select);
     }
     $query->where([$instance->primaryKey => $pk]);
     return $query->one();
 }
Пример #16
0
 public static function login_from_cookie($token)
 {
     try {
         $m = new \QueryBuilder();
         $user = $m->select('users', array('remember_token = :remember_token AND token_validity > NOW()', array('remember_token' => array($token, \PDO::PARAM_STR))));
         if ($user) {
             $_SESSION['auth.user.logged_in'] = true;
             $_SESSION['auth.user.id'] = $user['id'];
             return true;
         }
         return false;
     } catch (\Exception $ex) {
         throw $ex;
     }
 }
Пример #17
0
 public function getTextByName($textName, $groupName, $cacheMinutes = null)
 {
     if (empty($textName)) {
         throw new InvalidArgumentException("\$textName have to be non empty");
     }
     if (empty($groupName)) {
         throw new InvalidArgumentException("\$groupName have to be non empty");
     }
     $group = Reg::get(ConfigManager::getConfig("Texts")->Objects->TextsGroupManager)->getGroupByName($groupName, $cacheMinutes);
     $qb = new QueryBuilder();
     $qb->select(new Field("*"))->from(Tbl::get('TBL_TEXTS'))->where($qb->expr()->equal(new Field('name'), $textName))->andWhere($qb->expr()->equal(new Field('group_id'), $group->id));
     $this->query->exec($qb->getSQL(), $cacheMinutes);
     if ($this->query->countRecords() == 0) {
         throw new RuntimeException("There is no text with name {$textName}");
     }
     return $this->getTextObjectFromData($this->query->fetchRecord(), $cacheMinutes);
 }
Пример #18
0
 function __construct($host_id = null, $cacheMinutes = null, $dbInstanceKey = null)
 {
     if ($host_id !== null) {
         if (!is_numeric($host_id)) {
             throw new InvalidIntegerArgumentException("host_id argument should be an integer.");
         }
         $sql = MySqlDbManager::getQueryObject($dbInstanceKey);
         $qb = new QueryBuilder();
         $qb->select(new Field('*'))->from(Tbl::get('TBL_HOSTS'))->where($qb->expr()->equal(new Field('id'), $host_id));
         $sql->exec($qb->getSQL(), $cacheMinutes);
         if ($sql->countRecords()) {
             $res = $sql->fetchRecord();
             static::setData($res, $this);
         } else {
             throw new InvalidArgumentException("Wrong host id is given. No record with id: {$host_id} in table " . Tbl::get('TBL_HOSTS'));
         }
     }
 }
Пример #19
0
 public static function getAllLanguages(MysqlPager $pager = null, $cacheMinutes = null)
 {
     $languages = array();
     $sql = MySqlDbManager::getQueryObject();
     $qb = new QueryBuilder();
     $qb->select(new Field('*'))->from(Tbl::get('TBL_LANGUAGES'));
     if ($pager !== null) {
         $sql = $pager->executePagedSQL($qb->getSQL(), $cacheMinutes);
     } else {
         $sql->exec($qb->getSQL(), $cacheMinutes);
     }
     while (($lang_data = $sql->fetchRecord()) != false) {
         $l = new Language();
         static::setData($lang_data, $l);
         $languages[] = $l;
     }
     return $languages;
 }
Пример #20
0
 /**
  * Is remote IP blocked by country
  * 
  * @return boolean
  */
 private function isBlockedByCountry($cacheMinutes = null)
 {
     $myLocation = Reg::get(ConfigManager::getConfig('GeoIP', 'GeoIP')->Objects->GeoIP)->getLocation();
     if (empty($myLocation)) {
         return false;
     }
     $countryCode = $myLocation->country;
     if (empty($countryCode)) {
         return false;
     }
     $qb = new QueryBuilder();
     $qb->select($qb->expr()->count('*', 'count'))->from(Tbl::get('TBL_SECURITY_BLACKLISTED_COUNTRIES'))->where($qb->expr()->equal(new Field('country'), $countryCode));
     $this->query->exec($qb->getSQL(), $cacheMinutes);
     $count = $this->query->fetchField('count');
     if ($count > 0) {
         return true;
     }
     return false;
 }
Пример #21
0
 /**
  * Validate given code using paramsArray
  * @param string $code
  * @param array $paramsArray
  * @return boolean
  */
 public function validate($code, $paramsArray = array())
 {
     if (empty($code)) {
         throw new InvalidArgumentException("Empty \$code supplied for validation!");
     }
     $qb = new QueryBuilder();
     $orX = new Orx();
     $orX->add($qb->expr()->isNull(new Field('valid_until')));
     $orX->add($qb->expr()->greaterEqual(new Field('valid_until'), new Func('NOW')));
     $qb->select(new Field('*'))->from(Tbl::get('TBL_ONE_TIME_CODES'))->where($qb->expr()->equal(new Field('code'), $code))->andWhere($orX);
     $this->query->exec($qb->getSQL());
     if ($this->query->countRecords() == 0) {
         return false;
     }
     $dbRow = $this->query->fetchRecord();
     $paramsArrayFromCode = $this->getArrayFromCode($dbRow['code']);
     if ($paramsArrayFromCode === false) {
         return false;
     }
     $resultingArray = array_diff_assoc($paramsArray, $paramsArrayFromCode);
     if (count($resultingArray) != 0) {
         return false;
     }
     if ($dbRow['multi'] == '1') {
         if ($dbRow['usage_limit'] > 0) {
             $qb = new QueryBuilder();
             if ($dbRow['usage_count'] < $dbRow['usage_limit']) {
                 $qb->update(Tbl::get('TBL_ONE_TIME_CODES'))->set(new Field('usage_count'), $qb->expr()->sum(new Field('usage_count'), 1))->where($qb->expr()->equal(new Field('id'), $dbRow['id']));
                 $this->query->exec($qb->getSQL());
             } else {
                 $qb->delete(Tbl::get('TBL_ONE_TIME_CODES'))->where($qb->expr()->equal(new Field("id"), $dbRow['id']));
                 $this->query->exec($qb->getSQL());
                 return false;
             }
         }
     } else {
         $qb = new QueryBuilder();
         $qb->delete(Tbl::get('TBL_ONE_TIME_CODES'))->where($qb->expr()->equal(new Field("id"), $dbRow['id']));
         $this->query->exec($qb->getSQL());
     }
     return true;
 }
Пример #22
0
 public function hookInvalidLoginAttempt($params)
 {
     if ($this->config->AuxConfig->loginBruteForceProtectionEnabled) {
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $sql = MySqlDbManager::getQueryObject();
             $qb = new QueryBuilder();
             $sql->exec($qb->select(new Field('count'))->from(Tbl::get('TBL_SECURITY_INVALID_LOGINS_LOG', 'RequestLimiter'))->where($qb->expr()->equal(new Field('ip'), $_SERVER['REMOTE_ADDR']))->getSQL());
             $failedAuthCount = $sql->fetchField('count');
             $newFailedAuthCount = $failedAuthCount + 1;
             if ($newFailedAuthCount >= $this->config->AuxConfig->failedLoginLimit) {
                 Reg::get(ConfigManager::getConfig("Security", "RequestLimiter")->Objects->RequestLimiter)->blockIP();
                 $qb = new QueryBuilder();
                 $sql->exec($qb->delete(Tbl::get('TBL_SECURITY_INVALID_LOGINS_LOG', 'RequestLimiter'))->where($qb->expr()->equal(new Field('ip'), $_SERVER['REMOTE_ADDR']))->getSQL());
                 throw new RequestLimiterTooManyAuthTriesException("Too many unsucessful authorization tries.");
             }
             $qb = new QueryBuilder();
             $sql->exec($qb->insert(Tbl::get('TBL_SECURITY_INVALID_LOGINS_LOG', 'RequestLimiter'))->values(array('ip' => $_SERVER['REMOTE_ADDR']))->onDuplicateKeyUpdate()->set(new Field('count'), $qb->expr()->sum(new Field('count'), 1))->getSQL());
         }
     }
 }
Пример #23
0
 public function getText($textName, $groupName, Host $host = null, Language $lang = null, $cacheMinutes = null)
 {
     if ($host === null) {
         $host = $this->host;
     }
     if ($lang === null) {
         $lang = $this->language;
     }
     $text = Reg::get(ConfigManager::getConfig("Texts")->Objects->TextsManager)->getTextByName($textName, $groupName);
     $hostLangId = HostLanguageManager::getHostLanguageId($host, $lang);
     $qb = new QueryBuilder();
     $qb->select(new Field("*"))->from(Tbl::get('TBL_TEXTS_VALUES'))->where($qb->expr()->equal(new Field('text_id'), $text->id))->andWhere($qb->expr()->equal(new Field('host_language'), $hostLangId));
     $this->query->exec($qb->getSQL(), $cacheMinutes);
     if ($this->query->countRecords() == 1) {
         return $this->getTextValueObjectFromData($this->query->fetchRecord());
     } elseif (Reg::get(ConfigManager::getConfig("Texts")->Objects->TextsAliasManager)->isAliased($text, $hostLangId, $cacheMinutes)) {
         $qbAlias = new QueryBuilder();
         $qbAlias->select(new Field("*", 'tv'))->from(Tbl::get('TBL_TEXTS_ALIASES', 'TextsAliasManager'), 'ta')->leftJoin(Tbl::get('TBL_TEXTS_VALUES'), 'tv', $qbAlias->expr()->equal(new Field('id', 'tv'), new Field('value_id', 'ta')))->where($qbAlias->expr()->equal(new Field('host_language', 'ta'), $hostLangId))->andWhere($qbAlias->expr()->equal(new Field('text_id'), $text->id));
         $this->query->exec($qbAlias->getSQL(), $cacheMinutes);
         return $this->getTextValueObjectFromData($this->query->fetchRecord());
     } else {
         return false;
     }
 }
Пример #24
0
 /**
  * Get list of forms ordered by it's count
  *
  * @param QueryBuilder $query
  * @param integer $limit
  * @param integer $offset
  *
  * @return array
  * @throws \Doctrine\ORM\NoResultException
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function getMostSubmitted($query, $limit = 10, $offset = 0, $column = 'fs.id', $as = 'submissions')
 {
     $asSelect = $as ? ' as ' . $as : '';
     $query->select('f.name as title, f.id, count(distinct ' . $column . ')' . $asSelect)->groupBy('f.id, f.name')->orderBy($as, 'DESC')->setMaxResults($limit)->setFirstResult($offset);
     $results = $query->execute()->fetchAll();
     return $results;
 }
 /**
  * Count a value in a column
  *
  * @param QueryBuilder $query
  *
  * @return array
  * @throws \Doctrine\ORM\NoResultException
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function countValue($query, $column, $value)
 {
     $query->select('count(' . $column . ') as quantity')->from(MAUTIC_TABLE_PREFIX . 'leads', 'l')->leftJoin('l', MAUTIC_TABLE_PREFIX . 'lead_points_change_log', 'lp', 'lp.lead_id = l.id')->andwhere($query->expr()->eq($column, ':value'))->setParameter('value', $value);
     $result = $query->execute()->fetch();
     return $result['quantity'];
 }
Пример #26
0
 /**
  * Generated from @assert select('U.field AS field', 'U1.`field` AS `field`')->text() [==] "SELECT U.`field` AS `field`,U1.`field` AS `field`".
  *
  * @covers Kotchasan\Database\QueryBuilder::select
  */
 public function testSelect18()
 {
     $this->assertEquals("SELECT U.`field` AS `field`,U1.`field` AS `field`", $this->object->select('U.field AS field', 'U1.`field` AS `field`')->text());
 }
 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;
 }
Пример #28
0
 private function closestParent($node_id, $parents, $cacheMinutes = null)
 {
     $my_id = $node_id;
     foreach ($parents as $parent) {
         if ($node_id == $parent['node_id']) {
             return $parent;
         }
     }
     while ($my_id != static::ROOT_NODE) {
         $qb = new QueryBuilder();
         $qb->select(new Field('parent_id'))->from(Tbl::get('TBL_TREE'))->where($qb->expr()->equal(new Field('id'), $my_id));
         $this->query->exec($qb->getSQL(), $cacheMinutes);
         $par_id = $this->query->fetchField('parent_id');
         foreach ($parents as $parent) {
             if ($par_id == $parent['node_id']) {
                 return $parent;
             }
         }
         $my_id = $par_id;
     }
     return false;
 }
 public function testSelectWithInvalidVersion()
 {
     $this->setExpectedException('SPF\\SolrQueryBuilder\\UnsupportedVersionException');
     $qb = new QueryBuilder(999);
     $qb->select();
 }
Пример #30
0
 /**
  * @param integer $inviterUserId
  * @param integer $invitedUserId
  * @deprecated Sessions log insertd by mysql TRIGGER chat_sessions_log 
  */
 protected function insertSessionLog($inviterUserId, $invitedUserId)
 {
     if ($inviterUserId > $invitedUserId) {
         $userId1 = $inviterUserId;
         $userId2 = $invitedUserId;
     } else {
         $userId1 = $invitedUserId;
         $userId2 = $inviterUserId;
     }
     $qb = new QueryBuilder();
     $qb->select(new Field('id'))->from(Tbl::get('TBL_CHAT_SESSIONS_LOG'));
     $andClause1 = new Andx();
     $andClause1->add($qb->expr()->equal(new Field('user1_id', Tbl::get('TBL_CHAT_SESSIONS_LOG')), $userId1));
     $andClause1->add($qb->expr()->equal(new Field('user2_id', Tbl::get('TBL_CHAT_SESSIONS_LOG')), $userId2));
     $andClause2 = new Andx();
     $andClause2->add($qb->expr()->equal(new Field('user1_id', Tbl::get('TBL_CHAT_SESSIONS_LOG')), $userId2));
     $andClause2->add($qb->expr()->equal(new Field('user2_id', Tbl::get('TBL_CHAT_SESSIONS_LOG')), $userId1));
     $orClause = new Orx();
     $orClause->add($andClause1);
     $orClause->add($andClause2);
     $qb->andWhere($orClause);
     $this->query->exec($qb->getSQL());
     $qb = new QueryBuilder();
     if ($this->query->countRecords()) {
         $sesionId = $this->query->fetchField("id");
         $qb->update(Tbl::get('TBL_CHAT_SESSIONS_LOG'))->set(new Field('datetime'), date(DEFAULT_DATETIME_FORMAT))->where($qb->expr()->equal(new Field('id'), $sesionId));
     } else {
         $qb->insert(Tbl::get('TBL_CHAT_SESSIONS_LOG'))->values(array('user1_id' => $userId1, 'user2_id' => $userId2, 'datetime' => date(DEFAULT_DATETIME_FORMAT)));
     }
     $this->query->exec($qb->getSQL());
     return $this->query->affected();
 }