‪TYPO3CMS  ‪main
ReloadSqlDataViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\CMS\Core\Imaging\IconSize;
29 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
30 
36 final class ‪ReloadSqlDataViewHelper extends AbstractTagBasedViewHelper
37 {
41  protected ‪$tagName = 'a';
42 
43  protected static string ‪$registryNamespace = 'extensionDataImport';
44 
45  public function ‪initializeArguments()
46  {
47  parent::initializeArguments();
48  $this->registerUniversalTagAttributes();
49  $this->registerArgument('extension', 'array', 'Extension key', true);
50  }
51 
52  public function ‪render(): string
53  {
54  $extension = $this->arguments['extension'];
55  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
56 
57  $staticSqlDataFile = $extension['packagePath'] . 'ext_tables_static+adt.sql';
58  if (!file_exists($staticSqlDataFile)) {
59  return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', IconSize::SMALL)->render() . '</span>';
60  }
61 
62  $registry = GeneralUtility::makeInstance(Registry::class);
63  $oldMd5Hash = $registry->get(self::$registryNamespace, ‪PathUtility::stripPathSitePrefix($staticSqlDataFile));
64 
65  $md5HashIsEqual = true;
66  // We used to only store "1" in the database when data was imported
67  // No need to compare file content here and just show the reload icon
68  if (!empty($oldMd5Hash) && $oldMd5Hash !== 1) {
69  $currentMd5Hash = md5_file($staticSqlDataFile);
70  $md5HashIsEqual = $oldMd5Hash === $currentMd5Hash;
71  }
72 
73  if ($md5HashIsEqual) {
74  $iconIdentifier = 'actions-database-reload';
75  $languageKey = 'extensionList.databaseReload';
76  } else {
77  $iconIdentifier = 'actions-database-import';
78  $languageKey = 'extensionList.databaseImport';
79  }
80 
81  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
83  $renderingContext = $this->renderingContext;
85  $request = $renderingContext->getRequest();
86  $uriBuilder->setRequest($request);
87  $uriBuilder->reset();
88  $uri = $uriBuilder->uriFor(
89  'reloadExtensionData',
90  ['extensionKey' => $extension['key']],
91  'Action'
92  );
93  $this->tag->addAttribute('href', $uri);
94  $this->tag->addAttribute('title', htmlspecialchars($this->‪getLanguageService()->sL(
95  'LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:' . $languageKey
96  )));
97  $this->tag->setContent($iconFactory->getIcon($iconIdentifier, IconSize::SMALL)->render());
98 
99  return $this->tag->render();
100  }
101 
102  protected function ‪getLanguageService(): ‪LanguageService
103  {
104  return ‪$GLOBALS['LANG'];
105  }
106 }
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper
Definition: ReloadSqlDataViewHelper.php:37
‪TYPO3\CMS\Core\Utility\PathUtility\stripPathSitePrefix
‪static stripPathSitePrefix(string $path)
Definition: PathUtility.php:428
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\initializeArguments
‪initializeArguments()
Definition: ReloadSqlDataViewHelper.php:44
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\$registryNamespace
‪static string $registryNamespace
Definition: ReloadSqlDataViewHelper.php:42
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\$tagName
‪string $tagName
Definition: ReloadSqlDataViewHelper.php:40
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\getLanguageService
‪getLanguageService()
Definition: ReloadSqlDataViewHelper.php:101
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:24
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\render
‪render()
Definition: ReloadSqlDataViewHelper.php:51
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:35