‪TYPO3CMS  9.5
Helper.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 
28 
34 {
53 
60 
66  protected ‪$repository;
67 
71  protected ‪$repositoryRepository;
72 
76  protected ‪$extensionRepository;
77 
81  protected ‪$objectManager;
82 
83  public function ‪__construct()
84  {
85  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
86  ‪$repositoryRepository = $this->objectManager->get(RepositoryRepository::class);
87  $this->extensionRepository = $this->objectManager->get(ExtensionRepository::class);
90  if (is_object(‪$repository)) {
92  }
93  }
94 
104  {
105  $this->repository = ‪$repository;
106  }
107 
116  public function ‪fetchExtListFile()
117  {
119  }
120 
129  public function ‪fetchMirrorListFile()
130  {
132  }
133 
143  protected function ‪fetchFile($remoteResource, $localResource)
144  {
145  $isOffline = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'offlineMode');
146  if ($isOffline) {
147  throw new ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078780);
148  }
149  if (is_string($remoteResource) && is_string($localResource) && !empty($remoteResource) && !empty($localResource)) {
150  $fileContent = GeneralUtility::getUrl($remoteResource);
151  if ($fileContent !== false) {
152  if (GeneralUtility::writeFileToTypo3tempDir($localResource, $fileContent) !== null) {
153  throw new ExtensionManagerException(sprintf('Could not write to file %s.', $localResource), 1342635378);
154  }
155  } else {
156  throw new ExtensionManagerException(sprintf('Could not access remote resource %s.', $remoteResource), 1342635425);
157  }
158  }
159  }
160 
167  public function ‪getLocalExtListFile()
168  {
169  return ‪Environment::getVarPath() . '/extensionmanager/' . (int)$this->repository->getUid() . '.extensions.xml.gz';
170  }
171 
178  public function ‪getRemoteExtListFile()
179  {
180  $mirror = $this->‪getMirrors(true)->getMirror();
181  $filePath = 'https://' . $mirror['host'] . $mirror['path'] . 'extensions.xml.gz';
182  return $filePath;
183  }
184 
191  public function ‪getRemoteExtHashFile()
192  {
193  $mirror = $this->‪getMirrors(true)->getMirror();
194  $filePath = 'https://' . $mirror['host'] . $mirror['path'] . 'extensions.md5';
195  return $filePath;
196  }
197 
204  public function ‪getLocalMirrorListFile()
205  {
206  return ‪Environment::getVarPath() . '/extensionmanager/' . (int)$this->repository->getUid() . '.mirrors.xml.gz';
207  }
208 
215  public function ‪getRemoteMirrorListFile()
216  {
217  $filePath = $this->repository->getMirrorListUrl();
218  return $filePath;
219  }
220 
232  public function ‪getMirrors($forcedUpdateFromRemote = true)
233  {
234  $assignedMirror = $this->repository->getMirrors();
235  if ($forcedUpdateFromRemote || $assignedMirror === null || !is_object($assignedMirror)) {
236  if ($forcedUpdateFromRemote || !is_file($this->‪getLocalMirrorListFile())) {
237  $this->‪fetchMirrorListFile();
238  }
239  $objMirrorListImporter = GeneralUtility::makeInstance(MirrorListUtility::class);
240  $this->repository->addMirrors($objMirrorListImporter->getMirrors($this->getLocalMirrorListFile()));
241  }
242  return $this->repository->getMirrors();
243  }
244 
253  public function ‪isExtListUpdateNecessary()
254  {
255  if ($this->repository === null) {
256  throw new ExtensionManagerException('No extension repository was found.', 1500060252);
257  }
258  $updateNecessity = 0;
259  if ($this->extensionRepository->countByRepository($this->repository->getUid()) <= 0) {
260  $updateNecessity |= ‪self::PROBLEM_NO_VERSIONS_IN_DATABASE;
261  }
262  if (!is_file($this->‪getLocalExtListFile())) {
264  } else {
265  $remotemd5 = GeneralUtility::getUrl($this->‪getRemoteExtHashFile());
266  if ($remotemd5 !== false) {
267  $localmd5 = md5_file($this->‪getLocalExtListFile());
268  if ($remotemd5 !== $localmd5) {
269  $updateNecessity |= ‪self::PROBLEM_EXTENSION_HASH_CHANGED;
270  }
271  } else {
272  throw new ExtensionManagerException('Could not retrieve extension hash file from remote server.', 1342635016);
273  }
274  }
275  return $updateNecessity;
276  }
277 
286  public function ‪updateExtList()
287  {
288  $updated = false;
289  $updateNecessity = $this->‪isExtListUpdateNecessary();
290  if ($updateNecessity !== 0) {
291  // retrieval of file necessary
292  $tmpBitmask = self::PROBLEM_EXTENSION_FILE_NOT_EXISTING | ‪self::PROBLEM_EXTENSION_HASH_CHANGED;
293  if (($tmpBitmask & $updateNecessity) > 0) {
294  $this->‪fetchExtListFile();
295  $updateNecessity &= ~$tmpBitmask;
296  }
297  // database table cleanup
298  if ($updateNecessity & self::PROBLEM_NO_VERSIONS_IN_DATABASE) {
299  $updateNecessity &= ~self‪::PROBLEM_NO_VERSIONS_IN_DATABASE;
300  } else {
301  // Use straight query as extbase "remove" is too slow here
302  // This truncates the whole table. It would be more correct to remove only rows of a specific
303  // repository, but multiple repository handling is not implemented, and truncate is quicker.
304  GeneralUtility::makeInstance(ConnectionPool::class)
305  ->getConnectionForTable('tx_extensionmanager_domain_model_extension')
306  ->truncate('tx_extensionmanager_domain_model_extension');
307  }
308  // no further problems - start of import process
309  if ($updateNecessity === 0) {
310  $uid = $this->repository->getUid();
311  $objExtListImporter = $this->objectManager->get(ExtensionListUtility::class);
312  $objExtListImporter->import($this->‪getLocalExtListFile(), $uid);
313  $updated = true;
314  }
315  }
316  return $updated;
317  }
318 }
‪TYPO3\CMS\Extensionmanager\Utility\Importer\MirrorListUtility
Definition: MirrorListUtility.php:22
‪TYPO3\CMS\Extensionmanager\Utility\Repository
Definition: Helper.php:2
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\fetchFile
‪fetchFile($remoteResource, $localResource)
Definition: Helper.php:139
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\getMirrors
‪TYPO3 CMS Extensionmanager Domain Model Mirrors getMirrors($forcedUpdateFromRemote=true)
Definition: Helper.php:228
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\getLocalMirrorListFile
‪string getLocalMirrorListFile()
Definition: Helper.php:200
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:42
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\PROBLEM_NO_VERSIONS_IN_DATABASE
‪const PROBLEM_NO_VERSIONS_IN_DATABASE
Definition: Helper.php:59
‪TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository\findOneTypo3OrgRepository
‪TYPO3 CMS Extensionmanager Domain Model Repository findOneTypo3OrgRepository()
Definition: RepositoryRepository.php:55
‪TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
Definition: RepositoryRepository.php:22
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\updateExtList
‪bool updateExtList()
Definition: Helper.php:282
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\fetchExtListFile
‪fetchExtListFile()
Definition: Helper.php:112
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\getLocalExtListFile
‪string getLocalExtListFile()
Definition: Helper.php:163
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\PROBLEM_EXTENSION_FILE_NOT_EXISTING
‪const PROBLEM_EXTENSION_FILE_NOT_EXISTING
Definition: Helper.php:46
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\$extensionRepository
‪ExtensionRepository $extensionRepository
Definition: Helper.php:73
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\$repository
‪Repository $repository
Definition: Helper.php:65
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility
Definition: ExtensionListUtility.php:27
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\isExtListUpdateNecessary
‪int isExtListUpdateNecessary()
Definition: Helper.php:249
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:27
‪TYPO3\CMS\Extensionmanager\Domain\Model\Repository
Definition: Repository.php:22
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\getRemoteExtHashFile
‪string getRemoteExtHashFile()
Definition: Helper.php:187
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:23
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\getRemoteMirrorListFile
‪string getRemoteMirrorListFile()
Definition: Helper.php:211
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\getRemoteExtListFile
‪string getRemoteExtListFile()
Definition: Helper.php:174
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
Definition: Helper.php:34
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\__construct
‪__construct()
Definition: Helper.php:79
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\$repositoryRepository
‪RepositoryRepository $repositoryRepository
Definition: Helper.php:69
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\setRepository
‪setRepository(Repository $repository)
Definition: Helper.php:99
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\fetchMirrorListFile
‪fetchMirrorListFile()
Definition: Helper.php:125
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\PROBLEM_EXTENSION_HASH_CHANGED
‪const PROBLEM_EXTENSION_HASH_CHANGED
Definition: Helper.php:52
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper\$objectManager
‪ObjectManager $objectManager
Definition: Helper.php:77
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165