public static function cleanUpData() { Helper::dropTable(static::getTableName()); // ORACLE: OK, MSSQL: OK $sql = "create table " . static::getTableName() . " \n\t\t\t(\n\t\t\t\tLOCATION_ID " . Helper::getSqlForDataType('int') . ",\n\t\t\t\tSITE_ID " . Helper::getSqlForDataType('char', 2) . ",\n\n\t\t\t\tprimary key (LOCATION_ID, SITE_ID)\n\t\t\t)"; Main\HttpApplication::getConnection()->query($sql); }
public static function resetLegacyPath() { $dbConnection = Main\HttpApplication::getConnection(); $locTable = static::getTableName(); $types = array(); $res = TypeTable::getList(array('filter' => array('CODE' => array('COUNTRY', 'REGION', 'CITY')), 'select' => array('ID', 'CODE'))); while ($item = $res->fetch()) { $types[$item['CODE']] = $item['ID']; } if (!empty($types)) { if (!$dbConnection->isTableExists('b_sale_loc_rebind')) { $dbConnection->query("create table b_sale_loc_rebind (TARGET_ID " . Helper::getSqlForDataType('int') . ", LOCATION_ID " . Helper::getSqlForDataType('int') . ")"); } else { $dbConnection->query("truncate table b_sale_loc_rebind"); } $sqlWhere = array(); foreach ($types as $code => $id) { $sqlWhere[] = "'" . intval($id) . "'"; } $dbConnection->query("update " . $locTable . " set COUNTRY_ID = NULL, REGION_ID = NULL, CITY_ID = NULL where TYPE_ID in (" . implode(', ', $sqlWhere) . ")"); if (intval($types['REGION']) && intval($types['COUNTRY'])) { // countries for regions $dbConnection->query("insert into b_sale_loc_rebind (TARGET_ID, LOCATION_ID) select A.ID as ONE, B.ID as TWO from " . $locTable . " A inner join " . $locTable . " B on A.TYPE_ID = '" . intval($types['REGION']) . "' and B.TYPE_ID = '" . intval($types['COUNTRY']) . "' and B.LEFT_MARGIN <= A.LEFT_MARGIN and B.RIGHT_MARGIN >= A.RIGHT_MARGIN"); Helper::mergeTables($locTable, 'b_sale_loc_rebind', array('COUNTRY_ID' => 'LOCATION_ID'), array('ID' => 'TARGET_ID')); $dbConnection->query("truncate table b_sale_loc_rebind"); } if (intval($types['REGION']) && intval($types['CITY'])) { // regions for cities $dbConnection->query("insert into b_sale_loc_rebind (TARGET_ID, LOCATION_ID) select A.ID as ONE, B.ID as TWO from " . $locTable . " A inner join " . $locTable . " B on A.TYPE_ID = '" . intval($types['CITY']) . "' and B.TYPE_ID = '" . intval($types['REGION']) . "' and B.LEFT_MARGIN <= A.LEFT_MARGIN and B.RIGHT_MARGIN >= A.RIGHT_MARGIN"); Helper::mergeTables($locTable, 'b_sale_loc_rebind', array('REGION_ID' => 'LOCATION_ID'), array('ID' => 'TARGET_ID')); $dbConnection->query("truncate table b_sale_loc_rebind"); } if (intval($types['COUNTRY']) && intval($types['CITY'])) { // countries for cities $dbConnection->query("insert into b_sale_loc_rebind (TARGET_ID, LOCATION_ID) select A.ID as ONE, B.ID as TWO from " . $locTable . " A inner join " . $locTable . " B on A.TYPE_ID = '" . intval($types['CITY']) . "' and B.TYPE_ID = '" . intval($types['COUNTRY']) . "' and B.LEFT_MARGIN <= A.LEFT_MARGIN and B.RIGHT_MARGIN >= A.RIGHT_MARGIN"); Helper::mergeTables($locTable, 'b_sale_loc_rebind', array('COUNTRY_ID' => 'LOCATION_ID'), array('ID' => 'TARGET_ID')); } Helper::dropTable('b_sale_loc_rebind'); if (intval($types['COUNTRY'])) { $dbConnection->query("update " . $locTable . " set COUNTRY_ID = ID where TYPE_ID = '" . intval($types['COUNTRY']) . "'"); } if (intval($types['REGION'])) { $dbConnection->query("update " . $locTable . " set REGION_ID = ID where TYPE_ID = '" . intval($types['REGION']) . "'"); } if (intval($types['CITY'])) { $dbConnection->query("update " . $locTable . " set CITY_ID = ID where TYPE_ID = '" . intval($types['CITY']) . "'"); } } }
public static function resetLegacyPath() { Helper::dropTable(self::TABLE_LEGACY_RELATIONS); $dbConnection = \Bitrix\Main\HttpApplication::getConnection(); $dbConnection->query("create table " . self::TABLE_LEGACY_RELATIONS . " (\n\t\t\tID " . Helper::getSqlForDataType('int') . ",\n\t\t\tCOUNTRY_ID " . Helper::getSqlForDataType('int') . ",\n\t\t\tREGION_ID " . Helper::getSqlForDataType('int') . ",\n\t\t\tCITY_ID " . Helper::getSqlForDataType('int') . "\n\t\t)"); $dbConnection->query("insert into " . self::TABLE_LEGACY_RELATIONS . " (ID, COUNTRY_ID, REGION_ID, CITY_ID) select ID, COUNTRY_ID, REGION_ID, CITY_ID from b_sale_location"); Location\LocationTable::resetLegacyPath(); }
public static function cleanUpData() { Helper::dropTable(static::getTableName()); Main\HttpApplication::getConnection()->query("create table " . static::getTableName() . " (\n\n\t\t\tLOCATION_ID " . Helper::getSqlForDataType('int') . ",\n\t\t\tRELEVANCY " . Helper::getSqlForDataType('int') . " default '0',\n\t\t\tPOSITION " . Helper::getSqlForDataType('int') . " default '0',\n\n\t\t\tprimary key (POSITION, LOCATION_ID)\n\n\t\t)"); }
public static function cleanUpData() { $dbConnection = Main\HttpApplication::getConnection(); Helper::dropTable(static::getTableName()); $binary = ToLower($dbConnection->getType()) == 'mysql' ? 'binary' : ''; // http://bugs.mysql.com/bug.php?id=34096 // ORACE: OK, MSSQL: OK Main\HttpApplication::getConnection()->query("create table " . static::getTableName() . " (\n\n\t\t\tID " . Helper::getSqlForDataType('int') . " not null " . Helper::getSqlForAutoIncrement() . " primary key,\n\t\t\tWORD " . Helper::getSqlForDataType('varchar', 50) . " " . $binary . " not null,\n\t\t\tPOSITION " . Helper::getSqlForDataType('int') . " default '0'\n\t\t)"); Helper::addAutoIncrement(static::getTableName()); // only for ORACLE Helper::createIndex(static::getTableName(), 'TMP', array('WORD'), true); Helper::dropTable(static::getTableNameWord2Location()); // ORACLE: OK, MSSQL: OK Main\HttpApplication::getConnection()->query("create table " . static::getTableNameWord2Location() . " (\n\n\t\t\tLOCATION_ID " . Helper::getSqlForDataType('int') . " not null,\n\t\t\tWORD_ID " . Helper::getSqlForDataType('int') . " not null,\n\n\t\t\tprimary key (LOCATION_ID, WORD_ID)\n\t\t)"); Helper::dropTable(static::getTableNamePositionTemporal()); $dbConnection->query("create table " . static::getTableNamePositionTemporal() . " (\n\t\t\tWORD_ID " . Helper::getSqlForDataType('int') . " not null,\n\t\t\tPOSITION " . Helper::getSqlForDataType('int') . " default '0'\n\t\t)"); }