TYPO3 CMS  TYPO3_7-6
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  */
16 
24 class ExtensionListUtility implements \SplObserver
25 {
31  protected $parser;
32 
38  protected $sumRecords = 0;
39 
45  protected $arrRows = [];
46 
52  protected static $fieldNames = [
53  'extension_key',
54  'version',
55  'integer_version',
56  'current_version',
57  'alldownloadcounter',
58  'downloadcounter',
59  'title',
60  'ownerusername',
61  'author_name',
62  'author_email',
63  'authorcompany',
64  'last_updated',
65  'md5hash',
66  'repository',
67  'state',
68  'review_state',
69  'category',
70  'description',
71  'serialized_dependencies',
72  'update_comment'
73  ];
74 
80  protected static $fieldIndicesNoQuote = [2, 3, 5, 11, 13, 14, 15, 16];
81 
89  protected $repositoryUid = 1;
90 
95 
100 
104  protected $extensionModel;
105 
113  public function __construct()
114  {
116  $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
117  $this->repositoryRepository = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class);
118  $this->extensionRepository = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository::class);
119  $this->extensionModel = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
120  // @todo catch parser exception
122  if (is_object($this->parser)) {
123  $this->parser->attach($this);
124  } else {
125  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(get_class($this) . ': No XML parser available.');
126  }
127  }
128 
136  public function import($localExtensionListFile, $repositoryUid = null)
137  {
138  if (!is_null($repositoryUid) && is_int($repositoryUid)) {
139  $this->repositoryUid = $repositoryUid;
140  }
141  $zlibStream = 'compress.zlib://';
142  $this->sumRecords = 0;
143  $this->parser->parseXML($zlibStream . $localExtensionListFile);
144  // flush last rows to database if existing
145  if (!empty($this->arrRows)) {
146  $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('tx_extensionmanager_domain_model_extension', self::$fieldNames, $this->arrRows, self::$fieldIndicesNoQuote);
147  }
148  $extensions = $this->extensionRepository->insertLastVersion($this->repositoryUid);
149  $this->repositoryRepository->updateRepositoryCount($extensions, $this->repositoryUid);
150  return $this->sumRecords;
151  }
152 
159  protected function loadIntoDatabase(\SplSubject &$subject)
160  {
161  // flush every 50 rows to database
162  if ($this->sumRecords !== 0 && $this->sumRecords % 50 === 0) {
163  $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('tx_extensionmanager_domain_model_extension', self::$fieldNames, $this->arrRows, self::$fieldIndicesNoQuote);
164  $this->arrRows = [];
165  }
166  $versionRepresentations = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionStringToArray($subject->getVersion());
167  // order must match that of self::$fieldNames!
168  $this->arrRows[] = [
169  $subject->getExtkey(),
170  $subject->getVersion(),
171  $versionRepresentations['version_int'],
172  // initialize current_version, correct value computed later:
173  0,
174  (int)$subject->getAlldownloadcounter(),
175  (int)$subject->getDownloadcounter(),
176  !is_null($subject->getTitle()) ? $subject->getTitle() : '',
177  $subject->getOwnerusername(),
178  !is_null($subject->getAuthorname()) ? $subject->getAuthorname() : '',
179  !is_null($subject->getAuthoremail()) ? $subject->getAuthoremail() : '',
180  !is_null($subject->getAuthorcompany()) ? $subject->getAuthorcompany() : '',
181  (int)$subject->getLastuploaddate(),
182  $subject->getT3xfilemd5(),
184  $this->extensionModel->getDefaultState($subject->getState() ?: ''),
185  (int)$subject->getReviewstate(),
186  $this->extensionModel->getCategoryIndexFromStringOrNumber($subject->getCategory() ?: ''),
187  $subject->getDescription() ?: '',
188  $subject->getDependencies() ?: '',
189  $subject->getUploadcomment() ?: ''
190  ];
192  }
193 
200  public function update(\SplSubject $subject)
201  {
202  if (is_subclass_of($subject, \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser::class)) {
203  $this->loadIntoDatabase($subject);
204  }
205  }
206 }
static getParserInstance($parserType, $excludeClassNames='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']