Commit 30bd5b93 authored by speedprogs_de's avatar speedprogs_de

fixed file utility, added local cache for t3x files on mirrors

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51976 735d13b6-9817-0410-8766-e36946ffe9aa
parent bc93452e
......@@ -51,7 +51,7 @@
/**
* @var string
*/
protected $imageCachePath = 'typo3temp/pics/';
protected $imageCachePath = 'typo3temp/tx_terfe2/images/';
/**
......
......@@ -43,6 +43,10 @@
*/
protected $mirrorService;
/**
* @var string
*/
protected $fileCachePath = '';
/**
......@@ -61,6 +65,11 @@
$this->repositoryId = (int) $this->configuration['repositoryId'];
}
// Set local file cache path
if (!empty($this->configuration['fileCachePath'])) {
$this->fileCachePath = Tx_TerFe2_Utility_File::getAbsoluteDirectory($this->configuration['fileCachePath']);
}
// Get repository for extension manager cache entries
$this->extensionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_ExtensionManagerCacheEntryRepository');
......@@ -108,6 +117,17 @@
*/
public function getFileUrl(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
$filename = $this->getFileName($version, $fileType);
$localName = '';
// Get local filename for t3x files
if (!empty($this->fileCachePath) && $fileType === 't3x') {
$localName = $this->fileCachePath . basename($filename);
}
// Check local cache first
if (!empty($localName) && $fileType === 't3x' && Tx_TerFe2_Utility_File::fileExists($localName)) {
return Tx_TerFe2_Utility_File::getUrlFromAbsolutePath($localName);
}
// Get filename on mirror server
$filename = $this->mirrorService->getUrlToFile($filename);
......@@ -120,6 +140,12 @@
throw new Exception('File "' . $filename . '" not found');
}
// Copy file to local cache and return it
if (!empty($localName)) {
Tx_TerFe2_Utility_File::copyFile($filename, $localName);
return Tx_TerFe2_Utility_File::getUrlFromAbsolutePath($localName);
}
// Get local url from absolute path
if (Tx_TerFe2_Utility_File::isAbsolutePath($filename)) {
return Tx_TerFe2_Utility_File::getUrlFromAbsolutePath($filename);
......
......@@ -260,6 +260,12 @@
return FALSE;
}
// Check if file already exists
$toFileExists = self::fileExists($toFileName);
if ($toFileExists && !$overwrite) {
return FALSE;
}
// Check if target directory exists
if (!self::fileExists(dirname($toFileName))) {
return FALSE;
......@@ -272,14 +278,12 @@
// Get file content
$fromFile = t3lib_div::getURL($fromFileName);
// Check files
if ($fromFile === FALSE || ($toFileExists && !$overwrite)) {
if ($fromFile === FALSE) {
return FALSE;
}
// Remove existing
if (self::fileExists($toFileName) && $overwrite) {
// Remove existing when successfully fetched new file
if ($toFileExists) {
unlink($toFileName);
}
......
......@@ -25,7 +25,7 @@ $EM_CONF[$_EXTKEY] = array(
'state' => 'alpha',
'internal' => '',
'uploadfolder' => 0,
'createDirs' => '',
'createDirs' => 'typo3temp/tx_terfe2/images/,typo3temp/tx_terfe2/files/',
'modify_tables' => '',
'clearCacheOnLoad' => 0,
'lockType' => '',
......
......@@ -30,6 +30,7 @@
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xml:tx_terfe2_provider_extensionmanagerprovider.name',
'configuration' => array(
'repositoryId' => 1,
'fileCachePath' => 'typo3temp/tx_terfe2/files/',
),
);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$_EXTKEY]['extensionProviders']['file'] = array(
......
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