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