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