[!!!][TASK] Remove CMS base ViewHelper classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / ReloadSqlDataViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
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
17 use TYPO3\CMS\Core\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Core\Registry;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
22
23 /**
24 * View helper for update script link
25 */
26 class ReloadSqlDataViewHelper extends Link\ActionViewHelper
27 {
28 /**
29 * @var string
30 */
31 protected static $registryNamespace = 'extensionDataImport';
32
33 public function initializeArguments()
34 {
35 parent::initializeArguments();
36 $this->registerArgument('extension', 'array', 'Extension key', true);
37 }
38
39 /**
40 * Renders a link to re-import the static SQL data of an extension
41 *
42 * @return string The rendered a tag
43 */
44 public function render()
45 {
46 $extension = $this->arguments['extension'];
47 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
48
49 $staticSqlDataFile = $extension['siteRelPath'] . 'ext_tables_static+adt.sql';
50 if (!file_exists(PATH_site . $staticSqlDataFile)) {
51 return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
52 }
53
54 $registry = GeneralUtility::makeInstance(Registry::class);
55 $oldMd5Hash = $registry->get(static::$registryNamespace, $staticSqlDataFile);
56
57 $md5HashIsEqual = true;
58 // We used to only store "1" in the database when data was imported
59 // No need to compare file content here and just show the reload icon
60 if (!empty($oldMd5Hash) && $oldMd5Hash !== 1) {
61 $currentMd5Hash = md5_file(PATH_site . $staticSqlDataFile);
62 $md5HashIsEqual = $oldMd5Hash === $currentMd5Hash;
63 }
64
65 if ($md5HashIsEqual) {
66 $iconIdentifier = 'actions-database-reload';
67 $languageKey = 'extensionList.databaseReload';
68 } else {
69 $iconIdentifier = 'actions-database-import';
70 $languageKey = 'extensionList.databaseImport';
71 }
72
73 $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
74 $uriBuilder->reset();
75 $uri = $uriBuilder->uriFor('reloadExtensionData', ['extension' => $extension['key']], 'Action');
76 $this->tag->addAttribute('href', $uri);
77 $this->tag->addAttribute('title', LocalizationUtility::translate($languageKey, 'extensionmanager'));
78 $this->tag->setContent($iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render());
79
80 return $this->tag->render();
81 }
82 }