‪TYPO3CMS  9.5
ExtensionListUtility.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  */
21 
26 class ‪ExtensionListUtility implements \SplObserver
27 {
33  protected ‪$parser;
34 
40  protected ‪$sumRecords = 0;
41 
47  protected ‪$arrRows = [];
48 
54  protected static ‪$fieldNames = [
55  'extension_key',
56  'version',
57  'integer_version',
58  'current_version',
59  'alldownloadcounter',
60  'downloadcounter',
61  'title',
62  'ownerusername',
63  'author_name',
64  'author_email',
65  'authorcompany',
66  'last_updated',
67  'md5hash',
68  'repository',
69  'state',
70  'review_state',
71  'category',
72  'description',
73  'serialized_dependencies',
74  'update_comment'
75  ];
76 
82  protected static ‪$tableName = 'tx_extensionmanager_domain_model_extension';
83 
90  protected ‪$maxRowsPerChunk = 50;
91 
97  protected static ‪$fieldIndicesNoQuote = [2, 3, 5, 11, 13, 14, 15, 16];
98 
106  protected ‪$repositoryUid = 1;
107 
111  protected ‪$repositoryRepository;
112 
116  protected ‪$extensionRepository;
117 
122 
126  protected ‪$objectManager;
127 
134  protected ‪$minimumDateToImport;
135 
143  public function ‪__construct()
144  {
146  $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
147  $this->repositoryRepository = $this->objectManager->get(\‪TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class);
148  $this->extensionRepository = $this->objectManager->get(\‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository::class);
149  $this->extensionModel = $this->objectManager->get(\‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
150  // @todo catch parser exception
152  if (is_object($this->parser)) {
153  $this->parser->attach($this);
154  } else {
155  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
156  static::class . ': No XML parser available.',
157  1476108717
158  );
159  }
160 
161  $connection = GeneralUtility::makeInstance(ConnectionPool::class)
162  ->getConnectionForTable(self::$tableName);
164  $connection->getDatabasePlatform()
165  );
166  $countOfBindParamsPerRow = count(self::$fieldNames);
167  // flush at least chunks of 50 elements - in case the currently used
168  // database platform does not support that, the threshold is lowered
169  $this->maxRowsPerChunk = min(
170  $this->maxRowsPerChunk,
171  floor($maxBindParameters / $countOfBindParamsPerRow)
172  );
173  // Only import extensions that are compatible with 7.6 or higher.
174  // TER only allows to publish extensions with compatibility if the TYPO3 version has been released
175  // And 7.6 was released on 10th of November 2015.
176  // This effectively reduces the number of extensions imported into this TYPO3 installation
177  // by more than 70%. As long as the extensions.xml from TER includes these files, we need to "hack" this
178  // within TYPO3 Core.
179  // For TYPO3 v10.0, this date could be set to 2017-04-04 (8 LTS release).
180  // Also see https://decisions.typo3.org/t/reduce-size-of-extension-manager-db-table/329/
181  $this->minimumDateToImport = strtotime('2015-11-10T00:00:00+00:00');
182  }
183 
191  public function import($localExtensionListFile, ‪$repositoryUid = null)
192  {
193  if (‪$repositoryUid !== null && is_int(‪$repositoryUid)) {
194  $this->repositoryUid = ‪$repositoryUid;
195  }
196  $zlibStream = 'compress.zlib://';
197  $this->sumRecords = 0;
198  $this->parser->parseXml($zlibStream . $localExtensionListFile);
199  // flush last rows to database if existing
200  if (!empty($this->arrRows)) {
201  GeneralUtility::makeInstance(ConnectionPool::class)
202  ->getConnectionForTable('tx_extensionmanager_domain_model_extension')
203  ->bulkInsert(
204  'tx_extensionmanager_domain_model_extension',
205  $this->arrRows,
206  self::$fieldNames
207  );
208  }
209  $extensions = $this->extensionRepository->insertLastVersion($this->repositoryUid);
210  $this->repositoryRepository->updateRepositoryCount($extensions, $this->repositoryUid);
211  return ‪$this->sumRecords;
212  }
213 
219  protected function ‪loadIntoDatabase(AbstractExtensionXmlParser &$subject)
220  {
221  if ($this->sumRecords !== 0 && $this->sumRecords % $this->maxRowsPerChunk === 0) {
222  GeneralUtility::makeInstance(ConnectionPool::class)
223  ->getConnectionForTable(self::$tableName)
224  ->bulkInsert(
225  self::$tableName,
226  $this->arrRows,
227  self::$fieldNames
228  );
229  $this->arrRows = [];
230  }
231  $versionRepresentations = ‪VersionNumberUtility::convertVersionStringToArray($subject->getVersion());
232  // order must match that of self::$fieldNames!
233  $this->arrRows[] = [
234  $subject->getExtkey(),
235  $subject->getVersion(),
236  $versionRepresentations['version_int'],
237  // initialize current_version, correct value computed later:
238  0,
239  (int)$subject->getAlldownloadcounter(),
240  (int)$subject->getDownloadcounter(),
241  $subject->getTitle() !== null ? $subject->getTitle() : '',
242  $subject->getOwnerusername(),
243  $subject->getAuthorname() !== null ? $subject->getAuthorname() : '',
244  $subject->getAuthoremail() !== null ? $subject->getAuthoremail() : '',
245  $subject->getAuthorcompany() !== null ? $subject->getAuthorcompany() : '',
246  (int)$subject->getLastuploaddate(),
247  $subject->getT3xfilemd5(),
249  $this->extensionModel->getDefaultState($subject->getState() ?: ''),
250  (int)$subject->getReviewstate(),
251  $this->extensionModel->getCategoryIndexFromStringOrNumber($subject->getCategory() ?: ''),
252  $subject->getDescription() ?: '',
253  $subject->getDependencies() ?: '',
254  $subject->getUploadcomment() ?: ''
255  ];
257  }
258 
264  public function ‪update(\SplSubject $subject)
265  {
266  if (is_subclass_of($subject, AbstractExtensionXmlParser::class)) {
267  if ((int)$subject->getLastuploaddate() > $this->minimumDateToImport) {
268  $this->‪loadIntoDatabase($subject);
269  }
270  }
271  }
272 }
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:21
‪TYPO3\CMS\Extensionmanager\Utility\Importer
Definition: ExtensionListUtility.php:2
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getAuthorname
‪string getAuthorname()
Definition: AbstractExtensionXmlParser.php:198
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionStringToArray
‪static array convertVersionStringToArray($version)
Definition: VersionNumberUtility.php:153
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getLastuploaddate
‪string getLastuploaddate()
Definition: AbstractExtensionXmlParser.php:264
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getState
‪string getState()
Definition: AbstractExtensionXmlParser.php:297
‪TYPO3
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$extensionRepository
‪TYPO3 CMS Extensionmanager Domain Repository ExtensionRepository $extensionRepository
Definition: ExtensionListUtility.php:106
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$fieldNames
‪static array $fieldNames
Definition: ExtensionListUtility.php:50
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$arrRows
‪array $arrRows
Definition: ExtensionListUtility.php:44
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$tableName
‪static string $tableName
Definition: ExtensionListUtility.php:77
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\update
‪update(\SplSubject $subject)
Definition: ExtensionListUtility.php:251
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getDownloadcounter
‪string getDownloadcounter()
Definition: AbstractExtensionXmlParser.php:242
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getAuthorcompany
‪string getAuthorcompany()
Definition: AbstractExtensionXmlParser.php:176
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$fieldIndicesNoQuote
‪static array $fieldIndicesNoQuote
Definition: ExtensionListUtility.php:90
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\__construct
‪__construct()
Definition: ExtensionListUtility.php:130
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getOwnerusername
‪string getOwnerusername()
Definition: AbstractExtensionXmlParser.php:275
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility
Definition: ExtensionListUtility.php:27
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxBindParameters
‪static int getMaxBindParameters(AbstractPlatform $platform)
Definition: PlatformInformation.php:71
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$sumRecords
‪int $sumRecords
Definition: ExtensionListUtility.php:38
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getUploadcomment
‪string getUploadcomment()
Definition: AbstractExtensionXmlParser.php:330
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getCategory
‪string getCategory()
Definition: AbstractExtensionXmlParser.php:209
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser
Definition: AbstractExtensionXmlParser.php:22
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getT3xfilemd5
‪string getT3xfilemd5()
Definition: AbstractExtensionXmlParser.php:308
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getAuthoremail
‪string getAuthoremail()
Definition: AbstractExtensionXmlParser.php:187
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$minimumDateToImport
‪int $minimumDateToImport
Definition: ExtensionListUtility.php:121
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$repositoryRepository
‪TYPO3 CMS Extensionmanager Domain Repository RepositoryRepository $repositoryRepository
Definition: ExtensionListUtility.php:102
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getReviewstate
‪string getReviewstate()
Definition: AbstractExtensionXmlParser.php:286
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getDescription
‪string getDescription()
Definition: AbstractExtensionXmlParser.php:231
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getAlldownloadcounter
‪string getAlldownloadcounter()
Definition: AbstractExtensionXmlParser.php:165
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$objectManager
‪TYPO3 CMS Extbase Object ObjectManager $objectManager
Definition: ExtensionListUtility.php:114
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$maxRowsPerChunk
‪int $maxRowsPerChunk
Definition: ExtensionListUtility.php:84
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$repositoryUid
‪int $repositoryUid
Definition: ExtensionListUtility.php:98
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getDependencies
‪string getDependencies()
Definition: AbstractExtensionXmlParser.php:220
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$extensionModel
‪TYPO3 CMS Extensionmanager Domain Model Extension $extensionModel
Definition: ExtensionListUtility.php:110
‪TYPO3\CMS\Core\Database\Platform\PlatformInformation
Definition: PlatformInformation.php:31
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getVersion
‪string getVersion()
Definition: AbstractExtensionXmlParser.php:341
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\$parser
‪AbstractExtensionXmlParser $parser
Definition: ExtensionListUtility.php:32
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getTitle
‪string getTitle()
Definition: AbstractExtensionXmlParser.php:319
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extensionmanager\Utility\Importer\ExtensionListUtility\loadIntoDatabase
‪loadIntoDatabase(AbstractExtensionXmlParser &$subject)
Definition: ExtensionListUtility.php:206
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\getExtkey
‪string getExtkey()
Definition: AbstractExtensionXmlParser.php:253
‪TYPO3\CMS\Extensionmanager\Utility\Parser\XmlParserFactory\getParserInstance
‪static TYPO3 CMS Extensionmanager Utility Parser AbstractExtensionXmlParser getParserInstance($parserType, $excludeClassNames='')
Definition: XmlParserFactory.php:58