Commit bb9b14e8 authored by Jochen Roth's avatar Jochen Roth Committed by Benni Mack
Browse files

[BUGFIX] Fix undefined array key warnings for PHP8

Added fallback for undefined array keys
in backend, core, recycler, impexp, scheduler and
linkvalidator

Resolves: #94542
Releases: master
Change-Id: Ieeda20879f1906c9e9a743e0377767cfce8dec09
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69813


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 49b5a49a
......@@ -258,10 +258,10 @@ class ElementHistoryController
$singleLine = [];
$elParts = explode(':', $key);
// Turn around diff because it should be a "rollback preview"
if ((int)$diff['insertsDeletes'][$key] === 1) {
if ((int)($diff['insertsDeletes'][$key] ?? 0) === 1) {
// insert
$singleLine['insertDelete'] = 'delete';
} elseif ((int)$diff['insertsDeletes'][$key] === -1) {
} elseif ((int)($diff['insertsDeletes'][$key] ?? 0) === -1) {
$singleLine['insertDelete'] = 'insert';
}
// Build up temporary diff array
......
......@@ -212,7 +212,7 @@ class BackendLayoutWizardElement extends AbstractFormElement
$columns = $row['columns.'];
for ($j = 1; $j <= $colCount; $j++) {
$cellData = [];
if (!$spannedMatrix[$i][$j]) {
if (!($spannedMatrix[$i][$j] ?? false)) {
if (is_array($columns) && !empty($columns)) {
$column = array_shift($columns);
if (isset($column['colspan'])) {
......
......@@ -2875,7 +2875,15 @@ class DataHandler implements LoggerAwareInterface
foreach ($dataValues[$key] as $vKey => $data) {
if ($callBackFunc) {
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);
$res = $this->callBackObj->{$callBackFunc}(
$pParams,
$fieldConfiguration,
$dataValues[$key][$vKey] ?? null,
$dataValues_current[$key][$vKey] ?? null,
$uploadedFiles[$key][$vKey] ?? null,
$structurePath . $key . '/' . $vKey . '/',
$workspaceOptions
);
} else {
$res = $this->{$callBackFunc}(
$pParams,
......@@ -4822,7 +4830,7 @@ class DataHandler implements LoggerAwareInterface
$recordWorkspaceId = 0;
if (BackendUtility::isTableWorkspaceEnabled($table)) {
$recordToDelete = BackendUtility::getRecord($table, $uid);
$recordWorkspaceId = (int)$recordToDelete['t3ver_wsid'];
$recordWorkspaceId = (int)($recordToDelete['t3ver_wsid'] ?? 0);
}
// Clear cache before deleting the record, else the correct page cannot be identified by clear_cache
......
......@@ -212,7 +212,7 @@ class IconFactory
unset($recordType[$key]);
}
}
$recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'];
$recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'] ?? '';
if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask'])
&& isset($row[$column]) && is_string($row[$column])
) {
......
......@@ -57,7 +57,7 @@ class UserFileInlineLabelService
try {
$metaDataRepository = GeneralUtility::makeInstance(MetaDataRepository::class);
$metaData = $metaDataRepository->findByFileUid($fileRecord['uid']);
$fullTitle = $metaData['title'];
$fullTitle = $metaData['title'] ?? '';
} catch (InvalidUidException $e) {
/**
* We just catch the exception here
......
......@@ -566,7 +566,7 @@ class ExtendedTemplateService extends TemplateService
foreach ($keyArr as $key => $value) {
$HTML = '';
$a++;
$deeper = is_array($arr[$key . '.']);
$deeper = is_array($arr[$key . '.'] ?? false);
$row = $arr[$key];
$LN = $a == $c ? 'blank' : 'line';
$BTM = $a == $c ? 'top' : '';
......@@ -630,7 +630,7 @@ class ExtendedTemplateService extends TemplateService
unset($this->clearList_setup_temp[$row['templateID']]);
unset($this->clearList_const_temp[$row['templateID']]);
$this->templateTitles[$row['templateID']] = $row['title'];
if ($row['templateID'] == $this->hierarchyInfo[$pointer - 1]['templateParent']) {
if ($row['templateID'] == ($this->hierarchyInfo[$pointer - 1]['templateParent'] ?? '')) {
$depthDataArr[$row['templateID'] . '.'] = $this->ext_process_hierarchyInfo([], $pointer);
}
}
......@@ -832,10 +832,10 @@ class ExtendedTemplateService extends TemplateService
foreach ($this->categories[$category] as $name => $type) {
$params = $theConstants[$name];
if (is_array($params)) {
if ($subcat != $params['subcat_name']) {
if ($subcat !== (string)($params['subcat_name'] ?? '')) {
$categoryLoop++;
$subcat = $params['subcat_name'];
$subcat_name = $params['subcat_name'] ? $this->constantParser->getSubCategories()[$params['subcat_name']][0] : 'Others';
$subcat = (string)($params['subcat_name'] ?? '');
$subcat_name = $subcat ? (string)($this->constantParser->getSubCategories()[$subcat][0] ?? '') : 'Others';
$groupedOutput[$categoryLoop] = [
'label' => $subcat_name,
'fields' => []
......
......@@ -46,6 +46,9 @@ class ElementsBasicInputEvalCest extends AbstractElementsBasicCest
$I->click($editRecordLinkCssPath);
$I->waitForElementNotVisible('#t3js-ui-block');
$I->waitForText('Edit Form', 3, 'h1');
// scroll up all the way to get a clean shot to the tab panel
$this->ensureTopOfFrameIsUsedAndClickTab($I, 'input', 'input_23');
}
/**
......
......@@ -26,7 +26,7 @@ use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;
*/
class InlineFalCest
{
protected static string $filenameSelector = '.tab-content .form-irre-header-cell .form-irre-header-body dd';
protected static string $filenameSelector = '.form-irre-header-body > span > dl.row:first-child > dd:last-child';
protected static string $saveButtonLink = '//*/button[@name="_savedok"][1]';
/**
......
......@@ -585,9 +585,9 @@ class Import extends ImportExport
if (is_array($this->dat['header']['pagetree'])) {
$pagesFromTree = $this->flatInversePageTree($this->dat['header']['pagetree']);
foreach ($pagesFromTree as $uid) {
$thisRec = $this->dat['header']['records']['pages'][$uid];
$thisRec = $this->dat['header']['records']['pages'][$uid] ?? 0;
// PID: Set the main $pid, unless a NEW-id is found
$setPid = $this->import_newId_pids[$thisRec['pid']] ?? $pid;
$setPid = $this->import_newId_pids[$thisRec['pid'] ?? null] ?? $pid;
$this->addSingle('pages', $uid, $setPid);
unset($pageRecords[$uid]);
}
......@@ -808,10 +808,10 @@ class Import extends ImportExport
*/
public function addSingle($table, $uid, $pid)
{
if ($this->import_mode[$table . ':' . $uid] === 'exclude') {
if (($this->import_mode[$table . ':' . $uid] ?? '') === 'exclude') {
return;
}
$record = $this->dat['records'][$table . ':' . $uid]['data'];
$record = $this->dat['records'][$table . ':' . $uid]['data'] ?? null;
if (is_array($record)) {
if ($this->update && $this->doesRecordExist($table, $uid) && $this->import_mode[$table . ':' . $uid] !== 'as_new') {
$ID = $uid;
......@@ -873,14 +873,14 @@ class Import extends ImportExport
} else {
// Inserts:
$this->import_data[$table][$ID]['pid'] = $pid;
if (($this->import_mode[$table . ':' . $uid] === 'force_uid' && $this->update || $this->force_all_UIDS) && $this->getBackendUser()->isAdmin()) {
if ((($this->import_mode[$table . ':' . $uid] ?? '') === 'force_uid' && $this->update || $this->force_all_UIDS) && $this->getBackendUser()->isAdmin()) {
$this->import_data[$table][$ID]['uid'] = $uid;
$this->suggestedInsertUids[$table . ':' . $uid] = 'DELETE';
}
}
// Setting db/file blank:
foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
switch ((string)$config['type']) {
switch ((string)($config['type'] ?? '')) {
case 'db':
case 'file':
......@@ -995,7 +995,7 @@ class Import extends ImportExport
if ($table === 'sys_file_reference' && $field === 'uid_local') {
continue;
}
switch ((string)$config['type']) {
switch ((string)($config['type'] ?? '')) {
case 'db':
if (is_array($config['itemArray']) && !empty($config['itemArray'])) {
$itemConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
......@@ -1137,7 +1137,7 @@ class Import extends ImportExport
$thisNewUid = BackendUtility::wsMapId($table, $this->import_mapId[$table][$uid]);
// Traverse relation fields of each record
foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
switch ((string)$config['type']) {
switch ((string)($config['type'] ?? '')) {
case 'flex':
// Get XML content and set as default value (string, non-processed):
$updateData[$table][$thisNewUid][$field] = $this->dat['records'][$table . ':' . $uid]['data'][$field];
......@@ -1210,14 +1210,14 @@ class Import extends ImportExport
// Extract parameters:
[, , , $config] = $pParams;
// In case the $path is used as index without a trailing slash we will remove that
if (!is_array($config['flexFormRels']['db'][$path]) && is_array($config['flexFormRels']['db'][rtrim($path, '/')])) {
if (!is_array($config['flexFormRels']['db'][$path] ?? false) && is_array($config['flexFormRels']['db'][rtrim($path, '/')] ?? false)) {
$path = rtrim($path, '/');
}
if (is_array($config['flexFormRels']['db'][$path])) {
if (is_array($config['flexFormRels']['db'][$path] ?? false)) {
$valArray = $this->setRelations_db($config['flexFormRels']['db'][$path], $dsConf);
$dataValue = implode(',', $valArray);
}
if (is_array($config['flexFormRels']['file'][$path])) {
if (is_array($config['flexFormRels']['file'][$path] ?? false)) {
$valArr = [];
foreach ($config['flexFormRels']['file'][$path] as $fI) {
$valArr[] = $this->import_addFileNameToBeCopied($fI);
......@@ -1365,7 +1365,7 @@ class Import extends ImportExport
// Default is current token value:
$insertValue = $cfg['subst']['tokenValue'];
// Based on mode:
switch ((string)$this->softrefCfg[$tokenID]['mode']) {
switch ((string)($this->softrefCfg[$tokenID]['mode'] ?? '')) {
case 'exclude':
// Exclude is a simple passthrough of the value
break;
......@@ -1383,7 +1383,7 @@ class Import extends ImportExport
case 'db':
default:
// Trying to map database element if found in the mapID array:
[$tempTable, $tempUid] = explode(':', $cfg['subst']['recordRef']);
[$tempTable, $tempUid] = explode(':', ($cfg['subst']['recordRef'] ?? ''));
if (isset($this->import_mapId[$tempTable][$tempUid])) {
$insertValue = BackendUtility::wsMapId($tempTable, $this->import_mapId[$tempTable][$tempUid]);
if (strpos($cfg['subst']['tokenValue'], ':') !== false) {
......
......@@ -981,7 +981,7 @@ abstract class ImportExport
$idH = array_reverse($idH);
foreach ($idH as $k => $v) {
$a[$v['uid']] = $v['uid'];
if (is_array($v['subrow'])) {
if (is_array($v['subrow'] ?? false)) {
$a = $this->flatInversePageTree($v['subrow'], $a);
}
}
......
......@@ -190,7 +190,7 @@ class LinkAnalyzer
protected function checkLinks(array $links, array $linkTypes)
{
foreach ($this->hookObjectsArr as $key => $hookObj) {
if (!is_array($links[$key]) || (!in_array($key, $linkTypes, true))) {
if (!is_array($links[$key] ?? false) || (!in_array($key, $linkTypes, true))) {
continue;
}
......@@ -203,7 +203,7 @@ class LinkAnalyzer
$record['record_uid'] = $entryValue['uid'];
$record['table_name'] = $table;
$record['link_type'] = $key;
$record['link_title'] = $entryValue['link_title'];
$record['link_title'] = $entryValue['link_title'] ?? '';
$record['field'] = $entryValue['field'];
$record['last_check'] = time();
$typeField = $GLOBALS['TCA'][$table]['ctrl']['type'] ?? false;
......@@ -223,6 +223,15 @@ class LinkAnalyzer
$url = $entryValue['substr']['tokenValue'];
}
$record['url'] = $url;
if (!($this->linkCounts[$table] ?? false)) {
$this->linkCounts[$table] = 0;
}
if (!($this->brokenLinkCounts[$table] ?? false)) {
$this->brokenLinkCounts[$table] = 0;
}
$this->linkCounts[$table]++;
$checkUrl = $hookObj->checkLink($url, $entryValue, $this);
......@@ -323,7 +332,7 @@ class LinkAnalyzer
$valueField = $record[$field];
// Check if a TCA configured field has soft references defined (see TYPO3 Core API document)
if (!$conf['softref'] || (string)$valueField === '') {
if (!($conf['softref'] ?? false) || (string)$valueField === '') {
continue;
}
......@@ -426,12 +435,12 @@ class LinkAnalyzer
}
// Type of referenced record
if (strpos($r['recordRef'], 'pages') !== false) {
if (strpos($r['recordRef'] ?? '', 'pages') !== false) {
$currentR = $r;
// Contains number of the page
$referencedRecordType = $r['tokenValue'];
$wasPage = true;
} elseif (strpos($r['recordRef'], 'tt_content') !== false && (isset($wasPage) && $wasPage === true)) {
} elseif (strpos($r['recordRef'] ?? '', 'tt_content') !== false && (isset($wasPage) && $wasPage === true)) {
$referencedRecordType = $referencedRecordType . '#c' . $r['tokenValue'];
$wasPage = false;
} else {
......
......@@ -41,7 +41,7 @@ class PagesRepository
*/
public function doesRootLineContainHiddenPages(array $pageInfo): bool
{
$pid = (int)($pageInfo['pid']);
$pid = (int)($pageInfo['pid'] ?? 0);
if ($pid === 0) {
return false;
}
......
......@@ -521,7 +521,7 @@ class ValidatorTask extends AbstractTask
protected function setCliArguments(): self
{
$_SERVER['argv'] = [
$_SERVER['argv'][0],
($_SERVER['argv'][0] ?? null),
'tx_link_scheduler_link',
'0',
'-ss',
......
......@@ -56,7 +56,7 @@ class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvid
if (empty($taskInfo['configuration'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['configuration'] = $taskInfo['linkvalidator']['configuration'];
$taskInfo['configuration'] = $taskInfo['linkvalidator']['configuration'] ?? '';
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['configuration'] = $task->getConfiguration();
} else {
......@@ -65,7 +65,7 @@ class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvid
}
if (empty($taskInfo['depth'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['depth'] = $taskInfo['linkvalidator']['depth'];
$taskInfo['depth'] = $taskInfo['linkvalidator']['depth'] ?? 0;
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['depth'] = $task->getDepth();
} else {
......@@ -74,7 +74,7 @@ class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvid
}
if (empty($taskInfo['page'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['page'] = $taskInfo['linkvalidator']['page'];
$taskInfo['page'] = $taskInfo['linkvalidator']['page'] ?? 0;
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['page'] = $task->getPage();
} else {
......@@ -83,7 +83,7 @@ class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvid
}
if (empty($taskInfo['languages'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['languages'] = $taskInfo['linkvalidator']['languages'];
$taskInfo['languages'] = $taskInfo['linkvalidator']['languages'] ?? '';
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['languages'] = $task->getLanguages();
} else {
......@@ -92,7 +92,7 @@ class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvid
}
if (empty($taskInfo['email'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['email'] = $taskInfo['linkvalidator']['email'];
$taskInfo['email'] = $taskInfo['linkvalidator']['email'] ?? '';
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['email'] = $task->getEmail();
} else {
......@@ -101,7 +101,7 @@ class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvid
}
if (empty($taskInfo['emailOnBrokenLinkOnly'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['emailOnBrokenLinkOnly'] = $taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] ?: 1;
$taskInfo['emailOnBrokenLinkOnly'] = ($taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] ?? false) ? (bool)$taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] : true;
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
} else {
......@@ -110,7 +110,7 @@ class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvid
}
if (empty($taskInfo['emailTemplateName'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
$taskInfo['emailTemplateName'] = $taskInfo['linkvalidator']['emailTemplateName'] ?: '';
$taskInfo['emailTemplateName'] = ($taskInfo['linkvalidator']['emailTemplateName'] ?? false) ? $taskInfo['linkvalidator']['emailTemplateName'] : '';
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
$taskInfo['emailTemplateName'] = $task->getEmailTemplateName();
} else {
......
......@@ -47,14 +47,14 @@ class CleanerFieldProvider extends AbstractAdditionalFieldProvider
$additionalFields = [];
$additionalFields['period'] = [
'code' => '<input type="text" class="form-control" name="tx_scheduler[RecyclerCleanerPeriod]" value="' . $taskInfo['RecyclerCleanerPeriod'] . '">',
'code' => '<input type="text" class="form-control" name="tx_scheduler[RecyclerCleanerPeriod]" value="' . ($taskInfo['RecyclerCleanerPeriod'] ?? 0) . '">',
'label' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskPeriod',
'cshKey' => '',
'cshLabel' => 'task_recyclerCleaner_selectedPeriod'
];
$additionalFields['tca'] = [
'code' => $this->getTcaSelectHtml($taskInfo['RecyclerCleanerTCA']),
'code' => $this->getTcaSelectHtml($taskInfo['RecyclerCleanerTCA'] ?? []),
'label' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskTCA',
'cshKey' => '',
'cshLabel' => 'task_recyclerCleaner_selectedTables'
......
......@@ -1358,7 +1358,7 @@ class SchedulerModuleController
}
// Delete
if ($this->getCurrentAction()->equals(Action::EDIT)) {
if (($queryParams['tx_scheduler']['uid'] ?? false) && $this->getCurrentAction()->equals(Action::EDIT)) {
$deleteButton = $buttonBar->makeLinkButton()
->setHref($this->moduleUri . '&CMD=' . Action::DELETE . '&tx_scheduler[uid]=' . $queryParams['tx_scheduler']['uid'])
->setClasses('t3js-modal-trigger')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment