[BUGFIX] Fix error in filelist after deleting file with broken refs 62/33562/9
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:26:20 +0000 (19:26 +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/33562
Reviewed-by: Cornel Boppart <cboppart@snowflake.ch>
Tested-by: Cornel Boppart <cboppart@snowflake.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
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 01eaaf0..1bf928b 100644 (file)
@@ -343,29 +343,51 @@ class ExtendedFileUtility extends 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);
+                                                       $icon = '<a href="#" class="t3-js-clickmenutrigger" data-table="' . $row['tablename'] . '" data-uid="' . $row['recuid'] . '" data-listframe="1" data-iteminfo="%2Binfo,history,edit">' . $icon . '</a>';
+                                                       $shortcutContent[] = $icon . htmlspecialchars((BackendUtility::getRecordTitle($row['tablename'], $shortcutRecord) . '  [' . BackendUtility::getRecordPath($shortcutRecord['pid'], '', 80) . ']'));
+                                               } else {
+                                                       $brokenReferences[] = $fileReferenceRow['ref_uid'];
+                                               }
                                        }
-                                       $shortcutRecord = BackendUtility::getRecord($row['tablename'], $row['recuid']);
-                                       $icon = IconUtility::getSpriteIconForRecord($row['tablename'], $shortcutRecord);
-                                       $icon = '<a href="#" class="t3-js-clickmenutrigger" data-table="' . $row['tablename'] . '" data-uid="' . $row['recuid'] . '" data-listframe="1" data-iteminfo="%2Binfo,history,edit">' . $icon . '</a>';
-                                       $shortcutContent[] = $icon . 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(
+                                               FlashMessage::class,
+                                               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(
+                                               FlashMessage::class,
+                                               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(
-                                       FlashMessage::class,
-                                       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);
-                       } else {
+                       if ($deleteFile) {
                                try {
                                        $result = $fileObject->delete();
 
index ad86957..8048610 100644 (file)
@@ -753,6 +753,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>