TYPO3 CMS  TYPO3_8-7
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  */
18 
22 class ExtensionListUtility implements \SplObserver
23 {
29  protected $parser;
30 
36  protected $sumRecords = 0;
37 
43  protected $arrRows = [];
44 
50  protected static $fieldNames = [
51  'extension_key',
52  'version',
53  'integer_version',
54  'current_version',
55  'alldownloadcounter',
56  'downloadcounter',
57  'title',
58  'ownerusername',
59  'author_name',
60  'author_email',
61  'authorcompany',
62  'last_updated',
63  'md5hash',
64  'repository',
65  'state',
66  'review_state',
67  'category',
68  'description',
69  'serialized_dependencies',
70  'update_comment'
71  ];
72 
78  protected static $fieldIndicesNoQuote = [2, 3, 5, 11, 13, 14, 15, 16];
79 
87  protected $repositoryUid = 1;
88 
93 
98 
102  protected $extensionModel;
103 
111  public function __construct()
112  {
114  $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
115  $this->repositoryRepository = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class);
116  $this->extensionRepository = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository::class);
117  $this->extensionModel = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
118  // @todo catch parser exception
120  if (is_object($this->parser)) {
121  $this->parser->attach($this);
122  } else {
123  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
124  get_class($this) . ': No XML parser available.',
125  1476108717
126  );
127  }
128  }
129 
137  public function import($localExtensionListFile, $repositoryUid = null)
138  {
139  if (!is_null($repositoryUid) && is_int($repositoryUid)) {
140  $this->repositoryUid = $repositoryUid;
141  }
142  $zlibStream = 'compress.zlib://';
143  $this->sumRecords = 0;
144  $this->parser->parseXml($zlibStream . $localExtensionListFile);
145  // flush last rows to database if existing
146  if (!empty($this->arrRows)) {
147  GeneralUtility::makeInstance(ConnectionPool::class)
148  ->getConnectionForTable('tx_extensionmanager_domain_model_extension')
149  ->bulkInsert(
150  'tx_extensionmanager_domain_model_extension',
151  $this->arrRows,
152  self::$fieldNames
153  );
154  }
155  $extensions = $this->extensionRepository->insertLastVersion($this->repositoryUid);
156  $this->repositoryRepository->updateRepositoryCount($extensions, $this->repositoryUid);
157  return $this->sumRecords;
158  }
159 
165  protected function loadIntoDatabase(\SplSubject &$subject)
166  {
167  // flush every 50 rows to database
168  if ($this->sumRecords !== 0 && $this->sumRecords % 50 === 0) {
169  GeneralUtility::makeInstance(ConnectionPool::class)
170  ->getConnectionForTable('tx_extensionmanager_domain_model_extension')
171  ->bulkInsert(
172  'tx_extensionmanager_domain_model_extension',
173  $this->arrRows,
174  self::$fieldNames
175  );
176  $this->arrRows = [];
177  }
178  $versionRepresentations = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionStringToArray($subject->getVersion());
179  // order must match that of self::$fieldNames!
180  $this->arrRows[] = [
181  $subject->getExtkey(),
182  $subject->getVersion(),
183  $versionRepresentations['version_int'],
184  // initialize current_version, correct value computed later:
185  0,
186  (int)$subject->getAlldownloadcounter(),
187  (int)$subject->getDownloadcounter(),
188  !is_null($subject->getTitle()) ? $subject->getTitle() : '',
189  $subject->getOwnerusername(),
190  !is_null($subject->getAuthorname()) ? $subject->getAuthorname() : '',
191  !is_null($subject->getAuthoremail()) ? $subject->getAuthoremail() : '',
192  !is_null($subject->getAuthorcompany()) ? $subject->getAuthorcompany() : '',
193  (int)$subject->getLastuploaddate(),
194  $subject->getT3xfilemd5(),
196  $this->extensionModel->getDefaultState($subject->getState() ?: ''),
197  (int)$subject->getReviewstate(),
198  $this->extensionModel->getCategoryIndexFromStringOrNumber($subject->getCategory() ?: ''),
199  $subject->getDescription() ?: '',
200  $subject->getDependencies() ?: '',
201  $subject->getUploadcomment() ?: ''
202  ];
204  }
205 
211  public function update(\SplSubject $subject)
212  {
213  if (is_subclass_of($subject, \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser::class)) {
214  $this->loadIntoDatabase($subject);
215  }
216  }
217 }
static makeInstance($className,... $constructorArguments)
static getParserInstance($parserType, $excludeClassNames='')