|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info> 00006 * Steffen Kamper <info@sk-typo3.de> 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * 00018 * This script is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * This copyright notice MUST APPEAR in all copies of the script! 00024 ***************************************************************/ 00025 /** 00026 * class.tx_em_import_extensionlistimporter.php 00027 * 00028 * Module: Extension manager - Extension list importer 00029 * 00030 * $Id: class.tx_em_import_extensionlistimporter.php 2016 2010-03-14 04:01:47Z mkrause $ 00031 * 00032 * @author Marcus Krause <marcus#exp2010@t3sec.info> 00033 * @author Steffen Kamper <info@sk-typo3.de> 00034 */ 00035 00036 /** 00037 * Importer object for extension list 00038 * 00039 * @author Marcus Krause <marcus#exp2010@t3sec.info> 00040 * @author Steffen Kamper <info@sk-typo3.de> 00041 * 00042 * @since 2010-02-10 00043 * @package TYPO3 00044 * @subpackage EM 00045 */ 00046 class tx_em_Import_ExtensionListImporter implements SplObserver { 00047 00048 /** 00049 * Keeps instance of a XML parser. 00050 * 00051 * @var tx_em_Parser_ExtensionXmlAbstractParser 00052 */ 00053 protected $parser; 00054 00055 /** 00056 * Keeps number of processed version records. 00057 * 00058 * @var integer 00059 */ 00060 protected $sumRecords = 0; 00061 00062 /** 00063 * Keeps record values to be inserted into database. 00064 * 00065 * @var array 00066 */ 00067 protected $arrRows = array(); 00068 00069 /** 00070 * Keeps fieldnames of cache_extension table. 00071 * 00072 * @var array 00073 */ 00074 static protected $fieldNames = array( 00075 'extkey', 00076 'version', 00077 'intversion', 00078 'alldownloadcounter', 00079 'downloadcounter', 00080 'title', 00081 'ownerusername', 00082 'authorname', 00083 'authoremail', 00084 'authorcompany', 00085 'lastuploaddate', 00086 't3xfilemd5', 00087 'repository', 00088 'state', 00089 'reviewstate', 00090 'category', 00091 'description', 00092 'dependencies', 00093 'uploadcomment', 00094 //'lastversion', 00095 //'lastreviewedversion' 00096 ); 00097 00098 /** 00099 * Keeps indexes of fields that should not be quoted. 00100 * 00101 * @var array 00102 */ 00103 static protected $fieldIndicesNoQuote = array(2, 3, 4, 10, 12, 13, 14, 15); 00104 00105 00106 /** 00107 * Keeps repository UID. 00108 * 00109 * The UID is necessary for inserting records. 00110 * 00111 * @var integer 00112 */ 00113 protected $repositoryUID = 1; 00114 00115 00116 /** 00117 * Class constructor. 00118 * 00119 * Method retrieves and initializes extension XML parser instance. 00120 * 00121 * @access public 00122 * @return void 00123 * @throws tx_em_XmlException in case no valid parser instance is available 00124 */ 00125 function __construct() { 00126 // TODO catch parser exception 00127 $this->parser = tx_em_Parser_XmlParserFactory::getParserInstance('extension'); 00128 if (is_object($this->parser)) { 00129 $this->parser->attach($this); 00130 } else { 00131 throw new tx_em_XmlException(get_class($this) . ': ' . 'No XML parser available.'); 00132 } 00133 } 00134 00135 /** 00136 * Method initializes parsing of extension.xml.gz file. 00137 * 00138 * @access public 00139 * @param string $localExtListFile absolute path to (gzipped) local extension list xml file 00140 * @param integer $repositoryUID UID of repository to be used when inserting records into DB 00141 * @return integer total number of imported extension versions 00142 */ 00143 public function import($localExtListFile, $repositoryUID = NULL) { 00144 if (!is_null($repositoryUID) && is_int($repositoryUID)) { 00145 $this->repositoryUID = $repositoryUID; 00146 } 00147 $zlibStream = 'compress.zlib://'; 00148 $this->sumRecords = 0; 00149 00150 $this->parser->parseXML($zlibStream . $localExtListFile); 00151 00152 // flush last rows to database if existing 00153 if (count($this->arrRows)) { 00154 $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows( 00155 'cache_extensions', 00156 self::$fieldNames, 00157 $this->arrRows, 00158 self::$fieldIndicesNoQuote 00159 ); 00160 } 00161 $extensions = tx_em_Database::insertLastVersion($this->repositoryUID); 00162 tx_em_Database::updateRepositoryCount($extensions, $this->repositoryUID); 00163 00164 return $this->sumRecords; 00165 } 00166 00167 /** 00168 * Method collects and stores extension version details into the database. 00169 * 00170 * @access protected 00171 * @param SplSubject $subject a subject notifying this observer 00172 * @return void 00173 */ 00174 protected function loadIntoDB(SplSubject &$subject) { 00175 // flush every 50 rows to database 00176 if ($this->sumRecords !== 0 && $this->sumRecords % 50 === 0) { 00177 $GLOBALS['TYPO3_DB']->exec_INSERTmultipleRows( 00178 'cache_extensions', 00179 self::$fieldNames, 00180 $this->arrRows, 00181 self::$fieldIndicesNoQuote 00182 ); 00183 $this->arrRows = array(); 00184 } 00185 // order must match that of self::$fieldNamses! 00186 $this->arrRows[] = array( 00187 $subject->getExtkey(), 00188 $subject->getVersion(), 00189 tx_em_Tools::makeVersion($subject->getVersion(), 'int'), 00190 intval($subject->getAlldownloadcounter()), 00191 intval($subject->getDownloadcounter()), 00192 !is_null($subject->getTitle()) ? $subject->getTitle() : '', 00193 $subject->getOwnerusername(), 00194 !is_null($subject->getAuthorname()) ? $subject->getAuthorname() : '', 00195 !is_null($subject->getAuthoremail()) ? $subject->getAuthoremail() : '', 00196 !is_null($subject->getAuthorcompany()) ? $subject->getAuthorcompany() : '', 00197 intval($subject->getLastuploaddate()), 00198 $subject->getT3xfilemd5(), 00199 $this->repositoryUID, 00200 tx_em_Tools::getDefaultState($subject->getState() ? $subject->getState() : ''), 00201 intval($subject->getReviewstate()), 00202 tx_em_Tools::getDefaultCategory($subject->getCategory() ? $subject->getCategory() : ''), 00203 $subject->getDescription() ? $subject->getDescription() : '', 00204 $subject->getDependencies() ? $subject->getDependencies() : '', 00205 $subject->getUploadcomment() ? $subject->getUploadcomment() : '', 00206 ); 00207 ++$this->sumRecords; 00208 } 00209 00210 /** 00211 * Method receives an update from a subject. 00212 * 00213 * @access public 00214 * @param SplSubject $subject a subject notifying this observer 00215 * @return void 00216 */ 00217 public function update(SplSubject $subject) { 00218 if (is_subclass_of($subject, 'tx_em_Parser_ExtensionXmlAbstractParser')) { 00219 $this->loadIntoDB($subject); 00220 } 00221 } 00222 } 00223 00224 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/import/class.tx_em_import_extensionlistimporter.php'])) { 00225 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/import/class.tx_em_import_extensionlistimporter.php']); 00226 } 00227 00228 ?>
1.8.0