‪TYPO3CMS  11.5
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 
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
26 
31 class ‪ReloadSqlDataViewHelper extends AbstractTagBasedViewHelper
32 {
36  protected ‪$tagName = 'a';
37 
38  protected static string ‪$registryNamespace = 'extensionDataImport';
39 
40  public function ‪initializeArguments()
41  {
42  parent::initializeArguments();
43  $this->registerUniversalTagAttributes();
44  $this->registerArgument('extension', 'array', 'Extension key', true);
45  }
46 
52  public function ‪render()
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', ‪Icon::SIZE_SMALL)->render() . '</span>';
60  }
61 
62  $registry = GeneralUtility::makeInstance(Registry::class);
63  $oldMd5Hash = $registry->get(static::$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);
82  $uriBuilder->setRequest($this->renderingContext->getRequest());
83  $uriBuilder->reset();
84  $uri = $uriBuilder->uriFor(
85  'reloadExtensionData',
86  ['extension' => $extension['key']],
87  'Action'
88  );
89  $this->tag->addAttribute('href', $uri);
90  $this->tag->addAttribute('title', ‪LocalizationUtility::translate($languageKey, 'extensionmanager'));
91  $this->tag->setContent($iconFactory->getIcon($iconIdentifier, ‪Icon::SIZE_SMALL)->render());
92 
93  return $this->tag->render();
94  }
95 }
‪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:39
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:25
‪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:41
‪TYPO3\CMS\Core\Utility\PathUtility\stripPathSitePrefix
‪static string stripPathSitePrefix($path)
Definition: PathUtility.php:445
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\$registryNamespace
‪static string $registryNamespace
Definition: ReloadSqlDataViewHelper.php:37
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\$tagName
‪string $tagName
Definition: ReloadSqlDataViewHelper.php:35
‪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\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\render
‪string render()
Definition: ReloadSqlDataViewHelper.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50