public static function setupInstance($db)
 {
     if (isset($_SERVER['HTTP_HOST'])) {
         $cfg = erConfigClassLhConfig::getInstance();
         $subdomain = str_replace('.' . $cfg->getSetting('site', 'seller_domain'), '', $_SERVER['HTTP_HOST']);
         $session = erLhcoreClassInstance::getSession();
         $q = $session->createFindQuery('erLhcoreClassModelInstance');
         $q->where($q->expr->eq('address', $q->bindValue($subdomain)) . ' OR (full_domain = 1 AND ' . $q->expr->eq('address', $q->bindValue($_SERVER['HTTP_HOST'])) . ')');
         $items = $session->find($q);
         if (!empty($items)) {
             erLhcoreClassInstance::$instanceChat = array_shift($items);
             $db->query('USE ' . $cfg->getSetting('db', 'database_user_prefix') . erLhcoreClassInstance::$instanceChat->id);
         } else {
             header('Location: ' . $cfg->getSetting('site', 'seller_url'));
             exit;
         }
     }
 }
 public static function getList($paramsSearch = array())
 {
     $paramsDefault = array('limit' => 32, 'offset' => 0);
     $params = array_merge($paramsDefault, $paramsSearch);
     $session = erLhcoreClassInstance::getSession();
     $q = $session->createFindQuery('erLhcoreClassModelInstance');
     $conditions = array();
     if (isset($params['filter']) && count($params['filter']) > 0) {
         foreach ($params['filter'] as $field => $fieldValue) {
             $conditions[] = $q->expr->eq($field, $q->bindValue($fieldValue));
         }
     }
     if (isset($params['filterin']) && count($params['filterin']) > 0) {
         foreach ($params['filterin'] as $field => $fieldValue) {
             $conditions[] = $q->expr->in($field, $fieldValue);
         }
     }
     if (isset($params['filterlt']) && count($params['filterlt']) > 0) {
         foreach ($params['filterlt'] as $field => $fieldValue) {
             $conditions[] = $q->expr->lt($field, $q->bindValue($fieldValue));
         }
     }
     if (isset($params['filtergt']) && count($params['filtergt']) > 0) {
         foreach ($params['filtergt'] as $field => $fieldValue) {
             $conditions[] = $q->expr->gt($field, $q->bindValue($fieldValue));
         }
     }
     if (count($conditions) > 0) {
         $q->where($conditions);
     }
     $q->limit($params['limit'], $params['offset']);
     $q->orderBy(isset($params['sort']) ? $params['sort'] : 'id ASC');
     $objects = $session->find($q);
     return $objects;
 }
<?php

$cfg = erConfigClassLhConfig::getInstance();
$secretHash = $cfg->getSetting('site', 'seller_secret_hash');
$validateHash = sha1((string) $Params['user_parameters']['address'] . $secretHash);
// http://manager.livehelperchat.com/index.php/instance/terminateinstance/remdex/138d07f5c478cbd4d1fcbfcc6ccd49d5961273bd
if ((string) $Params['user_parameters']['hash'] == $validateHash) {
    $list = erLhcoreClassModelInstance::getList(array('filter' => array('address' => (string) $Params['user_parameters']['address'])));
    if (!empty($list)) {
        $instance = array_shift($list);
        // Instance is initialized
        if ($instance->status == 1) {
            $instance->terminate = 1;
            $instance->saveThis();
        } elseif ($instance->status == 0) {
            // We can remove instantly instance
            erLhcoreClassInstance::getSession()->delete($instance);
        }
        echo json_encode(array('error' => 'false', 'msg' => 'instance terminated'));
    } else {
        echo json_encode(array('error' => 'false', 'msg' => 'Could not find an instance'));
    }
} else {
    echo json_encode(array('error' => 'true', 'reason' => 'invalid hash'));
}
exit;
 public static function getList($paramsSearch = array())
 {
     if (isset($paramsSearch['switch_db'])) {
         $db = ezcDbInstance::get();
         $cfg = erConfigClassLhConfig::getInstance();
         $db->query('USE ' . $cfg->getSetting('db', 'database'));
     }
     $paramsDefault = array('limit' => 32, 'offset' => 0);
     $params = array_merge($paramsDefault, $paramsSearch);
     $session = erLhcoreClassInstance::getSession();
     $q = $session->createFindQuery('erLhcoreClassModelInstance');
     $conditions = array();
     if (isset($params['filter']) && count($params['filter']) > 0) {
         foreach ($params['filter'] as $field => $fieldValue) {
             $conditions[] = $q->expr->eq($field, $q->bindValue($fieldValue));
         }
     }
     if (isset($params['filterin']) && count($params['filterin']) > 0) {
         foreach ($params['filterin'] as $field => $fieldValue) {
             $conditions[] = $q->expr->in($field, $fieldValue);
         }
     }
     if (isset($params['filterlt']) && count($params['filterlt']) > 0) {
         foreach ($params['filterlt'] as $field => $fieldValue) {
             $conditions[] = $q->expr->lt($field, $q->bindValue($fieldValue));
         }
     }
     if (isset($params['filtergt']) && count($params['filtergt']) > 0) {
         foreach ($params['filtergt'] as $field => $fieldValue) {
             $conditions[] = $q->expr->gt($field, $q->bindValue($fieldValue));
         }
     }
     if (count($conditions) > 0) {
         $q->where($conditions);
     }
     $q->limit($params['limit'], $params['offset']);
     $q->orderBy(isset($params['sort']) ? $params['sort'] : 'id ASC');
     $objects = $session->find($q);
     if (isset($paramsSearch['switch_db'])) {
         $db->query('USE ' . $cfg->getSetting('db', 'database_user_prefix') . erLhcoreClassInstance::$instanceChat->id);
     }
     return $objects;
 }