[TASK] Add button to reload static database data of an extension 10/51310/6
authorNicole Cordes <typo3@cordes.co>
Fri, 13 Jan 2017 19:16:20 +0000 (20:16 +0100)
committerHelmut Hummel <typo3@helhum.io>
Mon, 20 Feb 2017 22:12:56 +0000 (23:12 +0100)
This patch re-adds the possibility to manually trigger a reload of
static database data an extension might ships. In the EM list view, an
inconspicuous button is added for each extension which has an own
ext_tables_static+adt.sql file. Furthermore the import is changed, so
that a md5 hash of the file content is stored in the database. If the
extension is updated and the content if the file changes, a more visible
button is shown to indicate an update should be considered.

Resolves: #60748
Releases: master, 7.6
Change-Id: I8ccb01d7e1f98a4adfc70a4d1aa80db4e76bbc9d
Reviewed-on: https://review.typo3.org/51310
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Matthes
Tested-by: Christian Matthes
Tested-by: Joerg Kummer <service@enobe.de>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Tested-by: Helmut Hummel <typo3@helhum.io>
typo3/sysext/extensionmanager/Classes/Controller/ActionController.php
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
typo3/sysext/extensionmanager/Classes/ViewHelpers/ReloadSqlDataViewHelper.php [new file with mode: 0644]
typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf
typo3/sysext/extensionmanager/Resources/Private/Templates/List/Index.html
typo3/sysext/extensionmanager/ext_tables.php

index fa16187..fc0e8ca 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Extensionmanager\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Registry;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Controller for handling extension related actions like
  * installing, removing, downloading of data or files
@@ -174,4 +177,22 @@ class ActionController extends AbstractController
         }
         $this->fileHandlingUtility->sendSqlDumpFileToBrowserAndDelete($filePath, $fileName);
     }
+
+    /**
+     * Reloads the static SQL data of an extension
+     *
+     * @param string $extension
+     */
+    protected function reloadExtensionDataAction($extension)
+    {
+        $extension = $this->installUtility->enrichExtensionWithDetails($extension, false);
+        $registryKey = $extension['siteRelPath'] . 'ext_tables_static+adt.sql';
+
+        $registry = GeneralUtility::makeInstance(Registry::class);
+        $registry->remove('extensionDataImport', $registryKey);
+
+        $this->installUtility->processDatabaseUpdates($extension);
+
+        $this->redirect('index', 'List');
+    }
 }
index 6e02759..ec665cf 100644 (file)
@@ -675,11 +675,13 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
         $extTablesStaticSqlRelFile = $extensionSiteRelPath . 'ext_tables_static+adt.sql';
         if (!$this->registry->get('extensionDataImport', $extTablesStaticSqlRelFile)) {
             $extTablesStaticSqlFile = PATH_site . $extTablesStaticSqlRelFile;
+            $shortFileHash = '';
             if (file_exists($extTablesStaticSqlFile)) {
                 $extTablesStaticSqlContent = file_get_contents($extTablesStaticSqlFile);
+                $shortFileHash = md5($extTablesStaticSqlContent);
                 $this->importStaticSql($extTablesStaticSqlContent);
             }
-            $this->registry->set('extensionDataImport', $extTablesStaticSqlRelFile, 1);
+            $this->registry->set('extensionDataImport', $extTablesStaticSqlRelFile, $shortFileHash);
             $this->emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile);
         }
     }
diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ReloadSqlDataViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ReloadSqlDataViewHelper.php
new file mode 100644 (file)
index 0000000..631c426
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Imaging\Icon;
+use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\Registry;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+
+/**
+ * View helper for update script link
+ */
+class ReloadSqlDataViewHelper extends Link\ActionViewHelper
+{
+    /**
+     * @var string
+     */
+    protected static $registryNamespace = 'extensionDataImport';
+
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('extension', 'array', 'Extension key', true);
+    }
+
+    /**
+     * Renders a link to re-import the static SQL data of an extension
+     *
+     * @return string The rendered a tag
+     */
+    public function render()
+    {
+        $extension = $this->arguments['extension'];
+        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+
+        $staticSqlDataFile = $extension['siteRelPath'] . 'ext_tables_static+adt.sql';
+        if (!file_exists(PATH_site . $staticSqlDataFile)) {
+            return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
+        }
+
+        $registry = GeneralUtility::makeInstance(Registry::class);
+        $oldMd5Hash = $registry->get(static::$registryNamespace, $staticSqlDataFile);
+
+        $md5HashIsEqual = true;
+        // We used to only store "1" in the database when data was imported
+        // No need to compare file content here and just show the reload icon
+        if (!empty($oldMd5Hash) && $oldMd5Hash !== 1) {
+            $currentMd5Hash = md5_file(PATH_site . $staticSqlDataFile);
+            $md5HashIsEqual = $oldMd5Hash === $currentMd5Hash;
+        }
+
+        if ($md5HashIsEqual) {
+            $iconIdentifier = 'actions-database-reload';
+            $languageKey = 'extensionList.databaseReload';
+        } else {
+            $iconIdentifier = 'actions-database-import';
+            $languageKey = 'extensionList.databaseImport';
+        }
+
+        $uriBuilder = $this->controllerContext->getUriBuilder();
+        $uriBuilder->reset();
+        $uri = $uriBuilder->uriFor('reloadExtensionData', ['extension' => $extension['key']], 'Action');
+        $this->tag->addAttribute('href', $uri);
+        $this->tag->addAttribute('class', 'downloadExtensionData btn btn-default');
+        $this->tag->addAttribute('title', LocalizationUtility::translate($languageKey, 'extensionmanager'));
+        $this->tag->setContent($iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render());
+
+        return $this->tag->render();
+    }
+}
index fb92dc2..db98142 100644 (file)
                        <trans-unit id="extensionList.updateConfirmation.message">
                                <source>Update Comments:</source>
                        </trans-unit>
+                       <trans-unit id="extensionList.databaseImport">
+                               <source>The static database data has changed. You should re-import the data.</source>
+                       </trans-unit>
+                       <trans-unit id="extensionList.databaseReload">
+                               <source>Nothing has changed since last import. You might want to reload static database data.</source>
+                       </trans-unit>
                        <trans-unit id="extensionList.updateConfirmation.questionVersionComments">
                                <source>Version Comments</source>
                        </trans-unit>
index 8032050..fe48054 100644 (file)
@@ -91,6 +91,7 @@
                                                                </f:link.action>
                                                        </span>
                                                        <em:downloadExtensionData class="btn btn-default" extension="{extension}" />
+                                                       <em:reloadSqlData class="btn btn-default" extension="{extension}" />
                                                </em:processAvailableActions>
                                        </div>
                                </td>
                </tbody>
        </table>
        </div>
-</f:section>
\ No newline at end of file
+</f:section>
index 1172044..40c69b3 100644 (file)
@@ -7,7 +7,7 @@ if (TYPO3_MODE === 'BE') {
         'tools',
         'extensionmanager', '', [
             'List' => 'index,unresolvedDependencies,ter,showAllVersions,distributions',
-            'Action' => 'toggleExtensionInstallationState,installExtensionWithoutSystemDependencyCheck,removeExtension,downloadExtensionZip,downloadExtensionData',
+            'Action' => 'toggleExtensionInstallationState,installExtensionWithoutSystemDependencyCheck,removeExtension,downloadExtensionZip,downloadExtensionData,reloadExtensionData',
             'Configuration' => 'showConfigurationForm,save,saveAndClose',
             'Download' => 'checkDependencies,installFromTer,installExtensionWithoutSystemDependencyCheck,installDistribution,updateExtension,updateCommentForUpdatableVersions',
             'UpdateScript' => 'show',