Last active
December 19, 2015 15:19
-
-
Save sorenmalling/5975542 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processDatamap_postProcessFieldArray ($status, $table, $id, &$fieldArray, $parentObject) { | |
if($table == 'sys_file_collection' && in_array($status, array('update', 'new'))) { | |
if(array_key_exists('uploadfile', $fieldArray)) { | |
$uploadFolder = $GLOBALS['TCA'][$table]['columns']['uploadfile']['config']['uploadfolder']; | |
$uploadedImages = explode(',', $fieldArray['uploadfile']); | |
unset($fieldArray['uploadfile']); // Don't want it to get persistsed as it serves a dummy | |
/** @var $fileCollectionRepository TYPO3\CMS\Core\Resource\FileCollectionRepository */ | |
$fileCollectionRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileCollectionRepository'); | |
$fileCollectionObject = $fileCollectionRepository->findByUid($id); | |
$fileCollectionObject->loadContents(); | |
/** @var $resourceFactory \TYPO3\CMS\Core\Resource\ResourceFactory */ | |
$resourceFactory = \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($resourceFactory); | |
// run indexing of every storage | |
$storageRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_file_storage', 'deleted = 0 AND uid = 4'); | |
foreach ($uploadedImages as $image) { | |
$fileObject = $resourceFactory->getFileObjectFromCombinedIdentifier('4:' . $image); #retrieveFileOrFolderObject($uploadFolder . DIRECTORY_SEPARATOR . $image); | |
$indexedFileObject = $indexerService->indexFile($fileObject); | |
$fileCollectionObject->add($indexedFileObject); | |
} | |
$fileCollectionObject->persist(); // Nothing is persisted, no file objects are saved to the collection | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment