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 @@
* @return void
*/
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 @@
* @return void
*/
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 @@
*/
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
......@@ -55,10 +70,13 @@
* @return void
*/
protected function initializeController() {
$this->extensionRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_ExtensionRepository');
$this->categoryRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_CategoryRepository');
$this->tagRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_TagRepository');
$this->authorRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_AuthorRepository');
$this->extensionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_ExtensionRepository');
$this->categoryRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_CategoryRepository');
$this->tagRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_TagRepository');
$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 @@
* @return void
*/
public function downloadAction(Tx_TerFe2_Domain_Model_Version $version, $format = 't3x') {
// Get extension provider
$providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$provider = $providerManager->getProvider($version->getExtensionProvider());
if ($format === 't3x') {
$provider = $this->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
$fileUrl = $provider->getFileUrl($version, $format);
if (empty($fileUrl)) {
// Check if file exists
if (empty($fileUrl) || !Tx_TerFe2_Utility_File::fileExists($fileUrl)) {
$this->redirectWithMessage('index', 'file_not_found');
}
// Check file hash
$fileHash = Tx_TerFe2_Utility_File::getFileHash($fileUrl);
if ($fileHash != $version->getFileHash()) {
$this->redirectWithMessage('index', 'file_hash_not_equal');
// Check file hash of t3x packages
if ($format === 't3x') {
$fileHash = Tx_TerFe2_Utility_File::getFileHash($fileUrl);
if ($fileHash != $version->getFileHash()) {
$this->redirectWithMessage('index', 'file_hash_not_equal');
}
}
// Check session if user has already downloaded this file today
$extensionKey = $version->getExtension()->getExtKey();
$session = $this->objectManager->get('Tx_TerFe2_Persistence_Session');
$downloads = $session->get('downloads');
$downloads = $this->session->get('downloads');
if (empty($downloads) || !in_array($extensionKey, $downloads)) {
// Add +1 to download counter and save immediately
$version->incrementDownloadCounter();
$persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
$persistenceManager->persistAll();
$this->persistenceManager->persistAll();
// Add extension key to session
$downloads[] = $extensionKey;
......
......@@ -46,7 +46,7 @@
* @return void
*/
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 @@
protected $manual;
/**
* media
* Media references
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Media>
*/
protected $media;
/**
* experience
* Experiences
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Experience>
*/
protected $experience;
/**
* softwareRelation
* Software relations
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Relation>
*/
protected $softwareRelation;
/**
* extension
* Parent extension object
* @var Tx_TerFe2_Domain_Model_Extension
* @lazy
*/
protected $extension;
/**
* Extension Provider
* Extension provider
* @var string
*/
protected $extensionProvider;
/**
* Path to the zip file
* @var string
*/
protected $zipFile;
/**
* Constructor. Initializes all Tx_Extbase_Persistence_ObjectStorage instances.
......@@ -958,5 +964,26 @@
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 @@
*/
class Tx_TerFe2_Task_CreateZipArchivesTask extends Tx_TerFe2_Task_AbstractTask {
/**
* @var string
*/
public $zipFilePath = 'fileadmin/extensionFiles/';
/**
* @var Tx_TerFe2_Domain_Repository_VersionRepository
*/
protected $versionRepository;
/**
* @var Tx_TerFe2_Provider_ProviderManager
*/
protected $providerManager;
/**
* @var Tx_Extbase_Persistence_Manager
*/
protected $persistenceManager;
/**
* Initialize task
......@@ -40,13 +55,16 @@
* @return void
*/
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
*
*
* @param integer $lastRun Timestamp of the last run
* @param integer $offset Starting point
* @param integer $count Element count to process at once
......@@ -54,10 +72,40 @@
*/
protected function executeTask($lastRun, $offset, $count) {
// 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;
}
......
......@@ -34,7 +34,7 @@
* @return void
*/
protected function addAdditionalFields() {
// TODO: Implement functionality
$this->addInputField('zipFilePath', 'fileadmin/extensionFiles/');
}
......@@ -45,8 +45,7 @@
* @return boolean TRUE if validation was ok
*/
protected function checkAdditionalFields(array $submittedData) {
// TODO: Implement functionality
return TRUE;
return (!empty($submittedData['zipFilePath']) && is_string($submittedData['zipFilePath']));
}
}
......
......@@ -78,7 +78,7 @@
/**
* Execute the task
*
*
* @param integer $lastRun Timestamp of the last run
* @param integer $offset Starting point
* @param integer $count Element count to process at once
......@@ -97,15 +97,16 @@
// Get extension structure from provider
$provider = $this->providerManager->getProvider($this->providerName);
$extensions = $provider->getExtensions($lastRun, $offset, $count);
if (empty($extensions)) {
return FALSE;
}
// Build extensions...
if (!empty($extensions)) {
foreach ($extensions as $extensionRow) {
$this->createOrUpdateExtension($extensionRow);
}
foreach ($extensions as $extensionRow) {
$this->createOrUpdateExtension($extensionRow);
}
return !empty($extensions);
return TRUE;
}
......@@ -172,7 +173,7 @@
/**
* Check whether a storage page is configured or not
*
*
* @return TRUE if a storage page was found
*/
protected function storagePageConfigured() {
......
......@@ -51,7 +51,7 @@
* @return boolean TRUE if validation was ok
*/
protected function checkAdditionalFields(array $submittedData) {
return (!empty($submittedData['providerName']));
return (!empty($submittedData['providerName']) && is_string($submittedData['providerName']));
}
}
......
......@@ -154,7 +154,7 @@
}
// Create ZIP archive
self::createArchive($zipFile, $files);
self::createZipArchive($zipFile, $files);
return TRUE;
}
......
......@@ -51,21 +51,43 @@
/**
* 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
*/
public static function getAbsoluteDirectory($path) {
public static function getAbsoluteDirectory($path, $create = TRUE) {
if (empty($path)) {
return PATH_site;
}
if (!self::fileExists(PATH_site . $path)) {
t3lib_div::mkdir_deep(PATH_site . $path);
if ($create && !self::fileExists(PATH_site . $path)) {
t3lib_div::mkdir_deep(PATH_site, $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
*
......@@ -326,7 +348,7 @@
*/
public static function getUrlFromAbsolutePath($path) {
$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 @@
$TCA['tx_terfe2_domain_model_version'] = array(
'ctrl' => $TCA['tx_terfe2_domain_model_version']['ctrl'],
'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(
'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(
'1' => array('showitem' => ''),
......@@ -364,6 +364,15 @@
'type' => 'passthrough',
),
),
'zip_file' => array(
'exclude' => 1,
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xml:tx_terfe2_domain_model_version.zip_file',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'trim',
),
),
),
);
?>
\ No newline at end of file
......@@ -33,9 +33,10 @@
<label index="tx_terfe2_domain_model_version.load_order">Loading order in Extension Manager</label>
<label index="tx_terfe2_domain_model_version.modify_tables">Information which existing DB tables will be modified</label>
<label index="tx_terfe2_domain_model_version.manual">Relation to manual object of ter_doc extension</label>
<label index="tx_terfe2_domain_model_version.media">media</label>
<label index="tx_terfe2_domain_model_version.experience">experience</label>
<label index="tx_terfe2_domain_model_version.software_relation">softwareRelation</label>
<label index="tx_terfe2_domain_model_version.media">Media references</label>
<label index="tx_terfe2_domain_model_version.experience">Experiences</label>
<label index="tx_terfe2_domain_model_version.software_relation">Software relations</label>
<label index="tx_terfe2_domain_model_version.zip_file">Zip file path</label>
<label index="tx_terfe2_domain_model_media">Any type of media associated to an extension</label>
<label index="tx_terfe2_domain_model_media.title">Title of the media</label>
<label index="tx_terfe2_domain_model_media.type">Media type (link, image, video, pdf)</label>
......@@ -60,6 +61,7 @@
<label index="tx_terfe2_task_elementsPerRun">Element count to process at once</label>
<label index="tx_terfe2_task_clearCachePages">Clear cache of these pages after run</label>
<label index="tx_terfe2_task_providerName">Fetch extensions from this source</label>
<label index="tx_terfe2_task_zipFilePath">Relative path to zip file diretory</label>
<label index="tx_terfe2_task_updateextensionlisttask.name">Get new extensions</label>
<label index="tx_terfe2_task_updateextensionlisttask.description">Get new extensions in ter directory</label>
<label index="tx_terfe2_task_createziparchivestask.name">Convert t3x to zip</label>
......
......@@ -32,9 +32,10 @@
<label index="cgl_compliance_note.description">Note for the CGL compliance</label>
<label index="review_state.description">Review state</label>
<label index="manual.description">Relation to manual object of ter_doc extension</label>
<label index="media.description">media</label>
<label index="experience.description">experience</label>
<label index="software_relation.description">softwareRelation</label>
<label index="media.description">Media references</label>
<label index="experience.description">Experiences</label>
<label index="software_relation.description">Software relations</label>
<label index="zip_file.description">Path to the zip file of this version</label>
</languageKey>
</data>
</T3locallang>
\ No newline at end of file
......@@ -20,7 +20,9 @@
<ul>
<li><f:link.action controller="Extension" action="download" arguments="{version : extension.lastVersion}"><f:translate key="download_t3x"/></f:link.action></li>
<li><f:link.action controller="Extension" action="download" arguments="{version : extension.lastVersion, format : 'zip'}"><f:translate key="download_zip"/></f:link.action></li>
<f:if condition="{extension.lastVersion.zipFile}">
<li><f:link.action controller="Extension" action="download" arguments="{version : extension.lastVersion, format : 'zip'}"><f:translate key="download_zip"/></f:link.action></li>
</f:if>
<li><f:translate key="read_manual"/>: <terfe2:documentationLink version="{extension.lastVersion}" /></li>
</ul>
......
......@@ -24,6 +24,7 @@
'tx_terfe2_domain_repository_extensionmanagercacheentryrepository' => $extensionClassesPath . 'Domain/Repository/ExtensionManagerCacheEntryRepository.php',
'tx_terfe2_domain_repository_extensionrepository' => $extensionClassesPath . 'Domain/Repository/ExtensionRepository.php',
'tx_terfe2_domain_repository_tagrepository' => $extensionClassesPath . 'Domain/Repository/TagRepository.php',
'tx_terfe2_domain_repository_versionrepository' => $extensionClassesPath . 'Domain/Repository/VersionRepository.php',
'tx_terfe2_provider_abstractprovider' => $extensionClassesPath . 'Provider/AbstractProvider.php',
'tx_terfe2_provider_extensionmanagerprovider' => $extensionClassesPath . 'Provider/ExtensionManagerProvider.php',
'tx_terfe2_provider_fileprovider' => $extensionClassesPath . 'Provider/FileProvider.php',
......
......@@ -147,6 +147,7 @@ CREATE TABLE tx_terfe2_domain_model_version (
experience int(11) unsigned DEFAULT '0' NOT NULL,
software_relation int(11) unsigned DEFAULT '0' NOT NULL,
extension_provider tinytext,
zip_file tinytext,
tstamp int(11) unsigned DEFAULT '0' NOT NULL,
crdate int(11) unsigned DEFAULT '0' NOT NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment