[TASK] Install tool test action fatals if image not exists 31/23331/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 26 Aug 2013 18:35:44 +0000 (20:35 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Mon, 26 Aug 2013 19:34:43 +0000 (21:34 +0200)
The install tool test section creates test images. If permissions
on the target folder are not set up correctly, the file may not
be created, but a correct file location is returned.
In this case not caught exceptions are thrown. This is
now sanitized with a simple file exists view helper to
show some error message instead.

Change-Id: Ic840b0128e5c69f8ce6f601952b8f17e59713e27
Resolves: #51366
Releases: 6.2
Reviewed-on: https://review.typo3.org/23331
Reviewed-by: Simon Schmidt
Tested-by: Simon Schmidt
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/install/Classes/ViewHelpers/File/ExistsViewHelper.php [new file with mode: 0644]
typo3/sysext/install/Resources/Private/Partials/Action/Tool/TestSetup/DisplayTwinImage.html

diff --git a/typo3/sysext/install/Classes/ViewHelpers/File/ExistsViewHelper.php b/typo3/sysext/install/Classes/ViewHelpers/File/ExistsViewHelper.php
new file mode 100644 (file)
index 0000000..8283bc5
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+namespace TYPO3\CMS\Install\ViewHelpers\File;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Simple view helper to check if given file is a regular file
+ *
+ * = Examples =
+ *
+ * <code title="Default">
+ * <f:file.exists file="Absolute-path" />
+ * </code>
+ *
+ * <output>
+ * TRUE or FALSE
+ * </output>
+ */
+class ExistsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+
+       /**
+        * Check if given file is a regular file
+        *
+        * @param string $file Absolute path
+        * @return boolean
+        */
+       public function render($file) {
+               $result = FALSE;
+               if (file_exists($file) && is_file($file)) {
+                       $result = TRUE;
+               }
+               return $result;
+       }
+}
+?>
\ No newline at end of file
index 468d854..9ad7789 100644 (file)
                                        <td>
                                                <f:if condition="{test.outputFile}">
                                                        <f:then>
-                                                               <img src="../../../../{test.outputFile -> i:file.relativePath()}?{time}" />
+                                                               <f:if condition="{i:file.exists(file:test.outputFile)}">
+                                                                       <f:then>
+                                                                               <img src="../../../../{test.outputFile -> i:file.relativePath()}?{time}" />
+                                                                       </f:then>
+                                                                       <f:else>
+                                                                               <div class="typo3-message message-error" >
+                                                                                       <div class="header-container">
+                                                                                               <div class="message-header"><strong>No image</strong></div>
+                                                                                       </div>
+                                                                                       <div class="message-body">
+                                                                                               Your system generated no image, it was probably unable to write the file. Do you have a permission problem?
+                                                                                       </div>
+                                                                               </div>
+                                                                       </f:else>
+                                                               </f:if>
                                                        </f:then>
                                                        <f:else>
                                                                <div class="typo3-message message-error" >
@@ -36,7 +50,7 @@
                                                                                <div class="message-header"><strong>No image</strong></div>
                                                                        </div>
                                                                        <div class="message-body">
-                                                                               Your system generated no image at all. This is probaly a misconfiguration.
+                                                                               Your system generated no image at all. This is probably a misconfiguration.
                                                                        </div>
                                                                </div>
                                                        </f:else>
                                        <td>
                                                <f:if condition="{test.outputFile}">
                                                        <f:then>
-                                                               {test.outputFile -> i:file.size()}Bytes,
-                                                               {test.outputFile -> i:file.imageDimension()}
-                                                               x {test.outputFile -> i:file.imageDimension(dimension:'height')} pixel
+                                                               <f:if condition="{i:file.exists(file:test.outputFile)}">
+                                                                       <f:then>
+                                                                               {test.outputFile -> i:file.size()}Bytes,
+                                                                               {test.outputFile -> i:file.imageDimension()}
+                                                                               x {test.outputFile -> i:file.imageDimension(dimension:'height')} pixel
+                                                                       </f:then>
+                                                               </f:if>
                                                        </f:then>
                                                </f:if>
                                        </td>