Skip to content

Commit

Permalink
Compatibility to TYPO3 v12 (#210)
Browse files Browse the repository at this point in the history
* [DOCS] Update README.md
* Raise compatibility to TYPO3 v12
* Use executeQuery() or executeStatement() instead of execute()
* Use use-statements in Configuration/
* Add .editorconfig
* Code cleanup
* Remove dynamicReturnTypeMeta.json as the plugin is outdated and neither usable nor necessary.
* Remove BE-mode check from ext_localconf.php. This is not needed and breaks in v12
* "use" statements in ext_localconf.php
* Add TODO for EventDispatcher for EXT:solrfal for v12
* Update Aspects
* parameter types for properties and method arguments
* copyright
* declare(strict_types=1)
* order declare/copyright/namespaces
* remove PHPDoc if only type hints or method name
* Update ExtensionConfiguration
* Declare correct type for Context\UserAspect::$user
* Update ItemProvider
* documentation of constructor arguments for v11
* parameter type for properties
* PHPDoc
* Update BePublicUrlController
* BePublicUrlController::$resourceFactory only provided by Dependency Injection
* BePublicUrlController::$processedFileRepository provided by Dependency Injection
* Make BePublicUrlController::dumpFile() more resilient
* catch FileDoesNotExistException for 'f'-file and respond with 404
* respond with 404 for deleted or missing 'f'-file like changed for 'p' in #102
* catch \RuntimeException for 'p'-file and respond with 404. This prevents null pointer for $orgFile->getStorage()
* Update FileTreeController
* FileTreeController::$resourceFactory only provided by Dependency Injection
* Error message instead of empty response for missing storage
* Update FileTreeStateController
* add @throws declarations
* Constructor arguments of FileTreeStateController only provided by Dependency Injection
* Remove unused class Domain/Repository/ProcessedFileRepository
* Update FolderChangedEventListener
* added registration information and added @noinspection PHPUnused
* Add FolderChangedEventListener::updateFolderPermissions()
* Extracted duplicate code to new method
* Update GeneratePublicUrlForResourceEventListener
* added registration information and @noinspection PHPUnused
* Update ModifyIconForResourcePropertiesEventListener
* change list() to short array syntax
* Update Events
* added @noinspection PHPUnused
* Update DownloadStatistics
* added @throws
* Update AbstractBeButtons and DocHeaderButtonsHook
* parameter types for properties and methods
* Update CmsLayout
* CmsLayout::$resourceFactory only provided by Dependency Injection
* Update FileDumpHook
* catch UnknownLinkHandlerException and add error message
* Update KeSearchFilesHook
* Update ProcessDatamapHook
* parameter types for methods
* Update EidFrontendAuthentication
* Remove DocHeaderButtonsHook::addFolderPermissionsButton(). Used in TYPO3 <= v7 and usage removed in a6f079b Updated extension to fully support TYPO3 8.7 and removed old below TYPO3 7.6 support.
* Update CheckPermissions
* switch from Folder to FolderInterface as not necessary
* replace PHP8 str_contains() with strpos()
* Update LeafStateService
* LeafStateService::$resourceFactory only provided by Dependency Injection
* Update UserFileMountService
* Update Utility
* Update ViewHelpers
* add PHPDoc type hints
* Rename TypoScript files from *.txt to *.typoscript
* Fix typos in locallang_be.xlf
* Formatting of HTML files, fluid namespace declaration
* Update CollapsibleFolderTree.js
* Fix typo
* Fix formatting
* Reuse jQuery selector for folders
* Update SVG files
* Update .editorconfig and format accordingly
* Remove ext_icon.png. Available in Resources/Public/Icons/Extension.png https://docs.typo3.org/c/typo3/cms-core/11.5/en-us/Changelog/8.3/Feature-77349-AdditionalLocationsForExtensionIcons.html?highlight=ext_icon
* Move icon registration to ext_localconf.php. Should always have been there: https://docs.typo3.org/c/typo3/cms-core/12.4/en-us/Changelog/7.5/Feature-68741-IntroduceNewIconFactoryAsBaseForReplaceTheIconSkinningAPI.html
* Update ext_tables.sql. Database management fields are generated automatically: https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.3/Feature-85160-AutoCreateManagementDBFieldsFromTCACtrl.html?highlight=85160
* [BUGFIX] Catch FolderDoesNotExistException. $file->getParentFolder() may throw a FolderDoesNotExistException which currently is not part of PHPDoc in TYPO3 core. This may lead to this exception being thrown in the backend in case of an offline protected storage instead of displaying the file tree. This change makes sure the file tree is shown by catching the exception.
* Context menu using ES6 module in TYPO3 v12. Adding a context menu using RequireJS does only work in TYPO3 v11 but no longer in v12, even if the documentation hints it should: https://docs.typo3.org/m/typo3/reference-coreapi/12.4/en-us/ApiOverview/Backend/JavaScript/ES6/Index.html#migration-from-requirejs
* Remove ['TYPO3_CONF_VARS']['EXTCONF'] usage from FileDumpHook. Using this is removed since TYPO3 v10
* Migrate Hooks\FileDumpHook to EventListener\ModifyFileDumpEventListener https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Events/Events/Core/Resource/ModifyFileDumpEvent.html
* Remove comparison to EXT:naw_securedl from documentation. EXT:naw_securedl is outdated and not relevant anymore
* IconFactoryAspect uses constructor and SingletonInterface
* Use UserFileMountService of core. Instead of using an outdated copy of the UserFileMountService from core simply override the config and use the core service. The UserFileMountService is deprecated in v12 and will be removed in v13, but currently selection of a storage root folder is not possible from the element browser, therefore migration to type=folder is not an option currently. https://forge.typo3.org/issues/100789
* Remove unnecessary option to select storage. As displayCond already makes sure a storage is selected, the dropdown item in the folder selection is not needed.
* Add typoscript option to disable javascript include
* Rename event variables and remove type hints
* Remove unused method CheckPermissions::getBackendUser()
* Pass request to UserAuthentication. This is required for TYPO3 v12
* Avoid TCA migrations in TYPO3 v12
* Replace strpos() with str_contains(). As TYPO3 v11 uses a polyfill this is possible also with PHP 7.4
* Use FileInterface for ModifyFileDumpEventListener::dumpFileContents(). The object to be dumped may also be a ProcessedFile.
  • Loading branch information
sgrossberndt committed Jun 15, 2023
1 parent c328253 commit 2dc2d90
Show file tree
Hide file tree
Showing 67 changed files with 1,438 additions and 1,494 deletions.
55 changes: 55 additions & 0 deletions .editorconfig
@@ -0,0 +1,55 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

# TS/JS-Files
[*.{ts,js}]
indent_size = 2

# JSON-Files
[*.json]
indent_style = tab

# ReST-Files
[*.{rst,rst.txt}]
indent_size = 4
max_line_length = 80

# Markdown-Files
[*.md]
max_line_length = 80

# YAML-Files
[*.{yaml,yml}]
indent_size = 2

# JSON-Files
[composer.json]
indent_style = space

# TypoScript
[*.{typoscript,tsconfig}]
indent_size = 2

# XLF-Files
[*.xlf]
indent_style = tab

# SQL-Files
[*.sql]
indent_style = tab
indent_size = 2

# .htaccess
[{_.htaccess,.htaccess}]
indent_style = tab
74 changes: 40 additions & 34 deletions Classes/Aspects/IconFactoryAspect.php
@@ -1,7 +1,8 @@
<?php
namespace BeechIt\FalSecuredownload\Aspects;

/***************************************************************
declare(strict_types=1);

/*
* Copyright notice
*
* (c) 2017 Frans Saris <frans@beech.it>
Expand All @@ -22,57 +23,62 @@
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
*/

namespace BeechIt\FalSecuredownload\Aspects;

use BeechIt\FalSecuredownload\Security\CheckPermissions;
use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceInterface;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class IconFactoryAspect
*/
class IconFactoryAspect
class IconFactoryAspect implements SingletonInterface
{

/**
* @param ResourceInterface $resource
* @param string $size
* @param array $options
* @param string $iconIdentifier
* @param string $overlayIdentifier
* @return array
*/
private CheckPermissions $checkPermissions;

public function __construct()
{
$this->checkPermissions = GeneralUtility::makeInstance(CheckPermissions::class);;
}

public function buildIconForResource(
ResourceInterface $resource,
$size,
string $size,
array $options,
$iconIdentifier,
$overlayIdentifier
) {
if (!$resource->getStorage()->isPublic()) {
/** @var $checkPermissionsService CheckPermissions */
$checkPermissionsService = GeneralUtility::makeInstance(CheckPermissions::class);
string $iconIdentifier,
?string $overlayIdentifier
): array
{
$storage = $resource->getStorage();
if (!$storage->isPublic()) {

$currentPermissionsCheck = $storage->getEvaluatePermissions();
$storage->setEvaluatePermissions(false);

$currentPermissionsCheck = $resource->getStorage()->getEvaluatePermissions();
$resource->getStorage()->setEvaluatePermissions(false);
try {
$folder = $resource instanceof Folder ? $resource : $resource->getParentFolder();

$folder = $resource instanceof Folder ? $resource : $resource->getParentFolder();
if ($resource instanceof File && $resource->getProperty('fe_groups')) {
$overlayIdentifier = 'overlay-restricted';

if ($resource instanceof File && $resource->getProperty('fe_groups')) {
$overlayIdentifier = 'overlay-restricted';
// check if there are permissions set on this specific folder
} elseif ($folder === $resource && $this->checkPermissions->getFolderPermissions($folder) !== false) {
$overlayIdentifier = 'overlay-restricted';

// check if there are permissions set on this specific folder
} elseif ($folder === $resource && $checkPermissionsService->getFolderPermissions($folder) !== false) {
$overlayIdentifier = 'overlay-restricted';
// check if there are access restrictions in the root line of this folder
} elseif (!$this->checkPermissions->checkFolderRootLineAccess($folder, false)) {
$overlayIdentifier = 'overlay-inherited-permissions';
}

// check if there are access restrictions in the root line of this folder
} elseif (!$checkPermissionsService->checkFolderRootLineAccess($folder, false)) {
$overlayIdentifier = 'overlay-inherited-permissions';
} catch (FolderDoesNotExistException $e) {
// $resource->getParentFolder() may throw a FolderDoesNotExistException which currently is not documented in PHPDoc
}

$resource->getStorage()->setEvaluatePermissions($currentPermissionsCheck);
$storage->setEvaluatePermissions($currentPermissionsCheck);
}
return [$resource, $size, $options, $iconIdentifier, $overlayIdentifier];
}
Expand Down
59 changes: 28 additions & 31 deletions Classes/Aspects/PublicUrlAspect.php
@@ -1,7 +1,8 @@
<?php
namespace BeechIt\FalSecuredownload\Aspects;

/***************************************************************
declare(strict_types=1);

/*
* Copyright notice
*
* (c) 2014 Frans Saris <frans@beech.it>
Expand All @@ -22,67 +23,57 @@
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Resource\ResourceStorage;
*/

namespace BeechIt\FalSecuredownload\Aspects;

use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Resource\Driver\DriverInterface;
use TYPO3\CMS\Core\Resource\ResourceInterface;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Resource;
use TYPO3\CMS\Core\Resource\ResourceInterface;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class PublicUrlAspect
*/
class PublicUrlAspect implements SingletonInterface
{

/**
* Flag to en-/disable rendering of BE user link instead of FE link
*
* @var bool
*/
protected $enabled = true;
protected bool $enabled = true;

/**
* Get enabled
*
* @return bool
*/
public function getEnabled()
public function getEnabled(): bool
{
return $this->enabled;
}

/**
* Set enabled
*
* @param bool $enabled
*/
public function setEnabled($enabled)
public function setEnabled(bool $enabled): void
{
$this->enabled = $enabled;
}

/**
* Generate public url for file
*
* @param Resource\ResourceStorage $storage
* @param Resource\Driver\DriverInterface $driver
* @param Resource\ResourceInterface $resourceObject
* @param ResourceStorage $storage
* @param DriverInterface $driver
* @param ResourceInterface $resourceObject
* @param mixed $relativeToCurrentScript Deprecated. Will be removed in a future version
* @param array $urlData
* @throws RouteNotFoundException
*/
public function generatePublicUrl(
ResourceStorage $storage,
DriverInterface $driver,
ResourceInterface $resourceObject,
$relativeToCurrentScript,
array $urlData
) {
): void
{

// We only render special links for non-public files
if ($this->enabled && $resourceObject instanceof FileInterface && !$storage->isPublic()) {
Expand All @@ -99,8 +90,14 @@ public function generatePublicUrl(
'BeResourceStorageDumpFile'
);

// $urlData['publicUrl'] is passed by reference, so we can change that here and the value will be taken into account
/** @var UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);

/**
* $urlData['publicUrl'] is passed by reference, so we can change that here and the value will be taken into account
* @noinspection PhpArrayWriteIsNotUsedInspection
* @noinspection PhpArrayUsedOnlyForWriteInspection
*/
$urlData['publicUrl'] = (string)$uriBuilder->buildUriFromRoute(
'ajax_dump_file',
$queryParameterArray,
Expand Down
28 changes: 9 additions & 19 deletions Classes/Aspects/SolrFalAspect.php
@@ -1,39 +1,29 @@
<?php

namespace BeechIt\FalSecuredownload\Aspects;
declare(strict_types=1);

/**
/*
* This source file is proprietary property of Beech Applications B.V.
* Date: 12-03-2015 11:07
* All code (c) Beech Applications B.V. all rights reserved
*/

namespace BeechIt\FalSecuredownload\Aspects;

use ApacheSolrForTypo3\Solrfal\Queue\Item;
use ArrayObject;
use BeechIt\FalSecuredownload\Security\CheckPermissions;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class SolrFalAspect
*/
class SolrFalAspect implements SingletonInterface
{

/**
* @var CheckPermissions
*/
protected $checkPermissionsService;
protected CheckPermissions $checkPermissionsService;
protected PublicUrlAspect $publicUrlAspect;

/**
* @var PublicUrlAspect
*/
protected $publicUrlAspect;

/**
* Constructor
*/
public function __construct()
{
$this->checkPermissionsService = GeneralUtility::makeInstance(CheckPermissions::class);
Expand All @@ -44,9 +34,9 @@ public function __construct()
* Add correct fe_group info and public_url
*
* @param Item $item
* @param \ArrayObject $metadata
* @param ArrayObject $metadata
*/
public function fileMetaDataRetrieved(Item $item, \ArrayObject $metadata)
public function fileMetaDataRetrieved(Item $item, ArrayObject $metadata): void
{
if ($item->getFile() instanceof File && !$item->getFile()->getStorage()->isPublic()) {
$resourcePermissions = $this->checkPermissionsService->getPermissions($item->getFile());
Expand Down

0 comments on commit 2dc2d90

Please sign in to comment.