- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/location/import/import.php
- Класс: BitrixSaleLocationImportImportProcess
- Вызов: ImportProcess::stageDownloadFiles
protected function stageDownloadFiles()
{
if($this->checkSource(self::SOURCE_FILE)) // user uploaded file
{
$this->data['files'] = array(
array(
'size' => filesize($_SERVER['DOCUMENT_ROOT'].self::LOCAL_PATH.self::getFileNameByIndex(0)),
'memgroup' => 'static'
)
);
$this->nextStage();
}
elseif($this->checkSource(self::SOURCE_REMOTE)) // get locations from remote server
{
if($this->getStep() == 0)
{
$this->data['files'] = array();
$this->cleanWorkDirectory();
// layout
$this->determineLayoutToImport();
// type groups
$typeGroups = $this->getRemoteTypeGroups();
// find out what groups we will include
$this->data['requiredGroups'] = array();
foreach($typeGroups as $code => $types)
{
if($code == 'LAYOUT') // layout is always included
continue;
foreach($types as $type)
{
if(isset($this->data['types']['allowed'][$type]))
{
$this->data['requiredGroups'][] = ToLower($code);
break;
}
}
}
}
else
{
if($this->getStep() == 1) // get layout (root) file
{
$this->data['files'][0] = array(
'size' => $this->downloadFile(self::REMOTE_LAYOUT_FILE, self::getFileNameByIndex(0)),
'onlyThese' => array_flip($this->data['settings']['bundles']['allpoints']),
'memgroup' => 'static'
);
$this->data['fileDownload']['currentEndPoint'] = 0;
$this->data['fileDownload']['currentFileOffset'] = 1;
}
$i =& $this->data['fileDownload']['currentEndPoint'];
$j =& $this->data['fileDownload']['currentFileOffset'];
while($this->checkQuota() && isset($this->data['settings']['bundles']['endpoints'][$i])) // process as many bundles as possible
{
$ep = $this->data['settings']['bundles']['endpoints'][$i];
foreach($this->data['requiredGroups'] as $code)
{
$name = self::getFileNameByIndex($j);
$file = self::REMOTE_SETS_PATH.$ep.'_'.$code.'.csv';
try
{
$this->data['files'][$j] = array(
'size' => $this->downloadFile($file, $name),
'memgroup' => $ep
);
$j++;
}
catch(MainSystemException $e) // 404 or smth - just skip for now
{
}
}
$i++;
}
if(!isset($this->data['settings']['bundles']['endpoints'][$i])) // no more bundles to process, all files downloaded
{
unset($this->data['requiredGroups']);
unset($this->data['settings']['bundles']['endpoints']);
$this->nextStage();
return;
}
}
$this->nextStep();
}
}