TYPO3 CMS  TYPO3_7-6
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 
22 
27 {
31  protected static $registryNamespace = 'extensionDataImport';
32 
33  public function initializeArguments()
34  {
35  parent::initializeArguments();
36  $this->registerArgument('extension', 'array', 'Extension key', true);
37  }
38 
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->controllerContext->getUriBuilder();
74  $uriBuilder->reset();
75  $uri = $uriBuilder->uriFor('reloadExtensionData', ['extension' => $extension['key']], 'Action');
76  $this->tag->addAttribute('href', $uri);
77  $this->tag->addAttribute('class', 'downloadExtensionData btn btn-default');
78  $this->tag->addAttribute('title', LocalizationUtility::translate($languageKey, 'extensionmanager'));
79  $this->tag->setContent($iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render());
80 
81  return $this->tag->render();
82  }
83 }
static translate($key, $extensionName, $arguments=null)
registerArgument($name, $type, $description, $required=false, $defaultValue=null)