Commit b99d1acb authored by speedprogs_de's avatar speedprogs_de
Browse files

modified zip creation scheduler task to also create images

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@52055 735d13b6-9817-0410-8766-e36946ffe9aa
parent 43d646d3
......@@ -237,13 +237,21 @@
* @return void
*/
public function downloadAction(Tx_TerFe2_Domain_Model_Version $version, $format = 't3x') {
if ($format !== 't3x' && $format !== 'zip') {
throw new Exception('A download action for the format "' . $format . '" is not implemented');
}
// Get file path
$provider = $this->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');
if (empty($this->settings['mediaRootPath'])) {
throw new Exception('No directory for extension media files configured');
}
$extKey = $version->getExtension()->getExtKey();
$extensionMediaPath = Tx_TerFe2_Utility_File::getAbsoluteDirectory($this->settings['mediaRootPath'] . $extKey);
$fileUrl = $extensionMediaPath . basename($provider->getFileName($version, $format));
}
// Check if file exists
......
......@@ -223,10 +223,10 @@
protected $extensionProvider;
/**
* Path to the zip file
* @var string
* Media was created for this version
* @var boolean
*/
protected $zipFile;
protected $mediaCreated;
/**
......@@ -989,23 +989,23 @@
/**
* Setter for zipFile
* Setter for mediaCreated
*
* @param string $zipFile Set zip file path
* @param boolean $mediaCreated Media was created
* @return void
*/
public function setZipFile($zipFile) {
$this->zipFile = $zipFile;
public function setMediaCreated($mediaCreated) {
$this->mediaCreated = $mediaCreated;
}
/**
* Getter for zipFile
* Getter for mediaCreated
*
* @return string Zip file path
* @return boolean Media was created
*/
public function getZipFile() {
return $this->zipFile;
public function getMediaCreated() {
return $this->mediaCreated;
}
}
......
......@@ -29,20 +29,17 @@
class Tx_TerFe2_Domain_Repository_VersionRepository extends Tx_TerFe2_Domain_Repository_AbstractRepository {
/**
* Get all versions without zip file
* Get all versions where media was not created for
*
* @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) {
public function findForMediaCreation($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)
));
$query->matching($query->equals('mediaCreated', FALSE));
if (!empty($offset)) {
$query->setOffset((int) $offset);
}
......
<?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!
******************************************************************/
/**
* Service for gallery images
*/
class Tx_TerFe2_Service_Image implements t3lib_Singleton {
/**
* @var tslib_cObj
*/
protected $contentObject;
/**
* @param Tx_Extbase_Configuration_ConfigurationManager $configurationManager
* @return void
*/
public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManager $configurationManager) {
$this->contentObject = $configurationManager->getContentObject();
}
/**
* Converts all images with given settings
*
* @param array $files All files to process
* @param array $settings Image configuration
* @param boolean $createTag Returns images with complete tag
* @return array Relative image paths
*/
public function processImages(array $files, array $settings = array(), $createTag = FALSE) {
if (empty($files) || empty($settings)) {
return array();
}
$images = array();
foreach ($files as $key => $file) {
$file = str_replace(PATH_site, '', $file);
if ($createTag) {
$images[$key] = $this->contentObject->cImage($file, array('file.' => $settings));
} else {
$info = $this->contentObject->getImgResource($file, $settings);
$images[$key] = (!empty($info[3]) ? $info[3] : $file);
}
}
return $images;
}
}
?>
\ No newline at end of file
......@@ -51,7 +51,7 @@
/**
* @var array
*/
protected $settings;
protected $setup;
/**
* @var Tx_Extbase_Configuration_ConfigurationManager
......@@ -79,9 +79,9 @@
$this->objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
// Configuration is required to be loaded in object manager for persistence mapping
$this->settings = Tx_TerFe2_Utility_TypoScript::getSetup('plugin.tx_terfe2');
$this->setup = Tx_TerFe2_Utility_TypoScript::getSetup('plugin.tx_terfe2');
$this->configurationManager = $this->objectManager->get('Tx_Extbase_Configuration_ConfigurationManager');
$this->configurationManager->setConfiguration($this->settings);
$this->configurationManager->setConfiguration($this->setup);
// Load registry
$this->registry = $this->objectManager->get('Tx_TerFe2_Persistence_Registry');
......
......@@ -24,14 +24,9 @@
******************************************************************/
/**
* Create zip archives from t3x files
* Create zip archives from t3x files and generate images
*/
class Tx_TerFe2_Task_CreateZipArchivesTask extends Tx_TerFe2_Task_AbstractTask {
/**
* @var string
*/
public $zipFilePath = 'fileadmin/extensionFiles/';
class Tx_TerFe2_Task_CreateExtensionFilesTask extends Tx_TerFe2_Task_AbstractTask {
/**
* @var Tx_TerFe2_Domain_Repository_VersionRepository
......@@ -48,6 +43,16 @@
*/
protected $persistenceManager;
/**
* @var string
*/
protected $mediaRootPath = '';
/**
* @var array
*/
protected $imageSizes = array('small', 'large');
/**
* Initialize task
......@@ -58,7 +63,11 @@
$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);
if (empty($this->setup['settings.']['mediaRootPath'])) {
throw new Exception('Please configure "plugin.tx_terfe2.settings.mediaRootPath" in TypoScript setup');
}
$this->mediaRootPath = $this->setup['settings.']['mediaRootPath'];
}
......@@ -71,35 +80,104 @@
* @return boolean TRUE on success
*/
protected function executeTask($lastRun, $offset, $count) {
// Get all versions without zip file
$versions = $this->versionRepository->findWithoutZipFile($offset, $count);
// Get all unprocessed versions
$versions = $this->versionRepository->findForMediaCreation($offset, $count);
if (empty($versions)) {
return FALSE;
}
// Build zip files
// Simulate working directory "htdocs", required for file_exists check
// in t3lib_stdGraphic::getImageDimensions
$currentDir = getcwd();
chdir(PATH_site);
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');
}
// Get media path for the extension
$extKey = $version->getExtension()->getExtKey();
$extensionMediaPath = Tx_TerFe2_Utility_File::getAbsoluteDirectory($this->mediaRootPath . $extKey);
// Create zip file
$this->createZipFile($version, $extensionMediaPath);
// Create images
$this->createImages($version, $extensionMediaPath);
// Mark version as processed
$version->setMediaCreated(TRUE);
$this->persistenceManager->persistAll();
}
// Revert working directory
chdir($currentDir);
return TRUE;
}
// Convert...
$result = TRUE;
if (!Tx_TerFe2_Utility_File::fileExists($zipFile)) {
$result = Tx_TerFe2_Utility_Archive::convertT3xToZip($t3xFile, $zipFile);
/**
* Create a zip file for given version
*
* @param Tx_TerFe2_Domain_Model_Version $version Path to t3x file
* @param string $extensionMediaPath Path to media files
* @return boolean TRUE if success
*/
protected function createZipFile(Tx_TerFe2_Domain_Model_Version $version, $extensionMediaPath) {
if (empty($extensionMediaPath)) {
return FALSE;
}
$provider = $this->providerManager->getProvider($version->getExtensionProvider());
$t3xFileName = $provider->getFileUrl($version, 't3x');
$zipFileName = $extensionMediaPath . basename($provider->getFileName($version, 'zip'));
// Check file hash
$fileHash = Tx_TerFe2_Utility_File::getFileHash($t3xFileName);
if ($fileHash != $version->getFileHash()) {
throw new Exception('File was changed and is therefore corrupt');
}
// Create zip file
if (!Tx_TerFe2_Utility_File::fileExists($zipFileName)) {
return Tx_TerFe2_Utility_Archive::convertT3xToZip($t3xFileName, $zipFileName);
}
return TRUE;
}
/**
* Create images for given version
*
* @param Tx_TerFe2_Domain_Model_Version $version Path to t3x file
* @param string $extensionMediaPath Path to media files
* @return boolean TRUE if success
*/
protected function createImages(Tx_TerFe2_Domain_Model_Version $version, $extensionMediaPath) {
if (empty($extensionMediaPath)) {
return FALSE;
}
// Get image files
$imageFiles = array();
$mediaObjects = $version->getMedia();
foreach ($mediaObjects as $media) {
if ($media->getType() === 'image') {
// Source must contains only image file name without path
$imageFiles[] = $extensionMediaPath . $media->getSource();
}
}
// Save relative path into version model
if (!empty($result)) {
$zipFile = Tx_TerFe2_Utility_File::getRelativeDirectory($zipFile);
$version->setZipFile($zipFile);
$this->persistenceManager->persistAll();
if (empty($imageFiles)) {
return TRUE;
}
foreach ($this->imageSizes as $imageSize) {
if (empty($this->setup['settings.'][$imageSize . 'Image'])) {
continue;
}
$images = Tx_TerFe2_Service_Image::processImages($imageFiles, $this->setup['settings.'][$imageSize . 'Image']);
if (empty($images)) {
throw new Exception('Could not create image files');
}
}
......
......@@ -24,9 +24,9 @@
******************************************************************/
/**
* Additional field provider for the create zip archives task
* Additional field provider for the create extension files task
*/
class Tx_TerFe2_Task_CreateZipArchivesTaskAdditionalFieldProvider extends Tx_TerFe2_Task_AbstractAdditionalFieldProvider {
class Tx_TerFe2_Task_CreateExtensionFilesTaskAdditionalFieldProvider extends Tx_TerFe2_Task_AbstractAdditionalFieldProvider {
/**
* Add some input fields to configure the task
......@@ -34,7 +34,7 @@
* @return void
*/
protected function addAdditionalFields() {
$this->addInputField('zipFilePath', 'fileadmin/extensionFiles/');
}
......@@ -45,7 +45,7 @@
* @return boolean TRUE if validation was ok
*/
protected function checkAdditionalFields(array $submittedData) {
return (!empty($submittedData['zipFilePath']) && is_string($submittedData['zipFilePath']));
return TRUE;
}
}
......
......@@ -91,7 +91,7 @@
*/
protected function executeTask($lastRun, $offset, $count) {
// Check static setup
if (empty($this->settings['settings.'])) {
if (empty($this->setup['settings.'])) {
throw new Exception('Please include static setup "TER Frontend - Default Configuration (ter_fe2)" on root page');
}
......@@ -186,7 +186,7 @@
*/
protected function storagePageConfigured() {
$setup = Tx_TerFe2_Utility_TypoScript::getSetup('config.tx_extbase.persistence');
$setup = Tx_Extbase_Utility_Arrays::arrayMergeRecursiveOverrule($setup, $this->settings['persistence.'], FALSE, FALSE);
$setup = Tx_Extbase_Utility_Arrays::arrayMergeRecursiveOverrule($setup, $this->setup['persistence.'], FALSE, FALSE);
if (!empty($setup['storagePid'])) {
return TRUE;
}
......
......@@ -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,experiences,software_relations,zip_file',
'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,experiences,software_relations,media_created',
),
'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,experiences,software_relations,zip_file'),
'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,experiences,software_relations,media_created'),
),
'palettes' => array(
'1' => array('showitem' => ''),
......@@ -364,13 +364,12 @@
'type' => 'passthrough',
),
),
'zip_file' => array(
'media_created' => array(
'exclude' => 1,
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xml:tx_terfe2_domain_model_version.zip_file',
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xml:tx_terfe2_domain_model_version.media_created',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'trim',
'type' => 'check',
'default' => 0,
),
),
),
......
......@@ -3,46 +3,74 @@
# ======================================================================
plugin.tx_terfe2 {
settings {
# cat=TER Frontend/settings/100; type=int+; label=Count of latest Extensions
# cat=TER Frontend/settings/100; type=int+; label=Latest count: Count of latest Extensions
latestCount = 10
# cat=TER Frontend/settings/110; type=int+; label=Count of top rated Extensions
# cat=TER Frontend/settings/110; type=int+; label=Top rated count: Count of top rated Extensions
topRatedCount = 10
# cat=TER Frontend/settings/120; type=int+; label=Count of random Authors
# cat=TER Frontend/settings/120; type=int+; label=Random author count: Count of random Authors
randomAuthorCount = 10
# cat=TER Frontend/settings/130; type=int+; label=Crop description at this count of signs
# cat=TER Frontend/settings/130; type=int+; label=Description length: Crop description at this count of signs
descriptionLength = 350
# cat=TER Frontend/settings/130; type=string; label=Date format
# cat=TER Frontend/settings/140; type=string; label=Date format: Date format
dateFormat = F j, Y
# cat=TER Frontend/settings/130; type=string; label=Media root path
mediaRootPath = uploads/ter_fe2/
# cat=TER Frontend/settings/150; type=string; label=Media root path: Media root path for zip files and images
mediaRootPath = fileadmin/extensionFiles/
smallImage {
# cat=TER Frontend/settings/200; type=int+; label=Small image maxW: Maximal width for small images
maxW = 200
# cat=TER Frontend/settings/210; type=int+; label=Small image maxH: Maximal height for small images
maxH = 160
# cat=TER Frontend/settings/220; type=int+; label=Small image quality: Quality of small images
quality = 70
# cat=TER Frontend/settings/230; type=string; label=Small image format: Output format of small images
ext = jpg
}
largeImage {
# cat=TER Frontend/settings/240; type=int+; label=Large image maxW: Maximal width for large images in fullscreen mode
maxW = 1024
# cat=TER Frontend/settings/250; type=int+; label=Large image maxH: Maximal height for large images in fullscreen mode
maxH = 768
# cat=TER Frontend/settings/260; type=int+; label=Large image quality: Quality of large images
quality = 70
# cat=TER Frontend/settings/270; type=string; label=Large image format: Output format of large images
ext = jpg
}
}
persistence {
# cat=TER Frontend/persistence/200; type=int+; label=General storage PID for the TER Frontend Index
# cat=TER Frontend/persistence/300; type=int+; label=Storage PID: General storage PID for the TER Frontend Index
storagePid = 0
}
view {
# cat=TER Frontend/view/300; type=string; label=Path to template root
# cat=TER Frontend/view/400; type=string; label=Template root path: Path to template root
templateRootPath = EXT:ter_fe2/Resources/Private/Templates/
# cat=TER Frontend/view/310; type=string; label=Path to template partials
# cat=TER Frontend/view/410; type=string; label=Partial root path: Path to template partials
partialRootPath = EXT:ter_fe2/Resources/Private/Partials/
# cat=TER Frontend/view/320; type=string; label=Path to template layouts
# cat=TER Frontend/view/420; type=string; label=Layout root path: Path to template layouts
layoutRootPath = EXT:ter_fe2/Resources/Private/Layouts/
}
libraries {
# cat=TER Frontend/libraries/400; type=string; label=Load jQuery
# cat=TER Frontend/libraries/500; type=string; label=Load jQuery: Load jQuery libraray into footer
jquery.load = 1
# cat=TER Frontend/libraries/400; type=string; label=Load jqPlot
# cat=TER Frontend/libraries/510; type=string; label=Load jqPlot: Load jqPlot libraray into footer
jqplot.load = 1
}
......
......@@ -10,6 +10,20 @@ plugin.tx_terfe2 {
descriptionLength = {$plugin.tx_terfe2.settings.descriptionLength}
dateFormat = {$plugin.tx_terfe2.settings.dateFormat}
mediaRootPath = {$plugin.tx_terfe2.settings.mediaRootPath}
smallImage {
maxW = {$plugin.tx_terfe2.settings.smallImage.maxW}
maxH = {$plugin.tx_terfe2.settings.smallImage.maxH}
quality = {$plugin.tx_terfe2.settings.smallImage.quality}
ext = {$plugin.tx_terfe2.settings.smallImage.ext}
}
largeImage {
maxW = {$plugin.tx_terfe2.settings.largeImage.maxW}
maxH = {$plugin.tx_terfe2.settings.largeImage.maxH}
quality = {$plugin.tx_terfe2.settings.largeImage.quality}
ext = {$plugin.tx_terfe2.settings.largeImage.ext}
}
}
## Storage settings
......
......@@ -65,11 +65,11 @@
<label index="tx_terfe2_task_forceLastRun">Force last run time</label>
<label index="tx_terfe2_task_forceOffset">Force offset</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_extensionFilePath">Relative path to extension files directory</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>
<label index="tx_terfe2_task_createziparchivestask.description">Create zip archives from t3x files</label>
<label index="tx_terfe2_task_createextensionfilestask.name">Create extension related files</label>
<label index="tx_terfe2_task_createextensionfilestask.description">Create extension related files like zip file or images</label>
<label index="tx_terfe2_provider_extensionmanagerprovider.name">Local Extension Manager</label>
<label index="tx_terfe2_provider_fileprovider.name">Local Filesystem</label>
<label index="tx_terfe2_provider_soapprovider.name">SOAP Server</label>
......
......@@ -138,7 +138,7 @@
<div class="extension-buttons">
<span class="extension-button extension-row-toggle"><f:translate key="details"/></span>
<span class="extension-button extension-button-right"><f:link.action controller="Extension" action="download" arguments="{version : extension.lastVersion}"><f:translate key="download_t3x"/></f:link.action></span>
<f:if condition="{extension.lastVersion.zipFile}">
<f:if condition="{extension.lastVersion.mediaCreated}">
<span class="extension-button extension-button-right"><f:link.action controller="Extension" action="download" arguments="{version : extension.lastVersion, format : 'zip'}"><f:translate key="download_zip"/></f:link.action></span>
</f:if>
</div>
......
......@@ -39,12 +39,13 @@
'tx_terfe2_persistence_registry' => $extensionClassesPath . 'Persistence/Registry.php',
'tx_terfe2_persistence_session' => $extensionClassesPath . 'Persistence/Session.php',
'tx_terfe2_service_documentation' => $extensionClassesPath . 'Service/Documentation.php',
'tx_terfe2_service_image' => $extensionClassesPath . 'Service/Image.php',
'tx_terfe2_service_mirror' => $extensionClassesPath . 'Service/Mirror.php',
'tx_terfe2_service_soap' => $extensionClassesPath . 'Service/Soap.php',
'tx_terfe2_task_abstracttask' => $extensionClassesPath . 'Task/AbstractTask.php',
'tx_terfe2_task_abstractadditionalfieldprovider' => $extensionClassesPath . 'Task/AbstractAdditionalFieldProvider.php',
'tx_terfe2_task_createziparchivestask' => $extensionClassesPath . 'Task/CreateZipArchivesTask.php',
'tx_terfe2_task_createziparchivestaskadditionalfieldprovider' => $extensionClassesPath . 'Task/CreateZipArchivesTaskAdditionalFieldProvider.php',
'tx_terfe2_task_createextensionfilestask' => $extensionClassesPath . 'Task/CreateExtensionFilesTask.php',
'tx_terfe2_task_createextensionfilestaskadditionalfieldprovider' => $extensionClassesPath . 'Task/CreateExtensionFilesTaskAdditionalFieldProvider.php',
'tx_terfe2_task_updateextensionlisttask' => $extensionClassesPath . 'Task/UpdateExtensionListTask.php',
'tx_terfe2_task_updateextensionlisttaskadditionalfieldprovider' => $extensionClassesPath . 'Task/UpdateExtensionListTaskAdditionalFieldProvider.php',
'tx_terfe2_utility_archive' => $extensionClassesPath . 'Utility/Archive.php',
......
......@@ -57,11 +57,11 @@
);
// Register create zip archives task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler'