TYPO3 CMS  TYPO3_6-2
ExtensionListUtility.php
Go to the documentation of this file.
1 <?php
3 
29 class ExtensionListUtility implements \SplObserver {
30 
36  protected $parser;
37 
43  protected $sumRecords = 0;
44 
50  protected $arrRows = array();
51 
57  static protected $fieldNames = array(
58  'extension_key',
59  'version',
60  'integer_version',
61  'current_version',
62  'alldownloadcounter',
63  'downloadcounter',
64  'title',
65  'ownerusername',
66  'author_name',
67  'author_email',
68  'authorcompany',
69  'last_updated',
70  'md5hash',
71  'repository',
72  'state',
73  'review_state',
74  'category',
75  'description',
76  'serialized_dependencies',
77  'update_comment'
78  );
79 
85  static protected $fieldIndicesNoQuote = array(2, 3, 5, 11, 13, 14, 15, 16);
86 
94  protected $repositoryUid = 1;
95 
100 
105 
109  protected $extensionModel;
110 
118  public function __construct() {
120  $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
121  $this->repositoryRepository = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository');
122  $this->extensionRepository = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository');
123  $this->extensionModel = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
124  // TODO catch parser exception
126  if (is_object($this->parser)) {
127  $this->parser->attach($this);
128  } else {
129  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(get_class($this) . ': No XML parser available.');
130  }
131  }
132 
140  public function import($localExtensionListFile, $repositoryUid = NULL) {
141  if (!is_null($repositoryUid) && is_int($repositoryUid)) {
142  $this->repositoryUid = $repositoryUid;
143  }
144  $zlibStream = 'compress.zlib://';
145  $this->sumRecords = 0;
146  $this->parser->parseXML($zlibStream . $localExtensionListFile);
147  // flush last rows to database if existing
148  if (count($this->arrRows)) {
149  $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('tx_extensionmanager_domain_model_extension', self::$fieldNames, $this->arrRows, self::$fieldIndicesNoQuote);
150  }
151  $extensions = $this->extensionRepository->insertLastVersion($this->repositoryUid);
152  $this->repositoryRepository->updateRepositoryCount($extensions, $this->repositoryUid);
153  return $this->sumRecords;
154  }
155 
162  protected function loadIntoDatabase(\SplSubject &$subject) {
163  // flush every 50 rows to database
164  if ($this->sumRecords !== 0 && $this->sumRecords % 50 === 0) {
165  $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('tx_extensionmanager_domain_model_extension', self::$fieldNames, $this->arrRows, self::$fieldIndicesNoQuote);
166  $this->arrRows = array();
167  }
168  $versionRepresentations = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionStringToArray($subject->getVersion());
169  // order must match that of self::$fieldNames!
170  $this->arrRows[] = array(
171  $subject->getExtkey(),
172  $subject->getVersion(),
173  $versionRepresentations['version_int'],
174  // initialize current_version, correct value computed later:
175  0,
176  (int)$subject->getAlldownloadcounter(),
177  (int)$subject->getDownloadcounter(),
178  !is_null($subject->getTitle()) ? $subject->getTitle() : '',
179  $subject->getOwnerusername(),
180  !is_null($subject->getAuthorname()) ? $subject->getAuthorname() : '',
181  !is_null($subject->getAuthoremail()) ? $subject->getAuthoremail() : '',
182  !is_null($subject->getAuthorcompany()) ? $subject->getAuthorcompany() : '',
183  (int)$subject->getLastuploaddate(),
184  $subject->getT3xfilemd5(),
186  $this->extensionModel->getDefaultState($subject->getState() ?: ''),
187  (int)$subject->getReviewstate(),
188  $this->extensionModel->getCategoryIndexFromStringOrNumber($subject->getCategory() ?: ''),
189  $subject->getDescription() ?: '',
190  $subject->getDependencies() ?: '',
191  $subject->getUploadcomment() ?: ''
192  );
194  }
195 
202  public function update(\SplSubject $subject) {
203  if (is_subclass_of($subject, 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\AbstractExtensionXmlParser')) {
204  $this->loadIntoDatabase($subject);
205  }
206  }
207 
208 }
static getParserInstance($parserType, $excludeClassNames='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]