[BUGFIX] Don't download language packs of not loaded extensions
[Packages/TYPO3.CMS.git] / typo3 / sysext / lang / Classes / Domain / Repository / ExtensionRepository.php
1 <?php
2 namespace TYPO3\CMS\Lang\Domain\Repository;
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\Utility\ExtensionManagementUtility;
18 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
19 use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
20 use TYPO3\CMS\Lang\Domain\Model\Extension;
21
22 /**
23 * Extension repository
24 */
25 class ExtensionRepository
26 {
27 /**
28 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
29 */
30 protected $objectManager;
31
32 /**
33 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
34 */
35 protected $listUtility;
36
37 /**
38 * @var array
39 */
40 protected $extensions = [];
41
42 /**
43 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
44 */
45 public function injectObjectManager(ObjectManagerInterface $objectManager)
46 {
47 $this->objectManager = $objectManager;
48 }
49
50 /**
51 * @param \TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility
52 */
53 public function injectListUtility(ListUtility $listUtility)
54 {
55 $this->listUtility = $listUtility;
56 }
57
58 /**
59 * Returns all objects of this repository
60 *
61 * @return array The extensions
62 */
63 public function findAll()
64 {
65 if (empty($this->extensions)) {
66 $extensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
67 foreach ($extensions as $entry) {
68 if (empty($entry['installed']) || $entry['installed'] !== true) {
69 continue;
70 }
71 /** @var $extension \TYPO3\CMS\Lang\Domain\Model\Extension */
72 $extension = $this->objectManager->get(
73 Extension::class,
74 $entry['key'],
75 $entry['title'],
76 $this->getExtensionIconWithPath($entry)
77 );
78 $extension->setVersionFromString($entry['version']);
79 if ($entry['ext_icon_width'] > 0) {
80 $extension->setIconWidth($entry['ext_icon_width']);
81 }
82 if ($entry['ext_icon_height'] > 0) {
83 $extension->setIconHeight($entry['ext_icon_height']);
84 }
85
86 $this->extensions[$entry['key']] = $extension;
87 }
88 ksort($this->extensions);
89 }
90 return $this->extensions;
91 }
92
93 /**
94 * Counts all objects of this repository
95 *
96 * @return int The extension count
97 */
98 public function countAll()
99 {
100 $extensions = $this->findAll();
101 return count($extensions);
102 }
103
104 /**
105 * Find one extension by offset
106 *
107 * @param int $offset The offset
108 * @return \TYPO3\CMS\Lang\Domain\Model\Extension The extension
109 */
110 public function findOneByOffset($offset)
111 {
112 $extensions = $this->findAll();
113 $extensions = array_values($extensions);
114 $offset = (int)$offset;
115 if (!empty($extensions[$offset])) {
116 return $extensions[$offset];
117 }
118 return null;
119 }
120
121 /**
122 * Returns the extension icon
123 *
124 * @param array $extensionEntry
125 * @return string
126 */
127 protected function getExtensionIconWithPath($extensionEntry)
128 {
129 $extensionIcon = $GLOBALS['TYPO3_LOADED_EXT'][$extensionEntry['key']]['ext_icon'];
130 if (empty($extensionIcon)) {
131 $extensionIcon = ExtensionManagementUtility::getExtensionIcon(PATH_site . $extensionEntry['siteRelPath'] . '/');
132 }
133 if (empty($extensionIcon)) {
134 $extensionIcon = ExtensionManagementUtility::siteRelPath('core') . 'Resources/Public/Icons/Extension.png';
135 } else {
136 $extensionIcon = '../' . $extensionEntry['siteRelPath'] . '/' . $extensionIcon;
137 }
138 return $extensionIcon;
139 }
140 }