Skip to content

Commit

Permalink
[TASK] PHP 8 compatibility 2/x
Browse files Browse the repository at this point in the history
Change-Id: I9b365a2adf98bfa52352a95b225f338e75f93871
Resolves: #93640
Releases: master
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68175
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Richard Haeser <richard@richardhaeser.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Richard Haeser <richard@richardhaeser.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
lolli42 authored and maddy2101 committed Mar 4, 2021
1 parent 3731c93 commit 873923f
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 100 deletions.
11 changes: 6 additions & 5 deletions typo3/sysext/backend/Classes/Utility/BackendUtility.php
Expand Up @@ -1415,14 +1415,15 @@ public static function getRecordTitle($table, $row, $prep = false, $forceResult
$recordTitle = $params['title'];
} else {
// No userFunc: Build label
$ctrlLabel = $GLOBALS['TCA'][$table]['ctrl']['label'] ?? '';
$recordTitle = self::getProcessedValue(
$table,
$GLOBALS['TCA'][$table]['ctrl']['label'],
$row[$GLOBALS['TCA'][$table]['ctrl']['label']],
$ctrlLabel,
$row[$ctrlLabel] ?? '',
0,
false,
false,
$row['uid'],
$row['uid'] ?? null,
$forceResult
) ?? '';
if (!empty($GLOBALS['TCA'][$table]['ctrl']['label_alt'])
Expand All @@ -1434,7 +1435,7 @@ public static function getRecordTitle($table, $row, $prep = false, $forceResult
$tA[] = $recordTitle;
}
foreach ($altFields as $fN) {
$recordTitle = trim(strip_tags($row[$fN]));
$recordTitle = trim(strip_tags($row[$fN] ?? ''));
if ((string)$recordTitle !== '') {
$recordTitle = self::getProcessedValue($table, $fN, $recordTitle, 0, false, false, $row['uid']);
if (!$GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) {
Expand All @@ -1443,7 +1444,7 @@ public static function getRecordTitle($table, $row, $prep = false, $forceResult
$tA[] = $recordTitle;
}
}
if ($GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) {
if ($GLOBALS['TCA'][$table]['ctrl']['label_alt_force'] ?? false) {
$recordTitle = implode(', ', $tA);
}
}
Expand Down
148 changes: 81 additions & 67 deletions typo3/sysext/core/Classes/DataHandling/DataHandler.php

Large diffs are not rendered by default.

Expand Up @@ -41,12 +41,12 @@ public function getProcessingItems($table, $pageId, $field, $row, $tcaConfig, $s
{
$pageId = $table === 'pages' ? $row['uid'] : $row['pid'];
$TSconfig = BackendUtility::getPagesTSconfig($pageId);
$fieldTSconfig = $TSconfig['TCEFORM.'][$table . '.'][$field . '.'];
$fieldTSconfig = $TSconfig['TCEFORM.'][$table . '.'][$field . '.'] ?? [];

$params = [];
$params['items'] = &$selectedItems;
$params['config'] = $tcaConfig;
$params['TSconfig'] = $fieldTSconfig['itemsProcFunc.'];
$params['TSconfig'] = $fieldTSconfig['itemsProcFunc.'] ?? null;
$params['table'] = $table;
$params['row'] = $row;
$params['field'] = $field;
Expand Down
4 changes: 3 additions & 1 deletion typo3/sysext/core/Classes/Database/RelationHandler.php
Expand Up @@ -16,6 +16,7 @@
namespace TYPO3\CMS\Core\Database;

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\Platform\PlatformInformation;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
Expand Down Expand Up @@ -201,8 +202,9 @@ class RelationHandler
*/
protected function getWorkspaceId(): int
{
$backendUser = $GLOBALS['BE_USER'] ?? null;
if (!isset($this->workspaceId)) {
$this->workspaceId = (int)$GLOBALS['BE_USER']->workspace;
$this->workspaceId = $backendUser instanceof BackendUserAuthentication ? (int)($backendUser->workspace) : 0;
}
return $this->workspaceId;
}
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/core/Classes/Utility/RootlineUtility.php
Expand Up @@ -492,7 +492,7 @@ protected function resolvePageId(int $pageId): int
}

$page = $this->resolvePageRecord($pageId);
if (!VersionState::cast($page['t3ver_state'])->equals(VersionState::MOVE_POINTER)) {
if (!isset($page['t3ver_state']) || !VersionState::cast($page['t3ver_state'])->equals(VersionState::MOVE_POINTER)) {
return $pageId;
}

Expand Down
Expand Up @@ -42,7 +42,11 @@ public function render($conf = [])
// If the currentRecord is set, we register, that this record has invoked this function.
// It should not be allowed to do this again then!!
if ($originalRec) {
++$frontendController->recordRegister[$originalRec];
if (isset($frontendController->recordRegister[$originalRec])) {
++$frontendController->recordRegister[$originalRec];
} else {
$frontendController->recordRegister[$originalRec] = 1;
}
}
$conf['table'] = trim((string)$this->cObj->stdWrapValue('table', $conf ?? []));
$conf['select.'] = !empty($conf['select.']) ? $conf['select.'] : [];
Expand Down Expand Up @@ -83,10 +87,11 @@ public function render($conf = [])
$_procObj = GeneralUtility::makeInstance($className);
$_procObj->modifyDBRow($row, $conf['table']);
}
if (!$frontendController->recordRegister[$conf['table'] . ':' . $row['uid']]) {
$registerField = $conf['table'] . ':' . $row['uid'];
if (!($frontendController->recordRegister[$registerField] ?? false)) {
$this->cObj->currentRecordNumber++;
$cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
$frontendController->currentRecord = $conf['table'] . ':' . $row['uid'];
$frontendController->currentRecord = $registerField;
$this->cObj->lastChanged($row['tstamp']);
$cObj->start($row, $conf['table'], $this->request);
$tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
Expand Down
Expand Up @@ -455,7 +455,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
public function __construct(TypoScriptFrontendController $typoScriptFrontendController = null, ContainerInterface $container = null)
{
$this->typoScriptFrontendController = $typoScriptFrontendController;
$this->contentObjectClassMap = $GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'];
$this->contentObjectClassMap = $GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'] ?? [];
$this->container = $container;
}

Expand Down Expand Up @@ -4504,13 +4504,13 @@ public function getGlobal($keyString, $source = null)
$keys = explode('|', $keyString);
$numberOfLevels = count($keys);
$rootKey = trim($keys[0]);
$value = isset($source) ? $source[$rootKey] : $GLOBALS[$rootKey];
$value = isset($source) ? ($source[$rootKey] ?? '') : ($GLOBALS[$rootKey] ?? '');
for ($i = 1; $i < $numberOfLevels && isset($value); $i++) {
$currentKey = trim($keys[$i]);
if (is_object($value)) {
$value = $value->{$currentKey};
} elseif (is_array($value)) {
$value = $value[$currentKey];
$value = $value[$currentKey] ?? '';
} else {
$value = '';
break;
Expand Down Expand Up @@ -5742,8 +5742,8 @@ public function getQuery($table, $conf, $returnQueryArray = false)
foreach ($properties as $property) {
$conf[$property] = trim(
isset($conf[$property . '.'])
? $this->stdWrap($conf[$property], $conf[$property . '.'])
: $conf[$property]
? $this->stdWrap($conf[$property] ?? '', $conf[$property . '.'] ?? [])
: ($conf[$property] ?? null)
);
if ($conf[$property] === '') {
unset($conf[$property]);
Expand Down Expand Up @@ -5804,7 +5804,7 @@ public function getQuery($table, $conf, $returnQueryArray = false)
$conf['pidInList'] = implode(',', $expandedPidList);
}
}
if ((string)$conf['pidInList'] === '') {
if ((string)($conf['pidInList'] ?? '') === '') {
$conf['pidInList'] = 'this';
}

Expand All @@ -5816,28 +5816,28 @@ public function getQuery($table, $conf, $returnQueryArray = false)
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('*')->from($table);

if ($queryParts['where']) {
if ($queryParts['where'] ?? false) {
$queryBuilder->where($queryParts['where']);
}

if ($queryParts['groupBy']) {
if ($queryParts['groupBy'] ?? false) {
$queryBuilder->groupBy(...$queryParts['groupBy']);
}

if (is_array($queryParts['orderBy'])) {
if (is_array($queryParts['orderBy'] ?? false)) {
foreach ($queryParts['orderBy'] as $orderBy) {
$queryBuilder->addOrderBy(...$orderBy);
}
}

// Fields:
if ($conf['selectFields']) {
if ($conf['selectFields'] ?? false) {
$queryBuilder->selectLiteral($this->sanitizeSelectPart($conf['selectFields'], $table));
}

// Setting LIMIT:
$error = false;
if ($conf['max'] || $conf['begin']) {
if (($conf['max'] ?? false) || ($conf['begin'] ?? false)) {
// Finding the total number of records, if used:
if (strpos(strtolower($conf['begin'] . $conf['max']), 'total') !== false) {
$countQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
Expand Down Expand Up @@ -5872,23 +5872,23 @@ public function getQuery($table, $conf, $returnQueryArray = false)

if (!$error) {
// Setting up tablejoins:
if ($conf['join']) {
if ($conf['join'] ?? false) {
$joinParts = QueryHelper::parseJoin($conf['join']);
$queryBuilder->join(
$table,
$joinParts['tableName'],
$joinParts['tableAlias'],
$joinParts['joinCondition']
);
} elseif ($conf['leftjoin']) {
} elseif ($conf['leftjoin'] ?? false) {
$joinParts = QueryHelper::parseJoin($conf['leftjoin']);
$queryBuilder->leftJoin(
$table,
$joinParts['tableName'],
$joinParts['tableAlias'],
$joinParts['joinCondition']
);
} elseif ($conf['rightjoin']) {
} elseif ($conf['rightjoin'] ?? false) {
$joinParts = QueryHelper::parseJoin($conf['rightjoin']);
$queryBuilder->rightJoin(
$table,
Expand Down Expand Up @@ -6029,7 +6029,7 @@ protected function getQueryConstraints(string $table, array $conf): array
&& !empty($GLOBALS['TCA'][$table]['ctrl']['versioningWS'])
);

if (trim($conf['uidInList'])) {
if (trim($conf['uidInList'] ?? '')) {
$listArr = GeneralUtility::intExplode(',', str_replace('this', (string)$tsfe->contentPid, $conf['uidInList']));

// If moved records shall be considered, select via t3ver_oid
Expand Down Expand Up @@ -6172,9 +6172,10 @@ protected function getLanguageRestriction(ExpressionBuilder $expressionBuilder,
$languageQuery = $expressionBuilder->in($languageField, [0, -1]);
// Use this option to include records that don't have a default language counterpart ("free mode")
// (originalpointerfield is 0 and the language field contains the requested language)
if (isset($conf['includeRecordsWithoutDefaultTranslation']) || $conf['includeRecordsWithoutDefaultTranslation.']) {
$includeRecordsWithoutDefaultTranslation = isset($conf['includeRecordsWithoutDefaultTranslation.']) ?
$this->stdWrap($conf['includeRecordsWithoutDefaultTranslation'], $conf['includeRecordsWithoutDefaultTranslation.']) : $conf['includeRecordsWithoutDefaultTranslation'];
if (isset($conf['includeRecordsWithoutDefaultTranslation']) || !empty($conf['includeRecordsWithoutDefaultTranslation.'])) {
$includeRecordsWithoutDefaultTranslation = isset($conf['includeRecordsWithoutDefaultTranslation.'])
? $this->stdWrap($conf['includeRecordsWithoutDefaultTranslation'], $conf['includeRecordsWithoutDefaultTranslation.'])
: $conf['includeRecordsWithoutDefaultTranslation'];
$includeRecordsWithoutDefaultTranslation = trim($includeRecordsWithoutDefaultTranslation) !== '';
} else {
// Option was not explicitly set, check what's in for the language overlay type.
Expand Down Expand Up @@ -6267,7 +6268,7 @@ public function checkPidArray($pageIds)
*/
public function getQueryMarkers($table, $conf)
{
if (!is_array($conf['markers.'])) {
if (!isset($conf['markers.']) || !is_array($conf['markers.'])) {
return [];
}
// Parse markers and prepare their values
Expand Down
Expand Up @@ -8063,6 +8063,96 @@ public function mailSpamProtectionWithTypeAscii(string $content, string $expecte
);
}

public function getGlobalDataProvider(): array
{
return [
'simple' => [
'foo',
'HTTP_SERVER_VARS | something',
[
'HTTP_SERVER_VARS' => [
'something' => 'foo',
]
],
null
],
'simple source fallback' => [
'foo',
'HTTP_SERVER_VARS | something',
null,
[
'HTTP_SERVER_VARS' => [
'something' => 'foo',
]
],
],
'globals ignored if source given' => [
'',
'HTTP_SERVER_VARS | something',
[
'HTTP_SERVER_VARS' => [
'something' => 'foo',
]
],
[
'HTTP_SERVER_VARS' => [
'something-else' => 'foo',
]
],
],
'sub array is returned as empty string' => [
'',
'HTTP_SERVER_VARS | something',
[
'HTTP_SERVER_VARS' => [
'something' => [ 'foo' ],
]
],
null
],
'does not exist' => [
'',
'HTTP_SERVER_VARS | something',
[
'HTTP_SERVER_VARS' => [
'something-else' => 'foo',
]
],
null
],
'does not exist in source' => [
'',
'HTTP_SERVER_VARS | something',
null,
[
'HTTP_SERVER_VARS' => [
'something-else' => 'foo',
]
]
],
];
}

/**
* @test
* @dataProvider getGlobalDataProvider
* @param mixed $expected
* @param string $key
* @param array $globals
* @param null $source
*/
public function getGlobalReturnsExpectedResult($expected, string $key, ?array $globals, ?array $source): void
{
if (isset($globals['HTTP_SERVER_VARS'])) {
// Note we can't simply $GLOBALS = $globals, since phpunit backupGlobals works on existing array keys.
$GLOBALS['HTTP_SERVER_VARS'] = $globals['HTTP_SERVER_VARS'];
}
self::assertSame(
$expected,
(new ContentObjectRenderer())->getGlobal($key, $source)
);
}

/***************************************************************************
* End: Mixed tests
***************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
Expand Up @@ -1488,7 +1488,7 @@ protected function getUniqueFields($table): array
$listArr = [];
foreach ($GLOBALS['TCA'][$table]['columns'] ?? [] as $field => $configArr) {
if ($configArr['config']['type'] === 'input') {
$evalCodesArray = GeneralUtility::trimExplode(',', $configArr['config']['eval'], true);
$evalCodesArray = GeneralUtility::trimExplode(',', $configArr['config']['eval'] ?? '', true);
if (in_array('uniqueInPid', $evalCodesArray) || in_array('unique', $evalCodesArray)) {
$listArr[] = $field;
}
Expand Down
Expand Up @@ -839,7 +839,7 @@ protected function isPageAccessibleForCurrentUser($table, array $record)
protected function isLanguageAccessibleForCurrentUser($table, array $record)
{
if (BackendUtility::isTableLocalizable($table)) {
$languageUid = $record[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
$languageUid = $record[$GLOBALS['TCA'][$table]['ctrl']['languageField']] ?? 0;
} else {
return true;
}
Expand Down

0 comments on commit 873923f

Please sign in to comment.