‪TYPO3CMS  10.4
ExtensionListUtility.php
Go to the documentation of this file.
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 
17 
29 
34 class ‪ExtensionListUtility implements \SplObserver
35 {
41  protected ‪$parser;
42 
48  protected ‪$sumRecords = 0;
49 
55  protected ‪$arrRows = [];
56 
62  protected static ‪$fieldNames = [
63  'extension_key',
64  'version',
65  'integer_version',
66  'current_version',
67  'alldownloadcounter',
68  'downloadcounter',
69  'title',
70  'ownerusername',
71  'author_name',
72  'author_email',
73  'authorcompany',
74  'last_updated',
75  'md5hash',
76  'repository',
77  'state',
78  'review_state',
79  'category',
80  'description',
81  'serialized_dependencies',
82  'update_comment',
83  'documentation_link'
84  ];
85 
91  protected static ‪$tableName = 'tx_extensionmanager_domain_model_extension';
92 
99  protected ‪$maxRowsPerChunk = 50;
100 
108  protected ‪$repositoryUid = 1;
109 
114 
118  protected ‪$extensionRepository;
119 
123  protected ‪$extensionModel;
124 
128  protected ‪$objectManager;
129 
136  protected ‪$minimumDateToImport;
137 
145  public function ‪__construct()
146  {
148  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
149  $this->repositoryRepository = $this->objectManager->get(RepositoryRepository::class);
150  $this->extensionRepository = $this->objectManager->get(ExtensionRepository::class);
151  $this->extensionModel = $this->objectManager->get(Extension::class);
152  // @todo catch parser exception
153  $this->parser = ‪XmlParserFactory::getParserInstance('extension');
154  if (is_object($this->parser)) {
155  $this->parser->attach($this);
156  } else {
158  static::class . ': No XML parser available.',
159  1476108717
160  );
161  }
162 
163  $connection = GeneralUtility::makeInstance(ConnectionPool::class)
164  ->getConnectionForTable(self::$tableName);
166  $connection->getDatabasePlatform()
167  );
168  $countOfBindParamsPerRow = count(self::$fieldNames);
169  // flush at least chunks of 50 elements - in case the currently used
170  // database platform does not support that, the threshold is lowered
171  $this->maxRowsPerChunk = min(
172  $this->maxRowsPerChunk,
173  floor($maxBindParameters / $countOfBindParamsPerRow)
174  );
175  // Only import extensions that are compatible with 7.6 or higher.
176  // TER only allows to publish extensions with compatibility if the TYPO3 version has been released
177  // And 7.6 was released on 10th of November 2015.
178  // This effectively reduces the number of extensions imported into this TYPO3 installation
179  // by more than 70%. As long as the extensions.xml from TER includes these files, we need to "hack" this
180  // within TYPO3 Core.
181  // For TYPO3 v11.0, this date could be set to 2018-10-02 (v9 LTS release).
182  // Also see https://decisions.typo3.org/t/reduce-size-of-extension-manager-db-table/329/
183  $this->minimumDateToImport = strtotime('2017-04-04T00:00:00+00:00');
184  }
185 
193  public function import($localExtensionListFile, ‪$repositoryUid = null)
194  {
195  if (‪$repositoryUid !== null && is_int(‪$repositoryUid)) {
196  $this->repositoryUid = ‪$repositoryUid;
197  }
198  $zlibStream = 'compress.zlib://';
199  $this->sumRecords = 0;
200  $this->parser->parseXml($zlibStream . $localExtensionListFile);
201  // flush last rows to database if existing
202  if (!empty($this->arrRows)) {
203  GeneralUtility::makeInstance(ConnectionPool::class)
204  ->getConnectionForTable('tx_extensionmanager_domain_model_extension')
205  ->bulkInsert(
206  'tx_extensionmanager_domain_model_extension',
207  $this->arrRows,
208  self::$fieldNames
209  );
210  }
211  $extensions = $this->extensionRepository->insertLastVersion($this->repositoryUid);
212  $this->repositoryRepository->updateRepositoryCount($extensions, $this->repositoryUid);
213  return ‪$this->sumRecords;
214  }
215 
221  protected function ‪loadIntoDatabase(AbstractExtensionXmlParser &$subject)
222  {
223  if ($this->sumRecords !== 0 && $this->sumRecords % $this->maxRowsPerChunk === 0) {
224  GeneralUtility::makeInstance(ConnectionPool::class)
225  ->getConnectionForTable(self::$tableName)
226  ->bulkInsert(
227  self::$tableName,
228  $this->arrRows,
229  self::$fieldNames
230  );
231  $this->arrRows = [];
232  }
233  if (!$subject->isValidVersionNumber()) {
234  // Skip in case extension version is not valid
235  return;
236  }
237  $versionRepresentations = ‪VersionNumberUtility::convertVersionStringToArray($subject->getVersion());
238  // order must match that of self::$fieldNames!
239  $this->arrRows[] = [
240  $subject->getExtkey(),
241  $subject->getVersion(),
242  $versionRepresentations['version_int'],
243  // initialize current_version, correct value computed later:
244  0,
245  (int)$subject->getAlldownloadcounter(),
246  (int)$subject->getDownloadcounter(),
247  $subject->getTitle() ?? '',
248  $subject->getOwnerusername(),
249  $subject->getAuthorname() ?? '',
250  $subject->getAuthoremail() ?? '',
251  $subject->getAuthorcompany() ?? '',
252  (int)$subject->getLastuploaddate(),
253  $subject->getT3xfilemd5(),
255  $this->extensionModel->getDefaultState($subject->getState() ?: ''),
256  (int)$subject->getReviewstate(),
257  $this->extensionModel->getCategoryIndexFromStringOrNumber($subject->getCategory() ?: ''),
258  $subject->getDescription() ?: '',
259  $subject->getDependencies() ?: '',
260  $subject->getUploadcomment() ?: '',
261  $subject->getDocumentationLink() ?: '',
262  ];
264  }
265 
271  public function ‪update(\SplSubject $subject)
272  {
273  if (is_subclass_of($subject, AbstractExtensionXmlParser::class)) {
274  if ((int)$subject->getLastuploaddate() > $this->minimumDateToImport) {
275  $this->‪loadIntoDatabase($subject);
276  }
277  }
278  }
279 }
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:25
‪TYPO3\CMS\Extensionmanager\Utility\Importer
Definition: ExtensionListUtility.php:16
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getAuthorname
‪string getAuthorname()
Definition: AbstractExtensionXmlParser.php:205
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionStringToArray
‪static array convertVersionStringToArray($version)
Definition: VersionNumberUtility.php:163
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getLastuploaddate
‪string getLastuploaddate()
Definition: AbstractExtensionXmlParser.php:271
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getState
‪string getState()
Definition: AbstractExtensionXmlParser.php:304
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$extensionRepository
‪TYPO3 CMS Extensionmanager Domain Repository ExtensionRepository $extensionRepository
Definition: ExtensionListUtility.php:109
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\isValidVersionNumber
‪isValidVersionNumber()
Definition: AbstractExtensionXmlParser.php:356
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$fieldNames
‪static array $fieldNames
Definition: ExtensionListUtility.php:58
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$arrRows
‪array $arrRows
Definition: ExtensionListUtility.php:52
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$tableName
‪static string $tableName
Definition: ExtensionListUtility.php:86
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\update
‪update(\SplSubject $subject)
Definition: ExtensionListUtility.php:259
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getDownloadcounter
‪string getDownloadcounter()
Definition: AbstractExtensionXmlParser.php:249
‪TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
Definition: RepositoryRepository.php:26
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getAuthorcompany
‪string getAuthorcompany()
Definition: AbstractExtensionXmlParser.php:183
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\__construct
‪__construct()
Definition: ExtensionListUtility.php:133
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getOwnerusername
‪string getOwnerusername()
Definition: AbstractExtensionXmlParser.php:282
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility
Definition: ExtensionListUtility.php:35
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxBindParameters
‪static int getMaxBindParameters(AbstractPlatform $platform)
Definition: PlatformInformation.php:125
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$sumRecords
‪int $sumRecords
Definition: ExtensionListUtility.php:46
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:35
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getUploadcomment
‪string getUploadcomment()
Definition: AbstractExtensionXmlParser.php:337
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getCategory
‪string getCategory()
Definition: AbstractExtensionXmlParser.php:216
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser
Definition: AbstractExtensionXmlParser.php:23
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getT3xfilemd5
‪string getT3xfilemd5()
Definition: AbstractExtensionXmlParser.php:315
‪TYPO3\CMS\Extensionmanager\Utility\Parser\XmlParserFactory
Definition: XmlParserFactory.php:25
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:24
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getAuthoremail
‪string getAuthoremail()
Definition: AbstractExtensionXmlParser.php:194
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$minimumDateToImport
‪int $minimumDateToImport
Definition: ExtensionListUtility.php:124
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$repositoryRepository
‪TYPO3 CMS Extensionmanager Domain Repository RepositoryRepository $repositoryRepository
Definition: ExtensionListUtility.php:105
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getReviewstate
‪string getReviewstate()
Definition: AbstractExtensionXmlParser.php:293
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getDescription
‪string getDescription()
Definition: AbstractExtensionXmlParser.php:238
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getAlldownloadcounter
‪string getAlldownloadcounter()
Definition: AbstractExtensionXmlParser.php:172
‪TYPO3\CMS\Extensionmanager\Utility\Parser\XmlParserFactory\getParserInstance
‪static AbstractExtensionXmlParser getParserInstance($parserType, $excludeClassNames='')
Definition: XmlParserFactory.php:61
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$objectManager
‪TYPO3 CMS Extbase Object ObjectManager $objectManager
Definition: ExtensionListUtility.php:117
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$maxRowsPerChunk
‪int $maxRowsPerChunk
Definition: ExtensionListUtility.php:93
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$repositoryUid
‪int $repositoryUid
Definition: ExtensionListUtility.php:101
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getDependencies
‪string getDependencies()
Definition: AbstractExtensionXmlParser.php:227
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$extensionModel
‪TYPO3 CMS Extensionmanager Domain Model Extension $extensionModel
Definition: ExtensionListUtility.php:113
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation
Definition: PlatformInformation.php:33
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getVersion
‪string getVersion()
Definition: AbstractExtensionXmlParser.php:348
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$parser
‪AbstractExtensionXmlParser $parser
Definition: ExtensionListUtility.php:40
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getTitle
‪string getTitle()
Definition: AbstractExtensionXmlParser.php:326
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\loadIntoDatabase
‪loadIntoDatabase(AbstractExtensionXmlParser &$subject)
Definition: ExtensionListUtility.php:209
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getDocumentationLink
‪string getDocumentationLink()
Definition: AbstractExtensionXmlParser.php:365
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getExtkey
‪string getExtkey()
Definition: AbstractExtensionXmlParser.php:260