Skip to content

Commit

Permalink
Typo3 10 (#74)
Browse files Browse the repository at this point in the history
* [TASK] Remove  variable

* [TASK] Rise version numbers

* [TASK] Migrate PATH_typo3 constant in PHP

* [TASK] Migrate version_compare conditions - remove support for older TYPO3 versions

* [TASK] Migrate PATH_site constant in PHP

* [TASK] Migrate getTSConfigVal() method for getting user settings

* [TASK] Migration URL generation for clear cache hook

* [TASK] Disable caching in enabled development mode

* [TASK] Optimize composer.json

* [TASK] Revert changes

* [TASK] Make dyncss branch typo10-3 installable with TYPO3 9

Co-authored-by: Thomas Deuling <info@coding.ms>
Co-authored-by: Thomas Deuling <1298841+tdeuling@users.noreply.github.com>
Co-authored-by: Christian Bülter <cbuelter@coding.ms>
  • Loading branch information
4 people authored Jan 25, 2021
1 parent 9387011 commit bba224a
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 85 deletions.
46 changes: 18 additions & 28 deletions Classes/Hooks/Backend/Toolbar/ClearCacheActionsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
namespace KayStrobach\Dyncss\Hooks\Backend\Toolbar;

use TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Backend\Routing\UriBuilder;

class ClearCacheActionsHook implements ClearCacheActionsHookInterface
{
Expand All @@ -26,42 +25,33 @@ class ClearCacheActionsHook implements ClearCacheActionsHookInterface
*/
public function manipulateCacheActions(&$cacheActions, &$optionValues)
{
if ($this->getBackendUser()->getTSConfigVal('options.clearCache.system')
|| GeneralUtility::getApplicationContext()->isDevelopment()
|| ((bool)$GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === true && $this->getBackendUser()->isAdmin())
) {
$hrefParams = ['cacheCmd' => 'dyncss', 'ajaxCall' => 1];
/** @var \TYPO3\CMS\Core\Imaging\IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconFactory::class);
$clearCacheSystemUser = (bool)($this->getBackendUser()->getTSConfig()['options.']['clearCache.']['system'] ?? false);
$isDevelopment = GeneralUtility::getApplicationContext()->isDevelopment();
$clearCacheSystemSys = (bool)$GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === true;
$isAdmin = $this->getBackendUser()->isAdmin();
if ($clearCacheSystemUser || $isDevelopment || ($clearCacheSystemSys && $isAdmin)) {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriParameters = ['cacheCmd' => 'dyncss', 'ajaxCall' => 1];
$translationPrefix = 'LLL:EXT:dyncss/Resources/Private/Language/locallang.xlf:dyncss.toolbar.clearcache.';
if (version_compare(TYPO3_version, '8.7', '<')) {
$cacheActions[] = [
'id' => 'dyncss',
'title' => LocalizationUtility::translate($translationPrefix . 'title', 'Dyncss'),
'description' => LocalizationUtility::translate($translationPrefix . 'description', 'Dyncss'),
'href' => BackendUtility::getModuleUrl('tce_db', $hrefParams),
'icon' => $iconFactory->getIcon('actions-system-cache-clear-dyncss', Icon::SIZE_SMALL)->render()
];
} else {
$cacheActions[] = [
'id' => 'dyncss',
'title' => $translationPrefix . 'title',
'description' => $translationPrefix . 'description',
'href' => BackendUtility::getModuleUrl('tce_db', $hrefParams),
'iconIdentifier' => 'actions-system-cache-clear-dyncss'
];
}
$cacheActions[] = [
'id' => 'dyncss',
'title' => $translationPrefix . 'title',
'description' => $translationPrefix . 'description',
'href' => (string)$uriBuilder->buildUriFromRoute('tce_db', $uriParameters),
'iconIdentifier' => 'actions-system-cache-clear-dyncss'
];
$optionValues[] = 'dyncss';
}
}

/**
* Returns the current BE user.
*
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
* @return BackendUserAuthentication
*/
protected function getBackendUser()
{
return $GLOBALS['BE_USER'];
}

}
12 changes: 3 additions & 9 deletions Classes/Hooks/T3libTcemainHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace KayStrobach\Dyncss\Hooks;

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -24,15 +25,8 @@ public function clearCachePostProc(array $params, DataHandler &$pObj)
switch ($params['cacheCmd']) {
case 'dyncss':
$pObj->clear_cacheCmd("pages");
GeneralUtility::rmdir(
PATH_site.'typo3temp/Cache/Data/DynCss',
true
);

GeneralUtility::rmdir(
PATH_site.'typo3temp/DynCss',
true
);
GeneralUtility::rmdir(Environment::getPublicPath() . '/typo3temp/Cache/Data/DynCss', true);
GeneralUtility::rmdir(Environment::getPublicPath() . '/typo3temp/DynCss', true);
break;
default:

Expand Down
19 changes: 10 additions & 9 deletions Classes/Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace KayStrobach\Dyncss\Parser;

use KayStrobach\Dyncss\Utilities\ApplicationContext;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\ArrayUtility;

Expand Down Expand Up @@ -149,7 +150,7 @@ public function _postCompile($string)
*
* @todo missing declaration of inputFilename
*/
$relativePath = dirname(substr($this->inputFilename, strlen(PATH_site))).'/';
$relativePath = dirname(substr($this->inputFilename, strlen(Environment::getPublicPath() . '/'))).'/';

/*
* find all matches of url() and adjust uris
Expand Down Expand Up @@ -204,8 +205,8 @@ public function resolveUrlInCss($url)
return $url;
}
if (substr($url, 0, 1) === '/') {
if (substr($url, 0, strlen(PATH_site)) === PATH_site) {
return '../../'.substr($url, strlen(PATH_site));
if (substr($url, 0, strlen(Environment::getPublicPath() . '/')) === Environment::getPublicPath() . '/') {
return '../../'.substr($url, strlen(Environment::getPublicPath() . '/'));
}

return $url;
Expand All @@ -215,7 +216,7 @@ public function resolveUrlInCss($url)
return $url;
}
// anything inside TYPO3 has to be adjusted
return '../../../../'.dirname($this->removePrefixFromString(PATH_site, $this->inputFilename)).'/'.$url;
return '../../../../'.dirname($this->removePrefixFromString(Environment::getPublicPath() . '/', $this->inputFilename)).'/'.$url;
}

/**
Expand Down Expand Up @@ -279,7 +280,7 @@ public function compileFile($inputFilename, $outputFilename = null)
return $inputFilename;
}
if ($outputFilename === null) {
$outputFilename = PATH_site.$this->cachePath.basename($inputFilename);
$outputFilename = Environment::getPublicPath() . '/' .$this->cachePath.basename($inputFilename);
}
$outputFilenamePathInfo = pathinfo($outputFilename);
$noExtensionFilename = $outputFilename.'-'.hash('crc32b', $inputFilename).'-'.hash('crc32b', serialize($this->overrides)).'-'.hash('crc32b', filemtime($inputFilename));
Expand All @@ -297,7 +298,7 @@ public function compileFile($inputFilename, $outputFilename = null)
}

//write intermediate file, if the source has been changed, the rest is done by the cache management
if (@filemtime($outputFilename) < @filemtime($inputFilename) || $this->_checkIfCompileNeeded($inputFilename)) {
if (@filemtime($outputFilename) < @filemtime($inputFilename) || $this->_checkIfCompileNeeded($inputFilename) || ApplicationContext::isDevelopmentModeActive()) {
file_put_contents($preparedFilename, $this->_prepareCompile(file_get_contents($inputFilename)));

$fileContent = $this->_postCompile($this->_compileFile($inputFilename, $preparedFilename, $outputFilename, $cacheFilename));
Expand Down Expand Up @@ -329,14 +330,14 @@ public function compileFile($inputFilename, $outputFilename = null)
*/
public function prepareEnvironment($fname)
{
GeneralUtility::mkdir_deep(PATH_site.'typo3temp/', 'DynCss/');
if (!is_dir(PATH_site.$this->cachePath)) {
GeneralUtility::mkdir_deep(Environment::getPublicPath() . '/typo3temp/DynCss/');
if (!is_dir(Environment::getPublicPath() . '/' . $this->cachePath)) {
throw new \Exception('Can´t create cache directory PATH_site/'.$this->cachePath);
}
if (!is_file($fname)) {
return false;
}

return true;
}

}
18 changes: 6 additions & 12 deletions Classes/Service/DyncssService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace KayStrobach\Dyncss\Service;

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -49,17 +50,14 @@ protected static function fixPathForInput($file)
return GeneralUtility::getFileAbsFileName($file);
}
if (TYPO3_MODE === 'BE' && !self::isCliMode()) {
return GeneralUtility::resolveBackPath(PATH_typo3 . $file);
return GeneralUtility::resolveBackPath(Environment::getPublicPath() . '/typo3/' . $file);
}
return $file;
}

protected static function isCliRequest()
{
if (\version_compare(TYPO3_version, '8.0.0', '>=')) {
return (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI);
}
return TYPO3_cliMode;
return (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI);
}

/**
Expand All @@ -74,9 +72,9 @@ protected static function isCliRequest()
protected static function fixPathForOutput($file)
{
if (TYPO3_MODE === 'FE') {
$file = str_replace(PATH_site, '', $file);
$file = str_replace(Environment::getPublicPath(), '', $file);
} elseif (TYPO3_MODE === 'BE') {
$file = str_replace(PATH_site, '../', $file);
$file = str_replace(Environment::getPublicPath(), '../', $file);
if (array_key_exists('BACK_PATH', $GLOBALS)) {
$file = $GLOBALS['BACK_PATH'].$file;
}
Expand Down Expand Up @@ -122,10 +120,6 @@ public static function getOverrides()
*/
protected static function isCliMode()
{
if (version_compare(TYPO3_version, '8.0', '<')) {
return defined('TYPO3_cliMode');
} else {
return TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI;
}
return TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI;
}
}
4 changes: 2 additions & 2 deletions Tests/Unit/Parser/DummyParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function setUp()
'/absPath' => '/absPath',
'data:suiehihsidgfiu' => 'data:suiehihsidgfiu',
'../../Public/Contrib/bootstrap/fonts/glyphicons-halflings-regular.eot' => '../../../../typo3conf/ext/dyncss/Resources/Public/Less/../../Public/Contrib/bootstrap/fonts/glyphicons-halflings-regular.eot',
PATH_site.'yeah' => '../../yeah',
\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/yeah' => '../../yeah',
];
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public function _postCompile()
*/
public function resolveUrlInCss()
{
$this->fixture->inputFilename = PATH_site.'typo3conf/ext/dyncss/Resources/Public/Less/someLessFile.less';
$this->fixture->inputFilename = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3conf/ext/dyncss/Resources/Public/Less/someLessFile.less';
foreach ($this->urlsToCheck as $key => $url) {
$this->assertSame($url, $this->fixture->resolveUrlInCss($key), 'Failed with '.$key);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "typo3-cms-extension",
"license": "GPL-2.0+",
"require": {
"typo3/cms-core": ">=7.6.15 || ^8.7 || ^9.5"
"typo3/cms-core": ">=9.5,<10.5"
},
"replace": {
"dyncss": "self.version",
Expand Down
46 changes: 23 additions & 23 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@
// writing. "version" and "dependencies" must not be touched!
//#######################################################################

$EM_CONF[$_EXTKEY] = [
'title' => 'DynCss - BaseModule',
'description' => 'Compile your CSS dynamically with DynCss Adapters.',
'category' => 'fe',
'shy' => 0,
'version' => '0.8.3',
'dependencies' => '',
'conflicts' => '',
'priority' => '',
'loadOrder' => '',
'module' => '',
'state' => 'stable',
'uploadfolder' => 0,
'createDirs' => '',
'modify_tables' => '',
'clearcacheonload' => 0,
'lockType' => '',
'author' => 'Kay Strobach',
'author_email' => 'kay.strobach@typo3.org',
'author_company' => '',
'CGLcompliance' => '',
$EM_CONF['dyncss'] = [
'title' => 'DynCss - BaseModule',
'description' => 'Compile your CSS dynamically with DynCss Adapters.',
'category' => 'fe',
'shy' => 0,
'version' => '1.0.0',
'dependencies' => '',
'conflicts' => '',
'priority' => '',
'loadOrder' => '',
'module' => '',
'state' => 'stable',
'uploadfolder' => 0,
'createDirs' => '',
'modify_tables' => '',
'clearcacheonload' => 0,
'lockType' => '',
'author' => 'Kay Strobach',
'author_email' => 'kay.strobach@typo3.org',
'author_company' => '',
'CGLcompliance' => '',
'CGLcompliance_note' => '',
'constraints' => [
'constraints' => [
'depends' => [
'typo3' => '7.6.15-9.5.99',
'typo3' => '9.5.00-10.4.99',
],
'conflicts' => [
],
Expand Down
2 changes: 1 addition & 1 deletion ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ function ($extKey) {
}
}
},
$_EXTKEY
'dyncss'
);

0 comments on commit bba224a

Please sign in to comment.