/** * Removes all references in the sys_file_reference where files were not found * * @param array $missingManagedFiles Contains the records of sys_refindex which need to be updated * @param bool $dryRun if set, the references are just displayed, but not removed * @param SymfonyStyle $io the IO object for output * @return void */ protected function removeReferencesToMissingFiles(array $missingManagedFiles, bool $dryRun, SymfonyStyle $io) { foreach ($missingManagedFiles as $fileName => $references) { if ($io->isVeryVerbose()) { $io->writeln('Deleting references to missing file "' . $fileName . '"'); } foreach ($references as $hash => $recordReference) { $io->writeln('Removing reference in record "' . $recordReference . '"'); if (!$dryRun) { $sysRefObj = GeneralUtility::makeInstance(ReferenceIndex::class); $error = $sysRefObj->setReferenceValue($hash, null); if ($error) { $io->error('ReferenceIndex::setReferenceValue() reported "' . $error . '"'); } } } } }
/** * Removes given files from the uploads/ folder * * @param array $lostFiles Contains the lost files found * @param bool $dryRun if set, the files are just displayed, but not deleted * @param SymfonyStyle $io the IO object for output * @return void */ protected function deleteLostFiles(array $lostFiles, bool $dryRun, SymfonyStyle $io) { foreach ($lostFiles as $lostFile) { $absoluteFileName = GeneralUtility::getFileAbsFileName($lostFile); if ($io->isVeryVerbose()) { $io->writeln('Deleting file "' . $absoluteFileName . '"'); } if (!$dryRun) { if ($absoluteFileName && @is_file($absoluteFileName)) { unlink($absoluteFileName); if (!$io->isQuiet()) { $io->writeln('Permanently deleted file record "' . $absoluteFileName . '".'); } } else { $io->error('File "' . $absoluteFileName . '" was not found!'); } } } }
/** * Copies files which are referenced multiple times and updates the reference index so they are only used once * * @param array $multipleReferencesToFiles Contains files which have been referenced multiple times * @param bool $dryRun if set, the info is just displayed, but no files are copied nor reference index updated * @param SymfonyStyle $io the IO object for output * @return void */ protected function copyMultipleReferencedFiles(array $multipleReferencesToFiles, bool $dryRun, SymfonyStyle $io) { $fileFunc = GeneralUtility::makeInstance(BasicFileUtility::class); $referenceIndex = GeneralUtility::makeInstance(ReferenceIndex::class); foreach ($multipleReferencesToFiles as $fileName => $usages) { $absoluteFileName = GeneralUtility::getFileAbsFileName($fileName); if ($absoluteFileName && @is_file($absoluteFileName)) { if ($io->isVeryVerbose()) { $io->writeln('Processing file "' . $absoluteFileName . '"'); } $counter = 0; foreach ($usages as $hash => $recReference) { if ($counter++ === 0) { $io->writeln('Keeping "' . $fileName . '" for record "' . $recReference . '"'); } else { // Create unique name for file $newName = $fileFunc->getUniqueName(basename($fileName), dirname($absoluteFileName)); $io->writeln('Copying "' . $fileName . '" to "' . PathUtility::stripPathSitePrefix($newName) . '" for record "' . $recReference . '"'); if (!$dryRun) { GeneralUtility::upload_copy_move($absoluteFileName, $newName); clearstatcache(); if (@is_file($newName)) { $error = $referenceIndex->setReferenceValue($hash, basename($newName)); if ($error) { $io->error('ReferenceIndex::setReferenceValue() reported "' . $error . '"'); } } else { $io->error('File "' . $newName . '" could not be created.'); } } } } } else { $io->error('File "' . $absoluteFileName . '" was not found.'); } } }
/** * Removes all references to non-existing records or offline versions * * @param array $offlineVersionRecords Contains the records of offline versions of sys_refindex which need to be removed * @param array $nonExistingRecords Contains the records non-existing records of sys_refindex which need to be removed * @param bool $dryRun if set, the references are just displayed, but not removed * @param SymfonyStyle $io the IO object for output * @return void */ protected function removeReferencesToMissingRecords(array $offlineVersionRecords, array $nonExistingRecords, bool $dryRun, SymfonyStyle $io) { // Remove references to offline records foreach ($offlineVersionRecords as $fileName => $references) { if ($io->isVeryVerbose()) { $io->writeln('Removing references in offline versions which there are references pointing towards.'); } foreach ($references as $hash => $recordReference) { $io->writeln('Removing reference in record "' . $recordReference . '" (Hash: ' . $hash . ')'); if (!$dryRun) { $sysRefObj = GeneralUtility::makeInstance(ReferenceIndex::class); $error = $sysRefObj->setReferenceValue($hash, null); if ($error) { $io->error('ReferenceIndex::setReferenceValue() reported "' . $error . '"'); } } } } // Remove references to non-existing records foreach ($nonExistingRecords as $fileName => $references) { if ($io->isVeryVerbose()) { $io->writeln('Removing references to non-existing records.'); } foreach ($references as $hash => $recordReference) { $io->writeln('Removing reference in record "' . $recordReference . '" (Hash: ' . $hash . ')'); if (!$dryRun) { $sysRefObj = GeneralUtility::makeInstance(ReferenceIndex::class); $error = $sysRefObj->setReferenceValue($hash, null); if ($error) { $io->error('ReferenceIndex::setReferenceValue() reported "' . $error . '"'); } } } } }