- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/file.php
- Класс: BitrixDiskFile
- Вызов: File::moveToAnotherFolder
public function moveToAnotherFolder(Folder $folder, $movedBy, $generateUniqueName = false)
{
$realFolderId = $folder->getRealObject()->getId();
if($this->getParentId() == $realFolderId)
{
return true;
}
$possibleNewName = $this->name;
if($generateUniqueName)
{
$possibleNewName = static::generateUniqueName($this->name, $realFolderId);
}
$needToRename = $possibleNewName != $this->name;
if(!static::isUniqueName($possibleNewName, $realFolderId))
{
$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_OBJECT_MODEL_ERROR_NON_UNIQUE_NAME'), self::ERROR_NON_UNIQUE_NAME)));
return false;
}
$this->name = $possibleNewName;
if($needToRename)
{
$successUpdate = $this->update(array(
'NAME' => $possibleNewName
));
if(!$successUpdate)
{
return false;
}
}
/** @var FileTable $tableClassName */
$tableClassName = $this->getTableClassName();
$moveResult = $tableClassName::move($this->id, $realFolderId);
if(!$moveResult->isSuccess())
{
$this->errorCollection->addFromResult($moveResult);
return false;
}
$this->setAttributesFromResult($moveResult);
Driver::getInstance()->getRightsManager()->setAfterMove($this);
$subscribersAfterMove = Driver::getInstance()->collectSubscribers($this);
Driver::getInstance()->sendChangeStatus($subscribersAfterMove);
if($folder->getRealObject()->getStorageId() != $this->storageId)
{
$changeStorageIdResult = $tableClassName::changeStorageId($this->id, $folder->getRealObject()->getStorageId());
if(!$changeStorageIdResult->isSuccess())
{
$this->errorCollection->addFromResult($changeStorageIdResult);
return false;
}
}
$success = $this->update(array(
'UPDATE_TIME' => new DateTime(),
'UPDATED_BY' => $movedBy,
));
if(!$success)
{
return null;
}
return $this;
}