Skip to content

Commit

Permalink
[TASK] Fix PHP 8 compatibility issues part 4/x
Browse files Browse the repository at this point in the history
Milestone: With a last series of type handling and
array access fixes throughout core and in
typo3/testing-framework, a first set of functional
pre-merge tests can be enabled with PHP 8.0.

composer req --dev typo3/testing-framework:^6.7.2

Resolves: #93686
Releases: master
Change-Id: I2d35725967be563fe9408083ee8aee59ea1533e3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68294
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Richard Haeser <richard@richardhaeser.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Richard Haeser <richard@richardhaeser.com>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
lolli42 authored and bmack committed Mar 9, 2021
1 parent 197fdcc commit 5bd1f6c
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 70 deletions.
6 changes: 3 additions & 3 deletions Build/gitlab-ci/pre-merge/functional.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
functional mariadb 10.3 php 7.4 pre-merge:
functional mariadb 10.3 php 8.0 pre-merge:
stage: main
except:
refs:
- schedules
- master
parallel: 10
script:
- Build/Scripts/runTests.sh -s composerInstall -p 7.4
- Build/Scripts/runTests.sh -s functional -d mariadb -i 10.3 -p 7.4 -c $CI_NODE_INDEX/$CI_NODE_TOTAL
- Build/Scripts/runTests.sh -s composerInstall -p 8.0
- Build/Scripts/runTests.sh -s functional -d mariadb -i 10.3 -p 8.0 -c $CI_NODE_INDEX/$CI_NODE_TOTAL

functional postgres 10 php 7.4 pre-merge:
stage: main
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"phpstan/phpstan": "^0.12.64",
"phpunit/phpunit": "^8.5.13",
"typo3/cms-styleguide": "~11.1.0",
"typo3/testing-framework": "^6.6.3"
"typo3/testing-framework": "^6.7.2"
},
"suggest": {
"ext-gd": "GDlib/Freetype is required for building images with text (GIFBUILDER) and can also be used to scale images",
Expand Down
18 changes: 7 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/Utility/BackendUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ public static function getRecordTitle($table, $row, $prep = false, $forceResult
$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']) {
if (!($GLOBALS['TCA'][$table]['ctrl']['label_alt_force'] ?? false)) {
break;
}
$tA[] = $recordTitle;
Expand Down
18 changes: 13 additions & 5 deletions typo3/sysext/core/Classes/DataHandling/DataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ public function setDefaultsFromUserTS($userTS)
continue;
}

if (is_array($this->defaultValues[$k])) {
if (is_array($this->defaultValues[$k] ?? false)) {
$this->defaultValues[$k] = array_merge($this->defaultValues[$k], $v);
} else {
$this->defaultValues[$k] = $v;
Expand Down Expand Up @@ -1259,7 +1259,7 @@ public function fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray,

// Get original language record if available:
if (is_array($currentRecord)
&& $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']
&& ($GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField'] ?? false)
&& !empty($GLOBALS['TCA'][$table]['ctrl']['languageField'])
&& $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0
&& $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
Expand Down Expand Up @@ -2833,7 +2833,7 @@ public function checkValue_flex_procInData_travDS(&$dataValues, $dataValues_curr
$dataValues[$key]['vDEF'] = $fieldConfiguration['default'];
}
}
if (!is_array($fieldConfiguration) || !is_array($dataValues[$key])) {
if (!is_array($fieldConfiguration) || !isset($dataValues[$key]) || !is_array($dataValues[$key])) {
continue;
}

Expand All @@ -2842,7 +2842,15 @@ public function checkValue_flex_procInData_travDS(&$dataValues, $dataValues_curr
if (is_object($this->callBackObj)) {
$res = $this->callBackObj->{$callBackFunc}($pParams, $fieldConfiguration, $dataValues[$key][$vKey], $dataValues_current[$key][$vKey], $uploadedFiles[$key][$vKey], $structurePath . $key . '/' . $vKey . '/', $workspaceOptions);
} else {
$res = $this->{$callBackFunc}($pParams, $fieldConfiguration, $dataValues[$key][$vKey], $dataValues_current[$key][$vKey], $uploadedFiles[$key][$vKey], $structurePath . $key . '/' . $vKey . '/', $workspaceOptions);
$res = $this->{$callBackFunc}(
$pParams,
$fieldConfiguration,
$dataValues[$key][$vKey] ?? null,
$dataValues_current[$key][$vKey] ?? null,
$uploadedFiles[$key][$vKey] ?? null,
$structurePath . $key . '/' . $vKey . '/',
$workspaceOptions
);
}
} else {
// Default
Expand Down Expand Up @@ -6090,7 +6098,7 @@ public function processRemapStack()
foreach ($valueArray as $key => $value) {
if (strpos($value, 'NEW') !== false) {
if (strpos($value, '_') === false) {
$affectedTable = $tcaFieldConf['foreign_table'];
$affectedTable = $tcaFieldConf['foreign_table'] ?? '';
$prependTable = false;
} else {
$parts = explode('_', $value);
Expand Down
42 changes: 16 additions & 26 deletions typo3/sysext/core/Classes/Database/QueryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,6 @@ class QueryGenerator
*/
protected $formName = '';

/**
* @var int
*/
protected $limitBegin;

/**
* @var int
*/
protected $limitLength;

/**
* @var string
*/
Expand All @@ -263,20 +253,20 @@ public function makeFieldList()
{
$fieldListArr = [];
if (is_array($GLOBALS['TCA'][$this->table])) {
$fieldListArr = array_keys($GLOBALS['TCA'][$this->table]['columns']);
$fieldListArr = array_keys($GLOBALS['TCA'][$this->table]['columns'] ?? []);
$fieldListArr[] = 'uid';
$fieldListArr[] = 'pid';
$fieldListArr[] = 'deleted';
if ($GLOBALS['TCA'][$this->table]['ctrl']['tstamp']) {
if ($GLOBALS['TCA'][$this->table]['ctrl']['tstamp'] ?? false) {
$fieldListArr[] = $GLOBALS['TCA'][$this->table]['ctrl']['tstamp'];
}
if ($GLOBALS['TCA'][$this->table]['ctrl']['crdate']) {
if ($GLOBALS['TCA'][$this->table]['ctrl']['crdate'] ?? false) {
$fieldListArr[] = $GLOBALS['TCA'][$this->table]['ctrl']['crdate'];
}
if ($GLOBALS['TCA'][$this->table]['ctrl']['cruser_id']) {
if ($GLOBALS['TCA'][$this->table]['ctrl']['cruser_id'] ?? false) {
$fieldListArr[] = $GLOBALS['TCA'][$this->table]['ctrl']['cruser_id'];
}
if ($GLOBALS['TCA'][$this->table]['ctrl']['sortby']) {
if ($GLOBALS['TCA'][$this->table]['ctrl']['sortby'] ?? false) {
$fieldListArr[] = $GLOBALS['TCA'][$this->table]['ctrl']['sortby'];
}
}
Expand Down Expand Up @@ -1455,11 +1445,11 @@ public function makeSelectorTable($modSettings, $enableList = 'table,fields,quer
$this->extFieldLists['queryLimit'] = 100;
}
$parts = GeneralUtility::intExplode(',', $this->extFieldLists['queryLimit']);
$limitBegin = 0;
$limitLength = (int)($this->extFieldLists['queryLimit'] ?? 0);
if ($parts[1]) {
$this->limitBegin = $parts[0];
$this->limitLength = $parts[1];
} else {
$this->limitLength = $this->extFieldLists['queryLimit'];
$limitBegin = (int)$parts[0];
$limitLength = (int)$parts[1];
}
$this->extFieldLists['queryLimit'] = implode(',', array_slice($parts, 0, 2));
// Insert Descending parts
Expand Down Expand Up @@ -1530,23 +1520,23 @@ public function makeSelectorTable($modSettings, $enableList = 'table,fields,quer
$limit[] = ' <input type="text" class="form-control" value="' . htmlspecialchars($this->extFieldLists['queryLimit']) . '" name="SET[queryLimit]" id="queryLimit">';
$limit[] = '</div>';

$prevLimit = $this->limitBegin - $this->limitLength < 0 ? 0 : $this->limitBegin - $this->limitLength;
$prevLimit = $limitBegin - $limitLength < 0 ? 0 : $limitBegin - $limitLength;
$prevButton = '';
$nextButton = '';

if ($this->limitBegin) {
$prevButton = '<input type="button" class="btn btn-default" value="previous ' . htmlspecialchars($this->limitLength) . '" data-value="' . htmlspecialchars($prevLimit . ',' . $this->limitLength) . '">';
if ($limitBegin) {
$prevButton = '<input type="button" class="btn btn-default" value="previous ' . htmlspecialchars($limitLength) . '" data-value="' . htmlspecialchars($prevLimit . ',' . $limitLength) . '">';
}
if (!$this->limitLength) {
$this->limitLength = 100;
if (!$limitLength) {
$limitLength = 100;
}

$nextLimit = $this->limitBegin + $this->limitLength;
$nextLimit = $limitBegin + $limitLength;
if ($nextLimit < 0) {
$nextLimit = 0;
}
if ($nextLimit) {
$nextButton = '<input type="button" class="btn btn-default" value="next ' . htmlspecialchars($this->limitLength) . '" data-value="' . htmlspecialchars($nextLimit . ',' . $this->limitLength) . '">';
$nextButton = '<input type="button" class="btn btn-default" value="next ' . htmlspecialchars($limitLength) . '" data-value="' . htmlspecialchars($nextLimit . ',' . $limitLength) . '">';
}

$out[] = '<div class="form-group">';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function processDatamap_afterDatabaseOperations($status, $table, $id, $fi
}

$backendUserGroup = BackendUtility::getRecord($table, $id, 'explicit_allowdeny');
$explicitAllowDenyFields = GeneralUtility::trimExplode(',', $backendUserGroup['explicit_allowdeny']);
$explicitAllowDenyFields = GeneralUtility::trimExplode(',', $backendUserGroup['explicit_allowdeny'] ?? '');
foreach ($explicitAllowDenyFields as $value) {
if ($value !== '' && strpos($value, 'tt_content:list_type:') === 0) {
if (!in_array('tt_content:CType:list:ALLOW', $explicitAllowDenyFields, true)) {
Expand Down
6 changes: 4 additions & 2 deletions typo3/sysext/core/Classes/Imaging/IconFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ public function mapRecordTypeToIconIdentifier($table, array $row)
}
}
$recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'];
if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask'])) {
if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask'])
&& isset($row[$column]) && is_string($row[$column])
) {
$recordType[5] = str_replace(
'###TYPE###',
$row[$column],
$row[$column] ?? '',
$GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask']
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ public function localizeElementOfRelation()
public function moveContentOfRelationToDifferentPage()
{
$newTableIds = $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
$this->recordIds['movedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
// In workspaces new records are created and discard drops this one again, live creates no new record
if (isset($newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast])) {
$this->recordIds['movedContentId'] = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ public function changeParentContentSorting()
public function moveParentContentToDifferentPage()
{
$newRecordIds = $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
$this->recordIds['newContentId'] = $newRecordIds[self::TABLE_Content][self::VALUE_ContentIdLast];
// In workspaces new records are created and discard drops this one again, live creates no new record
if (isset($newRecordIds[self::TABLE_Content][self::VALUE_ContentIdLast])) {
$this->recordIds['newContentId'] = $newRecordIds[self::TABLE_Content][self::VALUE_ContentIdLast];
}
}

public function moveParentContentToDifferentPageTwice()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ public function changeParentContentSorting()
public function moveParentContentToDifferentPage()
{
$newRecordIds = $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
$this->recordIds['newContentId'] = $newRecordIds[self::TABLE_Content][self::VALUE_ContentIdLast];
// In workspaces new records are created and discard drops this one again, live creates no new record
if (isset($newRecordIds[self::TABLE_Content][self::VALUE_ContentIdLast])) {
$this->recordIds['newContentId'] = $newRecordIds[self::TABLE_Content][self::VALUE_ContentIdLast];
}
}

public function moveParentContentToDifferentPageTwice()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,11 @@ public function getQueryWithIdOrDateDataProvider(): array
*/
public function getQueryWithIdOrDate($inputValue, $inputValue1, string $expected, int $comparison = 64)
{
$GLOBALS['TCA'] = [];
$GLOBALS['TCA']['aTable'] = [];
$GLOBALS['TCA'] = [
'aTable' => [
'columns' => [],
]
];
$queryGenerator = new QueryGenerator();

$inputConf = [
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"phpspec/prophecy": "^1.12.2",
"phpstan/phpstan": "^0.12.64",
"typo3/cms-styleguide": "~11.1.0",
"typo3/testing-framework": "^6.6.3"
"typo3/testing-framework": "^6.7.2"
},
"suggest": {
"ext-fileinfo": "Used for proper file type detection in the file abstraction layer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function executeUpdate(): bool
foreach ($listOfAllTables as $table) {
foreach ($rowUpdaterInstances as $updater) {
if ($updater->hasPotentialUpdateForTable($table)) {
if (!is_array($tableToUpdaterList[$table])) {
if (!isset($tableToUpdaterList[$table]) || !is_array($tableToUpdaterList[$table])) {
$tableToUpdaterList[$table] = [];
}
$tableToUpdaterList[$table][] = $updater;
Expand Down
6 changes: 4 additions & 2 deletions typo3/sysext/seo/Classes/XmlSitemap/XmlSitemapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ protected function renderIndex(ServerRequestInterface $request, string $sitemapT
{
$sitemaps = [];
foreach ($this->configuration['config'][$sitemapType]['sitemaps'] ?? [] as $sitemap => $config) {
if (class_exists($config['provider']) &&
is_subclass_of($config['provider'], XmlSitemapDataProviderInterface::class)) {
if (!empty($config['provider']) && is_string($config['provider'])
&& class_exists($config['provider'])
&& is_subclass_of($config['provider'], XmlSitemapDataProviderInterface::class)
) {
/** @var XmlSitemapDataProviderInterface $provider */
$provider = GeneralUtility::makeInstance(
$config['provider'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function setUp(): void

/**
* @test
* @dataProvider getXslFilePaths
* @dataProvider getXslFilePathsDataProvider
*/
public function checkIfDefaultSitemapReturnsDefaultXsl($typoscriptSetupFiles, $sitemap, $xslFilePath): void
{
Expand Down Expand Up @@ -73,7 +73,7 @@ public function checkIfDefaultSitemapReturnsDefaultXsl($typoscriptSetupFiles, $s
self::assertRegExp('/<\?xml-stylesheet type="text\/xsl" href="' . $xslFilePath . '"\?>/', (string)$response->getBody());
}

public function getXslFilePaths()
public function getXslFilePathsDataProvider(): array
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function createContentAndLocalize()
$this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
$localizedContentId = $this->actionService->localizeRecord(self::TABLE_Content, $this->recordIds['newContentId'], self::VALUE_LanguageId);
$this->recordIds['localizedContentId'] = $localizedContentId[self::TABLE_Content][$this->recordIds['newContentId']];
$this->recordIds['versionedCopiedContentId'] = $this->actionService->getDataHandler()->getAutoVersionId(self::TABLE_Content, $this->recordIds['copiedContentId']);
}

public function changeContentSortingAndDeleteMovedRecord()
Expand Down Expand Up @@ -206,8 +205,6 @@ public function createNestedPagesAndCopyLiveParentPage()

$newTableIds = $this->actionService->copyRecord(static::TABLE_Page, static::VALUE_PageId, static::VALUE_PageIdTarget);
$this->recordIds['copiedPageId'] = $newTableIds[static::TABLE_Page][static::VALUE_PageId];
$this->recordIds['copiedPageIdFirst'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdFirst']];
$this->recordIds['copiedPageIdSecond'] = $newTableIds[static::TABLE_Page][$this->recordIds['newPageIdSecond']];

// Switch back to draft workspace
$this->setWorkspaceId(self::VALUE_WorkspaceId);
Expand Down Expand Up @@ -245,8 +242,7 @@ public function deleteContentAndCopyLivePage()
*/
public function changeContentSortingAndCopyDraftPage()
{
$newTableIds = $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
$this->recordIds['newContentId'] = $newTableIds[self::TABLE_Content][0];
$this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdSecond);
$newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
$this->recordIds['copiedPageId'] = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
}
Expand Down
Loading

0 comments on commit 5bd1f6c

Please sign in to comment.