/**
* Imports the given temporary file into the storage and creates the new resource object.
*
* Note: the temporary file is (re-)moved by this method.
*
* @param string $temporaryPathAndFileName
* @param string $collectionName
* @return PersistentResource
* @throws StorageException
*/
protected function importTemporaryFile($temporaryPathAndFileName, $collectionName)
{
$this->fixFilePermissions($temporaryPathAndFileName);
$sha1Hash = sha1_file($temporaryPathAndFileName);
$targetPathAndFilename = $this->getStoragePathAndFilenameByHash($sha1Hash);
if (!is_file($targetPathAndFilename)) {
$this->moveTemporaryFileToFinalDestination($temporaryPathAndFileName, $targetPathAndFilename);
} else {
unlink($temporaryPathAndFileName);
}
$resource = new PersistentResource();
$resource->setFileSize(filesize($targetPathAndFilename));
$resource->setCollectionName($collectionName);
$resource->setSha1($sha1Hash);
$resource->setMd5(md5_file($targetPathAndFilename));
return $resource;
}