From: Martin Borer Date: Mon, 12 Aug 2013 10:44:46 +0000 (+0200) Subject: [BUGFIX] Fields of type file_reference are not properly indexed X-Git-Tag: TYPO3_6-2-0beta1~123 X-Git-Url: http://git.typo3.org/Packages/TYPO3.CMS.git/commitdiff_plain/1dcb94c3e2344ccd226b75e67ffc9cd6b81c144b [BUGFIX] Fields of type file_reference are not properly indexed sys_refindex entries for TCA-fields of type group->file_reference are not correct. The fields ref_table and ref_uid are not filled. This results in a wrong number of references in the Ref column of the Filelist module and prevents a warning that a resource is still in use when deleting it. Resolves: #49538 Releases: 6.2, 6.1, 6.0 Change-Id: I1c44fc98b7ceefd6247ec372e5b28f8682a47bf1 Reviewed-on: https://review.typo3.org/21764 Reviewed-by: Markus Klein Tested-by: Markus Klein Reviewed-by: Anja Leichsenring Tested-by: Anja Leichsenring --- diff --git a/typo3/sysext/core/Classes/Database/ReferenceIndex.php b/typo3/sysext/core/Classes/Database/ReferenceIndex.php index 3b812d672595..61eabc2ce45a 100644 --- a/typo3/sysext/core/Classes/Database/ReferenceIndex.php +++ b/typo3/sysext/core/Classes/Database/ReferenceIndex.php @@ -469,41 +469,55 @@ class ReferenceIndex { * @param string $value Field value * @param array $conf Field configuration array of type "TCA/columns * @param integer $uid Field uid - * @retur array If field type is OK it will return an array with the files inside. Else FALSE + * @return array If field type is OK it will return an array with the files inside. Else FALSE * @todo Define visibility */ public function getRelations_procFiles($value, $conf, $uid) { - if ($conf['type'] == 'group' && ($conf['internal_type'] == 'file' || $conf['internal_type'] == 'file_reference')) { - // Collect file values in array: - if ($conf['MM']) { - $theFileValues = array(); - $dbAnalysis = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler'); - $dbAnalysis->start('', 'files', $conf['MM'], $uid); - foreach ($dbAnalysis->itemArray as $somekey => $someval) { - if ($someval['id']) { - $theFileValues[] = $someval['id']; - } + if ($conf['type'] !== 'group' || ($conf['internal_type'] !== 'file' && $conf['internal_type'] !== 'file_reference')) { + return FALSE; + } + + // Collect file values in array: + if ($conf['MM']) { + $theFileValues = array(); + $dbAnalysis = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler'); + $dbAnalysis->start('', 'files', $conf['MM'], $uid); + foreach ($dbAnalysis->itemArray as $someval) { + if ($someval['id']) { + $theFileValues[] = $someval['id']; } - } else { - $theFileValues = explode(',', $value); } - // Traverse the files and add them: - $uploadFolder = $conf['internal_type'] == 'file' ? $conf['uploadfolder'] : ''; - $dest = $this->destPathFromUploadFolder($uploadFolder); - $newValueFiles = array(); - foreach ($theFileValues as $file) { - if (trim($file)) { - $realFile = $dest . '/' . trim($file); - $newValueFiles[] = array( - 'filename' => basename($file), - 'ID' => md5($realFile), - 'ID_absFile' => $realFile - ); + } else { + $theFileValues = explode(',', $value); + } + // Traverse the files and add them: + $uploadFolder = $conf['internal_type'] == 'file' ? $conf['uploadfolder'] : ''; + $dest = $this->destPathFromUploadFolder($uploadFolder); + $newValueFiles = array(); + foreach ($theFileValues as $file) { + if (trim($file)) { + $realFile = $dest . '/' . trim($file); + $newValueFile = array( + 'filename' => basename($file), + 'ID' => md5($realFile), + 'ID_absFile' => $realFile + ); + // Set sys_file and id for referenced files + if ($conf['internal_type'] === 'file_reference') { + try { + $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($file); + if ($file instanceof \TYPO3\CMS\Core\Resource\FileInterface) { + $newValueFile['table'] = 'sys_file'; + $newValueFile['id'] = $file->getUid(); + } + } catch (\Exception $e) { + + } } + $newValueFiles[] = $newValueFile; } - return $newValueFiles; } - return FALSE; + return $newValueFiles; } /**