Skip to content

Instantly share code, notes, and snippets.

@sorenmalling
Created July 11, 2013 10:08
Show Gist options
  • Save sorenmalling/5974235 to your computer and use it in GitHub Desktop.
Save sorenmalling/5974235 to your computer and use it in GitHub Desktop.
A modified TCA field ("group") followed by indexing 'config' => array( 'type' => 'group', 'size' => '30', 'internal_type' => 'file', 'allowed' => 'jpg,png,gif,bmp,tiff,tif', 'disable_controls' => 'browser,list,delete', 'maxitems' => 999, 'uploadfolder' => 'fileadmin/gallerier' ) causing the following exception "Cannot add a file that is already …
$uploadFolder = $GLOBALS['TCA'][$table]['columns']['fileupload']['config']['uploadfolder'];
$uploadedImages = explode(',', $fieldArray['fileupload']);
/** @var $fileCollectionRepository TYPO3\CMS\Core\Resource\FileCollectionRepository */
// $fileCollectionRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileCollectionRepository');
// $fileCollectionObject = $fileCollectionRepository->findByUid($id);
/** @var $fileFactory \TYPO3\CMS\Core\Resource\ResourceFactory */
$fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
/** @var $indexerService \TYPO3\CMS\Core\Resource\Service\IndexerService */
$indexerService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService');
$indexerService->setFactory($fileFactory);
// run indexing of every storage
$storageRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_file_storage', 'deleted = 0 AND uid = 4');
foreach ($uploadedImages as $image) {
$storageObject = $fileFactory->getStorageObject($storageRecord['uid'], $storageRecord);
$rootLevelFolder = $storageObject->getRootLevelFolder();
$addedImage = $storageObject->addFile(PATH_site . $uploadFolder . DIRECTORY_SEPARATOR . $image, $storageObject->getRootLevelFolder());
// $fileCollectionObject->add($fileObject);
}
// $fileCollectionRepository->update($fileCollectionObject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment