‪TYPO3CMS  10.4
ReloadSqlDataViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
26 
32 {
36  protected static ‪$registryNamespace = 'extensionDataImport';
37 
38  public function ‪initializeArguments()
39  {
40  parent::initializeArguments();
41  $this->registerArgument('extension', 'array', 'Extension key', true);
42  }
43 
49  public function ‪render()
50  {
51  $extension = $this->arguments['extension'];
52  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
53 
54  $staticSqlDataFile = $extension['siteRelPath'] . 'ext_tables_static+adt.sql';
55  if (!file_exists(‪Environment::getPublicPath() . '/' . $staticSqlDataFile)) {
56  return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', ‪Icon::SIZE_SMALL)->render() . '</span>';
57  }
58 
59  $registry = GeneralUtility::makeInstance(Registry::class);
60  $oldMd5Hash = $registry->get(static::$registryNamespace, $staticSqlDataFile);
61 
62  $md5HashIsEqual = true;
63  // We used to only store "1" in the database when data was imported
64  // No need to compare file content here and just show the reload icon
65  if (!empty($oldMd5Hash) && $oldMd5Hash !== 1) {
66  $currentMd5Hash = md5_file(‪Environment::getPublicPath() . '/' . $staticSqlDataFile);
67  $md5HashIsEqual = $oldMd5Hash === $currentMd5Hash;
68  }
69 
70  if ($md5HashIsEqual) {
71  $iconIdentifier = 'actions-database-reload';
72  $languageKey = 'extensionList.databaseReload';
73  } else {
74  $iconIdentifier = 'actions-database-import';
75  $languageKey = 'extensionList.databaseImport';
76  }
77 
79  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
80  $uriBuilder->reset();
81  $uri = $uriBuilder->uriFor('reloadExtensionData', ['extension' => $extension['key']], 'Action');
82  $this->tag->addAttribute('href', $uri);
83  $this->tag->addAttribute('title', ‪LocalizationUtility::translate($languageKey, 'extensionmanager'));
84  $this->tag->setContent($iconFactory->getIcon($iconIdentifier, ‪Icon::SIZE_SMALL)->render());
85 
86  return $this->tag->render();
87  }
88 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper
Definition: ReloadSqlDataViewHelper.php:32
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\initializeArguments
‪initializeArguments()
Definition: ReloadSqlDataViewHelper.php:37
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\$registryNamespace
‪static string $registryNamespace
Definition: ReloadSqlDataViewHelper.php:35
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\render
‪string render()
Definition: ReloadSqlDataViewHelper.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46