Skip to content

Commit

Permalink
[TASK] Use ServerRequestInterface in File/RenameFileController
Browse files Browse the repository at this point in the history
* deprecate public properties
* deprecate public (non-routed) methods

Change-Id: Ic0b65e5fbbcffae4aa1ae5625c8166222a0f3f4b
Resolves: #84332
Releases: master
Reviewed-on: https://review.typo3.org/56209
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
mbrodala authored and lolli42 committed Mar 16, 2018
1 parent 8515354 commit c91617a
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 32 deletions.
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\Controller\File;

/*
Expand All @@ -17,10 +18,14 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\DocumentTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -31,20 +36,32 @@
*/
class RenameFileController
{
use PublicPropertyDeprecationTrait;

/**
* @var array
*/
protected $deprecatedPublicProperties = [
'title' => 'Using $title of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
'target' => 'Using $target of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
'returnUrl' => 'Using $returnUrl of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
'content' => 'Using $content of class RenameFileController from outside is discouraged as this variable is only used for internal storage.',
];

/**
* Name of the filemount
*
* @var string
*/
public $title;
protected $title;

/**
* Target path
*
* @var string
* @internal
*/
public $target;
protected $target;

/**
* The file or folder object that should be renamed
Expand All @@ -58,15 +75,15 @@ class RenameFileController
*
* @var string
*/
public $returnUrl;
protected $returnUrl;

/**
* Accumulating content
*
* @var string
* @internal
*/
public $content;
protected $content;

/**
* ModuleTemplate object
Expand All @@ -81,20 +98,48 @@ class RenameFileController
public function __construct()
{
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$GLOBALS['SOBE'] = $this;
$this->init();

// @deprecated since v9, will be moved out of __construct() in v10
$this->init($GLOBALS['TYPO3_REQUEST']);
}

/**
* Processes the request, currently everything is handled and put together via "renderContent()"
*
* @return ResponseInterface the response with the content
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$this->renderContent();

return new HtmlResponse($this->moduleTemplate->renderContent());
}

/**
* Main function, rendering the content of the rename form
*
* @deprecated since v9, will be removed in v10
*/
public function main()
{
trigger_error('Method main() will be replaced by protected method renderContent() in v10. Do not call from other extension', E_USER_DEPRECATED);
$this->renderContent();
}

/**
* Initialize
*
* @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
* @param ServerRequestInterface $request
* @throws InsufficientFileAccessPermissionsException
*/
protected function init()
protected function init(ServerRequestInterface $request): void
{
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();

// Initialize GPvars:
$this->target = GeneralUtility::_GP('target');
$this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
$this->target = $parsedBody['target'] ?? $queryParams['target'] ?? null;
$this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
// Cleaning and checking target
if ($this->target) {
$this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
Expand All @@ -105,7 +150,7 @@ protected function init()
throw new \RuntimeException($title . ': ' . $message, 1294586844);
}
if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889840);
throw new InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889840);
}

// If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
Expand Down Expand Up @@ -142,9 +187,9 @@ protected function init()
}

/**
* Main function, rendering the content of the rename form
* Render module content
*/
public function main()
protected function renderContent(): void
{
$assigns = [];
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
Expand Down Expand Up @@ -217,32 +262,17 @@ public function main()
}

/**
* Processes the request, currently everything is handled and put together via "main()"
*
* @return ResponseInterface the response with the content
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$this->main();
return new HtmlResponse($this->moduleTemplate->renderContent());
}

/**
* Returns LanguageService
*
* @return \TYPO3\CMS\Core\Localization\LanguageService
* @return LanguageService
*/
protected function getLanguageService()
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

/**
* Returns an instance of DocumentTemplate
*
* @return \TYPO3\CMS\Backend\Template\DocumentTemplate
* @return DocumentTemplate
*/
protected function getDocumentTemplate()
protected function getDocumentTemplate(): DocumentTemplate
{
return $GLOBALS['TBE_TEMPLATE'];
}
Expand Down
@@ -0,0 +1,53 @@
.. include:: ../../Includes.txt

==============================================================================
Deprecation: #84332 - Protected methods and properties in RenameFileController
==============================================================================

See :issue:`84332`

Description
===========

This file is about third party usage of :php:`TYPO3\CMS\Backend\Controller\File\RenameFileController`.

A series of class properties has been set to protected.
They will throw deprecation warnings if called public from outside:

* :php:`title`
* :php:`target`
* :php:`returnUrl`
* [not scanned] :php:`content`

All methods not used as entry points by :php:`TYPO3\CMS\Backend\Http\RouteDispatcher` will be
removed or set to protected in v10 and throw deprecation warnings if used from a third party:

* [not scanned] :php:`main()`

Additionally :php:`$GLOBALS['SOBE']` is not set by the :php:`RenameFileController` constructor anymore.


Impact
======

Calling one of the above methods or accessing one of the above properties on an instance of
:php:`RenameFileController` will throw a deprecation warning in v9 and a PHP fatal in v10.


Affected Installations
======================

The extension scanner will find most usages, but may also find some false positives. The most
common property and method names like :php:`$content` are not registered and will not be found
if an extension uses that on an instance of :php:`RenameFileController`.

In general all extensions that set properties or call methods except :php:`mainAction()` are affected.


Migration
=========

In general, extensions should not instantiate and re-use controllers of the core. Existing
usages should be rewritten to be free of calls like these.

.. index:: Backend, PHP-API, PartiallyScanned
Expand Up @@ -397,4 +397,19 @@
'Deprecation-84321-ProtectedMethodsAndPropertiesInAddController.rst',
],
],
'TYPO3\CMS\Backend\Controller\File\RenameFileController->title' => [
'restFiles' => [
'Deprecation-84332-ProtectedMethodsAndPropertiesInRenameFileController.rst',
],
],
'TYPO3\CMS\Backend\Controller\File\RenameFileController->target' => [
'restFiles' => [
'Deprecation-84332-ProtectedMethodsAndPropertiesInRenameFileController.rst',
],
],
'TYPO3\CMS\Backend\Controller\File\RenameFileController->returnUrl' => [
'restFiles' => [
'Deprecation-84332-ProtectedMethodsAndPropertiesInRenameFileController.rst',
],
],
];

0 comments on commit c91617a

Please sign in to comment.