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