[BUGFIX] Avoid using hardcoded uid of repository record
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / UpdateFromTerController.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
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 use TYPO3\CMS\Core\Localization\LanguageService;
17 use TYPO3\CMS\Extbase\Mvc\View\JsonView;
18
19 /**
20 * Controller for actions relating to update of full extension list from TER
21 * @internal This class is a specific controller implementation and is not considered part of the Public TYPO3 API.
22 */
23 class UpdateFromTerController extends AbstractController
24 {
25 /**
26 * @var \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
27 */
28 protected $repositoryHelper;
29
30 /**
31 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
32 */
33 protected $repositoryRepository;
34
35 /**
36 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
37 */
38 protected $listUtility;
39
40 /**
41 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
42 */
43 protected $extensionRepository;
44
45 /**
46 * @var JsonView
47 */
48 protected $defaultViewObjectName = JsonView::class;
49
50 /**
51 * @param \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper $repositoryHelper
52 */
53 public function injectRepositoryHelper(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper $repositoryHelper)
54 {
55 $this->repositoryHelper = $repositoryHelper;
56 }
57
58 /**
59 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository $repositoryRepository
60 */
61 public function injectRepositoryRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository $repositoryRepository)
62 {
63 $this->repositoryRepository = $repositoryRepository;
64 }
65
66 /**
67 * @param \TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility
68 */
69 public function injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility)
70 {
71 $this->listUtility = $listUtility;
72 }
73
74 /**
75 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
76 */
77 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
78 {
79 $this->extensionRepository = $extensionRepository;
80 }
81
82 /**
83 * Update extension list from TER
84 *
85 * @param bool $forceUpdateCheck
86 */
87 public function updateExtensionListFromTerAction($forceUpdateCheck = false)
88 {
89 $updated = false;
90 $errorMessage = '';
91
92 if ($this->extensionRepository->countAll() === 0 || $forceUpdateCheck) {
93 try {
94 $updated = $this->repositoryHelper->updateExtList();
95 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
96 $errorMessage = $e->getMessage();
97 }
98 }
99 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Repository $repository */
100 $repository = $this->repositoryRepository->findOneTypo3OrgRepository();
101
102 $timeFormat = $this->getLanguageService()->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.updateFromTer.lastUpdate.fullTimeFormat');
103 $lastUpdateTime = $repository ? $repository->getLastUpdate() : null;
104 if (null === $lastUpdateTime) {
105 $lastUpdatedSince = $this->getLanguageService()->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.updateFromTer.never');
106 $lastUpdateTime = date($timeFormat);
107 } else {
108 $lastUpdatedSince = \TYPO3\CMS\Backend\Utility\BackendUtility::calcAge(
109 time() - $lastUpdateTime->format('U'),
110 $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears')
111 );
112 $lastUpdateTime = $lastUpdateTime->format($timeFormat);
113 }
114 $this->view->assign('value', [
115 'updated' => $updated,
116 'lastUpdateTime' => $lastUpdateTime,
117 'timeSinceLastUpdate' => $lastUpdatedSince,
118 'errorMessage' => $errorMessage
119 ]);
120 }
121
122 /**
123 * @return LanguageService
124 */
125 protected function getLanguageService()
126 {
127 return $GLOBALS['LANG'];
128 }
129 }