Exemple #1
0
 private function insertNames()
 {
     $handle = new BlockInserter(array('entityName' => '\\Bitrix\\Sale\\Location\\Name\\LocationTable', 'exactFields' => array('LOCATION_ID', 'LANGUAGE_ID', 'NAME', 'SHORT_NAME', 'NAME_UPPER'), 'parameters' => array('mtu' => 9999)));
     if (is_array($this->data['NAME']) && !empty($this->data['NAME'])) {
         foreach ($this->data['NAME'] as $id => $nameLang) {
             if (is_array($nameLang)) {
                 foreach ($nameLang as $lang => $name) {
                     $handle->insert(array('LOCATION_ID' => $id, 'LANGUAGE_ID' => $lang, 'NAME' => $name['NAME'], 'NAME_UPPER' => ToUpper($name['NAME']), 'SHORT_NAME' => $name['SHORT_NAME']));
                 }
             }
         }
     }
     $handle->flush();
 }
Exemple #2
0
 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}");
 }
 /**
  * Removes all links and creates new ones
  * 
  */
 public static function resetMultipleForOwner($entityPrimary, $links = array())
 {
     $entityPrimary = Assert::expectStringNotNull($entityPrimary, '$entityPrimary');
     $links = static::checkUpdateLinks($links);
     static::deleteAllForOwner($entityPrimary, array('BATCH_MODE' => true));
     $map = static::getMap();
     $linkFld = static::getLinkField();
     $locationLinkFld = static::getLocationLinkField();
     $typeFld = static::getTypeField();
     $fields = array($linkFld => $map[$linkFld], $locationLinkFld => $map[$locationLinkFld]);
     if ($useGroups = static::getUseGroups()) {
         $fields[$typeFld] = $map[$typeFld];
     }
     // LOCATION_TYPE: L or G
     $inserter = new BlockInserter(array('tableName' => static::getTableName(), 'exactFields' => $fields));
     $smthAdded = false;
     if (is_array($links[self::DB_LOCATION_FLAG])) {
         foreach ($links[self::DB_LOCATION_FLAG] as $id) {
             $data = array($linkFld => $entityPrimary, $locationLinkFld => $id);
             if ($useGroups) {
                 $data[$typeFld] = self::DB_LOCATION_FLAG;
             }
             $inserter->insert($data);
             $smthAdded = true;
         }
     }
     static::setLinkUsage($entityPrimary, self::DB_LOCATION_FLAG, $smthAdded);
     $smthAdded = false;
     if (is_array($links[self::DB_GROUP_FLAG]) && $useGroups) {
         foreach ($links[self::DB_GROUP_FLAG] as $id) {
             $data = array($linkFld => $entityPrimary, $locationLinkFld => $id);
             if ($useGroups) {
                 $data[$typeFld] = self::DB_GROUP_FLAG;
             }
             $inserter->insert($data);
             $smthAdded = true;
         }
     }
     static::setLinkUsage($entityPrimary, self::DB_GROUP_FLAG, $smthAdded);
     $inserter->flush();
     $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data');
 }