Commit a5c34a9b authored by speedprogs_de's avatar speedprogs_de

rewrite step 1: cleaned extension structure and optimized extension providers

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51487 735d13b6-9817-0410-8766-e36946ffe9aa
parent 4b437fcf
......@@ -53,6 +53,12 @@
*/
protected $forgeLink;
/**
* Owner username
* @var string
*/
protected $username;
/**
* versions
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Version>
......@@ -153,6 +159,27 @@
}
/**
* Setter for username
*
* @param string $username Owner username
* @return void
*/
public function setUsername($username) {
$this->username = $username;
}
/**
* Getter for username
*
* @return string Owner username
*/
public function getUsername() {
return $this->username;
}
/**
* Getter for versions
*
......
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Extension manager cache entry
*/
class Tx_TerFe2_Domain_Model_ExtensionManagerCacheEntry extends Tx_Extbase_DomainObject_AbstractEntity {
// No attributes, getters and setters. Only required to get RAW result from respository
}
?>
\ No newline at end of file
......@@ -179,6 +179,12 @@
*/
protected $cglComplianceNote;
/**
* Review state
* @var integer
*/
protected $reviewState;
/**
* Relation to manual object of ter_doc extension
* @var string
......@@ -740,6 +746,27 @@
}
/**
* Setter for reviewState
*
* @param string $reviewState Review state
* @return void
*/
public function setReviewState($reviewState) {
$this->reviewState = $reviewState;
}
/**
* Getter for reviewState
*
* @return string Review state
*/
public function getReviewState() {
return $this->reviewState;
}
/**
* Setter for manual
*
......
......@@ -30,7 +30,7 @@
/**
* Returns random objects from db
*
*
* @param integer $limit Limit of the results
* @return Tx_Extbase_Persistence_QueryResult Query result
*/
......
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Repository for Tx_TerFe2_Domain_Model_ExtensionManagerCacheEntry
*/
class Tx_TerFe2_Domain_Repository_ExtensionManagerCacheEntryRepository extends Tx_TerFe2_Domain_Repository_AbstractRepository {
/**
* Get all updated extensions
*
* @param integer $lastUpdateDate Date of the last update
* @param integer $offset Offset to start with
* @param integer $count Extension count to load
* @return Tx_Extbase_Persistence_QueryResult Query result
*/
public function findLastUpdated($lastUpdateDate, $offset = 0, $count = 0) {
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
$query->getQuerySettings()->setRespectSysLanguage(FALSE);
$query->getQuerySettings()->setReturnRawQueryResult(TRUE);
$query->matching($query->greaterThan('lastuploaddate', (int) $lastUpdateDate));
if (!empty($offset)) {
$query->setOffset((int) $offset);
}
if (!empty($count)) {
$query->setLimit((int) $count);
}
return $query->execute();
}
}
?>
\ No newline at end of file
......@@ -60,7 +60,7 @@
/**
* Returns top rated extensions
*
*
* @param integer $topRatedCount Count of extensions
* @param boolean $rawResult Return raw data
* @return array An array of extensions
......@@ -110,7 +110,7 @@
/**
* Returns all extensions by an author
*
*
* @param Tx_TerFe2_Domain_Model_Author $author The Author to search for
* @return array An array of extensions
*/
......
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract extension provider
*/
abstract class Tx_TerFe2_ExtensionProvider_AbstractProvider implements Tx_TerFe2_ExtensionProvider_ProviderInterface {
/**
* @var Tx_Extbase_Object_ObjectManagerInterface
*/
protected $objectManager;
/**
* @var Tx_Extbase_Persistence_Mapper_DataMapFactory
*/
protected $dataMapFactory;
/**
* @var Tx_Extbase_Reflection_Service
*/
protected $reflectionService;
/**
* @var array Configuration array
*/
protected $configuration;
/**
* @var string
*/
protected $imageCachePath = 'typo3temp/pics/';
/**
* Get or create absolute path to image cache directory
*
* @return void
*/
public function __construct() {
$this->imageCachePath = Tx_TerFe2_Utility_Files::getAbsoluteDirectory($this->imageCachePath);
}
/*
* @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
* @return void
*/
public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
$this->objectManager = $objectManager;
}
/**
* @param Tx_Extbase_Persistence_Mapper_DataMapFactory $dataMapFactory
* @return void
*/
public function injectDataMapFactory(Tx_Extbase_Persistence_Mapper_DataMapFactory $dataMapFactory) {
$this->dataMapFactory = $dataMapFactory;
}
/**
* @param Tx_Extbase_Reflection_Service $reflectionService
* @return void
*/
public function injectReflectionService(Tx_Extbase_Reflection_Service $reflectionService) {
$this->reflectionService = $reflectionService;
}
/**
* Set configuration for the DataProvider
*
* @param array $configuration TypoScript configuration
* @return void
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
/**
* Returns the url to an extension related icon
*
* @param Tx_TerFe2_Domain_Model_Version $version Version object
* @param string $fileType File type
* @return string Url to icon file
*/
public function getIconUrl(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$filename = $this->getFileName($version, $fileType);
// Check local cache first
if (Tx_TerFe2_Utility_Files::fileExists($this->imageCachePath . $filename)) {
return t3lib_div::locationHeaderUrl($this->imageCachePath . $filename);
}
// Get icon from concrete extension provider
$iconUrl = $this->getFileUrl($filename);
// Copy icon to local cache
Tx_TerFe2_Utility_Files::copyFile($iconUrl, $this->imageCachePath . $filename);
return $iconUrl;
}
/**
* Returns an array with minimum and maximum version number from range
*
* @param string $version Range of versions
* @return array Minumum and maximum version number
*/
protected function getVersionByRange($version) {
$version = Tx_Extbase_Utility_Arrays::trimExplode('-', $version);
$minimum = (!empty($version[0]) ? t3lib_div::int_from_ver($version[0]) : 0);
$maximum = (!empty($version[1]) ? t3lib_div::int_from_ver($version[1]) : 0);
return array($minimum, $maximum);
}
}
?>
\ No newline at end of file
......@@ -24,190 +24,360 @@
******************************************************************/
/**
* An Extension Provider for local Extension Manager
* Extension provider for local extension manager
*/
class Tx_TerFe2_ExtensionProvider_ExtensionManagerProvider extends Tx_TerFe2_ExtensionProvider_AbstractExtensionProvider {
class Tx_TerFe2_ExtensionProvider_ExtensionManagerProvider extends Tx_TerFe2_ExtensionProvider_AbstractProvider {
/**
* @var string
*/
protected $extensionRootPath = 'fileadmin/ter/';
/**
* @var string
*/
protected $extensionListFile = 'typo3temp/extensions.xml.gz';
/**
* @var integer
*/
protected $maxMirrorChecks = 2;
/**
* @var string
*/
protected $mirrorUrl;
/**
* @var Tx_TerFe2_Domain_Repository_ExtensionManagerCacheEntryRepository
*/
protected $cacheEntryRepository;
/**
* Returns an array with information about all updated Extensions
* Initialize provider
*
* @param integer $lastUpdate Last update of the extension list
* @return array Update information
* @return void
*/
public function getUpdateInfo($lastUpdate) {
$extensionPath = (!empty($this->configuration['extensionRootPath']) ? $this->configuration['extensionRootPath'] : 'fileadmin/ter/');
$files = Tx_TerFe2_Utility_Files::getFiles($extensionPath, 't3x', (int) $lastUpdate, TRUE);
if (empty($files)) {
return array();
public function initializeProvider() {
// Check if extension manager is loaded
if (!t3lib_extMgm::isLoaded('em')) {
throw new Exception('Requierd system extension "em" is not loaded');
}
// Generate Extension information
$updateInfoArray = array();
foreach ($files as $fileName) {
$extensionInfo = $this->getExtensionInfo($fileName);
if (!empty($extensionInfo)) {
$updateInfoArray[] = $extensionInfo;
}
// Set extension root path
if (!empty($this->configuration['extensionRootPath'])) {
$this->extensionRootPath = rtrim($this->configuration['extensionRootPath'], '/ ') . '/';
}
return $updateInfoArray;
// Set extension list file
if (!empty($this->configuration['extensionListFile'])) {
$this->extensionListFile = $this->configuration['extensionListFile'];
}
// Set maximal mirror check count
if (!empty($this->configuration['maxMirrorChecks'])) {
$this->maxMirrorChecks = (int) $this->configuration['maxMirrorChecks'];
}
// Get repository for extension manager cache entries
$this->extensionRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_ExtensionManagerCacheEntryRepository');
}
/**
* Returns the URL to a file
* Returns all extensions since last run
*
* @param string $fileName File name
* @return string URL to file
* @param integer $lastRun Timestamp of last update
* @param integer $offset Offset to start with
* @param integer $count Extension count to load
* @return array Extension rows
*/
public function getUrlToFile($fileName) {
// Path: /t/e/ter_fe2
$fileName = $fileName[0] . '/' . $fileName[1] . '/' . $fileName;
// Use mirror system from local Extension Manager
if (!empty($this->configuration['useEmMirrors'])) {
$mirrorUrl = $this->getMirrorUrl();
if (!empty($mirrorUrl)) {
$urlToFile = $mirrorUrl . $fileName;
if (Tx_TerFe2_Utility_Files::isLocalUrl($urlToFile)) {
$urlToFile = Tx_TerFe2_Utility_Files::getLocalUrlPath($urlToFile);
}
if (Tx_TerFe2_Utility_Files::fileExists($urlToFile)) {
return $urlToFile;
public function getExtensions($lastRun, $offset, $count) {
// Get extension list
$extensions = $this->extensionRepository->findLastUpdated($lastRun, $offset, $count);
if (empty($extensions)) {
return array();
}
// Load missing information from ext_emconf.php
foreach ($extensions as $extensionKey => $extension) {
$info = $this->getExtensionInfo($extension['extkey'], $extension['version'], $extension['t3xfilemd5']);
foreach ($info as $key => $value) {
if (empty($extension[$key])) {
$extensions[$extensionKey][$key] = $value;
}
}
}
// Get path to local Extension directory
$extensionRootPath = 'fileadmin/ter/';
if (!empty($this->configuration['extensionRootPath'])) {
$extensionRootPath = rtrim($this->configuration['extensionRootPath'], '/ ') . '/';
return $this->buildExtensionStructure($extensions);
}
/**
* Returns the url to an extension related file
*
* @param Tx_TerFe2_Domain_Model_Version $version Version object
* @param string $fileType File type
* @return string Url to file
*/
public function getFileUrl(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$filename = $this->getFileName($version, $fileType);
// Get filename on mirror server
$filename = $this->getMirrorFileUrl($filename);
if (Tx_TerFe2_Utility_Files::isLocalUrl($filename)) {
$filename = Tx_TerFe2_Utility_Files::getAbsolutePathFromUrl($filename);
}
// Check if file exists and is readable
if (Tx_TerFe2_Utility_Files::fileExists(PATH_site . $extensionRootPath . $fileName)) {
return t3lib_div::locationHeaderUrl($extensionRootPath . $fileName);
// Check if file exists
if (!Tx_TerFe2_Utility_Files::fileExists($filename)) {
throw new Exception('File "' . $filename . '" not found');
}
return '';
// Get local url from absolute path
if (Tx_TerFe2_Utility_Files::isAbsolutePath($filename)) {
return Tx_TerFe2_Utility_Files::getUrlFromAbsolutePath($filename);
}
return $filename;
}
/**
* Generates an array with all Extension information
* Returns name of an extension related file
*
* @param string $fileName Filename of the relating t3x file
* @return array Extension information
* @param Tx_TerFe2_Domain_Model_Version $version Version object
* @param string $fileType File type
* @return string File name
*/
protected function getExtensionInfo($fileName) {
if (empty($fileName)) {
return array();
public function getFileName(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$extension = $version->getExtension()->getExtKey();
$version = $version->getVersionString();
$this->generateFileName($extension, $version, $fileType);
}
/**
* Generates the name of an extension related file
*
* @param string $extension Extension key
* @param string $version Version string
* @param string $fileType File type
* @return string File name
*/
protected function generateFileName($extension, $version, $fileType) {
if (empty($extension) || empty($version) || empty($fileType)) {
return '';
}
$extension = strtolower($extension);
$fileType = strtolower(trim($fileType, '. '));
return $extension[0] . '/' . $extension[1] . '/' . $extension . '_' . $version . '.' . $fileType;
}
// Unpack file and get extension details
$extensionContent = Tx_TerFe2_Utility_Files::unpackT3xFile($fileName);
unset($extensionContent['FILES']);
// Map fields
$extensionInfo = $extensionContent['EM_CONF'];
$extensionInfo['extKey'] = $extensionContent['extKey'];
$extensionInfo['forgeLink'] = '';
$extensionInfo['hudsonLink'] = '';
$extensionInfo['uploadComment'] = '';
$extensionInfo['fileName'] = $fileName;
$extensionInfo['versionString'] = $extensionInfo['version'];
$extensionInfo['authorName'] = $extensionInfo['author'];
$extensionInfo['authorEmail'] = $extensionInfo['author_email'];
$extensionInfo['authorCompany'] = $extensionInfo['author_company'];
$extensionInfo['authorForgeLink'] = '';
$extensionInfo['emCategory'] = $extensionInfo['category'];
$extensionInfo['doNotLoadInFe'] = $extensionInfo['doNotLoadInFE'];
$extensionInfo['modifyTables'] = $extensionInfo['modify_tables'];
$extensionInfo['clearCacheOnLoad'] = $extensionInfo['clearcacheonload'];
$extensionInfo['cglCompliance'] = $extensionInfo['CGLcompliance'];
$extensionInfo['cglComplianceNote'] = $extensionInfo['CGLcompliance_note'];
// Add TYPO3 version requirement
if (!empty($extensionInfo['TYPO3_version'])) {