2 namespace TYPO3\CMS\Extensionmanager\Utility\Importer
;
4 /***************************************************************
7 * (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
8 * Steffen Kamper <info@sk-typo3.de>
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Module: Extension manager - Extension list importer
30 * @author Marcus Krause <marcus#exp2010@t3sec.info>
31 * @author Steffen Kamper <info@sk-typo3.de>
34 * Importer object for extension list
36 * @author Marcus Krause <marcus#exp2010@t3sec.info>
37 * @author Steffen Kamper <info@sk-typo3.de>
39 * @package Extension Manager
40 * @subpackage Utility/Importer
42 class ExtensionListUtility
implements \SplObserver
{
45 * Keeps instance of a XML parser.
47 * @var \TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlAbstractParser
52 * Keeps number of processed version records.
56 protected $sumRecords = 0;
59 * Keeps record values to be inserted into database.
63 protected $arrRows = array();
66 * Keeps fieldnames of tx_extensionmanager_domain_model_extension table.
70 static protected $fieldNames = array(
93 * Keeps indexes of fields that should not be quoted.
97 static protected $fieldIndicesNoQuote = array(2, 3, 4, 10, 12, 13, 14, 15);
100 * Keeps repository UID.
102 * The UID is necessary for inserting records.
106 protected $repositoryUid = 1;
109 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
111 protected $repositoryRepository;
114 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
116 protected $extensionRepository;
119 * @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension
121 protected $extensionModel;
126 * Method retrieves and initializes extension XML parser instance.
128 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
130 public function __construct() {
131 /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
132 $this->objectManager
= \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
133 $this->repositoryRepository
= $this->objectManager
->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository');
134 $this->extensionRepository
= $this->objectManager
->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository');
135 $this->extensionModel
= $this->objectManager
->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
136 // TODO catch parser exception
137 $this->parser
= \TYPO3\CMS\Extensionmanager\Utility\Parser\XmlParserFactory
::getParserInstance('extension');
138 if (is_object($this->parser
)) {
139 $this->parser
->attach($this);
141 throw new \TYPO3\CMS\Extensionmanager\Exception\
ExtensionManagerException(get_class($this) . ': No XML parser available.');
146 * Method initializes parsing of extension.xml.gz file.
148 * @param string $localExtensionListFile absolute path to extension list xml.gz
149 * @param integer $repositoryUid UID of repository when inserting records into DB
150 * @return integer total number of imported extension versions
152 public function import($localExtensionListFile, $repositoryUid = NULL) {
153 if (!is_null($repositoryUid) && is_int($repositoryUid)) {
154 $this->repositoryUid
= $repositoryUid;
156 $zlibStream = 'compress.zlib://';
157 $this->sumRecords
= 0;
158 $this->parser
->parseXML($zlibStream . $localExtensionListFile);
159 // flush last rows to database if existing
160 if (count($this->arrRows
)) {
161 $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('tx_extensionmanager_domain_model_extension', self
::$fieldNames, $this->arrRows
, self
::$fieldIndicesNoQuote);
163 $extensions = $this->extensionRepository
->insertLastVersion($this->repositoryUid
);
164 $this->repositoryRepository
->updateRepositoryCount($extensions, $this->repositoryUid
);
165 return $this->sumRecords
;
169 * Method collects and stores extension version details into the database.
171 * @param SplSubject &$subject a subject notifying this observer
174 protected function loadIntoDatabase(\SplSubject
&$subject) {
175 // flush every 50 rows to database
176 if ($this->sumRecords
!== 0 && $this->sumRecords %
50 === 0) {
177 $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows('tx_extensionmanager_domain_model_extension', self
::$fieldNames, $this->arrRows
, self
::$fieldIndicesNoQuote);
178 $this->arrRows
= array();
180 $versionRepresentations = \TYPO3\CMS\Core\Utility\VersionNumberUtility
::convertVersionStringToArray($subject->getVersion());
181 // order must match that of self::$fieldNamses!
182 $this->arrRows
[] = array(
183 $subject->getExtkey(),
184 $subject->getVersion(),
185 $versionRepresentations['version_int'],
186 intval($subject->getAlldownloadcounter()),
187 intval($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 intval($subject->getLastuploaddate()),
194 $subject->getT3xfilemd5(),
195 $this->repositoryUid
,
196 $this->extensionModel
->getDefaultState($subject->getState() ?
$subject->getState() : ''),
197 intval($subject->getReviewstate()),
198 $this->extensionModel
->getDefaultCategory($subject->getCategory() ?
$subject->getCategory() : ''),
199 $subject->getDescription() ?
$subject->getDescription() : '',
200 $subject->getDependencies() ?
$subject->getDependencies() : '',
201 $subject->getUploadcomment() ?
$subject->getUploadcomment() : ''
207 * Method receives an update from a subject.
209 * @param SplSubject $subject a subject notifying this observer
212 public function update(\SplSubject
$subject) {
213 if (is_subclass_of($subject, 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\ExtensionXmlAbstractParser')) {
214 $this->loadIntoDatabase($subject);