/**
  * Initialize the storage repository.
  */
 public function init()
 {
     $this->storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
     $this->storages = $this->storageRepository->findAll();
     // Add default storage for core files
     $this->storages[] = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject(0);
 }
 /**
  * Retrieve page details from given page id
  *
  * @param integer $storageId
  * @param string $location
  * @return string Rendered string
  */
 public function render($storageId, $location = '/')
 {
     $output = null;
     if (!isset($this->storage[$storageId]) || !$this->storage[$storageId] instanceof \TYPO3\CMS\Core\Resource\ResourceStorage) {
         try {
             $this->storage[$storageId] = $this->storageRepository->findByUid($storageId);
         } catch (\Exception $e) {
         }
     }
     /** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */
     $storage = $this->storage[$storageId];
     if ($storage instanceof \TYPO3\CMS\Core\Resource\ResourceStorage) {
         $folder = null;
         try {
             $folder = $storage->getFolder($location);
         } catch (\Exception $e) {
         }
         if ($folder instanceof \TYPO3\CMS\Core\Resource\Folder) {
             $output = $folder->getPublicUrl();
         }
     }
     if (empty($output)) {
         $output = $storageId . ': ' . $location;
     }
     return $output;
 }
Exemple #3
0
 /**
  * Returns a ResourceStorage for a given uid
  *
  * @param int $storageUid
  * @return ResourceStorage
  * @throws PersistenceManagerException
  */
 protected function getStorageByUid(int $storageUid) : ResourceStorage
 {
     $storage = $this->storageRepository->findByUid($storageUid);
     if (!$storage instanceof ResourceStorage || !$storage->isBrowsable()) {
         throw new PersistenceManagerException(sprintf('Could not access storage with uid "%d".', $storageUid), 1471630581);
     }
     return $storage;
 }
 /**
  * @param $relFolderPath
  * @param $pathExists
  * @return \TYPO3\CMS\Core\Resource\Folder
  */
 protected function createFolderObject($relFolderPath, $pathExists)
 {
     if (!$pathExists) {
         $storage = $this->folderRepository->findByUid(1);
         return $this->fileFactory->createFolderObject($storage, $relFolderPath, 'upload_folder');
     } else {
         return $this->fileFactory->getFolderObjectFromCombinedIdentifier("1:{$relFolderPath}");
     }
 }
Exemple #5
0
 /**
  * Convert all PNG images (except processed) from specified storage.
  *
  * @param int $storageUid
  * @return boolean
  */
 public function convertStorage($storageUid)
 {
     $this->storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
     $storage = $this->storageRepository->findByUid($storageUid);
     if ($storage) {
         // Convert all storage files
         $files = $storage->getFilesInFolder($storage->getRootLevelFolder(FALSE), 0, 0, TRUE, TRUE);
         foreach ($files as $file) {
             if ($file instanceof File) {
                 $this->convertPngImage($file);
             }
             unset($file);
         }
     } else {
         $this->logger->error('No storage found', array('storage' => $storageUid));
         return FALSE;
     }
 }
 /**
  * @return \TYPO3\CMS\Core\Resource\ResourceStorage
  */
 protected function getDefaultStorage()
 {
     // Get the first storage available.
     // Notice if no storage is found, a storage is created on the fly.
     $storages = $this->storageRepository->findAll();
     // Makes sure to return a storage having a local driver
     foreach ($storages as $storage) {
     }
     /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
     return $storages[0];
 }
 /**
  * Takes the existing absolute filemounts (base=0) and migrates them to use
  * the existing fileadmin/ storage or a new storage.
  *
  * @return void
  */
 protected function migrateAbsoluteFilemounts()
 {
     $description = 'This is the local %s directory. This storage mount has been created by the TYPO3 upgrade wizards.';
     $fileadminDir = PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
     $absoluteFilemounts = $this->db->exec_SELECTgetRows('*', 'sys_filemounts', 'base = 0' . BackendUtility::deleteClause('sys_filemounts'));
     foreach ($absoluteFilemounts as $filemount) {
         if (stristr($filemount['path'], $fileadminDir)) {
             $storageId = $this->storage->getUid();
             $storagePath = rtrim(str_replace($fileadminDir, '', $filemount['path']), '/') . '/';
         } else {
             $storageId = $this->storageRepository->createLocalStorage($filemount['title'] . ' (auto-created)', $filemount['path'], 'absolute', sprintf($description, $filemount['path']));
             $storagePath = '/';
             $this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
         }
         $this->db->exec_UPDATEquery('sys_filemounts', 'uid=' . (int) $filemount['uid'], array('base' => $storageId, 'path' => $storagePath));
         $this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
     }
 }
 /**
  * Constructor
  *
  * @param StorageRepository $repository Application StorageRepository
  */
 public function __construct(StorageRepository $repository)
 {
     $this->storage = $repository->findByUid(self::$fileadminStorageId);
 }
 /**
  * Set the storage and folder to use for the Plugins
  *
  * @throws \Exception
  * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
  * @return void
  */
 protected function resolveStorageInformation()
 {
     $selectedFolderParts = explode(':', $this->settings['default']['folder']);
     $this->selectedStorage = $this->storageRepository->findByUid($selectedFolderParts[1]);
     $this->selectedFolder = $this->selectedStorage->getFolder($selectedFolderParts[2]);
 }
 /**
  * @param Share $share
  * @return \TYPO3\CMS\Core\Resource\File[]
  */
 private function getFilesFromShare(Share $share)
 {
     $storage = $this->storageRepository->findByUid($share->getStorage());
     $folder = $storage->getFolder($share->getFolder());
     return $folder->getFiles();
 }