Skip to content

Commit

Permalink
[TASK] Add PHP types to EXT:workspaces
Browse files Browse the repository at this point in the history
This change is a prerequisite for splitting
some parts within EXT:workspaces into separate
parts for further refactoring.

Resolves: #102393
Releases: main
Change-Id: I6979484148818a46ed7f78ec7010f78321253140
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81745
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
  • Loading branch information
bmack authored and maddy2101 committed Nov 18, 2023
1 parent 1b08933 commit c33dab5
Show file tree
Hide file tree
Showing 27 changed files with 419 additions and 1,165 deletions.
5 changes: 0 additions & 5 deletions Build/phpstan/phpstan-baseline.neon
Expand Up @@ -2634,8 +2634,3 @@ parameters:
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: ../../typo3/sysext/webhooks/Tests/Functional/WebhookExecutionTest.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
path: ../../typo3/sysext/workspaces/Classes/Service/GridDataService.php
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/Utility/BackendUtility.php
Expand Up @@ -821,7 +821,7 @@ protected static function getRecordsSortedByTitle(array $fields, $table, $titleF

while ($record = $res->fetchAssociative()) {
// store the uid, because it might be unset if it's not among the requested $fields
$recordId = $record['uid'];
$recordId = (int)$record['uid'];
$record[$titleField] = self::getRecordTitle($table, $record);

// include only the requested fields in the result
Expand Down
Expand Up @@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);

// Get CMD array
$cmd = $this->workspaceService->getCmdArrayForPublishWS($workspaceRecord['uid']);
$cmd = $this->workspaceService->getCmdArrayForPublishWS((int)$workspaceRecord['uid']);
$tce = GeneralUtility::makeInstance(DataHandler::class);
$tce->start([], $cmd);
$tce->process_cmdmap();
Expand Down
Expand Up @@ -33,10 +33,7 @@
*/
class AjaxDispatcher
{
/**
* @var array
*/
protected $classMap = [
protected array $classMap = [
'RemoteServer' => RemoteServer::class,
'MassActions' => MassActionHandler::class,
'Actions' => ActionHandler::class,
Expand Down
Expand Up @@ -208,6 +208,7 @@ public function loadColumnModel()
*/
public function sendToNextStageWindow($uid, $table, $t3ver_oid)
{
$uid = (int)$uid;
$elementRecord = BackendUtility::getRecord($table, $uid);
if (is_array($elementRecord)) {
$workspaceRecord = WorkspaceRecord::get($elementRecord['t3ver_wsid']);
Expand Down Expand Up @@ -239,6 +240,7 @@ public function sendToNextStageWindow($uid, $table, $t3ver_oid)
*/
public function sendToPrevStageWindow($uid, $table)
{
$uid = (int)$uid;
$elementRecord = BackendUtility::getRecord($table, $uid);
if (is_array($elementRecord)) {
$workspaceRecord = WorkspaceRecord::get($elementRecord['t3ver_wsid']);
Expand Down Expand Up @@ -282,7 +284,7 @@ public function sendToSpecificStageWindow($nextStageId, array $elements)
foreach ($elements as $element) {
$this->stagesService->getRecordService()->add(
$element->table,
$element->uid
(int)$element->uid
);
}

Expand Down Expand Up @@ -616,7 +618,7 @@ public function sendToSpecificStageExecute(\stdClass $parameters)
protected function getSentToStageWindow($nextStage)
{
if (!$nextStage instanceof StageRecord) {
$nextStage = WorkspaceRecord::get($this->getCurrentWorkspace())->getStage($nextStage);
$nextStage = WorkspaceRecord::get($this->getCurrentWorkspace())->getStage((int)$nextStage);
}

$result = [];
Expand Down
Expand Up @@ -32,10 +32,7 @@ class MassActionHandler
{
public const MAX_RECORDS_TO_PROCESS = 30;

/**
* @var WorkspaceService
*/
protected $workspaceService;
protected WorkspaceService $workspaceService;

public function __construct()
{
Expand All @@ -44,10 +41,8 @@ public function __construct()

/**
* Publishes the current workspace.
*
* @return array
*/
public function publishWorkspace(\stdClass $parameters)
public function publishWorkspace(\stdClass $parameters): array
{
$result = [
'init' => false,
Expand All @@ -72,10 +67,8 @@ public function publishWorkspace(\stdClass $parameters)

/**
* Flushes the current workspace.
*
* @return array
*/
public function flushWorkspace(\stdClass $parameters)
public function flushWorkspace(\stdClass $parameters): array
{
$result = [
'init' => false,
Expand All @@ -99,15 +92,11 @@ public function flushWorkspace(\stdClass $parameters)

/**
* Initializes the command map to be used for publishing.
*
* @param int $workspace
* @param int $language
* @return int
*/
protected function initPublishData($workspace, $language = null)
protected function initPublishData(int $workspace, int $language = null): int
{
// workspace might be -98 a.k.a "All Workspaces but that's save here
$publishData = $this->workspaceService->getCmdArrayForPublishWS($workspace, false, 0, $language);
// workspace might be -98 a.k.a "All Workspaces" but that's safe here
$publishData = $this->workspaceService->getCmdArrayForPublishWS($workspace, false, $language);
$recordCount = 0;
foreach ($publishData as $table => $recs) {
$recordCount += count($recs);
Expand All @@ -122,15 +111,11 @@ protected function initPublishData($workspace, $language = null)

/**
* Initializes the command map to be used for flushing.
*
* @param int $workspace
* @param int $language
* @return int
*/
protected function initFlushData($workspace, $language = null)
protected function initFlushData(int $workspace, int $language = null): int
{
// workspace might be -98 a.k.a "All Workspaces but that's save here
$flushData = $this->workspaceService->getCmdArrayForFlushWS($workspace, true, 0, $language);
// workspace might be -98 a.k.a "All Workspaces" but that's safe here
$flushData = $this->workspaceService->getCmdArrayForFlushWS($workspace, $language);
$recordCount = 0;
foreach ($flushData as $table => $recs) {
$recordCount += count($recs);
Expand All @@ -145,10 +130,8 @@ protected function initFlushData($workspace, $language = null)

/**
* Processes the data.
*
* @return int
*/
protected function processData()
protected function processData(): int
{
$processData = $this->getBackendUser()->getSessionData('workspaceMassAction');
$recordsProcessed = $this->getBackendUser()->getSessionData('workspaceMassAction_processed');
Expand Down Expand Up @@ -195,10 +178,8 @@ protected function processData()
/**
* Validates whether the submitted language parameter can be
* interpreted as integer value.
*
* @return int|null
*/
protected function validateLanguageParameter(\stdClass $parameters)
protected function validateLanguageParameter(\stdClass $parameters): ?int
{
$language = null;
if (isset($parameters->language) && MathUtility::canBeInterpretedAsInteger($parameters->language)) {
Expand All @@ -209,8 +190,6 @@ protected function validateLanguageParameter(\stdClass $parameters)

/**
* Gets the current workspace ID.
*
* @return int The current workspace ID
*/
protected function getCurrentWorkspace(): int
{
Expand Down
31 changes: 12 additions & 19 deletions typo3/sysext/workspaces/Classes/Controller/Remote/RemoteServer.php
Expand Up @@ -99,11 +99,11 @@ public function getWorkspaceInfos($parameter, ServerRequestInterface $request)
}
$versions = $this->workspaceService->selectVersionsInWorkspace(
$this->getCurrentWorkspace(),
$parameter->stage,
(int)$parameter->stage,
$pageId,
$parameter->depth,
(int)$parameter->depth,
'tables_select',
$parameter->language
$parameter->language !== null ? (int)$parameter->language : null
);
$data = $this->gridDataService->generateGridListFromVersions($versions, $parameter, $this->getCurrentWorkspace(), $request);
return $data;
Expand Down Expand Up @@ -389,8 +389,8 @@ protected function getCommentsForRecord(array $historyEntries, array $additional
foreach ($historyEntries as $entry) {
$preparedEntry = [];
$beUserRecord = BackendUtility::getRecord('be_users', $entry['userid']);
$preparedEntry['stage_title'] = htmlspecialchars($this->stagesService->getStageTitle($entry['history_data']['next']));
$preparedEntry['previous_stage_title'] = htmlspecialchars($this->stagesService->getStageTitle($entry['history_data']['current']));
$preparedEntry['stage_title'] = htmlspecialchars($this->stagesService->getStageTitle((int)$entry['history_data']['next']));
$preparedEntry['previous_stage_title'] = htmlspecialchars($this->stagesService->getStageTitle((int)$entry['history_data']['current']));
$preparedEntry['user_uid'] = (int)$entry['userid'];
$preparedEntry['user_username'] = is_array($beUserRecord) ? htmlspecialchars($beUserRecord['username']) : '';
$preparedEntry['tstamp'] = htmlspecialchars(BackendUtility::datetime($entry['tstamp']));
Expand All @@ -404,7 +404,7 @@ protected function getCommentsForRecord(array $historyEntries, array $additional
$sysLogEntry = [];
$data = $this->unserializeLogData($sysLogRow['log_data'] ?? '');
$beUserRecord = BackendUtility::getRecord('be_users', $sysLogRow['userid']);
$sysLogEntry['stage_title'] = htmlspecialchars($this->stagesService->getStageTitle($data['stage']));
$sysLogEntry['stage_title'] = htmlspecialchars($this->stagesService->getStageTitle((int)$data['stage']));
$sysLogEntry['previous_stage_title'] = '';
$sysLogEntry['user_uid'] = (int)$sysLogRow['userid'];
$sysLogEntry['user_username'] = is_array($beUserRecord) ? htmlspecialchars($beUserRecord['username']) : '';
Expand Down Expand Up @@ -467,10 +467,9 @@ protected function getLanguageService(): LanguageService
* given set of affected elements.
*
* @param CombinedRecord[] $affectedElements
* @return IntegrityService
* @see getAffectedElements
*/
protected function createIntegrityService(array $affectedElements)
protected function createIntegrityService(array $affectedElements): IntegrityService
{
$integrityService = GeneralUtility::makeInstance(IntegrityService::class);
$integrityService->setAffectedElements($affectedElements);
Expand All @@ -482,15 +481,13 @@ protected function createIntegrityService(array $affectedElements)
* Affected elements have a dependency, e.g. translation overlay
* and the default origin record - thus, the default record would be
* affected if the translation overlay shall be published.
*
* @return array
*/
protected function getAffectedElements(\stdClass $parameters)
protected function getAffectedElements(\stdClass $parameters): array
{
$affectedElements = [];
if ($parameters->type === 'selection') {
foreach ((array)$parameters->selection as $element) {
$affectedElements[] = CombinedRecord::create($element->table, $element->liveId, $element->versionId);
$affectedElements[] = CombinedRecord::create($element->table, (int)$element->liveId, (int)$element->versionId);
}
} elseif ($parameters->type === 'all') {
$versions = $this->workspaceService->selectVersionsInWorkspace(
Expand All @@ -503,7 +500,7 @@ protected function getAffectedElements(\stdClass $parameters)
);
foreach ($versions as $table => $tableElements) {
foreach ($tableElements as $element) {
$affectedElement = CombinedRecord::create($table, $element['t3ver_oid'], $element['uid']);
$affectedElement = CombinedRecord::create($table, (int)$element['t3ver_oid'], (int)$element['uid']);
$affectedElement->getVersionRecord()->setRow($element);
$affectedElements[] = $affectedElement;
}
Expand All @@ -515,10 +512,8 @@ protected function getAffectedElements(\stdClass $parameters)
/**
* Validates whether the submitted language parameter can be
* interpreted as integer value.
*
* @return int|null
*/
protected function validateLanguageParameter(\stdClass $parameters)
protected function validateLanguageParameter(\stdClass $parameters): ?int
{
$language = null;
if (isset($parameters->language) && MathUtility::canBeInterpretedAsInteger($parameters->language)) {
Expand All @@ -529,10 +524,8 @@ protected function validateLanguageParameter(\stdClass $parameters)

/**
* Gets the current workspace ID.
*
* @return int The current workspace ID
*/
protected function getCurrentWorkspace()
protected function getCurrentWorkspace(): int
{
return $this->workspaceService->getCurrentWorkspace();
}
Expand Down

0 comments on commit c33dab5

Please sign in to comment.