Project

General

Profile

Bug #62480 » deleteFileWithBrokenReferences.patch

Cornel Boppart, 2014-10-26 19:45

View differences:

typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
);
if (count($refIndexRecords) > 0) {
$shortcutContent = array();
$brokenReferences = array();
foreach ($refIndexRecords as $fileReferenceRow) {
$row = $fileReferenceRow;
if ($fileReferenceRow['tablename'] === 'sys_file_reference') {
$row = $this->transformFileReferenceToRecordReference($fileReferenceRow);
$shortcutRecord = BackendUtility::getRecord($row['tablename'], $row['recuid']);
if ($shortcutRecord) {
$icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($row['tablename'], $shortcutRecord);
$onClick = 'Clickmenu.show("' . $row['tablename'] . '", "' . $row['recuid'] . '", "1", "+info,history,edit", "|", "");return false;';
$shortcutContent[] = '<a href="#" oncontextmenu="this.click();return false;" onclick="' . htmlspecialchars($onClick) . '">' . $icon . '</a>' . htmlspecialchars((BackendUtility::getRecordTitle($row['tablename'], $shortcutRecord) . ' [' . BackendUtility::getRecordPath($shortcutRecord['pid'], '', 80) . ']'));
} else {
$brokenReferences[] = $fileReferenceRow['ref_uid'];
}
}
$shortcutRecord = BackendUtility::getRecord($row['tablename'], $row['recuid']);
$icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($row['tablename'], $shortcutRecord);
$onClick = 'Clickmenu.show("' . $row['tablename'] . '", "' . $row['recuid'] . '", "1", "+info,history,edit", "|", "");return false;';
$shortcutContent[] = '<a href="#" oncontextmenu="this.click();return false;" onclick="' . htmlspecialchars($onClick) . '">' . $icon . '</a>' . htmlspecialchars((BackendUtility::getRecordTitle($row['tablename'], $shortcutRecord) . ' [' . BackendUtility::getRecordPath($shortcutRecord['pid'], '', 80) . ']'));
}
// render a message that the file could not be deleted
$flashMessage = GeneralUtility::makeInstance(
'\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotDeletedHasReferences'), $fileObject->getName()) . '<br />' . implode('<br />', $shortcutContent),
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
TRUE
);
$this->addFlashMessage($flashMessage);
} else {
try {
$result = $fileObject->delete();
// show the user that the file was deleted
if (!empty($shortcutContent)) {
// render a message that the file could not be deleted
$flashMessage = GeneralUtility::makeInstance(
'\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileDeleted'), $fileObject->getName()),
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileDeleted'),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK,
sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotDeletedHasReferences'), $fileObject->getName()) . '<br />' . implode('<br />', $shortcutContent),
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
TRUE
);
$this->addFlashMessage($flashMessage);
}
if (!empty($brokenReferences)) {
// render a message that the file has broken references
$flashMessage = GeneralUtility::makeInstance(
'\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileHasBrokenReferences'), count($brokenReferences)),
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileHasBrokenReferences'),
\TYPO3\CMS\Core\Messaging\FlashMessage::INFO,
TRUE
);
$this->addFlashMessage($flashMessage);
// Log success
$this->writelog(4, 0, 1, 'File "%s" deleted', array($fileObject->getIdentifier()));
} catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
$this->writelog(4, 1, 112, 'You are not allowed to access the file', array($fileObject->getIdentifier()));
} catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
$this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
} catch (\RuntimeException $e) {
$this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($fileObject->getIdentifier()));
}
// return here without deleting the file
return $result;
}
try {
$result = $fileObject->delete();
// show the user that the file was deleted
$flashMessage = GeneralUtility::makeInstance(
'\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileDeleted'), $fileObject->getName()),
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileDeleted'),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK,
TRUE
);
$this->addFlashMessage($flashMessage);
// Log success
$this->writelog(4, 0, 1, 'File "%s" deleted', array($fileObject->getIdentifier()));
} catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
$this->writelog(4, 1, 112, 'You are not allowed to access the file', array($fileObject->getIdentifier()));
} catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
$this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
} catch (\RuntimeException $e) {
$this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($fileObject->getIdentifier()));
}
} else {
try {
typo3/sysext/lang/locallang_core.xlf
<trans-unit id="message.description.fileNotDeletedHasReferences" xml:space="preserve">
<source>The file cannot be deleted since it is still used at the following places:</source>
</trans-unit>
<trans-unit id="message.header.fileHasBrokenReferences" xml:space="preserve">
<source>File has broken references</source>
</trans-unit>
<trans-unit id="message.description.fileHasBrokenReferences" xml:space="preserve">
<source>The file has %s broken reference(s) but can get deleted regardless of that.</source>
</trans-unit>
<trans-unit id="message.header.fileDeleted" xml:space="preserve">
<source>File deleted</source>
</trans-unit>
(3-3/4)