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 rollBack() { if (Helper::checkTableExists(self::TABLE_LEGACY_RELATIONS)) { Helper::mergeTables('b_sale_location', self::TABLE_LEGACY_RELATIONS, array('COUNTRY_ID' => 'COUNTRY_ID', 'REGION_ID' => 'REGION_ID', 'CITY_ID' => 'CITY_ID'), array('ID' => 'ID')); } Helper::truncateTable(self::TABLE_LOCATION_NAME); Helper::truncateTable(self::TABLE_LOCATION_EXTERNAL); \CSaleLocation::locationProSetRolledBack(); }
public static function resort($dontCareEvents = false) { $edges = array(); $nodes = array(); $res = parent::getList(array('select' => array('ID', 'PARENT_ID', 'LEFT_MARGIN', 'RIGHT_MARGIN'))); while ($item = $res->Fetch()) { $nodes[$item['ID']] = array('LEFT_MARGIN' => $item['LEFT_MARGIN'], 'RIGHT_MARGIN' => $item['RIGHT_MARGIN']); if (!intval($item['PARENT_ID'])) { $edges['ROOT'][] = $item['ID']; } else { $edges[$item['PARENT_ID']][] = $item['ID']; } } // walk tree in-deep to obtain correct margins self::walkTreeInDeep('ROOT', $edges, $nodes, 0, 0, $dontCareEvents); // now massively insert new values into the database, using a temporal table $tabName = 'b_sale_location_temp_' . rand(99, 9999); $entityTableName = static::getTableName(); $dbConnection = Main\HttpApplication::getConnection(); $dbConnection->query("create table " . $tabName . " (\n\t\t\tID " . Helper::getSqlForDataType('int') . ",\n\t\t\tLEFT_MARGIN " . Helper::getSqlForDataType('int') . ",\n\t\t\tRIGHT_MARGIN " . Helper::getSqlForDataType('int') . ",\n\t\t\tDEPTH_LEVEL " . Helper::getSqlForDataType('int') . "\n\t\t)"); $handle = new BlockInserter(array('tableName' => $tabName, 'exactFields' => array('ID' => array('data_type' => 'integer'), 'LEFT_MARGIN' => array('data_type' => 'integer'), 'RIGHT_MARGIN' => array('data_type' => 'integer'), 'DEPTH_LEVEL' => array('data_type' => 'integer')), 'parameters' => array('mtu' => self::BLOCK_INSERT_MTU))); foreach ($nodes as $id => $node) { $node['ID'] = $id; $handle->insert($node); } $handle->flush(); // merge temp table with location table Helper::mergeTables($entityTableName, $tabName, array('LEFT_MARGIN' => 'LEFT_MARGIN', 'RIGHT_MARGIN' => 'RIGHT_MARGIN', 'DEPTH_LEVEL' => 'DEPTH_LEVEL'), array('ID' => 'ID')); $dbConnection->query("drop table {$tabName}"); }
public static function mergeResort() { Helper::mergeTables(static::getTableName(), static::getTableNamePositionTemporal(), array('POSITION' => 'POSITION'), array('ID' => 'WORD_ID')); Main\HttpApplication::getConnection()->query("drop table " . static::getTableNamePositionTemporal()); }