Beispiel #1
0
 public static function get($sql)
 {
     Trace::addMessage(__CLASS__, sprintf('Get:<br>%s', $sql));
     $result = parent::get($sql);
     Trace::addMessage(__CLASS__, sprintf('Get finished'));
     return $result;
 }
Beispiel #2
0
 /**
  * Удаляет ряд из бд
  * @param int $nId Индекс ряда
  * @param boolean $bRecursive удалять ли детей данного элемента. ВНИМАНИЕ!!! Устанавливайте значение в false, только если вы точно знаете, что делаете!
  */
 public static function delete($parent, $nId, $bRecursive = true)
 {
     $nId = intval($nId);
     // Определяем установлен ли флаг рекурсивного удаления
     if ($bRecursive) {
         $aChild = self::selectChild($nId);
         foreach ($aChild as $row) {
             self::delete(null, $row['id']);
         }
     }
     //
     $sql = 'SELECT * FROM `%s` WHERE `id`="%d"';
     $sql = sprintf($sql, SYSTEMREGISTER_TABLE, $nId);
     $aInfo = DB::get($sql);
     if (!empty($aInfo)) {
         // Запрос в бд
         $sql = 'DELETE FROM `%s` WHERE `id`="%d"';
         $sql = sprintf($sql, SYSTEMREGISTER_TABLE, $nId);
         DB::post($sql);
         self::updateGetCache($aInfo['name'], $parent->getId(), true);
     } else {
     }
     if (is_object($parent)) {
         // Обновляем кеш для предка
         self::updateChildCache($parent->getId());
         self::updateChildCache($nId, true);
     }
 }
Beispiel #3
0
 /**
  *   Возвращает пользователя с nUserId
  *   @return
  */
 public static function getUser($nUserId)
 {
     $nUserId = intval($nUserId);
     //
     $sql = 'SELECT * FROM `%s` WHERE `id`="%d" LIMIT 0,1';
     $sql = sprintf($sql, CMS_AUTH_TABLE, $nUserId);
     return DB::get($sql);
 }
Beispiel #4
0
 protected static function lookForEmail($email)
 {
     $sql = 'SELECT * FROM `%s` WHERE STRCMP(`email`,"%s") = 0';
     $sql = sprintf($sql, USERS_TABLE, $email);
     $aFound = DB::get($sql);
     if (empty($aFound)) {
         throw new \NotFoundException('Email not found in database');
     }
     return $aFound;
 }
Beispiel #5
0
 protected static function isLimitExceeded()
 {
     $sql = sprintf(' select count(*) as `count` from %s where `ip`="%d" ', self::TableName, DB::escape(ip2long(self::$ip)));
     $data = DB::get($sql);
     if (!empty($data)) {
         $result = $data['count'];
     } else {
         $result = 0;
     }
     self::cleanDB();
     return $result >= self::$config['MaxConnections'];
 }
Beispiel #6
0
 /**
  *   -------------------------------------------------------------------------------------------
  *   Возвращаем историю
  *   @return
  *   -------------------------------------------------------------------------------------------
  */
 public static function foundByUrl($szUrl)
 {
     $sql = 'SELECT * FROM `%s` WHERE STRCMP(`url`,"%s") = 0 ORDER by `id` DESC LIMIT 0,1';
     $sql = sprintf($sql, SITEMAP_HISTORY_TABLE, $szUrl);
     $aFound = DB::get($sql);
     if (!empty($aFound)) {
         $aFound = Sitemap_Sample::get($aFound['page_id']);
         if (!empty($aFound)) {
             return $aFound['full_url'];
         } else {
             throw new SiteMapException('Page not found. Page="' . htmlspecialchars($aFound['page_id']) . '"');
         }
     } else {
         throw new SiteMapException('Url not found. Url="' . htmlspecialchars($szUrl) . '"');
     }
 }
Beispiel #7
0
 /**
  * Возвращает по ID его предка
  */
 public static function createById($nId)
 {
     $nId = IntegerHelper::toNatural($nId);
     //
     $sql = 'SELECT * FROM `%s` WHERE `id`="%d"';
     $sql = sprintf($sql, SYSTEMREGISTER_TABLE, $nId);
     //
     $aResult = DB::get($sql);
     if (empty($aResult)) {
         throw new SystemRegisterException('Key with id="' . $nId . '" not found');
     }
     // Нашли корневой элемент
     if ($aResult['parent'] == 0) {
         $result = new SystemRegister($aResult['name']);
     } else {
         $result = self::createById($aResult['parent'])->get($aResult['name']);
     }
     return $result;
 }
Beispiel #8
0
 public static function autoLoadFromCookie()
 {
     $isCookieSet = !empty($_COOKIE[self::cookieName]);
     if (!$isCookieSet) {
         return;
     }
     $passwordHash = $_COOKIE[self::cookieName];
     // Запрос провещяюрий есть ли юзер или нет и не забанен ли он
     $sql = 'SELECT * FROM `%s` WHERE LENGTH(`confirmation_code`) = 0 and md5(CONCAT(`password`,"%s",`id`)) = "%s"';
     $sql = sprintf($sql, USERS_TABLE, DB::escape(\Faid\Configure\Configure::read(\Extasy\CMS::SaltConfigureKey)), DB::escape($passwordHash));
     //
     $aFound = DB::get($sql);
     if (empty($aFound)) {
         return false;
     }
     try {
         self::forceLogin(new UserAccount($aFound));
         return true;
     } catch (Exception $e) {
         // Игнорируем случай неверной аутентификации
     }
     return false;
 }
Beispiel #9
0
 protected function changeLogin($password, $login)
 {
     $login = \Faid\DB::$connection->real_escape_string($login);
     $oUser = UsersLogin::getCurrentSession();
     if ($login == $oUser->login->getValue()) {
         return;
     }
     if ($this->register->get('front-end')->ignore_password_field->value == 0) {
         $isSamePassword = $this->checkPassword($password, $oUser);
         if (!$isSamePassword) {
             $this->addValidationError('updatePassword');
             return;
         }
     }
     $sql = 'SELECT * FROM `%s` WHERE `login` = "%s" and `id` <> %d';
     $sql = sprintf($sql, USERS_TABLE, $login, $oUser->id->getValue());
     //
     $aGet = DB::get($sql);
     // Ого! уже есть акк с таким емейлом, навиду подстава! ;)
     if (!empty($aGet)) {
         $this->addValidationError('updateLogin');
         return;
     }
     $old_login = $oUser->email->getValue();
     $oUser->login->setValue($login);
     $oUser->update();
     EventController::callEvent('users_after_update_login', $oUser, $old_login, $login);
     $this->addSuccess('updateLogin');
 }
Beispiel #10
0
    protected function getCounts()
    {
        $sql = <<<SQL
\t\tselect 
\t\t\t(select count(*) from `custom_config_groups`) as `tabcount`,
\t\t\t(select count(*) from `custom_config_items`) as `controlcount`
SQL;
        $result = DB::get($sql);
        return $result;
    }
Beispiel #11
0
 /**
  *
  * Enter description here ...
  */
 public function getSiblingPrevious($asDocument = true)
 {
     $this->needSitemapData();
     $sql = 'SELECT * FROM `%s` WHERE `order` < "%d" and `parent` = "%d" ORDER by `order` DESC LIMIT 0,1 ';
     $sql = sprintf($sql, SITEMAP_TABLE, $this->sitemapInfo['order'], $this->sitemapInfo['parent']);
     $sitemapData = DB::get($sql);
     // Return as ...
     return self::returnSitemapInfo($sitemapData, $asDocument, true);
 }
Beispiel #12
0
 /**
  * Тестируем каскадное удаление
  */
 public function testRecursiveRemoving()
 {
     $document = new TestDocument();
     $document->name = 'Test inserting';
     $document->insert();
     $nRoot = Sitemap::addPage('Test inserting', 'xx', TestDocument::ModelName, 1, 0);
     $document = new TestDocument();
     $document->name = 'Test inserting2';
     $document->insert();
     Sitemap::addPage('Test inserting2', 'xx', TestDocument::ModelName, 2, $nRoot);
     //
     Sitemap::removeDocument(TestDocument::ModelName, '1');
     // Проверяем удаление из бд
     $result = DB::get(sprintf('SELECT COUNT(*) as `count` FROM `%s`', TestDocument::TableName));
     $this->assertEquals($result['count'], 0);
 }
Beispiel #13
0
 /**
  * Проверяем, что документ добавляется в таблицу БД
  */
 public function testInsert()
 {
     $doc = new basicTestDocument();
     $doc->name = 'new name';
     $doc->content = 'new content';
     $doc->insert();
     // Проверяем на уровне бд
     $sql = 'select * from `basic_document` where `id`="%d" ';
     $sql = sprintf($sql, 2);
     $result = DB::get($sql);
     $this->assertEquals($result['name'], 'new name');
     $this->assertEquals($result['content'], 'new content');
     // Проверяем количество рядов в БД (должно быть 2)
     $sql = 'select count(*) as `count` from `basic_document`';
     $result = DB::getField($sql, 'count');
     $this->assertEquals($result, 2);
 }
Beispiel #14
0
 protected static function getByCode($code)
 {
     $sql = 'SELECT * FROM `%s` WHERE STRCMP(`confirmation_code`,"%s") = 0';
     $sql = sprintf($sql, USERS_TABLE, \Faid\DB::$connection->real_escape_string($code));
     $modelData = DB::get($sql);
     if (!empty($modelData)) {
         return new UserAccount($modelData);
     } else {
         return null;
     }
 }
Beispiel #15
0
 /**
  * Возвращает ряд с комментарием о шаблоне из бд
  */
 protected static function getFromDB($tpl)
 {
     $tpl = \Faid\DB::$connection->real_escape_string($tpl);
     //
     $sql = 'SELECT * FROM `%s` WHERE `path`="%s"';
     $sql = sprintf($sql, SITEMAP_TEMPLATE_TABLE, $tpl);
     //
     return DB::get($sql);
 }
Beispiel #16
0
 public static function getByUrl($url)
 {
     $url = \Faid\DB::escape($url);
     $sql = 'SELECT * FROM `%s` WHERE `full_url` = "%s" LIMIT 0,1';
     $sql = sprintf($sql, SITEMAP_TABLE, $url);
     $aInfo = DB::get($sql);
     if (empty($aInfo)) {
         throw new SiteMapException('Url `' . htmlspecialchars($url) . '`not found');
     }
     return $aInfo;
 }
Beispiel #17
0
 public static function getParent($nId)
 {
     $sql = 'SELECT * FROM `%s` WHERE `id`="%d"';
     $sql = sprintf($sql, SITEMAP_TABLE, $nId);
     return DB::get($sql);
 }
Beispiel #18
0
 public function updateSchema($name, $title)
 {
     if (empty($name)) {
         throw new CConfigException('Empty schemaName');
     }
     // Проверяем есть ли уже такая вкладка
     $sql = 'select * from `%s` where `name`="%s" and `id` <> "%d"';
     $sql = sprintf($sql, CCONFIG_SCHEMA_TABLE, \Faid\DB::escape($name), $this->id);
     $found = DB::get($sql);
     if ($found) {
         throw new CConfigException('Duplicate schema name `' . $name . '`');
     }
     $this->name = $name;
     $this->title = $title;
     $this->store();
 }
Beispiel #19
0
 /**
  *   Возвращает количество пользователей в системе
  *   @return
  */
 public static function getAccountCount()
 {
     $sql = 'SELECT count(*) as `count` FROM `%s`';
     $sql = sprintf($sql, USERS_TABLE);
     $aResult = DB::get($sql);
     return $aResult['count'];
 }
Beispiel #20
0
 protected static function checkSchemaExists($schemaName)
 {
     // Делаем запрос, на проверку существования записей в контролах
     $sql = 'select * from `%s` WHERE `name`="%s"';
     $sql = sprintf($sql, CCONFIG_SCHEMA_TABLE, \Faid\DB::escape($schemaName));
     $result = DB::get($sql);
     if (!empty($result)) {
         return $result;
     } else {
         return false;
     }
 }
Beispiel #21
0
 public static function getPagingInfo()
 {
     $sql = 'select FOUND_ROWS() as `found` ';
     $result = DB::get($sql);
     $found = !empty($result['found']) ? intval($result['found']) : 0;
     return array('page' => self::$lastSearchRequest->page, 'total' => $found);
 }
Beispiel #22
0
 public function testCreateTableWithDropTable()
 {
     $model = new TestModel();
     $model->createDatabaseTable(true);
     $found = DB::get(sprintf('show tables like "%s"', TestModel::TableName));
     $this->assertNotEmpty($found);
 }
Beispiel #23
0
 /**
  *   -------------------------------------------------------------------------------------------
  *   Возвращает полный урл для страницы
  * @return
  *   -------------------------------------------------------------------------------------------
  */
 public static function getFullUrl($nId)
 {
     if (!empty(self::$aResult[$nId])) {
         return self::$aResult[$nId];
     }
     // Получаем информацию о верхнем ряде
     $sql = 'SELECT * FROM `%s` WHERE `id`="%d" LIMIT 0,1';
     $sql = sprintf($sql, SITEMAP_TABLE, $nId);
     $aInfo = DB::get($sql);
     if (empty($aInfo)) {
         return '';
     }
     // Вызываем с верхним рядом
     if (!empty($aInfo['parent'])) {
         $szResult = self::getFullUrl($aInfo['parent']) . $aInfo['url_key'] . '/';
     } else {
         $szResult = '/' . $aInfo['url_key'] . '/';
     }
     return $szResult;
 }