Commit 31191884 authored by Thomas Löffler's avatar Thomas Löffler

Append Utility to all utility classes

parent 8b6590ee
Pipeline #2763 passed with stages
in 5 minutes and 8 seconds
......@@ -920,8 +920,8 @@ class tx_ter_api
break;
case 'ext_emconf.php':
$autoload = [];
if (is_callable('\T3o\TerFe2\Utility\Archive::extractEmConf')) {
$emConfData = \T3o\TerFe2\Utility\Archive::extractEmConf(base64_decode($fileData->content));
if (is_callable(\T3o\TerFe2\Utility\ArchiveUtility::class . '::extractEmConf')) {
$emConfData = \T3o\TerFe2\Utility\ArchiveUtility::extractEmConf(base64_decode($fileData->content));
if (!empty($emConfData['autoload'])) {
$autoload = $emConfData['autoload'];
}
......
......@@ -411,13 +411,13 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
if ($fileUrl === '') {
$t3xFileUrl = $provider->getFileUrl($version, 't3x');
$zipFileUrl = str_replace('.t3x', '.zip', $t3xFileUrl);
\T3o\TerFe2\Utility\Archive::convertT3xToZip(
\T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($t3xFileUrl),
\T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($zipFileUrl)
\T3o\TerFe2\Utility\ArchiveUtility::convertT3xToZip(
\T3o\TerFe2\Utility\FileUtility::getAbsolutePathFromUrl($t3xFileUrl),
\T3o\TerFe2\Utility\FileUtility::getAbsolutePathFromUrl($zipFileUrl)
);
// update ZIP filesize
$version->setZipFileSize(filesize(\T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($zipFileUrl)));
$version->setZipFileSize(filesize(\T3o\TerFe2\Utility\FileUtility::getAbsolutePathFromUrl($zipFileUrl)));
$this->versionRepository->update($version);
$this->persistenceManager->persistAll();
......@@ -426,13 +426,13 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
}
// Check if file exists
if (empty($fileUrl) || !\T3o\TerFe2\Utility\File::fileExists($fileUrl)) {
if (empty($fileUrl) || !\T3o\TerFe2\Utility\FileUtility::fileExists($fileUrl)) {
$this->redirectWithMessage($this->translate('msg.file_not_found') . ': ' . basename($fileUrl), 'show', '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, null, null, array('extension' => $extension));
}
// Check file hash of t3x packages
if ($format === 't3x') {
$fileHash = \T3o\TerFe2\Utility\File::getFileHash($fileUrl);
$fileHash = \T3o\TerFe2\Utility\FileUtility::getFileHash($fileUrl);
if ($fileHash != $version->getFileHash()) {
$this->redirectWithMessage($this->translate('msg.file_hash_not_equal'), 'show', '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, null, null, array('extension' => $extension));
}
......@@ -456,7 +456,7 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
}
// Send file to browser
if (!\T3o\TerFe2\Utility\File::transferFile($fileUrl)) {
if (!\T3o\TerFe2\Utility\FileUtility::transferFile($fileUrl)) {
$this->redirectWithMessage($this->translate('msg.could_not_transfer_file'), 'show', '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, null, null, array('extension' => $extension));
}
......@@ -506,7 +506,7 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
if (empty($form['comment'])) {
$this->forwardWithError($this->translate('msg.createVersionCommentEmpty'), 'uploadVersion');
}
$fileInfo = \T3o\TerFe2\Utility\File::getFileInfo('tx_terfe2_pi1.form.file');
$fileInfo = \T3o\TerFe2\Utility\FileUtility::getFileInfo('tx_terfe2_pi1.form.file');
if (empty($fileInfo) || empty($fileInfo['tmp_name']) || $fileInfo['error'] != UPLOAD_ERR_OK) {
$this->forwardWithError($this->translate('msg.createVersionFileEmpty'), 'uploadVersion');
}
......@@ -515,7 +515,7 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
}
$files = array();
try {
$extensionInfo = \T3o\TerFe2\Utility\Archive::getExtensionDetailsFromZipArchive($fileInfo['tmp_name'], $files);
$extensionInfo = \T3o\TerFe2\Utility\ArchiveUtility::getExtensionDetailsFromZipArchive($fileInfo['tmp_name'], $files);
} catch (\Exception $exception) {
$this->forwardWithError($exception->getMessage(), 'uploadVersion');
}
......
......@@ -15,7 +15,7 @@ namespace T3o\TerFe2\Domain\Model;
* The TYPO3 project - inspiring people to share!
*/
use T3o\TerFe2\Utility\Version as VersionUtility;
use T3o\TerFe2\Utility\VersionUtility;
/**
* Any type of relation of an extension
......
......@@ -1168,7 +1168,7 @@ class Version extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
$supportedTypo3Versions = [];
foreach ($typo3Versions as $label => $mainVersion) {
$supportedTypo3Versions[$label] = \T3o\TerFe2\Utility\Version::doesExtensionVersionSupportTypo3Version($this, $mainVersion);
$supportedTypo3Versions[$label] = \T3o\TerFe2\Utility\VersionUtility::doesExtensionVersionSupportTypo3Version($this, $mainVersion);
}
return $supportedTypo3Versions;
......
......@@ -51,7 +51,7 @@ abstract class AbstractProvider implements \T3o\TerFe2\Provider\ProviderInterfac
*/
public function __construct()
{
$this->imageCachePath = \T3o\TerFe2\Utility\File::getAbsoluteDirectory($this->imageCachePath);
$this->imageCachePath = \T3o\TerFe2\Utility\FileUtility::getAbsoluteDirectory($this->imageCachePath);
}
......@@ -110,8 +110,8 @@ abstract class AbstractProvider implements \T3o\TerFe2\Provider\ProviderInterfac
$localName = $this->imageCachePath . basename($filename);
// Check local cache first
if (\T3o\TerFe2\Utility\File::fileExists($localName)) {
return \T3o\TerFe2\Utility\File::getUrlFromAbsolutePath($localName);
if (\T3o\TerFe2\Utility\FileUtility::fileExists($localName)) {
return \T3o\TerFe2\Utility\FileUtility::getUrlFromAbsolutePath($localName);
}
// Get icon from concrete extension provider
......@@ -119,10 +119,10 @@ abstract class AbstractProvider implements \T3o\TerFe2\Provider\ProviderInterfac
// Copy icon to local cache
if (!empty($iconUrl)) {
\T3o\TerFe2\Utility\File::copyFile($iconUrl, $localName);
\T3o\TerFe2\Utility\FileUtility::copyFile($iconUrl, $localName);
}
return \T3o\TerFe2\Utility\File::getUrlFromAbsolutePath($localName);
return \T3o\TerFe2\Utility\FileUtility::getUrlFromAbsolutePath($localName);
}
......
......@@ -14,7 +14,7 @@ namespace T3o\TerFe2\Provider;
* The TYPO3 project - inspiring people to share!
*/
use T3o\TerFe2\Utility\Category;
use T3o\TerFe2\Utility\CategoryUtility;
/**
* Extension provider using local files
......@@ -44,7 +44,7 @@ class FileProvider extends \T3o\TerFe2\Provider\AbstractProvider
if (!empty($this->configuration['extensionRootPath'])) {
$this->extensionRootPath = $this->configuration['extensionRootPath'];
}
$this->extensionRootPath = \T3o\TerFe2\Utility\File::getAbsoluteDirectory($this->extensionRootPath);
$this->extensionRootPath = \T3o\TerFe2\Utility\FileUtility::getAbsoluteDirectory($this->extensionRootPath);
// Get repository for extension manager cache entries
$this->extensionManagerRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\ExtensionManagerCacheEntryRepository::class);
......@@ -98,17 +98,17 @@ class FileProvider extends \T3o\TerFe2\Provider\AbstractProvider
$filename = $this->extensionRootPath . $filename;
// Check if file exists
if (!\T3o\TerFe2\Utility\File::fileExists($filename)) {
if (!\T3o\TerFe2\Utility\FileUtility::fileExists($filename)) {
if ($fileType === 't3x' || $fileType === 'zip') {
//throw new \Exception('File "' . $filename . '" not found');
}
\T3o\TerFe2\Utility\Log::addMessage('File "' . $filename . '" not found', 'ter_fe2', 2);
\T3o\TerFe2\Utility\LogUtility::addMessage('File "' . $filename . '" not found', 'ter_fe2', 2);
return '';
}
// Get local url from absolute path
return \T3o\TerFe2\Utility\File::getUrlFromAbsolutePath($filename);
return \T3o\TerFe2\Utility\FileUtility::getUrlFromAbsolutePath($filename);
}
......@@ -187,18 +187,18 @@ class FileProvider extends \T3o\TerFe2\Provider\AbstractProvider
$content = \TYPO3\CMS\Core\Utility\GeneralUtility::getURL($filename);
$filesize = strlen($content);
if (empty($content)) {
\T3o\TerFe2\Utility\Log::addMessage('File "' . $filename . '" could not be fetched', 'ter_fe2', 2);
\T3o\TerFe2\Utility\LogUtility::addMessage('File "' . $filename . '" could not be fetched', 'ter_fe2', 2);
return array();
}
// Check file hash
if ($fileHash !== md5($content)) {
\T3o\TerFe2\Utility\Log::addMessage('File hash missmatch of file "' . $filename . '"', 'ter_fe2', 2);
\T3o\TerFe2\Utility\LogUtility::addMessage('File hash missmatch of file "' . $filename . '"', 'ter_fe2', 2);
return array();
}
// Get EM_CONF array
$extension = \T3o\TerFe2\Utility\Archive::decompressT3xStream($content);
$extension = \T3o\TerFe2\Utility\ArchiveUtility::decompressT3xStream($content);
$emConf = array();
if (!empty($extension['EM_CONF'])) {
$emConf = $extension['EM_CONF'];
......@@ -242,7 +242,7 @@ class FileProvider extends \T3o\TerFe2\Provider\AbstractProvider
$extensionModel = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
$states = $extensionModel->getDefaultState(null);
$states = array_flip($states);
$categories = Category::getDefaultCategories();
$categories = CategoryUtility::getDefaultCategories();
$categories = array_flip($categories);
$extensions = array();
......
......@@ -44,7 +44,7 @@ class MirrorProvider extends \T3o\TerFe2\Provider\FileProvider
if (!empty($this->configuration['fileCachePath'])) {
$this->fileCachePath = $this->configuration['fileCachePath'];
}
$this->fileCachePath = \T3o\TerFe2\Utility\File::getAbsoluteDirectory($this->fileCachePath);
$this->fileCachePath = \T3o\TerFe2\Utility\FileUtility::getAbsoluteDirectory($this->fileCachePath);
// Get repository id
$repositoryId = 1;
......@@ -76,25 +76,25 @@ class MirrorProvider extends \T3o\TerFe2\Provider\FileProvider
}
// Check local cache first
if (!empty($localName) && $fileType === 't3x' && \T3o\TerFe2\Utility\File::fileExists($localName)) {
return \T3o\TerFe2\Utility\File::getUrlFromAbsolutePath($localName);
if (!empty($localName) && $fileType === 't3x' && \T3o\TerFe2\Utility\FileUtility::fileExists($localName)) {
return \T3o\TerFe2\Utility\FileUtility::getUrlFromAbsolutePath($localName);
}
// Get filename on mirror server
$filename = $this->mirrorService->getUrlToFile($filename);
if (\T3o\TerFe2\Utility\File::isLocalUrl($filename)) {
$filename = \T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($filename);
if (\T3o\TerFe2\Utility\FileUtility::isLocalUrl($filename)) {
$filename = \T3o\TerFe2\Utility\FileUtility::getAbsolutePathFromUrl($filename);
}
// Copy file to local cache and return it
if (!empty($localName)) {
\T3o\TerFe2\Utility\File::copyFile($filename, $localName);
return \T3o\TerFe2\Utility\File::getUrlFromAbsolutePath($localName);
\T3o\TerFe2\Utility\FileUtility::copyFile($filename, $localName);
return \T3o\TerFe2\Utility\FileUtility::getUrlFromAbsolutePath($localName);
}
// Get local url from absolute path
if (\T3o\TerFe2\Utility\File::isAbsolutePath($filename)) {
return \T3o\TerFe2\Utility\File::getUrlFromAbsolutePath($filename);
if (\T3o\TerFe2\Utility\FileUtility::isAbsolutePath($filename)) {
return \T3o\TerFe2\Utility\FileUtility::getUrlFromAbsolutePath($filename);
}
return $filename;
......@@ -123,7 +123,7 @@ class MirrorProvider extends \T3o\TerFe2\Provider\FileProvider
// Check file hash
if ($fileHash !== md5($content)) {
\T3o\TerFe2\Utility\Log::addMessage('File hash missmatch of file "' . $filename . '"', 'ter_fe2', 2);
\T3o\TerFe2\Utility\LogUtility::addMessage('File hash missmatch of file "' . $filename . '"', 'ter_fe2', 2);
return array();
}
......@@ -134,7 +134,7 @@ class MirrorProvider extends \T3o\TerFe2\Provider\FileProvider
}
// Get EM_CONF array
$extension = \T3o\TerFe2\Utility\Archive::decompressT3xStream($content);
$extension = \T3o\TerFe2\Utility\ArchiveUtility::decompressT3xStream($content);
$emConf = array();
if (!empty($extension['EM_CONF'])) {
$emConf = $extension['EM_CONF'];
......
......@@ -187,7 +187,7 @@ class Mirror implements \TYPO3\CMS\Core\SingletonInterface
// Check mirrors if file exits
$attempts = 1;
$maxAttempts = $this->getMaxAttempts();
while (!\T3o\TerFe2\Utility\File::fileExists($mirrorUrl . $filename)) {
while (!\T3o\TerFe2\Utility\FileUtility::fileExists($mirrorUrl . $filename)) {
$attempts++;
if ($attempts > $maxAttempts) {
// throw new \Exception('File "' . $filename . '" could not be found on ' . $maxAttempts . ' mirrors, break');
......@@ -212,8 +212,8 @@ class Mirror implements \TYPO3\CMS\Core\SingletonInterface
{
$url = $this->getUrlToFile($filename);
if (\T3o\TerFe2\Utility\File::isLocalUrl($url)) {
$url = \T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($url);
if (\T3o\TerFe2\Utility\FileUtility::isLocalUrl($url)) {
$url = \T3o\TerFe2\Utility\FileUtility::getAbsolutePathFromUrl($url);
$content = \TYPO3\CMS\Core\Utility\GeneralUtility::getURL($url);
} else {
$content = \TYPO3\CMS\Core\Utility\GeneralUtility::getURL($url, 0, array(TYPO3_user_agent));
......
......@@ -17,7 +17,7 @@ namespace T3o\TerFe2\Solr\IndexQueue;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use T3o\TerFe2\Utility\Version;
use T3o\TerFe2\Utility\VersionUtility;
/**
* Class \T3o\TerFe2\Solr\IndexQueue\TerIndexer
......@@ -104,13 +104,13 @@ class TerIndexer extends \ApacheSolrForTypo3\Solr\IndexQueue\Indexer
// does this extension supports different versions?
// @todo: use JSON with all versions to get them
$lastVersion = $extension->getLastVersion();
$document->setField('supports7_boolS', Version::doesExtensionVersionSupportTypo3Version($lastVersion, 7006000));
$document->setField('supports8_boolS', Version::doesExtensionVersionSupportTypo3Version($lastVersion, 8007000));
$document->setField('supports7_boolS', VersionUtility::doesExtensionVersionSupportTypo3Version($lastVersion, 7006000));
$document->setField('supports8_boolS', VersionUtility::doesExtensionVersionSupportTypo3Version($lastVersion, 8007000));
$typo3Support = [];
if (Version::doesExtensionVersionSupportTypo3Version($lastVersion, 7006000)) {
if (VersionUtility::doesExtensionVersionSupportTypo3Version($lastVersion, 7006000)) {
$typo3Support[] = '7 LTS';
}
if (Version::doesExtensionVersionSupportTypo3Version($lastVersion, 8007000)) {
if (VersionUtility::doesExtensionVersionSupportTypo3Version($lastVersion, 8007000)) {
$typo3Support[] = '8 LTS';
}
$document->setField('typo3support_stringM', $typo3Support);
......@@ -188,7 +188,7 @@ class TerIndexer extends \ApacheSolrForTypo3\Solr\IndexQueue\Indexer
$fileType
);
if (file_exists(PATH_site . $iconPath . $iconFile)) {
$icon = \T3o\TerFe2\Utility\File::getRelativeUrlFromAbsolutePath($iconPath . $iconFile);
$icon = \T3o\TerFe2\Utility\FileUtility::getRelativeUrlFromAbsolutePath($iconPath . $iconFile);
break;
}
}
......
<?php
namespace T3o\TerFe2\Task;
use T3o\TerFe2\Utility\Category;
use T3o\TerFe2\Utility\CategoryUtility;
/*
* This file is part of the TYPO3 CMS project.
......
......@@ -219,7 +219,7 @@ class ImportExtensionsFromQueueTask extends Task
{
$extensionModel = GeneralUtility::makeInstance(Extension::class);
$states = $extensionModel->getDefaultState(null);
$categories = \T3o\TerFe2\Utility\Category::getDefaultCategories();
$categories = \T3o\TerFe2\Utility\CategoryUtility::getDefaultCategories();
$folder1 = substr($extData['extensionkey'], 0, 1);
$folder2 = substr($extData['extensionkey'], 1, 1);
......
......@@ -20,7 +20,7 @@ use PhpParser\ParserFactory;
/**
* Utilities to manage zip and t3x files
*/
class Archive
class ArchiveUtility
{
/**
......@@ -39,7 +39,7 @@ class Archive
}
// Check if file already exists
if (!$overwrite && \T3o\TerFe2\Utility\File::fileExists($filename)) {
if (!$overwrite && \T3o\TerFe2\Utility\FileUtility::fileExists($filename)) {
return true;
}
......@@ -85,12 +85,12 @@ class Archive
}
// Check if file exists
if (!\T3o\TerFe2\Utility\File::fileExists($filename)) {
if (!\T3o\TerFe2\Utility\FileUtility::fileExists($filename)) {
throw new \Exception('File "' . $filename . '" not found to extract');
}
// Check if path is writable
$path = \T3o\TerFe2\Utility\File::getAbsoluteDirectory($path);
$path = \T3o\TerFe2\Utility\FileUtility::getAbsoluteDirectory($path);
if (!is_writable($path)) {
throw new \Exception('Path "' . $path . '" is not writeable');
}
......@@ -129,7 +129,7 @@ class Archive
}
// Check if file exists
if (!\T3o\TerFe2\Utility\File::fileExists($filename)) {
if (!\T3o\TerFe2\Utility\FileUtility::fileExists($filename)) {
throw new \Exception('File "' . $filename . '" not found to extract');
}
......@@ -184,7 +184,7 @@ class Archive
}
// Check if file was cached
if (\T3o\TerFe2\Utility\File::fileExists($zipFile)) {
if (\T3o\TerFe2\Utility\FileUtility::fileExists($zipFile)) {
return true;
}
......@@ -199,7 +199,7 @@ class Archive
// Create ext_emconf.php if it doesn't exist
if (!isset($files['ext_emconf.php']) && !empty($content['extKey']) && !empty($content['EM_CONF']) && is_array($content['EM_CONF'])) {
$files['ext_emconf.php'] = \T3o\TerFe2\Utility\File::createExtEmconfFile(
$files['ext_emconf.php'] = \T3o\TerFe2\Utility\FileUtility::createExtEmconfFile(
$content['extKey'],
$content['EM_CONF']
);
......@@ -225,8 +225,8 @@ class Archive
}
// Get local file name if on same server
if (\T3o\TerFe2\Utility\File::isLocalUrl($filename)) {
$filename = \T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($filename);
if (\T3o\TerFe2\Utility\FileUtility::isLocalUrl($filename)) {
$filename = \T3o\TerFe2\Utility\FileUtility::getAbsolutePathFromUrl($filename);
}
// Get file content
......
......@@ -17,7 +17,7 @@ namespace T3o\TerFe2\Utility;
/**
* Utilities to manage versions
*/
class Category
class CategoryUtility
{
/** @var array The list of em categories (taken from em) */
......
......@@ -17,7 +17,7 @@ namespace T3o\TerFe2\Utility;
/**
* Utilities to manage files
*/
class File
class FileUtility
{
/**
......
......@@ -17,7 +17,7 @@ namespace T3o\TerFe2\Utility;
/**
* Utilities to manage logging
*/
class Log
class LogUtility
{
/**
......
......@@ -17,7 +17,7 @@ namespace T3o\TerFe2\Utility;
/**
* Utilities to manage versions
*/
class Version
class VersionUtility
{
/**
......
......@@ -70,13 +70,13 @@ class ExtensionIconViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractT
if (!empty($provider)) {
foreach ($this->fileIconOrder as $fileType) {
$imageUrl = $this->providerManager->getProvider($provider)->getIconUrl($version, $fileType);
if (!empty($imageUrl) && file_exists(\T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($imageUrl))) {
if (!empty($imageUrl) && file_exists(\T3o\TerFe2\Utility\FileUtility::getAbsolutePathFromUrl($imageUrl))) {
break;
}
}
}
if (empty($imageUrl) || !file_exists(\T3o\TerFe2\Utility\File::getAbsolutePathFromUrl($imageUrl))) {
if (empty($imageUrl) || !file_exists(\T3o\TerFe2\Utility\FileUtility::getAbsolutePathFromUrl($imageUrl))) {
return '';
}
......
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