- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/uf/userfieldmanager.php
- Класс: BitrixDiskUfUserFieldManager
- Вызов: UserFieldManager::cloneUfValuesFromAttachedObject
public function cloneUfValuesFromAttachedObject(array $attachedIds, $userId): ?array
{
$this->errorCollection->clear();
$userId = (int)$userId;
if ($userId <= 0)
{
$this->errorCollection[] = new Error('Invalid $userId');
return null;
}
$userStorage = Driver::getInstance()->getStorageByUserId($userId);
if (!$userStorage)
{
$this->errorCollection[] = new Error("Could not find storage for user {$userId}");
$this->errorCollection->add(Driver::getInstance()->getErrors());
return null;
}
$folder = $userStorage->getFolderForUploadedFiles();
if (!$folder)
{
$this->errorCollection[] = new Error("Could not create/find folder for upload");
$this->errorCollection->add($userStorage->getErrors());
return null;
}
$newValues = [];
foreach ($attachedIds as $id)
{
[$type, $realValue] = FileUserType::detectType($id);
if (FileUserType::TYPE_ALREADY_ATTACHED != $type)
{
continue;
}
$attachedObject = AttachedObject::loadById($realValue, ['OBJECT']);
if (!$attachedObject)
{
continue;
}
if (!$attachedObject->canRead($userId))
{
continue;
}
$file = $attachedObject->getFile();
if (!$file)
{
continue;
}
if (!$attachedObject->isSpecificVersion())
{
$newFile = $file->copyTo($folder, $userId, true);
if (!$newFile)
{
$this->errorCollection->add($file->getErrors());
continue;
}
}
else
{
$version = $attachedObject->getVersion();
if (!$version)
{
continue;
}
$newFile = $version->createNewFile($folder, $userId, true);
if (!$newFile)
{
$this->errorCollection->add($file->getErrors());
continue;
}
}
$newValues[$id] = FileUserType::NEW_FILE_PREFIX . $newFile->getId();
}
return $newValues;
}