diff --git a/typo3/sysext/lowlevel/Classes/Command/MissingRelationsCommand.php b/typo3/sysext/lowlevel/Classes/Command/MissingRelationsCommand.php index 456e670511a15eaa21e5bb54c2b9e496283a4bf0..7efe7983dba68d11dcbb84111d29263b6b8f316c 100644 --- a/typo3/sysext/lowlevel/Classes/Command/MissingRelationsCommand.php +++ b/typo3/sysext/lowlevel/Classes/Command/MissingRelationsCommand.php @@ -29,6 +29,7 @@ use TYPO3\CMS\Core\Core\Bootstrap; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ReferenceIndex; +use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -337,14 +338,7 @@ If you want to get more detailed information, use the --verbose option.') $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 . '"'); - } - } + $this->removeReference($hash, $recordReference, $dryRun, $io); } } @@ -354,15 +348,29 @@ If you want to get more detailed information, use the --verbose option.') $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 . '"'); - } - } + $this->removeReference($hash, $recordReference, $dryRun, $io); + } + } + } + + /** + * Remove a reference to a missing record + */ + protected function removeReference(string $hash, string $recordReference, bool $dryRun, SymfonyStyle $io): void + { + $io->writeln('Removing reference in record "' . $recordReference . '" (Hash: ' . $hash . ')'); + if ($dryRun) { + return; + } + + $sysRefObj = GeneralUtility::makeInstance(ReferenceIndex::class); + try { + $error = $sysRefObj->setReferenceValue($hash, null); + if ($error) { + $io->error('ReferenceIndex::setReferenceValue() reported "' . $error . '"'); } + } catch (FileDoesNotExistException $e) { + $io->error('Unexpected exception thrown: ' . $e->getMessage()); } }