/** * Populates the content-entries of the storage * * Queries the underlying storage for entries of the collection * and adds them to the collection data. * * If the content entries of the storage had not been loaded on creation * ($fillItems = false) this function is to be used for loading the contents * afterwards. * * @return void */ public function loadContents() { $entries = $this->folder->getFiles(); foreach ($entries as $entry) { $this->add($entry); } }
/** * Populates the content-entries of the storage * * Queries the underlying storage for entries of the collection * and adds them to the collection data. * * If the content entries of the storage had not been loaded on creation * ($fillItems = false) this function is to be used for loading the contents * afterwards. * * @return void */ public function loadContents() { if ($this->folder instanceof Folder) { $entries = $this->folder->getFiles(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $this->recursive); foreach ($entries as $entry) { $this->add($entry); } } }
/** * Populates the content-entries of the storage * * Queries the underlying storage for entries of the collection * and adds them to the collection data. * * If the content entries of the storage had not been loaded on creation * ($fillItems = false) this function is to be used for loading the contents * afterwards. * * @return void */ public function loadContents() { if ($this->folder instanceof \TYPO3\CMS\Core\Resource\Folder) { $entries = $this->folder->getFiles(); foreach ($entries as $entry) { $this->add($entry); } } }
/** * Gets a list of all files in a directory recursively and removes * old ones. * * @param Folder $folder the folder * @param int $timestamp Timestamp of the last file modification */ protected function cleanupRecycledFiles(Folder $folder, $timestamp) { foreach ($folder->getFiles() as $file) { if ($timestamp > $file->getModificationTime()) { $file->delete(); } } foreach ($folder->getSubfolders() as $subFolder) { $this->cleanupRecycledFiles($subFolder, $timestamp); // if no more files and subdirectories are in the folder, remove the folder as well if ($subFolder->getFileCount() === 0 && count($subFolder->getSubfolders()) === 0) { $subFolder->delete(true); } } }
/** * Returns a table with directories and files listed. * * @param array $rowlist Array of files from path * @return string HTML-table */ public function getTable($rowlist) { // prepare space icon $this->spaceIcon = '<span class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</span>'; // @todo use folder methods directly when they support filters $storage = $this->folderObject->getStorage(); $storage->resetFileAndFolderNameFiltersToDefault(); // Only render the contents of a browsable storage if ($this->folderObject->getStorage()->isBrowsable()) { try { $foldersCount = $storage->countFoldersInFolder($this->folderObject); $filesCount = $storage->countFilesInFolder($this->folderObject); } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) { $foldersCount = 0; $filesCount = 0; } if ($foldersCount <= $this->firstElementNumber) { $foldersFrom = FALSE; $foldersNum = FALSE; } else { $foldersFrom = $this->firstElementNumber; if ($this->firstElementNumber + $this->iLimit > $foldersCount) { $foldersNum = $foldersCount - $this->firstElementNumber; } else { $foldersNum = $this->iLimit; } } if ($foldersCount >= $this->firstElementNumber + $this->iLimit) { $filesFrom = FALSE; $filesNum = FALSE; } else { if ($this->firstElementNumber <= $foldersCount) { $filesFrom = 0; $filesNum = $this->iLimit - $foldersNum; } else { $filesFrom = $this->firstElementNumber - $foldersCount; if ($filesFrom + $this->iLimit > $filesCount) { $filesNum = $filesCount - $filesFrom; } else { $filesNum = $this->iLimit; } } } $folders = $storage->getFoldersInFolder($this->folderObject, $foldersFrom, $foldersNum, TRUE, FALSE, trim($this->sort), (bool) $this->sortRev); $files = $this->folderObject->getFiles($filesFrom, $filesNum, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, FALSE, trim($this->sort), (bool) $this->sortRev); $this->totalItems = $foldersCount + $filesCount; // Adds the code of files/dirs $out = ''; $titleCol = 'file'; // Cleaning rowlist for duplicates and place the $titleCol as the first column always! $rowlist = '_LOCALIZATION_,' . $rowlist; $rowlist = GeneralUtility::rmFromList($titleCol, $rowlist); $rowlist = GeneralUtility::uniqueList($rowlist); $rowlist = $rowlist ? $titleCol . ',' . $rowlist : $titleCol; if ($this->clipBoard) { $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CLIPBOARD_,', $rowlist); $this->addElement_tdCssClass['_CLIPBOARD_'] = 'col-clipboard'; } if ($this->bigControlPanel) { $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CONTROL_,', $rowlist); $this->addElement_tdCssClass['_CONTROL_'] = 'col-control'; } $this->fieldArray = explode(',', $rowlist); // Add classes to table cells $this->addElement_tdCssClass[$titleCol] = 'col-title'; $this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa'; $folders = ListUtility::resolveSpecialFolderNames($folders); $iOut = ''; // Directories are added $this->eCounter = $this->firstElementNumber; list($flag, $code) = $this->fwd_rwd_nav(); $iOut .= $code; $iOut .= $this->formatDirList($folders); // Files are added $iOut .= $this->formatFileList($files); $this->eCounter = $this->firstElementNumber + $this->iLimit <= $this->totalItems ? $this->firstElementNumber + $this->iLimit : $this->totalItems; list($flag, $code) = $this->fwd_rwd_nav(); $iOut .= $code; // Header line is drawn $theData = array(); foreach ($this->fieldArray as $v) { if ($v == '_CLIPBOARD_' && $this->clipBoard) { $cells = array(); $table = '_FILE'; $elFromTable = $this->clipObj->elFromTable($table); if (!empty($elFromTable) && $this->folderObject->checkActionPermission('write')) { $addPasteButton = TRUE; $elToConfirm = array(); foreach ($elFromTable as $key => $element) { $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element); if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject)) { $addPasteButton = FALSE; } $fileInfo = $clipBoardElement->getStorage()->getFileInfoByIdentifier(substr(strstr($element, ':'), 1)); $elToConfirm[$key] = $fileInfo['name']; } if ($addPasteButton) { $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $this->folderObject->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $this->path, 'into', $elToConfirm)) . '" title="' . $this->getLanguageService()->getLL('clip_paste', 1) . '">' . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>'; } } if ($this->clipObj->current !== 'normal' && $iOut) { $cells[] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-copy', array('title' => $this->getLanguageService()->getLL('clip_selectMarked', TRUE))), $table, 'setCB'); $cells[] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $this->getLanguageService()->getLL('clip_deleteMarked'))), $table, 'delete', $this->getLanguageService()->getLL('clip_deleteMarkedWarning')); $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;'; $cells[] = '<a class="btn btn-default" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->getLL('clip_markRecords', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-select') . '</a>'; } $theData[$v] = implode('', $cells); } else { // Normal row: $theT = $this->linkWrapSort($this->getLanguageService()->getLL('c_' . $v, TRUE), $this->folderObject->getCombinedIdentifier(), $v); $theData[$v] = $theT; } } $out .= '<thead>' . $this->addelement(1, '', $theData, '', '', '', 'th') . '</thead>'; $out .= '<tbody>' . $iOut . '</tbody>'; // half line is drawn // finish $out = ' <!-- File list table: --> <div class="table-fit"> <table class="table table-striped table-hover" id="typo3-filelist"> ' . $out . ' </table> </div>'; } else { /** @var $flashMessage FlashMessage */ $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->getLanguageService()->getLL('storageNotBrowsableMessage'), $this->getLanguageService()->getLL('storageNotBrowsableTitle'), FlashMessage::INFO); $out = $flashMessage->render(); } return $out; }
/** * Get a list of Files in a folder filtered by extension * * @param Folder $folder * @param array $extensionList * @return File[] */ protected function getFilesInFolder(Folder $folder, array $extensionList) { if (!empty($extensionList)) { /** @var FileExtensionFilter $filter */ $filter = GeneralUtility::makeInstance(FileExtensionFilter::class); $filter->setAllowedFileExtensions($extensionList); $folder->setFileAndFolderNameFilters(array(array($filter, 'filterFileList'))); } return $folder->getFiles(); }
/** * Get a list of Files in a folder filtered by extension * * @param \TYPO3\CMS\Core\Resource\Folder $folder * @param string $extensionList * @return \TYPO3\CMS\Core\Resource\File[] */ protected function getFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList) { if ($extensionList !== '') { /** @var \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter $filter */ $filter = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter'); $filter->setAllowedFileExtensions($extensionList); $folder->setFileAndFolderNameFilters(array(array($filter, 'filterFileList'))); } return $folder->getFiles(); }
/** * Indexes all files in a given storage folder. * currently this is done in a simple way, however could be changed to be more performant * * @param \TYPO3\CMS\Core\Resource\Folder $folder * @return int The number of indexed files. */ public function indexFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder) { $numberOfIndexedFiles = 0; // Index all files in this folder $fileObjects = $folder->getFiles(); // emit signal $this->emitPreMultipleFilesIndexSignal($fileObjects); foreach ($fileObjects as $fileObject) { $this->indexFile($fileObject); $numberOfIndexedFiles++; } // emit signal $this->emitPostMultipleFilesIndexSignal($fileObjects); // Call this function recursively for each subfolder $subFolders = $folder->getSubfolders(); foreach ($subFolders as $subFolder) { $numberOfIndexedFiles += $this->indexFilesInFolder($subFolder); } return $numberOfIndexedFiles; }
/** * Checks files in given folder recursively for for existing references. * * Creates a flash message if there are references. * * @param Folder $folder * @return bool TRUE if folder has files in use, FALSE otherwise */ public function folderHasFilesInUse(Folder $folder) { $files = $folder->getFiles(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, TRUE); if (empty($files)) { return FALSE; } /** @var int[] $fileUids */ $fileUids = array(); foreach ($files as $file) { $fileUids[] = $file->getUid(); } $numberOfReferences = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'sys_refindex', 'deleted=0 AND ref_table="sys_file" AND ref_uid IN (' . implode(',', $fileUids) . ') AND tablename<>"sys_file_metadata"'); $hasReferences = $numberOfReferences > 0; if ($hasReferences) { /** @var FlashMessage $flashMessage */ $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFilesWithReferences'), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFilesWithReferences'), FlashMessage::WARNING, TRUE); $this->addFlashMessage($flashMessage); } return $hasReferences; }
/** * Returns a table with directories and files listed. * * @param array $rowlist Array of files from path * @return string HTML-table * @todo Define visibility */ public function getTable($rowlist) { // TODO use folder methods directly when they support filters $storage = $this->folderObject->getStorage(); $storage->resetFileAndFolderNameFiltersToDefault(); // Only render the contents of a browsable storage if ($this->folderObject->getStorage()->isBrowsable()) { $folders = $storage->getFolderIdentifiersInFolder($this->folderObject->getIdentifier()); $files = $this->folderObject->getFiles(); $this->sort = trim($this->sort); if ($this->sort !== '') { $filesToSort = array(); /** @var $fileObject \TYPO3\CMS\Core\Resource\File */ foreach ($files as $fileObject) { switch ($this->sort) { case 'size': $sortingKey = $fileObject->getSize(); break; case 'rw': $sortingKey = $fileObject->checkActionPermission('read') ? 'R' : '' . $fileObject->checkActionPermission('write') ? 'W' : ''; break; case 'fileext': $sortingKey = $fileObject->getExtension(); break; case 'tstamp': $sortingKey = $fileObject->getModificationTime(); break; case 'file': $sortingKey = $fileObject->getName(); break; default: if ($fileObject->hasProperty($this->sort)) { $sortingKey = $fileObject->getProperty($this->sort); } else { $sortingKey = $fileObject->getName(); } } $i = 1000000; while (isset($filesToSort[$sortingKey . $i])) { $i++; } $filesToSort[$sortingKey . $i] = $fileObject; } uksort($filesToSort, 'strnatcasecmp'); if ((int) $this->sortRev === 1) { $filesToSort = array_reverse($filesToSort); } $files = $filesToSort; } $this->totalItems = count($folders) + count($files); // Adds the code of files/dirs $out = ''; $titleCol = 'file'; // Cleaning rowlist for duplicates and place the $titleCol as the first column always! $rowlist = GeneralUtility::rmFromList($titleCol, $rowlist); $rowlist = GeneralUtility::uniqueList($rowlist); $rowlist = $rowlist ? $titleCol . ',' . $rowlist : $titleCol; if ($this->bigControlPanel || $this->clipBoard) { $rowlist = str_replace('file,', 'file,_CLIPBOARD_,', $rowlist); } $this->fieldArray = explode(',', $rowlist); $folderObjects = array(); foreach ($folders as $folder) { $folderObjects[] = $storage->getFolder($folder, TRUE); } $folderObjects = \TYPO3\CMS\Core\Resource\Utility\ListUtility::resolveSpecialFolderNames($folderObjects); uksort($folderObjects, 'strnatcasecmp'); // Directories are added $iOut = $this->formatDirList($folderObjects); // Files are added $iOut .= $this->formatFileList($files, $titleCol); // Header line is drawn $theData = array(); foreach ($this->fieldArray as $v) { if ($v == '_CLIPBOARD_' && $this->clipBoard) { $cells = array(); $table = '_FILE'; $elFromTable = $this->clipObj->elFromTable($table); if (count($elFromTable) && $this->folderObject->checkActionPermission('write')) { $addPasteButton = TRUE; foreach ($elFromTable as $element) { $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element); if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject)) { $addPasteButton = FALSE; } } if ($addPasteButton) { $cells[] = '<a class="btn" href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $this->folderObject->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $this->path, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', 1) . '">' . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>'; } } if ($this->clipObj->current != 'normal' && $iOut) { $cells[] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-copy', array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', TRUE))), $table, 'setCB'); $cells[] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked'))), $table, 'delete', $GLOBALS['LANG']->getLL('clip_deleteMarkedWarning')); $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;'; $cells[] = '<a class="cbcCheckAll" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-select') . '</a>'; } $theData[$v] = implode('', $cells); } else { // Normal row: $theT = $this->linkWrapSort($GLOBALS['LANG']->getLL('c_' . $v, TRUE), $this->folderObject->getCombinedIdentifier(), $v); $theData[$v] = $theT; } } $out .= '<thead>' . $this->addelement(1, ' ', $theData) . '</thead>'; $out .= '<tbody>' . $iOut . '</tbody>'; // half line is drawn // finish $out = ' <!-- File list table: --> <table class="t3-table" id="typo3-filelist"> ' . $out . ' </table>'; } else { /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */ $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('storageNotBrowsableMessage'), $GLOBALS['LANG']->getLL('storageNotBrowsableTitle'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO); $out = $flashMessage->render(); } return $out; }
/** * Retrieve data from a file reference * * @param \TYPO3\CMS\Core\Resource\ResourceInterface|Folder|\TYPO3\CMS\Core\Resource\AbstractFile $originalResource * @return array */ protected function transformFileReference($originalResource) { static $depth = 0; if ($originalResource instanceof AbstractFileFolder) { if (++$depth > 10) { throw new \RuntimeException('Max nesting level'); } $result = $this->transformFileReference($originalResource->getOriginalResource()); $depth--; return $result; } try { if ($originalResource instanceof Folder) { $filesInFolder = array(); foreach ($originalResource->getFiles() as $currentFile) { $filesInFolder[] = $this->transformFileReference($currentFile); } return $filesInFolder; } if ($originalResource instanceof FileReference) { // This would expose all data // return $originalResource->getProperties(); list($title, $description) = $this->getTitleAndDescription($originalResource); return array('name' => $originalResource->getName(), 'mimeType' => $originalResource->getMimeType(), 'url' => $originalResource->getPublicUrl(), 'size' => $originalResource->getSize(), 'title' => $title, 'description' => $description); } if ($originalResource instanceof FileInterface) { return array('name' => $originalResource->getName(), 'mimeType' => $originalResource->getMimeType(), 'url' => $originalResource->getPublicUrl(), 'size' => $originalResource->getSize()); } return array('name' => $originalResource->getName()); } catch (\RuntimeException $exception) { return array(); } }
/** * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images. * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE * * @param \TYPO3\CMS\Core\Resource\Folder $folder The folder path to expand * @param string $extensionList List of fileextensions to show * @return string HTML output * @todo Define visibility */ public function TBE_dragNDrop(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '') { $extensionList = $extensionList == '*' ? '' : $extensionList; $out = ''; if ($folder) { if ($folder->getStorage()->isPublic()) { // Read files from directory: $files = $folder->getFiles($extensionList); if (is_array($files)) { $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files))); $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']); $picon = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />'; $picon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen)); $out .= $picon . '<br />'; // Init row-array: $lines = array(); // Add "drag-n-drop" message: $lines[] = ' <tr> <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td> </tr>'; // Traverse files: foreach ($files as $fileObject) { $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject); // URL of image: $iUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE)); // Show only web-images $fileExtension = strtolower($fileObject->getExtension()); if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) { $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE)); $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels'; $size = ' (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')'; $filenameAndIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size)); if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('noLimit')) { $maxW = 10000; $maxH = 10000; } else { $maxW = 380; $maxH = 500; } $IW = $imgInfo[0]; $IH = $imgInfo[1]; if ($IW > $maxW) { $IH = ceil($IH / $IW * $maxW); $IW = $maxW; } if ($IH > $maxH) { $IW = ceil($IW / $IH * $maxH); $IH = $maxH; } // Make row: $lines[] = ' <tr class="bgColor4"> <td nowrap="nowrap">' . $filenameAndIcon . ' </td> <td nowrap="nowrap">' . ($imgInfo[0] != $IW ? '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('noLimit' => '1'))) . '">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', 1) . '" alt="" />' . '</a>' : '') . $pDim . ' </td> </tr>'; $lines[] = ' <tr> <td colspan="2"><img src="' . $iUrl . '" data-htmlarea-file-uid="' . $fileObject->getUid() . '" width="' . $IW . '" height="' . $IH . '" border="1" alt="" /></td> </tr>'; $lines[] = ' <tr> <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td> </tr>'; } } // Finally, wrap all rows in a table tag: $out .= ' <!-- File listing / Drag-n-drop --> <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox"> ' . implode('', $lines) . ' </table>'; } } else { // Print this warning if the folder is NOT a web folder: $out .= $this->barheader($GLOBALS['LANG']->getLL('files')); $out .= $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2'); } } return $out; }
/** * Indexes all files in a given storage folder. * currently this is done in a simple way, however could be changed to be more performant * * @param \TYPO3\CMS\Core\Resource\Folder $folder * @return integer The number of indexed files. */ public function indexFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder) { $numberOfIndexedFiles = 0; $fileIdentifiers = array(); // Index all files in this folder $fileObjects = $folder->getFiles(); // emit signal $this->emitPreMultipleFilesIndexSignal($fileObjects); foreach ($fileObjects as $fileObject) { $this->indexFile($fileObject); $fileIdentifiers[] = $fileObject->getIdentifier(); $numberOfIndexedFiles++; } // check for deleted files (file not found during indexing are marked as missing) $fileIndexRecords = $this->getFileIndexRepository()->findByFolder($folder); foreach ($fileIndexRecords as $file) { if (!in_array($file['identifier'], $fileIdentifiers)) { /** @var $fileObject File */ $fileObject = $this->getRepository()->findByIdentifier($file['uid']); $fileObject->setMissing(TRUE); $this->getFileIndexRepository()->update($fileObject); } } // emit signal $this->emitPostMultipleFilesIndexSignal($fileObjects); // cleanup to prevent to much memory use on big folders unset($fileObjects); unset($fileIdentifiers); // Call this function recursively for each subfolder $subFolders = $folder->getSubfolders(); foreach ($subFolders as $subFolder) { $numberOfIndexedFiles += $this->indexFilesInFolder($subFolder); } return $numberOfIndexedFiles; }
/** * Checks files in given folder recursively for for existing references. * * Creates a flash message if there are references. * * @param Folder $folder * @return bool TRUE if folder has files in use, FALSE otherwise */ public function folderHasFilesInUse(Folder $folder) { $files = $folder->getFiles(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true); if (empty($files)) { return false; } /** @var int[] $fileUids */ $fileUids = []; foreach ($files as $file) { $fileUids[] = $file->getUid(); } $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex'); $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $numberOfReferences = $queryBuilder->count('hash')->from('sys_refindex')->where($queryBuilder->expr()->eq('ref_table', $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)), $queryBuilder->expr()->in('ref_uid', $queryBuilder->createNamedParameter($fileUids, Connection::PARAM_INT_ARRAY)), $queryBuilder->expr()->neq('tablename', $queryBuilder->createNamedParameter('sys_file_metadata', \PDO::PARAM_STR)))->execute()->fetchColumn(0); $hasReferences = $numberOfReferences > 0; if ($hasReferences) { /** @var FlashMessage $flashMessage */ $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:message.description.folderNotDeletedHasFilesWithReferences'), $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:message.header.folderNotDeletedHasFilesWithReferences'), FlashMessage::WARNING, true); $this->addFlashMessage($flashMessage); } return $hasReferences; }
/** * @param Folder $folder * @param string $extensionList * * @return FileInterface[]|Folder[] */ protected function getFolderContent(Folder $folder, $extensionList) { if ($extensionList !== '') { /** @var FileExtensionFilter $filter */ $filter = GeneralUtility::makeInstance(FileExtensionFilter::class); $filter->setAllowedFileExtensions($extensionList); $folder->setFileAndFolderNameFilters([[$filter, 'filterFileList']]); } return $folder->getFiles(); }
/** * @param Folder $folder * @return array */ protected function getFileUids(Folder $folder) { $files = array(); foreach ($folder->getFiles() as $file) { $files[] = $file->getUid(); } return $files; }