Skip to content

Commit

Permalink
[TASK] Cleanup code imports for all workspaces classes
Browse files Browse the repository at this point in the history
The system extension workspaces was never touched in terms of
checking if actually methods are needed, and a lot of code still uses
FQDN instead of the "use" keyword for a PHP class.

Some unused dependencies (e.g. to Extbase's objectmanager) are
removed as well.

Resolves: #84136
Releases: master
Change-Id: Ifa71ce9dddb6d0e68e09ee969d217d1514105a1a
Reviewed-on: https://review.typo3.org/56006
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
  • Loading branch information
bmack authored and wouter90 committed Mar 5, 2018
1 parent f3d273d commit 590c3a4
Show file tree
Hide file tree
Showing 29 changed files with 275 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -78,8 +79,7 @@ public function getDropDown()
$backendUser = $this->getBackendUser();
$view = $this->getFluidTemplateObject('DropDown.html');
$activeWorkspace = (int)$backendUser->workspace;
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
foreach ($this->availableWorkspaces as $workspaceId => $label) {
$workspaceId = (int)$workspaceId;
$item = [
Expand Down
6 changes: 4 additions & 2 deletions typo3/sysext/workspaces/Classes/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Workspaces\Service\WorkspaceService;

/**
* Implements the AJAX functionality for the various asynchronous calls
Expand Down Expand Up @@ -65,15 +67,15 @@ public function switchWorkspaceAction(ServerRequestInterface $request): Response
}

$ajaxResponse = [
'title' => \TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($workspaceId),
'title' => WorkspaceService::getWorkspaceTitle($workspaceId),
'workspaceId' => $workspaceId,
'pageId' => ($finalPageUid && $originalPageId == $finalPageUid) ? null : $finalPageUid
];
return new JsonResponse($ajaxResponse);
}

/**
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
* @return BackendUserAuthentication
*/
protected function getBackendUser()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AjaxDispatcher
*/
public function dispatch(ServerRequestInterface $request): ResponseInterface
{
$callStack = \GuzzleHttp\json_decode($request->getBody()->getContents());
$callStack = json_decode($request->getBody()->getContents());
if (!is_array($callStack)) {
$callStack = [$callStack];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Workspaces\Service\StagesService;
use TYPO3\CMS\Workspaces\Service\WorkspaceService;
use TYPO3Fluid\Fluid\View\ViewInterface;

/**
* Implements the preview controller of the workspace module.
Expand Down Expand Up @@ -55,7 +56,7 @@ class PreviewController
protected $moduleTemplate;

/**
* @var \TYPO3Fluid\Fluid\View\ViewInterface
* @var ViewInterface
*/
protected $view;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord;
use TYPO3\CMS\Workspaces\Service\IntegrityService;
use TYPO3\CMS\Workspaces\Service\WorkspaceService;

/**
* Class AbstractHandler
*/
Expand Down Expand Up @@ -53,11 +59,11 @@ protected function getErrorResponse($errorLabel, $errorCode = 0, $successFlagVal
/**
* Gets an instance of the workspaces service.
*
* @return \TYPO3\CMS\Workspaces\Service\WorkspaceService
* @return WorkspaceService
*/
protected function getWorkspaceService()
{
return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
return GeneralUtility::makeInstance(WorkspaceService::class);
}

/**
Expand All @@ -70,7 +76,7 @@ protected function getWorkspaceService()
protected function validateLanguageParameter(\stdClass $parameters)
{
$language = null;
if (isset($parameters->language) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($parameters->language)) {
if (isset($parameters->language) && MathUtility::canBeInterpretedAsInteger($parameters->language)) {
$language = $parameters->language;
}
return $language;
Expand All @@ -90,13 +96,13 @@ protected function getAffectedElements(\stdClass $parameters)
$affectedElements = [];
if ($parameters->type === 'selection') {
foreach ((array)$parameters->selection as $element) {
$affectedElements[] = \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord::create($element->table, $element->liveId, $element->versionId);
$affectedElements[] = CombinedRecord::create($element->table, $element->liveId, $element->versionId);
}
} elseif ($parameters->type === 'all') {
$versions = $this->getWorkspaceService()->selectVersionsInWorkspace($this->getCurrentWorkspace(), 0, -99, -1, 0, 'tables_select', $this->validateLanguageParameter($parameters));
foreach ($versions as $table => $tableElements) {
foreach ($tableElements as $element) {
$affectedElement = \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord::create($table, $element['t3ver_oid'], $element['uid']);
$affectedElement = CombinedRecord::create($table, $element['t3ver_oid'], $element['uid']);
$affectedElement->getVersionRecord()->setRow($element);
$affectedElements[] = $affectedElement;
}
Expand All @@ -109,14 +115,13 @@ protected function getAffectedElements(\stdClass $parameters)
* Creates a new instance of the integrity service for the
* given set of affected elements.
*
* @param \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord[] $affectedElements
* @return \TYPO3\CMS\Workspaces\Service\IntegrityService
* @param CombinedRecord[] $affectedElements
* @return IntegrityService
* @see getAffectedElements
*/
protected function createIntegrityService(array $affectedElements)
{
/** @var $integrityService \TYPO3\CMS\Workspaces\Service\IntegrityService */
$integrityService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\IntegrityService::class);
$integrityService = GeneralUtility::makeInstance(IntegrityService::class);
$integrityService->setAffectedElements($affectedElements);
return $integrityService;
}
Expand Down
48 changes: 16 additions & 32 deletions typo3/sysext/workspaces/Classes/Controller/Remote/ActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Workspaces\Domain\Record\StageRecord;
use TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord;
Expand Down Expand Up @@ -216,7 +220,7 @@ public function loadColumnModel()
*/
public function saveLanguageSelection($language)
{
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($language) === false && $language !== 'all') {
if (MathUtility::canBeInterpretedAsInteger($language) === false && $language !== 'all') {
$language = 'all';
}
$GLOBALS['BE_USER']->uc['moduleData']['Workspaces'][$GLOBALS['BE_USER']->workspace]['language'] = $language;
Expand Down Expand Up @@ -362,7 +366,7 @@ public function getRecipientList(array $uidOfRecipients, $additionalRecipients,
}

if ($stageRecord->hasPreselection() && !$stageRecord->isPreselectionChangeable()) {
$preselectedBackendUsers = $this->getStageService()->getBackendUsers(
$preselectedBackendUsers = $this->stageService->getBackendUsers(
implode(',', $this->stageService->getPreselectedRecipients($stageRecord))
);

Expand Down Expand Up @@ -411,12 +415,9 @@ public function getRecipientList(array $uidOfRecipients, $additionalRecipients,
public function discardStagesFromPage($pageId)
{
$cmdMapArray = [];
/** @var $workspaceService WorkspaceService */
$workspaceService = GeneralUtility::makeInstance(WorkspaceService::class);
/** @var $stageService StagesService */
$stageService = GeneralUtility::makeInstance(StagesService::class);
$workspaceItemsArray = $workspaceService->selectVersionsInWorkspace(
$stageService->getWorkspaceId(),
$this->stageService->getWorkspaceId(),
$filter = 1,
$stage = -99,
$pageId,
Expand Down Expand Up @@ -453,7 +454,7 @@ public function sentCollectionToStage(\stdClass $parameters)
$cmdMapArray = [];
$comment = $parameters->comments;
$stageId = $parameters->stageId;
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($stageId) === false) {
if (MathUtility::canBeInterpretedAsInteger($stageId) === false) {
throw new \InvalidArgumentException('Missing "stageId" in $parameters array.', 1319488194);
}
if (!is_object($parameters->affects) || empty($parameters->affects)) {
Expand Down Expand Up @@ -500,8 +501,7 @@ protected function processTcaCmd(array $cmdMapArray)
return $result;
}

/** @var \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler */
$dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start([], $cmdMapArray);
$dataHandler->process_cmdmap();

Expand Down Expand Up @@ -694,7 +694,7 @@ protected function getRecipientsOfStage($stageRecord)
}

$result = [];
$allRecipients = $this->getStageService()->getResponsibleBeUser($stageRecord);
$allRecipients = $this->stageService->getResponsibleBeUser($stageRecord);
$preselectedRecipients = $this->stageService->getPreselectedRecipients($stageRecord);
$isPreselectionChangeable = $stageRecord->isPreselectionChangeable();

Expand Down Expand Up @@ -727,23 +727,10 @@ protected function getRecipientsOfStage($stageRecord)
*/
protected function getDefaultCommentOfStage($stage)
{
$result = $this->getStageService()->getPropertyOfCurrentWorkspaceStage($stage, 'default_mailcomment');
$result = $this->stageService->getPropertyOfCurrentWorkspaceStage($stage, 'default_mailcomment');
return $result;
}

/**
* Gets an instance of the Stage service.
*
* @return StagesService
*/
protected function getStageService()
{
if (!isset($this->stageService)) {
$this->stageService = GeneralUtility::makeInstance(StagesService::class);
}
return $this->stageService;
}

/**
* Send all available workspace records to the previous stage.
*
Expand All @@ -761,7 +748,7 @@ public function sendPageToPreviousStage($id)
$recursionLevel = 0,
$selectionType = 'tables_modify'
);
list($currentStage, $previousStage) = $this->getStageService()->getPreviousStageForElementCollection($workspaceItemsArray);
list($currentStage, $previousStage) = $this->stageService->getPreviousStageForElementCollection($workspaceItemsArray);
// get only the relevant items for processing
$workspaceItemsArray = $workspaceService->selectVersionsInWorkspace(
$this->stageService->getWorkspaceId(),
Expand Down Expand Up @@ -796,7 +783,7 @@ public function sendPageToNextStage($id)
$recursionLevel = 0,
$selectionType = 'tables_modify'
);
list($currentStage, $nextStage) = $this->getStageService()->getNextStageForElementCollection($workspaceItemsArray);
list($currentStage, $nextStage) = $this->stageService->getNextStageForElementCollection($workspaceItemsArray);
// get only the relevant items for processing
$workspaceItemsArray = $workspaceService->selectVersionsInWorkspace(
$this->stageService->getWorkspaceId(),
Expand All @@ -823,9 +810,7 @@ public function sendPageToNextStage($id)
*/
public function updateStageChangeButtons($id)
{
/** @var StagesService $stageService */
$stageService = GeneralUtility::makeInstance(StagesService::class);
/** @var WorkspaceService $workspaceService */
$workspaceService = GeneralUtility::makeInstance(WorkspaceService::class);
// fetch the next and previous stage
$workspaceItemsArray = $workspaceService->selectVersionsInWorkspace(
Expand All @@ -839,7 +824,6 @@ public function updateStageChangeButtons($id)
list(, $nextStage) = $stageService->getNextStageForElementCollection($workspaceItemsArray);
list(, $previousStage) = $stageService->getPreviousStageForElementCollection($workspaceItemsArray);

/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$extensionPath = ExtensionManagementUtility::extPath('workspaces');
$view->setPartialRootPaths(['default' => $extensionPath . 'Resources/Private/Partials']);
Expand All @@ -862,7 +846,7 @@ public function updateStageChangeButtons($id)
/**
* @param int $workspaceId
* @return int Id of the original workspace
* @throws \TYPO3\CMS\Core\Exception
* @throws Exception
*/
protected function setTemporaryWorkspace($workspaceId)
{
Expand All @@ -871,7 +855,7 @@ protected function setTemporaryWorkspace($workspaceId)

if ($currentWorkspace !== $workspaceId) {
if (!$this->getBackendUser()->setTemporaryWorkspace($workspaceId)) {
throw new \TYPO3\CMS\Core\Exception(
throw new Exception(
'Cannot set temporary workspace to "' . $workspaceId . '"',
1371484524
);
Expand All @@ -882,7 +866,7 @@ protected function setTemporaryWorkspace($workspaceId)
}

/**
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
* @return BackendUserAuthentication
*/
protected function getBackendUser()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Workspaces\Service\WorkspaceService;

/**
* Class MassActionHandler
* Class encapsulates all actions which are triggered for all elements within the current workspace.
Expand Down Expand Up @@ -41,15 +43,15 @@ public function getMassStageActions($parameter)
$currentWorkspace = $this->getCurrentWorkspace();
$massActionsEnabled = $GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.enableMassActions') !== '0';
// in case we're working within "All Workspaces" we can't provide Mass Actions
if ($currentWorkspace != \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES && $massActionsEnabled) {
if ($currentWorkspace != WorkspaceService::SELECT_ALL_WORKSPACES && $massActionsEnabled) {
$publishAccess = $GLOBALS['BE_USER']->workspacePublishAccess($currentWorkspace);
if ($publishAccess && !($GLOBALS['BE_USER']->workspaceRec['publish_access'] & 1)) {
$actions[] = ['action' => 'publish', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':label_doaction_publish')];
if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
$actions[] = ['action' => 'swap', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':label_doaction_swap')];
}
}
if ($currentWorkspace !== \TYPO3\CMS\Workspaces\Service\WorkspaceService::LIVE_WORKSPACE_ID) {
if ($currentWorkspace !== WorkspaceService::LIVE_WORKSPACE_ID) {
$actions[] = ['action' => 'discard', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':label_doaction_discard')];
}
}
Expand Down
10 changes: 0 additions & 10 deletions typo3/sysext/workspaces/Classes/Controller/Remote/RemoteServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use TYPO3\CMS\Core\Utility\DiffUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Workspaces\Service\GridDataService;
use TYPO3\CMS\Workspaces\Service\HistoryService;
Expand Down Expand Up @@ -119,7 +118,6 @@ public function getRowDetails($parameter)
$diffReturnArray = [];
$liveReturnArray = [];
$diffUtility = $this->getDifferenceHandler();
/** @var $parseObj RteHtmlParser */
$parseObj = GeneralUtility::makeInstance(RteHtmlParser::class);
$liveRecord = BackendUtility::getRecord($parameter->table, $parameter->t3ver_oid);
$versionRecord = BackendUtility::getRecord($parameter->table, $parameter->uid);
Expand Down Expand Up @@ -504,12 +502,4 @@ protected function getDifferenceHandler()
}
return $this->differenceHandler;
}

/**
* @return \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected function getObjectManager()
{
return GeneralUtility::makeInstance(ObjectManager::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function indexAction()
$backendUser = $this->getBackendUser();
$moduleTemplate = $this->view->getModuleTemplate();

/** @var WorkspaceService $wsService */
$wsService = GeneralUtility::makeInstance(WorkspaceService::class);
if (GeneralUtility::_GP('id')) {
$pageRecord = BackendUtility::getRecord('pages', GeneralUtility::_GP('id'));
Expand Down Expand Up @@ -324,7 +323,6 @@ protected function getModuleUri(int $workspaceId): string
$this->uriBuilder->reset()->uriFor('fullIndex');
$parameters = array_merge($parameters, $this->uriBuilder->getArguments());
}
/** @var UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
return (string)$uriBuilder->buildUriFromRoute('web_WorkspacesWorkspaces', $parameters);
}
Expand Down

0 comments on commit 590c3a4

Please sign in to comment.