Exemplo n.º 1
0
 /**
  * Updates the properties of a file object with some that are freshly
  * fetched from the driver.
  *
  * @param \TYPO3\CMS\Core\Resource\AbstractFile $file
  * @param string $identifier The identifier of the file. If set, this will overwrite the file object's identifier (use e.g. after moving a file)
  * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
  * @return void
  */
 protected function updateFile(\TYPO3\CMS\Core\Resource\AbstractFile $file, $identifier = '', $storage = NULL)
 {
     if ($identifier === '') {
         $identifier = $file->getIdentifier();
     }
     $fileInfo = $this->driver->getFileInfoByIdentifier($identifier);
     // TODO extend mapping
     $newProperties = array('storage' => $fileInfo['storage'], 'identifier' => $fileInfo['identifier'], 'tstamp' => $fileInfo['mtime'], 'crdate' => $fileInfo['ctime'], 'mime_type' => $fileInfo['mimetype'], 'size' => $fileInfo['size'], 'name' => $fileInfo['name']);
     if ($storage !== NULL) {
         $newProperties['storage'] = $storage->getUid();
     }
     $file->updateProperties($newProperties);
     /** @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */
     $fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
     $fileRepository->update($file);
 }
Exemplo n.º 2
0
 /**
  * Adds a file from the local server hard disk to a given path in TYPO3s virtual file system.
  *
  * This assumes that the local file exists, so no further check is done here!
  *
  * @param string $localFilePath
  * @param \TYPO3\CMS\Core\Resource\Folder $targetFolder
  * @param string $fileName The name to add the file under
  * @param \TYPO3\CMS\Core\Resource\AbstractFile $updateFileObject File object to update (instead of creating a new object). With this parameter, this function can be used to "populate" a dummy file object with a real file underneath.
  * @todo \TYPO3\CMS\Core\Resource\File $updateFileObject should be \TYPO3\CMS\Core\Resource\FileInterface, but indexer logic is only in \TYPO3\CMS\Core\Resource\File
  * @return \TYPO3\CMS\Core\Resource\FileInterface
  */
 public function addFile($localFilePath, \TYPO3\CMS\Core\Resource\Folder $targetFolder, $fileName, \TYPO3\CMS\Core\Resource\AbstractFile $updateFileObject = NULL)
 {
     // as for the "virtual storage" for backwards-compatibility, this check always fails, as the file probably lies under PATH_site
     // thus, it is not checked here
     if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($localFilePath, $this->absoluteBasePath) && $this->storage->getUid() > 0) {
         throw new \InvalidArgumentException('Cannot add a file that is already part of this storage.', 1314778269);
     }
     $relativeTargetPath = ltrim($targetFolder->getIdentifier(), '/');
     $relativeTargetPath .= $fileName ? $fileName : basename($localFilePath);
     $targetPath = $this->absoluteBasePath . $relativeTargetPath;
     if (is_uploaded_file($localFilePath)) {
         $moveResult = move_uploaded_file($localFilePath, $targetPath);
     } else {
         $moveResult = rename($localFilePath, $targetPath);
     }
     if ($moveResult !== TRUE) {
         throw new \RuntimeException('Moving file ' . $localFilePath . ' to ' . $targetPath . ' failed.', 1314803096);
     }
     clearstatcache();
     // Change the permissions of the file
     \TYPO3\CMS\Core\Utility\GeneralUtility::fixPermissions($targetPath);
     $fileInfo = $this->getFileInfoByIdentifier($relativeTargetPath);
     if ($updateFileObject) {
         $updateFileObject->updateProperties($fileInfo);
         return $updateFileObject;
     } else {
         $fileObject = $this->getFileObject($fileInfo);
         return $fileObject;
     }
 }