Commit 2c275ecf authored by speedprogs_de's avatar speedprogs_de

code cleanup, added extension utility, cleaned json views

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@45928 735d13b6-9817-0410-8766-e36946ffe9aa
parent 53c144d7
......@@ -143,8 +143,8 @@
* @return string Translated label
*/
protected function translate($label, array $arguments = array()) {
$extKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extKey, $arguments);
$extensionKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extensionKey, $arguments);
}
}
......
......@@ -132,8 +132,8 @@
* @return string Translated label
*/
protected function translate($label, array $arguments = array()) {
$extKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extKey, $arguments);
$extensionKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extensionKey, $arguments);
}
}
......
......@@ -107,8 +107,7 @@
* @return void
*/
public function listAction() {
$rawData = ('json' == $this->request->getFormat());
$this->view->assign('extensions', $this->extensionRepository->findAll($rawData));
$this->view->assign('extensions', $this->extensionRepository->findAll());
}
......@@ -118,9 +117,8 @@
* @return void
*/
public function listLatestAction() {
$rawData = ('json' == $this->request->getFormat());
$latestCount = (!empty($this->settings['latestCount']) ? $this->settings['latestCount'] : 20);
$extensions = $this->extensionRepository->findNewAndUpdated($latestCount, $rawData);
$extensions = $this->extensionRepository->findNewAndUpdated($latestCount);
$this->view->assign('extensions', $extensions);
}
......@@ -279,23 +277,22 @@
}
// Check session if user has already downloaded this file today
$extKey = $version->getExtension()->getExtKey();
$extensionKey = $version->getExtension()->getExtKey();
Tx_TerFe2_Utility_Session::load();
if (!Tx_TerFe2_Utility_Session::hasDownloaded($extKey)) {
if (!Tx_TerFe2_Utility_Session::hasDownloaded($extensionKey)) {
// Add +1 to download counter
$version->incrementDownloadCounter();
$persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
$persistenceManager->persistAll();
// Add extension key to session
Tx_TerFe2_Utility_Session::addDownload($extKey);
Tx_TerFe2_Utility_Session::addDownload($extensionKey);
Tx_TerFe2_Utility_Session::save();
}
// Send file to browser
$format = (strtolower($format) == 'zip' ? 'zip' : 't3x');
$newFileName = $extensionProvider->getExtensionFileName($version, $format);
if ($format == 'zip') {
if (strcasecmp($format, 'zip')) {
$urlToFile = Tx_TerFe2_Utility_Zip::convertT3xToZip($urlToFile);
}
if (!Tx_TerFe2_Utility_Files::transferFile($urlToFile, $newFileName)) {
......@@ -315,8 +312,8 @@
* @return string Translated label
*/
protected function translate($label, array $arguments = array()) {
$extKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extKey, $arguments);
$extensionKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extensionKey, $arguments);
}
}
......
......@@ -145,8 +145,8 @@
* @return string Translated label
*/
protected function translate($label, array $arguments = array()) {
$extKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extKey, $arguments);
$extensionKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extensionKey, $arguments);
}
}
......
......@@ -36,12 +36,10 @@
/**
* Returns all extensions
*
* @param boolean $rawResult Return raw data
* @return array An array of extensions
*/
public function findAll($rawResult = FALSE) {
public function findAll() {
$query = $this->createQuery();
$query->getQuerySettings()->setReturnRawQueryResult($rawResult);
$query->setOrderings(
array('lastVersion.title' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING)
);
......@@ -53,12 +51,10 @@
* Returns new and updated extensions
*
* @param integer $latestCount Count of extensions
* @param boolean $rawResult Return raw data
* @return array An array of extensions
*/
public function findNewAndUpdated($latestCount, $rawResult = FALSE) {
public function findNewAndUpdated($latestCount) {
$query = $this->createQuery();
$query->getQuerySettings()->setReturnRawQueryResult($rawResult);
$query->setLimit((int) $latestCount);
$query->setOrderings(
array('lastUpload' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING)
......
......@@ -50,7 +50,7 @@
/**
* @var array Extension information schema
*/
protected $extInfoSchema = array();
protected $extensionInfoSchema = array();
/**
......@@ -95,7 +95,7 @@
*/
public function getExtensionIcon(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$fileName = $this->getExtensionFileName($version, $fileType);
$cachePath = Tx_TerFe2_Utility_Files::getAbsDirectory('typo3temp/pics/');
$cachePath = Tx_TerFe2_Utility_Files::getAbsoluteDirectory('typo3temp/pics/');
// Check local cache first
if (Tx_TerFe2_Utility_Files::fileExists($cachePath . $fileName)) {
......@@ -133,9 +133,9 @@
* @return string File name
*/
public function getExtensionFileName(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$extKey = $version->getExtension()->getExtKey();
$extensionKey = $version->getExtension()->getExtKey();
$versionString = $version->getVersionString();
$fileName = Tx_TerFe2_Utility_Files::generateFileName($extKey, $versionString, $fileType);
$fileName = Tx_TerFe2_Utility_Files::generateFileName($extensionKey, $versionString, $fileType);
if (empty($fileName)) {
throw new Exception('Could not generate file name for this Version object');
......@@ -166,55 +166,54 @@
/**
* Generates an array with all Extension information
*
* @param array $extData Extension data
* @param array $extInfoSchema Extension information schema
* @param array $extensionData Extension data
* @return array Extension information
*/
protected function getExtensionInfo(array $extData) {
$extInfoSchema = $this->getExtensionInfoSchema();
$extInfo = array('softwareRelation' => array());
protected function getExtensionInfo(array $extensionData) {
$extensionInfoSchema = $this->getExtensionInfoSchema();
$extensionInfo = array('softwareRelation' => array());
// Get field value
foreach ($extInfoSchema as $fieldName => $fieldConf) {
$extInfo[$fieldName] = '';
if (!empty($extData[$fieldName])) {
$extInfo[$fieldName] = $this->convertValue($extData[$fieldName], $fieldConf['type']);
foreach ($extensionInfoSchema as $fieldName => $fieldConf) {
$extensionInfo[$fieldName] = '';
if (!empty($extensionData[$fieldName])) {
$extensionInfo[$fieldName] = $this->convertValue($extensionData[$fieldName], $fieldConf['type']);
}
}
// Get upload date
if (empty($extInfo['uploadDate'])) {
$extInfo['uploadDate'] = (int) $GLOBALS['SIM_EXEC_TIME'];
if (empty($extensionInfo['uploadDate'])) {
$extensionInfo['uploadDate'] = (int) $GLOBALS['SIM_EXEC_TIME'];
}
// Get file hash
if (empty($extInfo['fileHash']) && !empty($extData['fileName'])) {
$extInfo['fileHash'] = Tx_TerFe2_Utility_Files::getFileHash($extData['fileName']);
if (empty($extensionInfo['fileHash']) && !empty($extensionData['fileName'])) {
$extensionInfo['fileHash'] = Tx_TerFe2_Utility_Files::getFileHash($extensionData['fileName']);
}
// Get version number
if (empty($extInfo['versionNumber']) && !empty($extInfo['versionString'])) {
$extInfo['versionNumber'] = t3lib_div::int_from_ver($extInfo['versionString']);
if (empty($extensionInfo['versionNumber']) && !empty($extensionInfo['versionString'])) {
$extensionInfo['versionNumber'] = t3lib_div::int_from_ver($extensionInfo['versionString']);
}
// Check required information afterwards
foreach ($extInfoSchema as $fieldName => $fieldConf) {
if (empty($extInfo[$fieldName]) && $fieldConf['required']) {
foreach ($extensionInfoSchema as $fieldName => $fieldConf) {
if (empty($extensionInfo[$fieldName]) && $fieldConf['required']) {
return array();
}
}
// Add relations
if (!empty($extData['relations']) && is_array($extData['relations'])) {
foreach ($extData['relations'] as $relation) {
if (!empty($extensionData['relations']) && is_array($extensionData['relations'])) {
foreach ($extensionData['relations'] as $relation) {
if (!empty($relation['relationType']) && !empty($relation['relationKey']) && !empty($relation['softwareType'])) {
$relation['versionRange'] = (!empty($relation['versionRange']) ? $relation['versionRange'] : '');
$extInfo['softwareRelation'][] = $relation;
$extensionInfo['softwareRelation'][] = $relation;
}
}
}
return $extInfo;
return $extensionInfo;
}
......@@ -224,8 +223,8 @@
* @return array Properties
*/
protected function getExtensionInfoSchema() {
if (!empty($this->extInfoSchema)) {
return $this->extInfoSchema;
if (!empty($this->extensionInfoSchema)) {
return $this->extensionInfoSchema;
}
// Get class structure and property options
......@@ -262,17 +261,17 @@
}
// Build field
$this->extInfoSchema[$propertyName] = array(
$this->extensionInfoSchema[$propertyName] = array(
'type' => $propertyData['type'],
'required' => $required,
);
}
}
unset($this->extInfoSchema['manual']);
unset($this->extInfoSchema['extensionProvider']);
unset($this->extensionInfoSchema['manual']);
unset($this->extensionInfoSchema['extensionProvider']);
return $this->extInfoSchema;
return $this->extensionInfoSchema;
}
......
......@@ -93,8 +93,8 @@
$updateInfoArray = array();
foreach ($this->settings['extensionProviders'] as $providerIdent => $providerSettings) {
// Get update info from one Extension Provider
$extensionProvider = $this->getConcreteExtensionProvider($providerIdent);
$updateInfo = $extensionProvider->getUpdateInfo($lastRunTime);
$extensionProvider = $this->getConcreteExtensionProvider($providerIdent, $providerSettings);
$updateInfo = $extensionProvider->getUpdateInfo($lastRunTime);
// Set providerIdent recursively
array_walk($updateInfo, array($this, 'setExtensionProvider'), $providerIdent);
......@@ -150,9 +150,10 @@
* Load a concrete Extension provider by identifier
*
* @param string $providerIdent Identifier of the Extension Provider
* @param array $providerSettings Provider specific settings
* @return Tx_TerFe2_ExtensionProvider_ExtensionProviderInterface Extension Provider
*/
protected function getConcreteExtensionProvider($providerIdent) {
protected function getConcreteExtensionProvider($providerIdent, array $providerSettings) {
if (empty($providerIdent)) {
throw new Exception('No Extension Provider given');
}
......@@ -161,12 +162,11 @@
return $this->concreteExtensionProviders[$providerIdent];
}
if (empty($this->settings['extensionProviders'][$providerIdent]['className'])) {
if (empty($providerSettings['className'])) {
throw new Exception('No className found for Extension Provider "' . $providerIdent . '"');
}
// Create new one from settings
$providerSettings = $this->settings['extensionProviders'][$providerIdent];
$extensionProvider = $this->objectManager->get($providerSettings['className']);
if ($extensionProvider instanceof Tx_TerFe2_ExtensionProvider_AbstractExtensionProvider) {
$extensionProvider->setConfiguration($providerSettings);
......@@ -183,13 +183,13 @@
/**
* Add Extension Provider to Extension information array
*
* @param array $extInfo Extension information
* @param array $extensionInfo Extension information
* @param string $key Array key
* @param string $providerIdent Ident of the Extension Provider
* @return void
*/
protected function setExtensionProvider(array &$extInfo, $key, $providerIdent) {
$extInfo['extensionProvider'] = $providerIdent;
protected function setExtensionProvider(array &$extensionInfo, $key, $providerIdent) {
$extensionInfo['extensionProvider'] = $providerIdent;
}
}
......
......@@ -45,8 +45,8 @@
* @return array Update information
*/
public function getUpdateInfo($lastUpdate) {
$extPath = (!empty($this->configuration['extensionRootPath']) ? $this->configuration['extensionRootPath'] : 'fileadmin/ter/');
$files = Tx_TerFe2_Utility_Files::getFiles($extPath, 't3x', (int) $lastUpdate, TRUE);
$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();
}
......@@ -54,9 +54,9 @@
// Generate Extension information
$updateInfoArray = array();
foreach ($files as $fileName) {
$extInfo = $this->getExtensionInfo($fileName);
if (!empty($extInfo)) {
$updateInfoArray[] = $extInfo;
$extensionInfo = $this->getExtensionInfo($fileName);
if (!empty($extensionInfo)) {
$updateInfoArray[] = $extensionInfo;
}
}
......@@ -115,48 +115,49 @@
}
// Unpack file and get extension details
$extContent = Tx_TerFe2_Utility_Files::unpackT3xFile($fileName);
unset($extContent['FILES']);
$extensionContent = Tx_TerFe2_Utility_Files::unpackT3xFile($fileName);
unset($extensionContent['FILES']);
// Map fields
$extData = $extContent['EM_CONF'];
$extData['extKey'] = $extContent['extKey'];
$extData['forgeLink'] = '';
$extData['hudsonLink'] = '';
$extData['uploadComment'] = '';
$extData['fileName'] = $fileName;
$extData['versionString'] = $extData['version'];
$extData['authorName'] = $extData['author'];
$extData['authorEmail'] = $extData['author_email'];
$extData['authorCompany'] = $extData['author_company'];
$extData['emCategory'] = $extData['category'];
$extData['doNotLoadInFe'] = $extData['doNotLoadInFE'];
$extData['modifyTables'] = $extData['modify_tables'];
$extData['clearCacheOnLoad'] = $extData['clearcacheonload'];
$extData['cglCompliance'] = $extData['CGLcompliance'];
$extData['cglComplianceNote'] = $extData['CGLcompliance_note'];
$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($extData['TYPO3_version'])) {
$extData['relations'][] = array(
if (!empty($extensionInfo['TYPO3_version'])) {
$extensionInfo['relations'][] = array(
'relationType' => 'dependancy',
'relationKey' => 'typo3',
'softwareType' => 'system',
'versionRange' => $extData['TYPO3_version'],
'versionRange' => $extensionInfo['TYPO3_version'],
);
}
// Add PHP version requirement
if (!empty($extData['PHP_version'])) {
$extData['relations'][] = array(
if (!empty($extensionInfo['PHP_version'])) {
$extensionInfo['relations'][] = array(
'relationType' => 'dependancy',
'relationKey' => 'php',
'softwareType' => 'system',
'versionRange' => $extData['PHP_version'],
'versionRange' => $extensionInfo['PHP_version'],
);
}
return parent::getExtensionInfo($extData);
return parent::getExtensionInfo($extensionInfo);
}
......@@ -203,8 +204,8 @@
}
// Build URL
$key = (!empty($emSettings['selectedMirror']) ? $emSettings['selectedMirror'] : array_rand($mirrors));
$mirrorUrl = 'http://' . $mirrors[$key]['host'] . $mirrors[$key]['path'];
$selectedMirror = (!empty($emSettings['selectedMirror']) ? $emSettings['selectedMirror'] : array_rand($mirrors));
$mirrorUrl = 'http://' . $mirrors[$selectedMirror]['host'] . $mirrors[$selectedMirror]['path'];
}
$this->mirrorUrl = rtrim($mirrorUrl, '/ ') . '/';
......
......@@ -68,8 +68,7 @@
}
// Get update information
$params = array('lastUpdate' => $lastUpdate);
$params = array('lastUpdate' => $lastUpdate);
$dataArray = Tx_TerFe2_Utility_Soap::call($this->configuration['updateFunc'], $params);
if (empty($dataArray)) {
return array();
......@@ -77,10 +76,10 @@
// Generate Extension information
$updateInfoArray = array();
foreach ($dataArray as $extData) {
$extInfo = $this->getExtensionInfo($extData);
if (!empty($extInfo)) {
$updateInfoArray[] = $extInfo;
foreach ($dataArray as $extensionData) {
$extensionInfo = $this->getExtensionInfo($extensionData);
if (!empty($extensionInfo)) {
$updateInfoArray[] = $extensionInfo;
}
}
......
......@@ -78,7 +78,7 @@
* - Additonal Version Info:
* - Codelines
* - Codebytes
* - Add "authorForgeLink" to extInfo
* - Add "authorForgeLink" to extensionInfo
* - Maybe make author name not required
*
* @return boolean TRUE on success
......@@ -94,19 +94,19 @@
}
// Create new Version and Extension objects
foreach ($updateInfoArray as $extInfo) {
foreach ($updateInfoArray as $extensionInfo) {
// Get new Version if version number has changed
$version = $this->getVersion($extInfo);
$version = $this->getVersion($extensionInfo);
if ($version === NULL) {
continue;
}
// Load Author if already exists, else create new one
$author = $this->getAuthor($extInfo);
$author = $this->getAuthor($extensionInfo);
$version->setAuthor($author);
// Load Extension if already exists, else create new one
$extension = $this->getExtension($extInfo);
$extension = $this->getExtension($extensionInfo);
$version->setExtension($extension);
// Add Version to Object Storages
......@@ -136,9 +136,9 @@
);
// Get TypoScript configuration
$setup = Tx_TerFe2_Utility_TypoScript::getSetup();
$setup = Tx_TerFe2_Utility_TypoScript::getSetup();
$this->settings = Tx_TerFe2_Utility_TypoScript::parse($setup['settings.'], FALSE);
$configuration = array_merge($configuration, $setup);
$configuration = array_merge($configuration, $setup);
// Load Dispatcher
$dispatcher = t3lib_div::makeInstance('Tx_Extbase_Core_Bootstrap');
......@@ -172,7 +172,7 @@
// Load Extension Provider and get update information
$extensionProvider = $this->objectManager->get('Tx_TerFe2_ExtensionProvider_ExtensionProvider');
$updateInfoArray = $extensionProvider->getUpdateInfo($lastRunTime);
$updateInfoArray = $extensionProvider->getUpdateInfo($lastRunTime);
return $updateInfoArray;
}
......@@ -181,44 +181,44 @@
/**
* Create Version object and add to Extension
*
* @param array $extInfo Extension information
* @param array $extensionInfo Extension information
* @return Tx_TerFe2_Domain_Model_Version New Version object
*/
public function getVersion(array $extInfo) {
public function getVersion(array $extensionInfo) {
// Check if a Version exists with given version number
if ($this->extensionRepository->countByExtKeyAndVersion($extInfo['extKey'], $extInfo['versionNumber'])) {
if ($this->extensionRepository->countByExtKeyAndVersion($extensionInfo['extKey'], $extensionInfo['versionNumber'])) {
return NULL;
}
// Create new Version
$version = t3lib_div::makeInstance('Tx_TerFe2_Domain_Model_Version');
$version->setTitle($extInfo['title']);
$version->setDescription($extInfo['description']);
$version->setFileHash($extInfo['fileHash']);
$version->setVersionNumber($extInfo['versionNumber']);
$version->setVersionString($extInfo['versionString']);
$version->setUploadDate(new DateTime());
$version->setUploadComment($extInfo['uploadComment']);
$version->setDownloadCounter(0);
$version->setState($extInfo['state']);
$version->setEmCategory($extInfo['emCategory']);
$version->setLoadOrder($extInfo['loadOrder']);
$version->setPriority($extInfo['priority']);
$version->setShy($extInfo['shy']);
$version->setInternal($extInfo['internal']);
$version->setModule($extInfo['module']);
$version->setDoNotLoadInFe($extInfo['doNotLoadInFe']);
$version->setUploadfolder($extInfo['uploadfolder']);
$version->setCreateDirs($extInfo['createDirs']);
$version->setModifyTables($extInfo['modifyTables']);
$version->setClearCacheOnLoad($extInfo['clearCacheOnLoad']);
$version->setLockType($extInfo['lockType']);
$version->setCglCompliance($extInfo['cglCompliance']);
$version->setCglComplianceNote($extInfo['cglComplianceNote']);
$version->setExtensionProvider($extInfo['extensionProvider']);
$version->setTitle( $extensionInfo['title']);
$version->setDescription( $extensionInfo['description']);
$version->setFileHash( $extensionInfo['fileHash']);
$version->setVersionNumber( $extensionInfo['versionNumber']);
$version->setVersionString( $extensionInfo['versionString']);
$version->setUploadDate( new DateTime());
$version->setUploadComment( $extensionInfo['uploadComment']);
$version->setDownloadCounter( 0);
$version->setState( $extensionInfo['state']);
$version->setEmCategory( $extensionInfo['emCategory']);
$version->setLoadOrder( $extensionInfo['loadOrder']);
$version->setPriority( $extensionInfo['priority']);
$version->setShy( $extensionInfo['shy']);
$version->setInternal( $extensionInfo['internal']);
$version->setModule( $extensionInfo['module']);
$version->setDoNotLoadInFe( $extensionInfo['doNotLoadInFe']);
$version->setUploadfolder( $extensionInfo['uploadfolder']);
$version->setCreateDirs( $extensionInfo['createDirs']);
$version->setModifyTables( $extensionInfo['modifyTables']);
$version->setClearCacheOnLoad( $extensionInfo['clearCacheOnLoad']);
$version->setLockType( $extensionInfo['lockType']);
$version->setCglCompliance( $extensionInfo['cglCompliance']);
$version->setCglComplianceNote($extensionInfo['cglComplianceNote']);
$version->setExtensionProvider($extensionInfo['extensionProvider']);
// Add software relations
foreach ($extInfo['softwareRelation'] as $relationInfo) {
foreach ($extensionInfo['softwareRelation'] as $relationInfo) {
$softwareRelation = $this->createSoftwareRelation($relationInfo);
$version->addSoftwareRelation($softwareRelation);
}
......@@ -235,15 +235,15 @@
*/
protected function createSoftwareRelation(array $relationInfo) {
// Get version range
$versionParts = Tx_Extbase_Utility_Arrays::trimExplode('-', $relationInfo['versionRange']);
$versionParts = Tx_Extbase_Utility_Arrays::trimExplode('-', $relationInfo['versionRange']);
$minimumVersion = (!empty($versionParts[0]) ? t3lib_div::int_from_ver($versionParts[0]) : 0);