function clearValues() { $connection = \Freetrix\Main\Application::getConnection(); $connection->query("\n\t\t\tDELETE FROM b_iblock_element_iprop\n\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t"); $connection->query("\n\t\t\tDELETE FROM b_iblock_section_iprop\n\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t"); $connection->query("\n\t\t\tDELETE FROM b_iblock_iblock_iprop\n\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t"); }
function clearValues() { $connection = \Freetrix\Main\Application::getConnection(); $sectionList = \Freetrix\Iblock\SectionTable::getList(array("select" => array("LEFT_MARGIN", "RIGHT_MARGIN"), "filter" => array("=ID" => $this->section_id))); $section = $sectionList->fetch(); if ($section) { $connection->query("\n\t\t\t\tDELETE FROM b_iblock_element_iprop\n\t\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\tAND ELEMENT_ID in (\n\t\t\t\t\tSELECT BSE.IBLOCK_ELEMENT_ID\n\t\t\t\t\tFROM b_iblock_section_element BSE\n\t\t\t\t\tINNER JOIN b_iblock_section BS ON BSE.IBLOCK_SECTION_ID = BS.ID AND BSE.ADDITIONAL_PROPERTY_ID IS NULL\n\t\t\t\t\tWHERE BS.IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\t\tAND BS.LEFT_MARGIN <= " . $section["RIGHT_MARGIN"] . "\n\t\t\t\t\tAND BS.RIGHT_MARGIN >= " . $section["LEFT_MARGIN"] . "\n\t\t\t\t)\n\t\t\t"); $connection->query("\n\t\t\t\tDELETE FROM b_iblock_section_iprop\n\t\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\tAND SECTION_ID in (\n\t\t\t\t\tSELECT BS.ID\n\t\t\t\t\tFROM b_iblock_section BS\n\t\t\t\t\tWHERE BS.IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\t\tAND BS.LEFT_MARGIN <= " . $section["RIGHT_MARGIN"] . "\n\t\t\t\t\tAND BS.RIGHT_MARGIN >= " . $section["LEFT_MARGIN"] . "\n\t\t\t\t)\n\t\t\t"); } }
public static function getActiveUsersCount() { if (ModuleManager::isModuleInstalled("intranet")) { $sql = "SELECT COUNT(U.ID) " . "FROM b_user U " . "WHERE U.ACTIVE = 'Y' " . " AND U.LAST_LOGIN IS NOT NULL " . " AND EXISTS(" . " SELECT 'x' " . " FROM b_utm_user UF, b_user_field F " . " WHERE F.ENTITY_ID = 'USER' " . " AND F.FIELD_NAME = 'UF_DEPARTMENT' " . " AND UF.FIELD_ID = F.ID " . " AND UF.VALUE_ID = U.ID " . " AND UF.VALUE_INT IS NOT NULL " . " AND UF.VALUE_INT <> 0" . " )"; } else { $sql = "SELECT COUNT(ID) " . "FROM b_user " . "WHERE ACTIVE = 'Y' " . " AND LAST_LOGIN IS NOT NULL"; } $connection = Application::getConnection(); return $connection->queryScalar($sql); }
public static function deleteBySiteId($siteId) { if (empty($siteId)) { throw new \Freetrix\Main\ArgumentNullException("siteId"); } $result = new \Freetrix\Main\Entity\DeleteResult(); // event PRE // delete $connection = \Freetrix\Main\Application::getConnection(); $helper = $connection->getSqlHelper(); $tableName = static::getEntity()->getDBTableName(); $sql = "DELETE FROM " . $tableName . " WHERE SITE_ID = '" . $helper->forSql($siteId) . "'"; $connection->queryExecute($sql); // event POST return $result; }
public static function getCurrentTemplateId($siteId) { $cacheFlags = Config\Configuration::getValue("cache_flags"); $ttl = isset($cacheFlags["site_template"]) ? $cacheFlags["site_template"] : 0; $connection = Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $field = $connection->getType() === "mysql" ? "`CONDITION`" : "CONDITION"; $path2templates = IO\Path::combine(Application::getDocumentRoot(), Application::getPersonalRoot(), "templates"); if ($ttl === false) { $sql = "\n\t\t\t\tSELECT " . $field . ", TEMPLATE\n\t\t\t\tFROM b_site_template\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\tORDER BY IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } else { $managedCache = Application::getInstance()->getManagedCache(); if ($managedCache->read($ttl, "b_site_template")) { $arSiteTemplateBySite = $managedCache->get("b_site_template"); } else { $arSiteTemplateBySite = array(); $sql = "\n\t\t\t\t\tSELECT " . $field . ", TEMPLATE, SITE_ID\n\t\t\t\t\tFROM b_site_template\n\t\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\t\tORDER BY SITE_ID, IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $arSiteTemplateBySite[$record['SITE_ID']][] = $record; } $managedCache->set("b_site_template", $arSiteTemplateBySite); } if (is_array($arSiteTemplateBySite[$siteId])) { foreach ($arSiteTemplateBySite[$siteId] as $record) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } } return ".default"; }
protected function execPlaceholders($matches) { $sqlHelper = Application::getConnection()->getSqlHelper(); $this->i++; $pre = $matches[1]; $ph = $matches[2]; if (isset($this->args[$this->i])) { $value = $this->args[$this->i]; if ($ph == '?' || $ph == '?s') { $value = "'" . $sqlHelper->forSql($value) . "'"; } elseif ($ph == '?#') { $value = $sqlHelper->quote($value); } elseif ($ph == '?i') { $value = (int) $value; } elseif ($ph == '?f') { $value = (double) $value; } return $pre . $value; } return $matches[0]; }
/** * @param bool $withPrefix * @return string */ public function getInitAlias($withPrefix = true) { $init_alias = strtolower($this->init_entity->getCode()); if ($withPrefix) { $init_alias .= $this->table_alias_postfix; } $connection = \Freetrix\Main\Application::getConnection(); $aliasLength = $connection->getSqlHelper()->getAliasLength(); if (strlen($init_alias) > $aliasLength) { $init_alias = 'base'; } return $init_alias; }
/** * Must be called on template delete. * * @param int $ipropertyId * @return void */ public function deleteValues($ipropertyId) { $ipropertyId = intval($ipropertyId); $connection = \Freetrix\Main\Application::getConnection(); $connection->query("\n\t\t\tDELETE FROM b_iblock_iblock_iprop\n\t\t\tWHERE IPROP_ID = " . $ipropertyId . "\n\t\t"); $connection->query("\n\t\t\tDELETE FROM b_iblock_section_iprop\n\t\t\tWHERE IPROP_ID = " . $ipropertyId . "\n\t\t"); $connection->query("\n\t\t\tDELETE FROM b_iblock_element_iprop\n\t\t\tWHERE IPROP_ID = " . $ipropertyId . "\n\t\t"); }
<? $connection = \Freetrix\Main\Application::getConnection(); $connection->queryExecute("SET NAMES 'utf8'"); $connection->queryExecute('SET collation_connection = "utf8_unicode_ci"'); ?>
public static function clearByPid($PID) { $connection = \Freetrix\Main\Application::getConnection(); $query = $connection->query("\nDELETE\nFROM " . self::getTableName() . "\nWHERE PID='" . intval($PID) . "'\n"); }
public function getSqlDefinition() { if (is_array($this->value) || $this->value instanceof ReferenceField || $this->value instanceof Base) { throw new \Exception(''); } if ($this->value instanceof ExpressionField) { $SQLBuildFrom = array(); foreach ($this->value->getBuildFromChains() as $chain) { $SQLBuildFrom[] = $chain->getSQLDefinition(); } // join $sql = call_user_func_array('sprintf', array_merge(array($this->value->getExpression()), $SQLBuildFrom)); } else { $connection = \Freetrix\Main\Application::getConnection(); $helper = $connection->getSqlHelper(); $sql = $helper->quote($this->getParameter('talias')) . '.'; $sql .= $helper->quote($this->value->getColumnName()); } return $sql; }
public function clearByTag($tag) { $con = Main\Application::getConnection(); $sqlHelper = $con->getSqlHelper(); if ($tag === true) { $sqlWhere = " WHERE TAG <> '*'"; } else { $sqlWhere = " WHERE TAG = '" . $sqlHelper->forSql($tag) . "'"; } $arDirs = array(); $rs = $con->query("SELECT * FROM b_cache_tag" . $sqlWhere); while ($ar = $rs->fetch()) { $arDirs[$ar["RELATIVE_PATH"]] = $ar; } $con->queryExecute("DELETE FROM b_cache_tag" . $sqlWhere); $cache = Cache::createInstance(); $managedCache = Main\Application::getInstance()->getManagedCache(); foreach ($arDirs as $path => $ar) { $con->queryExecute("\n\t\t\t\tDELETE FROM b_cache_tag\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($ar["SITE_ID"]) . "'\n\t\t\t\tAND CACHE_SALT = '" . $sqlHelper->forSql($ar["CACHE_SALT"]) . "'\n\t\t\t\tAND RELATIVE_PATH = '" . $sqlHelper->forSql($ar["RELATIVE_PATH"]) . "'\n\t\t\t"); if (preg_match("/^managed:(.+)\$/", $path, $match)) { $managedCache->cleanDir($match[1]); } else { $cache->cleanDir($path); } unset($this->dbCacheTags[$path]); } }
/** * Deletes row in entity table by primary key * * @param mixed $primary * @return DeleteResult */ public static function delete($primary) { // check primary static::normalizePrimary($primary); static::validatePrimary($primary); $entity = static::getEntity(); $result = new DeleteResult(); //event before delete $event = new Event($entity, self::EVENT_ON_BEFORE_DELETE, array("id" => $primary)); $event->send(); if ($event->getErrors($result)) { return $result; } //event on delete $event = new Event($entity, self::EVENT_ON_DELETE, array("id" => $primary)); $event->send(); // delete $connection = Main\Application::getConnection(); $helper = $connection->getSqlHelper(); $tableName = $entity->getDBTableName(); $id = array(); foreach ($primary as $k => $v) { $id[] = $k . " = '" . $helper->forSql($v) . "'"; } $where = implode(' AND ', $id); $sql = "DELETE FROM " . $tableName . " WHERE " . $where; $connection->queryExecute($sql); //event after delete $event = new Event($entity, self::EVENT_ON_AFTER_DELETE, array("id" => $primary)); $event->send(); return $result; }
protected function execPlaceholders($matches) { $this->i++; $id = $matches[1]; if (isset($this->args[$this->i])) { $value = $this->args[$this->i]; if ($id == '?' || $id == '?s') { return "'" . $this->DB->ForSql($value) . "'"; } elseif ($id == '?#') { $connection = \Freetrix\Main\Application::getConnection(); $helper = $connection->getSqlHelper(); return $helper->quote($value); } elseif ($id == '?i') { return (int) $value; } elseif ($id == '?f') { return (double) $value; } } return $id; }
protected function getCookieDomain() { static $bCache = false; static $cache = false; if ($bCache) { return $cache; } $context = \Freetrix\Main\Application::getInstance()->getContext(); $server = $context->getServer(); $cacheFlags = \Freetrix\Main\Config\Configuration::getValue("cache_flags"); $cacheTtl = isset($cacheFlags["site_domain"]) ? $cacheFlags["site_domain"] : 0; if ($cacheTtl === false) { $connection = \Freetrix\Main\Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $sql = "SELECT DOMAIN " . "FROM b_lang_domain " . "WHERE '" . $sqlHelper->forSql('.' . $server->getHttpHost()) . "' like " . $sqlHelper->getConcatFunction("'%.'", "DOMAIN") . " " . "ORDER BY " . $sqlHelper->getLengthFunction("DOMAIN") . " "; $recordset = $connection->query($sql); if ($record = $recordset->fetch()) { $cache = $record['DOMAIN']; } } else { $managedCache = \Freetrix\Main\Application::getInstance()->getManagedCache(); if ($managedCache->read($cacheTtl, "b_lang_domain", "b_lang_domain")) { $arLangDomain = $managedCache->get("b_lang_domain"); } else { $arLangDomain = array("DOMAIN" => array(), "LID" => array()); $connection = \Freetrix\Main\Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $recordset = $connection->query("SELECT * " . "FROM b_lang_domain " . "ORDER BY " . $sqlHelper->getLengthFunction("DOMAIN")); while ($record = $recordset->fetch()) { $arLangDomain["DOMAIN"][] = $record; $arLangDomain["LID"][$record["LID"]][] = $record; } $managedCache->set("b_lang_domain", $arLangDomain); } foreach ($arLangDomain["DOMAIN"] as $domain) { if (strcasecmp(substr('.' . $server->getHttpHost(), -(strlen($domain['DOMAIN']) + 1)), "." . $domain['DOMAIN']) == 0) { $cache = $domain['DOMAIN']; break; } } } $bCache = true; return $cache; }
public static function delete($moduleId, $filter = array()) { if (static::$cacheTtl === null) { static::$cacheTtl = self::getCacheTtl(); } if (static::$cacheTtl !== false) { $cache = Main\Application::getInstance()->getManagedCache(); $cache->clean("b_option"); } $con = Main\Application::getConnection(); $sqlHelper = $con->getSqlHelper(); $strSqlWhere = ""; if (isset($filter["name"])) { if (empty($filter["name"])) { throw new Main\ArgumentNullException("filter[name]"); } $strSqlWhere .= " AND NAME = '" . $sqlHelper->forSql($filter["name"]) . "' "; } if (isset($filter["site_id"])) { $strSqlWhere .= " AND SITE_ID " . ($filter["site_id"] == "" ? "IS NULL" : "= '" . $sqlHelper->forSql($filter["site_id"], 2) . "'"); } if ($moduleId == "main") { $con->queryExecute("DELETE FROM b_option " . "WHERE MODULE_ID = 'main' " . " AND NAME NOT LIKE '~%' " . "\tAND NAME NOT IN ('crc_code', 'admin_passwordh', 'server_uniq_id','PARAM_MAX_SITES', 'PARAM_MAX_USERS') " . $strSqlWhere); } else { $con->queryExecute("DELETE FROM b_option " . "WHERE MODULE_ID = '" . $sqlHelper->forSql($moduleId) . "' " . " AND NAME <> '~bsm_stop_date' " . $strSqlWhere); } if (isset($filter["site_id"])) { $siteKey = $filter["site_id"] == "" ? "-" : $filter["site_id"]; if (!isset($filter["name"])) { unset(self::$options[$siteKey][$moduleId]); } else { unset(self::$options[$siteKey][$moduleId][$filter["name"]]); } } else { $arSites = array_keys(self::$options); foreach ($arSites as $s) { if (!isset($filter["name"])) { unset(self::$options[$s][$moduleId]); } else { unset(self::$options[$s][$moduleId][$filter["name"]]); } } } }
protected function loadEventHandlers() { $arEvents = array(); $con = Application::getConnection(); $rs = $con->query("\n\t\t\tSELECT FROM_MODULE_ID, MESSAGE_ID, SORT, TO_MODULE_ID, TO_PATH,\n\t\t\t\tTO_CLASS, TO_METHOD, TO_METHOD_ARG, VERSION\n\t\t\tFROM b_module_to_module m2m\n\t\t\t\tINNER JOIN b_module m ON (m2m.TO_MODULE_ID = m.ID)\n\t\t\tORDER BY SORT\n\t\t"); while ($ar = $rs->fetch()) { $ar['TO_NAME'] = $this->formatEventName(array("TO_MODULE_ID" => $ar["TO_MODULE_ID"], "TO_CLASS" => $ar["TO_CLASS"], "TO_METHOD" => $ar["TO_METHOD"])); $ar["~FROM_MODULE_ID"] = strtoupper($ar["FROM_MODULE_ID"]); $ar["~MESSAGE_ID"] = strtoupper($ar["MESSAGE_ID"]); if (strlen($ar["TO_METHOD_ARG"]) > 0) { $ar["TO_METHOD_ARG"] = unserialize($ar["TO_METHOD_ARG"]); } else { $ar["TO_METHOD_ARG"] = array(); } $arEvents[] = $ar; } if (!is_array($arEvents)) { $arEvents = array(); } $handlers = $this->handlers; $hasHandlers = !empty($this->handlers); // compatibility with former event manager foreach ($arEvents as $ar) { $this->handlers[$ar["~FROM_MODULE_ID"]][$ar["~MESSAGE_ID"]][] = array("SORT" => $ar["SORT"], "TO_MODULE_ID" => $ar["TO_MODULE_ID"], "TO_PATH" => $ar["TO_PATH"], "TO_CLASS" => $ar["TO_CLASS"], "TO_METHOD" => $ar["TO_METHOD"], "TO_METHOD_ARG" => $ar["TO_METHOD_ARG"], "VERSION" => $ar["VERSION"], "TO_NAME" => $ar["TO_NAME"], "FROM_DB" => true); } if ($hasHandlers) { // need to re-sort because of AddEventHandler() calls (before loadEventHandlers) $funcSort = create_function('$a, $b', 'if ($a["SORT"] == $b["SORT"]) return 0; return ($a["SORT"] < $b["SORT"]) ? -1 : 1;'); foreach (array_keys($handlers) as $moduleId) { foreach (array_keys($handlers[$moduleId]) as $event) { uasort($this->handlers[$moduleId][$event], $funcSort); } } } $this->isHandlersLoaded = true; }
public function getSqlDefinition($with_alias = false) { $sql_def = $this->getLastElement()->getSqlDefinition(); if ($with_alias) { $connection = \Freetrix\Main\Application::getConnection(); $helper = $connection->getSqlHelper(); $sql_def .= ' AS ' . $helper->quote($this->getAlias()); } return $sql_def; }
public static function clearBySitemap($sitemapId) { $connection = \Freetrix\Main\Application::getConnection(); $connection->query("\nDELETE\nFROM " . self::getTableName() . "\nWHERE SITEMAP_ID=" . intval($sitemapId) . " AND ENTITY_TYPE='" . static::ENTITY_TYPE . "'\n"); }
public static function delayedDelete($count = 1, $level = 1) { $etime = time() + 2; for ($i = 0; $i < $count; $i++) { static::deleteOneDir($etime); if (time() > $etime) { break; } } $con = Main\Application::getConnection(); //try to adjust cache cleanup speed to cache cleanups $rs = $con->query("SELECT SITE_ID, CACHE_SALT, RELATIVE_PATH, TAG from b_cache_tag WHERE TAG='**'"); if ($ar = $rs->fetch()) { $last_count = intval($ar["RELATIVE_PATH"]); if (preg_match("/:(\\d+)\$/", $ar["RELATIVE_PATH"], $m)) { $last_time = intval($m[1]); } else { $last_time = 0; } } else { $last_count = 0; $last_time = 0; } $bWasStatRecFound = is_array($ar); $this_count = $con->queryScalar("SELECT count(1) CNT from b_cache_tag WHERE TAG='*'"); $delta = $this_count - $last_count; if ($delta > 0) { if ($last_time > 0) { $time_step = time() - $last_time; } if ($time_step <= 0) { $time_step = 1; } $count = intval($this_count * $time_step / 3600) + 1; //Rest of the queue in an hour } elseif ($count < 1) { $count = 1; } if ($bWasStatRecFound) { if ($last_count != $this_count) { $con->queryExecute("UPDATE b_cache_tag SET RELATIVE_PATH='" . $this_count . ":" . time() . "' WHERE TAG='**'"); } } else { $con->queryExecute("INSERT INTO b_cache_tag (TAG, RELATIVE_PATH) VALUES ('**', '" . $this_count . ":" . time() . "')"); } if ($this_count > 0) { return "\\Freetrix\\Main\\Data\\CacheEngineFiles::delayedDelete(" . $count . ");"; } else { return ""; } }