Commit 892e325e authored by speedprogs_de's avatar speedprogs_de

added filesize for t3x and zip files in version models

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@52412 735d13b6-9817-0410-8766-e36946ffe9aa
parent aa5a3856
......@@ -234,6 +234,18 @@
*/
protected $hasImages;
/**
* File size of the t3x file
* @var integer
*/
protected $t3xFileSize;
/**
* File size of the zip file
* @var integer
*/
protected $zipFileSize;
/**
* Constructor. Initializes all Tx_Extbase_Persistence_ObjectStorage instances.
......@@ -1035,5 +1047,47 @@
return $this->hasImages;
}
/**
* Setter for t3xFileSize
*
* @param integer $t3xFileSize File size
* @return void
*/
public function setT3xFileSize($t3xFileSize) {
$this->t3xFileSize = (int) $t3xFileSize;
}
/**
* Getter for t3xFileSize
*
* @return integer File size
*/
public function getT3xFileSize() {
return (int) $this->t3xFileSize;
}
/**
* Setter for zipFileSize
*
* @param integer $zipFileSize File size
* @return void
*/
public function setZipFileSize($zipFileSize) {
$this->zipFileSize = (int) $zipFileSize;
}
/**
* Getter for zipFileSize
*
* @return integer File size
*/
public function getZipFileSize() {
return (int) $this->zipFileSize;
}
}
?>
\ No newline at end of file
......@@ -166,7 +166,8 @@
// Fetch file from extension root path
$filename = $this->generateFileName($extension, $version, 't3x');
$filename = $this->extensionRootPath . $filename;
$content = t3lib_div::getURL($filename);
$content = t3lib_div::getURL($filename);
$filesize = strlen($content);
if (empty($content)) {
// TODO: Log the missing file
return array();
......@@ -209,6 +210,9 @@
}
}
// Add file size
$emConf['t3xfilesize'] = (int) $filesize;
return $emConf;
}
......@@ -265,6 +269,7 @@
'repository' => $extension['repository'],
'review_state' => $extension['reviewstate'],
'file_hash' => $extension['t3xfilemd5'],
't3x_file_size' => $extension['t3xfilesize'],
'relations' => array(),
);
......
......@@ -121,7 +121,8 @@
// Fetch file from server
$filename = $this->generateFileName($extension, $version, 't3x');
$content = $this->mirrorService->getFile($filename);
$content = $this->mirrorService->getFile($filename);
$filesize = strlen($content);
// Check file hash
if ($fileHash !== md5($content)) {
......@@ -143,6 +144,9 @@
}
unset($extension);
// Add file size
$emConf['t3xfilesize'] = (int) $filesize;
return $emConf;
}
......
......@@ -97,7 +97,9 @@
$extensionMediaPath = Tx_TerFe2_Utility_File::getAbsoluteDirectory($this->mediaRootPath . $extKey);
// Create zip file
if ($this->createZipFile($version, $extensionMediaPath)) {
$zipFile = $this->createZipFile($version, $extensionMediaPath);
if (!empty($zipFile)) {
$version->setZipFileSize(filesize($zipFile));
$version->setHasZipFile(TRUE);
}
......@@ -121,11 +123,11 @@
*
* @param Tx_TerFe2_Domain_Model_Version $version Path to t3x file
* @param string $extensionMediaPath Path to media files
* @return boolean TRUE if success
* @return string Name of the zip file
*/
protected function createZipFile(Tx_TerFe2_Domain_Model_Version $version, $extensionMediaPath) {
if (empty($extensionMediaPath)) {
return FALSE;
return '';
}
$provider = $this->providerManager->getProvider($version->getExtensionProvider());
......@@ -134,7 +136,7 @@
// Check if zip file already exists
if (Tx_TerFe2_Utility_File::fileExists($zipFileName)) {
return TRUE;
return $zipFileName;
}
// Check file hash
......@@ -144,7 +146,12 @@
}
// Create zip file
return Tx_TerFe2_Utility_Archive::convertT3xToZip($t3xFileName, $zipFileName);
$result = Tx_TerFe2_Utility_Archive::convertT3xToZip($t3xFileName, $zipFileName);
if (!empty($result)) {
return $zipFileName;
}
return '';
}
......
<?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!
******************************************************************/
/**
* Filesize view helper
*/
class Tx_TerFe2_ViewHelpers_FilesizeViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* Disable the escaping interceptor
*/
protected $escapingInterceptorEnabled = FALSE;
/**
* Renders filesize in given format
*
* @param integer $filesize Filesize in bytes
* @param string $format Output format
* @return string New file size in given format
*/
public function render($filesize = NULL, $format = 'kb') {
if ($filesize === NULL) {
$filesize = $this->renderChildren();
}
$filesize = (int) $filesize;
if (empty($format) || empty($filesize)) {
return $filesize;
}
switch (strtolower($format)) {
case 'kb' :
return round($filesize / 1024);
case 'mb' :
return round(($filesize / 1024) / 1024);
case 'gb' :
return round((($filesize / 1024) / 1024) / 1024);
default :
return $filesize;
}
}
}
?>
\ No newline at end of file
......@@ -388,6 +388,16 @@
'default' => 0,
),
),
't3x_file_size' => array(
'config' => array(
'type' => 'passthrough',
),
),
'zip_file_size' => array(
'config' => array(
'type' => 'passthrough',
),
),
),
);
?>
\ No newline at end of file
......@@ -31,14 +31,12 @@
<f:if condition="{extension.lastVersion.hasZipFile}">
<div class="ter-ext-single-download">
<f:link.action controller="Extension" action="download" arguments="{extension : extension, versionString : extension.lastVersion.versionString, format : 'zip'}" class="ter-download-icon ter-download-icon-zip"><f:translate key="download_zip"/></f:link.action>
<f:link.action controller="Extension" action="download" arguments="{extension : extension, versionString : extension.lastVersion.versionString, format : 'zip'}"><f:translate key="download_zip"/></f:link.action>
<div class="ter-ext-single-filesize"><f:translate key="filesize"/>: 21Kb TODO</div>
<div class="ter-ext-single-filesize"><f:translate key="filesize"/>: <terfe2:filesize filesize="{extension.lastVersion.zipFileSize}" format="kb" />Kb</div>
</div>
</f:if>
<div class="ter-ext-single-download">
<f:link.action controller="Extension" action="download" arguments="{extension : extension, versionString : extension.lastVersion.versionString, format : 't3x'}" class="ter-download-icon ter-download-icon-t3x"><f:translate key="download_t3x"/></f:link.action>
<f:link.action controller="Extension" action="download" arguments="{extension : extension, versionString : extension.lastVersion.versionString, format : 't3x'}"><f:translate key="download_t3x"/></f:link.action>
<div class="ter-ext-single-filesize"><f:translate key="filesize"/>: 21Kb TODO</div>
<div class="ter-ext-single-filesize"><f:translate key="filesize"/>: <terfe2:filesize filesize="{extension.lastVersion.t3xFileSize}" format="kb" />Kb</div>
</div>
</div>
......
......@@ -159,7 +159,7 @@ div.ter-ext-list-row:hover div.ter-ext-list-row-downloads {
background: url(../Icons/t3x.png) no-repeat;
}
.ter-download-icon-zip {
background: url(../Icons/t3x.png) no-repeat;
background: url(../Icons/zip.png) no-repeat;
}
/**
......
......@@ -66,6 +66,7 @@
'tx_terfe2_viewhelpers_documentationlinkviewhelper' => $extensionClassesPath . 'ViewHelpers/DocumentationLinkViewHelper.php',
'tx_terfe2_viewhelpers_extensioniconviewhelper' => $extensionClassesPath . 'ViewHelpers/ExtensionIconViewHelper.php',
'tx_terfe2_viewhelpers_extensionimageviewhelper' => $extensionClassesPath . 'ViewHelpers/ExtensionImageViewHelper.php',
'tx_terfe2_viewhelpers_filesizeviewhelper' => $extensionClassesPath . 'ViewHelpers/FilesizeViewHelper.php',
'tx_terfe2_viewhelpers_formatviewhelper' => $extensionClassesPath . 'ViewHelpers/FormatViewHelper.php',
'tx_terfe2_viewhelpers_rawviewhelper' => $extensionClassesPath . 'ViewHelpers/RawViewHelper.php',
);
......
......@@ -150,6 +150,8 @@ CREATE TABLE tx_terfe2_domain_model_version (
extension_provider tinytext,
has_zip_file tinyint(4) unsigned DEFAULT '0' NOT NULL,
has_images tinyint(4) unsigned DEFAULT '0' NOT NULL,
t3x_file_size bigint(15) unsigned DEFAULT '0' NOT NULL,
zip_file_size bigint(15) unsigned DEFAULT '0' NOT NULL,
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