- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/location/db/blockinserter.php
- Класс: BitrixSaleLocationDBBlockInserter
- Вызов: BlockInserter::__construct
public function __construct($parameters = array())
{
$this->dbConnection = MainHttpApplication::getConnection();
$this->dbHelper = $this->dbConnection->getSqlHelper();
$map = array();
$entityName = trim((string)($parameters['entityName'] ?? ''));
$tableName = trim((string)($parameters['tableName'] ?? ''));
if ($entityName !== '' && is_a($entityName, MainORMDataDataManager::class, true))
{
$table = $entityName;
/** @var MainORMDataDataManager $table */
$this->tableName = $table::getTableName();
$this->tableMap = $table::getMap();
// filter map throught $parameters['exactFields']
if (!empty($parameters['exactFields']) && is_array($parameters['exactFields']))
{
foreach($parameters['exactFields'] as $fld)
{
if(!isset($this->tableMap[$fld]))
{
throw new MainSystemException('Field does not exist in ORM class, but present in "exactFields" parameter: '.$fld, 0, __FILE__, __LINE__);
}
$map[] = $fld;
$this->fldVector[$fld] = true;
}
}
else
{
foreach($this->tableMap as $fld => $params)
{
$map[] = $fld;
$this->fldVector[$fld] = true;
}
}
}
elseif ($tableName !== '')
{
$this->tableName = $this->dbHelper->forSql($parameters['tableName']);
$this->tableMap = [];
if (!empty($parameters['exactFields']) && is_array($parameters['exactFields']))
{
$this->tableMap = $parameters['exactFields'];
}
// $this->tableMap as $fld => $params - is the right way!
/*
required for
$loc2site = new DBBlockInserter(array(
'tableName' => 'b_sale_loc_2site',
'exactFields' => array(
'LOCATION_ID' => array('data_type' => 'integer'),
'SITE_ID' => array('data_type' => 'string')
),
'parameters' => array(
'mtu' => 9999,
'autoIncrementFld' => 'ID'
)
));
*/
foreach($this->tableMap as $fld => $params)
{
$map[] = $fld;
$this->fldVector[$fld] = true;
}
}
// automatically insert to this field an auto-increment value
// beware of TransactSQL`s IDENTITY_INSERT when setting autoIncrementFld to a database-driven auto-increment field
$autoIncrementFld = trim((string)($parameters['parameters']['autoIncrementFld'] ?? ''));
if ($autoIncrementFld !== '')
{
$this->autoIncFld = $autoIncrementFld;
if (!isset($this->fldVector[$this->autoIncFld]))
{
$map[] = $this->autoIncFld;
$this->fldVector[$this->autoIncFld] = true;
$this->tableMap[$this->autoIncFld] = [
'data_type' => 'integer',
];
}
$this->initIndexFromField();
}
$this->dbType = MainHttpApplication::getConnection()->getType();
$this->mtu = (int)($parameters['parameters']['mtu'] ?? 0);
if ($this->mtu <= 0)
{
$this->mtu = 9999;
}
$this->mtu = min($this->mtu, (int)Helper::getMaxTransferUnit());
$this->insertHead = Helper::getBatchInsertHead($this->tableName, $map);
$this->insertTail = Helper::getBatchInsertTail();
if (
isset($parameters['parameters']['CALLBACKS']['ON_BEFORE_FLUSH'])
&& is_callable($parameters['parameters']['CALLBACKS']['ON_BEFORE_FLUSH'])
)
{
$this->callbacks['ON_BEFORE_FLUSH'] = $parameters['parameters']['CALLBACKS']['ON_BEFORE_FLUSH'];
}
$this->map = $map;
}