Commit 43a56613 authored by speedprogs_de's avatar speedprogs_de

finalized zip file creation task, added version repository, added functional...

finalized zip file creation task, added version repository, added functional download link for zip file on detail page

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51708 735d13b6-9817-0410-8766-e36946ffe9aa
parent 9b0f69d0
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* @return void * @return void
*/ */
protected function initializeController() { protected function initializeController() {
$this->authorRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_AuthorRepository'); $this->authorRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_AuthorRepository');
} }
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* @return void * @return void
*/ */
protected function initializeController() { protected function initializeController() {
$this->categoryRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_CategoryRepository'); $this->categoryRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_CategoryRepository');
} }
......
...@@ -48,6 +48,21 @@ ...@@ -48,6 +48,21 @@
*/ */
protected $authorRepository; protected $authorRepository;
/**
* @var Tx_TerFe2_Provider_ProviderManager
*/
protected $providerManager;
/**
* @var Tx_TerFe2_Persistence_Session
*/
protected $session;
/**
* @var Tx_Extbase_Persistence_Manager
*/
protected $persistenceManager;
/** /**
* Initializes the controller * Initializes the controller
...@@ -55,10 +70,13 @@ ...@@ -55,10 +70,13 @@
* @return void * @return void
*/ */
protected function initializeController() { protected function initializeController() {
$this->extensionRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_ExtensionRepository'); $this->extensionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_ExtensionRepository');
$this->categoryRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_CategoryRepository'); $this->categoryRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_CategoryRepository');
$this->tagRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_TagRepository'); $this->tagRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_TagRepository');
$this->authorRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_AuthorRepository'); $this->authorRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_AuthorRepository');
$this->providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$this->session = $this->objectManager->get('Tx_TerFe2_Persistence_Session');
$this->persistenceManager = $this->objectManager->get('Tx_Extbase_Persistence_Manager');
} }
...@@ -219,31 +237,35 @@ ...@@ -219,31 +237,35 @@
* @return void * @return void
*/ */
public function downloadAction(Tx_TerFe2_Domain_Model_Version $version, $format = 't3x') { public function downloadAction(Tx_TerFe2_Domain_Model_Version $version, $format = 't3x') {
// Get extension provider if ($format === 't3x') {
$providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager'); $provider = $this->providerManager->getProvider($version->getExtensionProvider());
$provider = $providerManager->getProvider($version->getExtensionProvider()); $fileUrl = $provider->getFileUrl($version, $format);
} else if ($format === 'zip') {
$fileUrl = PATH_site . $version->getZipFile();
} else {
throw new Exception('A download action for the format "' . $format . '" is not implemented');
}
// Get url to file // Check if file exists
$fileUrl = $provider->getFileUrl($version, $format); if (empty($fileUrl) || !Tx_TerFe2_Utility_File::fileExists($fileUrl)) {
if (empty($fileUrl)) {
$this->redirectWithMessage('index', 'file_not_found'); $this->redirectWithMessage('index', 'file_not_found');
} }
// Check file hash // Check file hash of t3x packages
$fileHash = Tx_TerFe2_Utility_File::getFileHash($fileUrl); if ($format === 't3x') {
if ($fileHash != $version->getFileHash()) { $fileHash = Tx_TerFe2_Utility_File::getFileHash($fileUrl);
$this->redirectWithMessage('index', 'file_hash_not_equal'); if ($fileHash != $version->getFileHash()) {
$this->redirectWithMessage('index', 'file_hash_not_equal');
}
} }
// Check session if user has already downloaded this file today // Check session if user has already downloaded this file today
$extensionKey = $version->getExtension()->getExtKey(); $extensionKey = $version->getExtension()->getExtKey();
$session = $this->objectManager->get('Tx_TerFe2_Persistence_Session'); $downloads = $this->session->get('downloads');
$downloads = $session->get('downloads');
if (empty($downloads) || !in_array($extensionKey, $downloads)) { if (empty($downloads) || !in_array($extensionKey, $downloads)) {
// Add +1 to download counter and save immediately // Add +1 to download counter and save immediately
$version->incrementDownloadCounter(); $version->incrementDownloadCounter();
$persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager'); $this->persistenceManager->persistAll();
$persistenceManager->persistAll();
// Add extension key to session // Add extension key to session
$downloads[] = $extensionKey; $downloads[] = $extensionKey;
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
* @return void * @return void
*/ */
protected function initializeController() { protected function initializeController() {
$this->tagRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_TagRepository'); $this->tagRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_TagRepository');
} }
......
...@@ -192,36 +192,42 @@ ...@@ -192,36 +192,42 @@
protected $manual; protected $manual;
/** /**
* media * Media references
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Media> * @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Media>
*/ */
protected $media; protected $media;
/** /**
* experience * Experiences
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Experience> * @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Experience>
*/ */
protected $experience; protected $experience;
/** /**
* softwareRelation * Software relations
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Relation> * @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Relation>
*/ */
protected $softwareRelation; protected $softwareRelation;
/** /**
* extension * Parent extension object
* @var Tx_TerFe2_Domain_Model_Extension * @var Tx_TerFe2_Domain_Model_Extension
* @lazy * @lazy
*/ */
protected $extension; protected $extension;
/** /**
* Extension Provider * Extension provider
* @var string * @var string
*/ */
protected $extensionProvider; protected $extensionProvider;
/**
* Path to the zip file
* @var string
*/
protected $zipFile;
/** /**
* Constructor. Initializes all Tx_Extbase_Persistence_ObjectStorage instances. * Constructor. Initializes all Tx_Extbase_Persistence_ObjectStorage instances.
...@@ -958,5 +964,26 @@ ...@@ -958,5 +964,26 @@
return $this->extensionProvider; return $this->extensionProvider;
} }
/**
* Setter for zipFile
*
* @param string $zipFile Set zip file path
* @return void
*/
public function setZipFile($zipFile) {
$this->zipFile = $zipFile;
}
/**
* Getter for zipFile
*
* @return string Zip file path
*/
public function getZipFile() {
return $this->zipFile;
}
} }
?> ?>
\ No newline at end of file
<?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_Version
*/
class Tx_TerFe2_Domain_Repository_VersionRepository extends Tx_TerFe2_Domain_Repository_AbstractRepository {
/**
* Get all versions without zip file
*
* @param integer $offset Offset to start with
* @param integer $count Extension count to load
* @return Tx_Extbase_Persistence_QueryResult Query result
*/
public function findWithoutZipFile($offset = 0, $count = 0) {
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
$query->getQuerySettings()->setRespectSysLanguage(FALSE);
$query->matching($query->logicalOr(
$query->equals('zipFile', ''),
$query->equals('zipFile', NULL)
));
if (!empty($offset)) {
$query->setOffset((int) $offset);
}
if (!empty($count)) {
$query->setLimit((int) $count);
}
return $query->execute();
}
}
?>
\ No newline at end of file
...@@ -28,11 +28,26 @@ ...@@ -28,11 +28,26 @@
*/ */
class Tx_TerFe2_Task_CreateZipArchivesTask extends Tx_TerFe2_Task_AbstractTask { class Tx_TerFe2_Task_CreateZipArchivesTask extends Tx_TerFe2_Task_AbstractTask {
/**
* @var string
*/
public $zipFilePath = 'fileadmin/extensionFiles/';
/** /**
* @var Tx_TerFe2_Domain_Repository_VersionRepository * @var Tx_TerFe2_Domain_Repository_VersionRepository
*/ */
protected $versionRepository; protected $versionRepository;
/**
* @var Tx_TerFe2_Provider_ProviderManager
*/
protected $providerManager;
/**
* @var Tx_Extbase_Persistence_Manager
*/
protected $persistenceManager;
/** /**
* Initialize task * Initialize task
...@@ -40,13 +55,16 @@ ...@@ -40,13 +55,16 @@
* @return void * @return void
*/ */
public function initializeTask() { public function initializeTask() {
$this->versionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_VersionRepository'); $this->versionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_VersionRepository');
$this->providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$this->persistenceManager = $this->objectManager->get('Tx_Extbase_Persistence_Manager');
$this->zipFilePath = Tx_TerFe2_Utility_File::getAbsoluteDirectory($this->zipFilePath);
} }
/** /**
* Execute the task * Execute the task
* *
* @param integer $lastRun Timestamp of the last run * @param integer $lastRun Timestamp of the last run
* @param integer $offset Starting point * @param integer $offset Starting point
* @param integer $count Element count to process at once * @param integer $count Element count to process at once
...@@ -54,10 +72,40 @@ ...@@ -54,10 +72,40 @@
*/ */
protected function executeTask($lastRun, $offset, $count) { protected function executeTask($lastRun, $offset, $count) {
// TODO: Remove testing values // TODO: Remove testing values
$lastRun = 1306920788; $offset = 0;
$offset = 0;
// Get all versions without zip file
$versions = $this->versionRepository->findWithoutZipFile($offset, $count);
if (empty($versions)) {
return FALSE;
}
// Build zip files
foreach ($versions as $version) {
$provider = $this->providerManager->getProvider($version->getExtensionProvider());
$t3xFile = $provider->getFileUrl($version, 't3x');
$zipFile = $this->zipFilePath . basename($provider->getFileName($version, 'zip'));
// Check file hash
$fileHash = Tx_TerFe2_Utility_File::getFileHash($t3xFile);
if ($fileHash != $version->getFileHash()) {
throw new Exception('File was changed and is therefore corrupt');
}
// Convert...
$result = TRUE;
if (!Tx_TerFe2_Utility_File::fileExists($zipFile)) {
$result = Tx_TerFe2_Utility_Archive::convertT3xToZip($t3xFile, $zipFile);
}
// Save relative path into version model
if (!empty($result)) {
$zipFile = Tx_TerFe2_Utility_File::getRelativeDirectory($zipFile);
$version->setZipFile($zipFile);
$this->persistenceManager->persistAll();
}
}
// TODO: Implement functionality
return TRUE; return TRUE;
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* @return void * @return void
*/ */
protected function addAdditionalFields() { protected function addAdditionalFields() {
// TODO: Implement functionality $this->addInputField('zipFilePath', 'fileadmin/extensionFiles/');
} }
...@@ -45,8 +45,7 @@ ...@@ -45,8 +45,7 @@
* @return boolean TRUE if validation was ok * @return boolean TRUE if validation was ok
*/ */
protected function checkAdditionalFields(array $submittedData) { protected function checkAdditionalFields(array $submittedData) {
// TODO: Implement functionality return (!empty($submittedData['zipFilePath']) && is_string($submittedData['zipFilePath']));
return TRUE;
} }
} }
......
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
/** /**
* Execute the task * Execute the task
* *
* @param integer $lastRun Timestamp of the last run * @param integer $lastRun Timestamp of the last run
* @param integer $offset Starting point * @param integer $offset Starting point
* @param integer $count Element count to process at once * @param integer $count Element count to process at once
...@@ -97,15 +97,16 @@ ...@@ -97,15 +97,16 @@
// Get extension structure from provider // Get extension structure from provider
$provider = $this->providerManager->getProvider($this->providerName); $provider = $this->providerManager->getProvider($this->providerName);
$extensions = $provider->getExtensions($lastRun, $offset, $count); $extensions = $provider->getExtensions($lastRun, $offset, $count);
if (empty($extensions)) {
return FALSE;
}
// Build extensions... // Build extensions...
if (!empty($extensions)) { foreach ($extensions as $extensionRow) {
foreach ($extensions as $extensionRow) { $this->createOrUpdateExtension($extensionRow);
$this->createOrUpdateExtension($extensionRow);
}
} }
return !empty($extensions); return TRUE;
} }
...@@ -172,7 +173,7 @@ ...@@ -172,7 +173,7 @@
/** /**
* Check whether a storage page is configured or not * Check whether a storage page is configured or not
* *
* @return TRUE if a storage page was found * @return TRUE if a storage page was found
*/ */
protected function storagePageConfigured() { protected function storagePageConfigured() {
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
* @return boolean TRUE if validation was ok * @return boolean TRUE if validation was ok
*/ */
protected function checkAdditionalFields(array $submittedData) { protected function checkAdditionalFields(array $submittedData) {
return (!empty($submittedData['providerName'])); return (!empty($submittedData['providerName']) && is_string($submittedData['providerName']));
} }
} }
......
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
} }
// Create ZIP archive // Create ZIP archive
self::createArchive($zipFile, $files); self::createZipArchive($zipFile, $files);
return TRUE; return TRUE;
} }
......
...@@ -51,21 +51,43 @@ ...@@ -51,21 +51,43 @@
/** /**
* Returns absolute path to given directory * Returns absolute path to given directory
* *
* @param string $path Path to the file / directory
* @param boolean $create Create if not exists
* @return string Absolute path * @return string Absolute path
*/ */
public static function getAbsoluteDirectory($path) { public static function getAbsoluteDirectory($path, $create = TRUE) {
if (empty($path)) { if (empty($path)) {
return PATH_site; return PATH_site;
} }
if (!self::fileExists(PATH_site . $path)) { if ($create && !self::fileExists(PATH_site . $path)) {
t3lib_div::mkdir_deep(PATH_site . $path); t3lib_div::mkdir_deep(PATH_site, $path);
} }
return PATH_site . rtrim($path, '/') . '/'; return PATH_site . rtrim($path, '/') . '/';
} }
/**
* Returns absolute path to given directory
*
* @param string $path Path to the file / directory
* @return string Relative path
*/
public static function getRelativeDirectory($path) {
if (empty($path)) {
return '';
}
$path = str_replace(PATH_site, '', $path);
if (is_dir($path)) {
$path = rtrim($path, '/') . '/';
}
return $path;
}
/** /**
* Returns the MD5 hash of a file * Returns the MD5 hash of a file
* *
...@@ -326,7 +348,7 @@ ...@@ -326,7 +348,7 @@
*/ */
public static function getUrlFromAbsolutePath($path) { public static function getUrlFromAbsolutePath($path) {
$hostUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '/'; $hostUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '/';
return $hostUrl . str_ireplace(PATH_site, '', $path); return $hostUrl . str_replace(PATH_site, '', $path);
} }
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
$TCA['tx_terfe2_domain_model_version'] = array( $TCA['tx_terfe2_domain_model_version'] = array(
'ctrl' => $TCA['tx_terfe2_domain_model_version']['ctrl'], 'ctrl' => $TCA['tx_terfe2_domain_model_version']['ctrl'],
'interface' => array( 'interface' => array(
'showRecordFieldList' => 'title,description,version_number,version_string,upload_date,upload_comment,download_counter,state,em_category,load_order,priority,shy,internal,do_not_load_in_fe,uploadfolder,clear_cache_on_load,module,create_dirs,modify_tables,lock_type,cgl_compliance,cgl_compliance_note,review_state,manual,media,experience,software_relation', 'showRecordFieldList' => 'title,description,version_number,version_string,upload_date,upload_comment,download_counter,state,em_category,load_order,priority,shy,internal,do_not_load_in_fe,uploadfolder,clear_cache_on_load,module,create_dirs,modify_tables,lock_type,cgl_compliance,cgl_compliance_note,review_state,manual,media,experience,software_relation,zip_file',
), ),
'types' => array( 'types' => array(
'1' => array('showitem' => 'title,description,version_number,version_string,upload_date,upload_comment,download_counter,state,em_category,load_order,priority,shy,internal,do_not_load_in_fe,uploadfolder,clear_cache_on_load,module,create_dirs,modify_tables,lock_type,cgl_compliance,cgl_compliance_note,review_state,manual,media,experience,software_relation'), '1' => array('showitem' => 'title,description,version_number,version_string,upload_date,upload_comment,download_counter,state,em_category,load_order,priority,shy,internal,do_not_load_in_fe,uploadfolder,clear_cache_on_load,module,create_dirs,modify_tables,lock_type,cgl_compliance,cgl_compliance_note,review_state,manual,media,experience,software_relation,zip_file'),
), ),
'palettes' => array( 'palettes' => array(
'1' => array('showitem' => ''), '1' => array('showitem' => ''),
...@@ -364,6 +364,15 @@ ...@@ -364,6 +364,15 @@
'type' => 'passthrough', 'type' => 'passthrough',
), ),
), ),
'zip_file' => array(
'exclude' => 1,