[BUGFIX] Fix error in filelist after deleting file with broken refs 43/35743/2
authorCornel Boppart <cboppart@snowflake.ch>
Sun, 26 Oct 2014 19:07:53 +0000 (20:07 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Fri, 2 Jan 2015 18:36:28 +0000 (19:36 +0100)
Always delete a file with corrupt relations.
Additionally issue a flash message informing about the broken references.

Resolves: #62480
Releases: master, 6.2
Change-Id: I3bfbcc1ec0dae4ebfe8356905ac2f0548bfaa12b
Reviewed-on: http://review.typo3.org/35743
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
typo3/sysext/lang/locallang_core.xlf

index 9242a3f..fe61c50 100644 (file)
@@ -15,6 +15,8 @@ namespace TYPO3\CMS\Core\Utility\File;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -400,29 +402,51 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                'deleted=0 AND ref_table="sys_file" AND ref_uid=' . (int)$fileObject->getUid()
                                . ' AND tablename != "sys_file_metadata"'
                        );
+                       $deleteFile = TRUE;
                        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 = 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) . ']'));
                                }
+                               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'),
+                                               FlashMessage::INFO,
+                                               TRUE
+                                       );
+                                       $this->addFlashMessage($flashMessage);
+                               }
+                               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.fileNotDeletedHasReferences'), $fileObject->getName()) . '<br />' . implode('<br />', $shortcutContent),
+                                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
+                                               FlashMessage::WARNING,
+                                               TRUE
+                                       );
+                                       $this->addFlashMessage($flashMessage);
+                                       $deleteFile = FALSE;
+                               }
+                       }
 
-                               // 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 {
+                       if ($deleteFile) {
                                try {
                                        $result = $fileObject->delete();
 
index da31596..ac3ceaf 100644 (file)
@@ -729,6 +729,12 @@ Would you like to save now in order to refresh the display?</source>
                        <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 it will be deleted regardless.</source>
+                       </trans-unit>
                        <trans-unit id="message.header.fileDeleted" xml:space="preserve">
                                <source>File deleted</source>
                        </trans-unit>