diff --git a/typo3/sysext/impexp/Classes/Command/ImportCommand.php b/typo3/sysext/impexp/Classes/Command/ImportCommand.php index 742f9b1e8da12351e71520ad387b29c1c7340f02..34910c893320b699d2b56bf48ab69e03173e9fbe 100644 --- a/typo3/sysext/impexp/Classes/Command/ImportCommand.php +++ b/typo3/sysext/impexp/Classes/Command/ImportCommand.php @@ -82,10 +82,10 @@ class ImportCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $fileName = $input->getArgument('file'); + $fileName = (string)$input->getArgument('file'); $fileName = GeneralUtility::getFileAbsFileName($fileName); - if (empty($fileName) || !file_exists($fileName)) { - throw new InvalidFileException('The given filename "' . ($fileName ?? $input->getArgument('file')) . '" could not be found', 1484483040); + if ($fileName === '' || !file_exists($fileName)) { + throw new InvalidFileException('The given filename "' . $fileName . '" could not be found', 1484483040); } $io = new SymfonyStyle($input, $output); diff --git a/typo3/sysext/impexp/Classes/Controller/ExportController.php b/typo3/sysext/impexp/Classes/Controller/ExportController.php index a210c8aecdabd948190471695099b3632da05dfa..7b5e2426c0f2d8f5345fdadc6947353b51ae5e10 100644 --- a/typo3/sysext/impexp/Classes/Controller/ExportController.php +++ b/typo3/sysext/impexp/Classes/Controller/ExportController.php @@ -144,7 +144,7 @@ class ExportController extends ImportExportController { // BUILDING EXPORT DATA: // Processing of InData array values: - $inData['filename'] = trim(preg_replace('/[^[:alnum:]._-]*/', '', preg_replace('/\\.(t3d|xml)$/', '', $inData['filename']))); + $inData['filename'] = trim((string)preg_replace('/[^[:alnum:]._-]*/', '', preg_replace('/\\.(t3d|xml)$/', '', $inData['filename']))); if ($inData['filename'] !== '') { $inData['filename'] .= $inData['filetype'] === 'xml' ? '.xml' : '.t3d'; } @@ -194,7 +194,7 @@ class ExportController extends ImportExportController if (is_array($inData['record'])) { foreach ($inData['record'] as $ref) { $rParts = explode(':', $ref); - $this->export->export_addRecord($rParts[0], BackendUtility::getRecord($rParts[0], $rParts[1])); + $this->export->export_addRecord($rParts[0], BackendUtility::getRecord($rParts[0], (int)$rParts[1])); } } // Configure which tables to export @@ -465,7 +465,7 @@ class ExportController extends ImportExportController $rParts = explode(':', $ref); [$tName, $rUid] = $rParts; $nameSuggestion .= $tName . '_' . $rUid; - $rec = BackendUtility::getRecordWSOL($tName, $rUid); + $rec = BackendUtility::getRecordWSOL((string)$tName, (int)$rUid); if (!empty($rec)) { $records[] = [ 'icon' => $this->iconFactory->getIconForRecord($tName, $rec, Icon::SIZE_SMALL)->render(), @@ -491,7 +491,7 @@ class ExportController extends ImportExportController if ($referenceParts[1] === '0') { $iconAndTitle = $this->iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render() . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; } else { - $record = BackendUtility::getRecordWSOL('pages', $referenceParts[1]); + $record = BackendUtility::getRecordWSOL('pages', (int)$referenceParts[1]); $iconAndTitle = $this->iconFactory->getIconForRecord('pages', $record, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $record, true); } diff --git a/typo3/sysext/impexp/Classes/Export.php b/typo3/sysext/impexp/Classes/Export.php index 15818e1eaed433b9a66656e2d9d6799b8171c339..841d6c07e2b5729114b9982be486af769dab3770 100644 --- a/typo3/sysext/impexp/Classes/Export.php +++ b/typo3/sysext/impexp/Classes/Export.php @@ -720,7 +720,7 @@ class Export extends ImportExport $fileMd5 = md5_file($fI['ID_absFile']); if (!$this->saveFilesOutsideExportFile) { // ... and finally add the heavy stuff: - $fileRec['content'] = file_get_contents($fI['ID_absFile']); + $fileRec['content'] = (string)file_get_contents($fI['ID_absFile']); } else { GeneralUtility::upload_copy_move($fI['ID_absFile'], $this->getTemporaryFilesPathForExport() . $fileMd5); } @@ -734,7 +734,7 @@ class Export extends ImportExport if ($this->includeExtFileResources && GeneralUtility::inList($this->extFileResourceExtensions, strtolower($html_fI['extension']))) { $uniquePrefix = '###' . md5($GLOBALS['EXEC_TIME']) . '###'; if (strtolower($html_fI['extension']) === 'css') { - $prefixedMedias = explode($uniquePrefix, preg_replace('/(url[[:space:]]*\\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\\))/i', '\\1' . $uniquePrefix . '\\2' . $uniquePrefix . '\\3', $fileRec['content'])); + $prefixedMedias = explode($uniquePrefix, (string)preg_replace('/(url[[:space:]]*\\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\\))/i', '\\1' . $uniquePrefix . '\\2' . $uniquePrefix . '\\3', $fileRec['content'])); } else { // html, htm: $htmlParser = GeneralUtility::makeInstance(HtmlParser::class); @@ -762,7 +762,7 @@ class Export extends ImportExport // Setting this data in the header $this->dat['header']['files'][$EXTres_ID] = $fileRec; // ... and finally add the heavy stuff: - $fileRec['content'] = file_get_contents($EXTres_absPath); + $fileRec['content'] = (string)file_get_contents($EXTres_absPath); $fileRec['content_md5'] = md5($fileRec['content']); $this->dat['files'][$EXTres_ID] = $fileRec; } @@ -1033,15 +1033,15 @@ class Export extends ImportExport /** * Returns a content part for a filename being build. * - * @param array $data Data to store in part + * @param string $data Data to store in part * @param bool $compress Compress file? * @return string Content stream. */ public function addFilePart($data, $compress = false) { if ($compress) { - $data = gzcompress($data); + $data = (string)gzcompress($data); } - return md5($data) . ':' . ($compress ? '1' : '0') . ':' . str_pad(strlen($data), 10, '0', STR_PAD_LEFT) . ':' . $data . ':'; + return md5($data) . ':' . ($compress ? '1' : '0') . ':' . str_pad((string)strlen($data), 10, '0', STR_PAD_LEFT) . ':' . $data . ':'; } } diff --git a/typo3/sysext/impexp/Classes/Import.php b/typo3/sysext/impexp/Classes/Import.php index cc3c47bf1dcc19bb4a8ef65541b593f9c43f9796..faa726f72c10694131b63d9584c1a20804a9b8f5 100644 --- a/typo3/sysext/impexp/Classes/Import.php +++ b/typo3/sysext/impexp/Classes/Import.php @@ -595,7 +595,7 @@ class Import extends ImportExport if (!empty($pageRecords)) { $remainingPageUids = array_keys($pageRecords); foreach ($remainingPageUids as $pUid) { - $this->addSingle('pages', $pUid, $pid); + $this->addSingle('pages', (int)$pUid, $pid); } } // Now write to database: @@ -696,6 +696,7 @@ class Import extends ImportExport $this->import_data = []; if (is_array($this->dat['header']['records'])) { foreach ($this->dat['header']['records'] as $table => $recs) { + $table = (string)$table; $this->addGeneralErrorsByTable($table); if ($table !== 'pages') { foreach ($recs as $uid => $thisRec) { @@ -1418,7 +1419,7 @@ class Import extends ImportExport if (GeneralUtility::isFirstPartOfStr($dirPrefix, $this->fileadminFolderName . '/')) { // File in fileadmin/ folder: // Create file (and possible resources) - $newFileName = $this->processSoftReferences_saveFile_createRelFile($dirPrefix, PathUtility::basename($relFileName), $cfg['file_ID'], $table, $uid); + $newFileName = $this->processSoftReferences_saveFile_createRelFile($dirPrefix, PathUtility::basename($relFileName), $cfg['file_ID'], $table, $uid) ?: ''; if (strlen($newFileName)) { $relFileName = $newFileName; } else { @@ -1452,7 +1453,7 @@ class Import extends ImportExport return PathUtility::stripPathSitePrefix($this->fileIDMap[$fileID]); } // Verify FileMount access to dir-prefix. Returns the best alternative relative path if any - $dirPrefix = $this->verifyFolderAccess($origDirPrefix); + $dirPrefix = (string)$this->verifyFolderAccess($origDirPrefix); if ($dirPrefix && (!$this->update || $origDirPrefix === $dirPrefix) && $this->checkOrCreateDir($dirPrefix)) { $fileHeaderInfo = $this->dat['header']['files'][$fileID]; $updMode = $this->update && $this->import_mapId[$table][$uid] === $uid && $this->import_mode[$table . ':' . $uid] !== 'as_new'; @@ -1465,7 +1466,7 @@ class Import extends ImportExport } else { // Create unique filename: $fileProcObj = $this->getFileProcObj(); - $newName = $fileProcObj->getUniqueName($fileName, Environment::getPublicPath() . '/' . $dirPrefix); + $newName = (string)$fileProcObj->getUniqueName($fileName, Environment::getPublicPath() . '/' . $dirPrefix); } if ($this->writeFileVerify($newName, $fileID)) { // If the resource was an HTML/CSS file with resources attached, we will write those as well! @@ -1500,7 +1501,7 @@ class Import extends ImportExport if (GeneralUtility::mkdir($resourceDir)) { foreach ($fileHeaderInfo['EXT_RES_ID'] as $res_fileID) { if ($this->dat['files'][$res_fileID]['filename']) { - $absResourceFileName = $fileProcObj->getUniqueName($this->dat['files'][$res_fileID]['filename'], $resourceDir); + $absResourceFileName = (string)$fileProcObj->getUniqueName($this->dat['files'][$res_fileID]['filename'], $resourceDir); $relResourceFileName = substr($absResourceFileName, strlen(PathUtility::dirname($resourceDir)) + 1); $this->writeFileVerify($absResourceFileName, $res_fileID); $tokenizedContent = str_replace('{EXT_RES_ID:' . $res_fileID . '}', $relResourceFileName, $tokenizedContent); @@ -1559,7 +1560,7 @@ class Import extends ImportExport } GeneralUtility::writeFile($fileName, $this->dat['files'][$fileID]['content']); $this->fileIDMap[$fileID] = $fileName; - if (hash_equals(md5(file_get_contents($fileName)), $this->dat['files'][$fileID]['content_md5'])) { + if (hash_equals(md5((string)file_get_contents($fileName)), $this->dat['files'][$fileID]['content_md5'])) { return true; } $this->error('ERROR: File content "' . $fileName . '" was corrupted'); @@ -1628,7 +1629,7 @@ class Import extends ImportExport } if (strtolower($fI['extension']) === 'xml') { // XML: - $xmlContent = file_get_contents($filename); + $xmlContent = (string)file_get_contents($filename); if (strlen($xmlContent)) { $this->dat = GeneralUtility::xml2array($xmlContent, '', true); if (is_array($this->dat)) { @@ -1646,18 +1647,17 @@ class Import extends ImportExport } else { // T3D if ($fd = fopen($filename, 'rb')) { - $this->dat['header'] = $this->getNextFilePart($fd, 1, 'header'); + $this->dat['header'] = $this->getNextFilePart($fd, true, 'header'); if ($all) { - $this->dat['records'] = $this->getNextFilePart($fd, 1, 'records'); - $this->dat['files'] = $this->getNextFilePart($fd, 1, 'files'); - $this->dat['files_fal'] = $this->getNextFilePart($fd, 1, 'files_fal'); + $this->dat['records'] = $this->getNextFilePart($fd, true, 'records'); + $this->dat['files'] = $this->getNextFilePart($fd, true, 'files'); + $this->dat['files_fal'] = $this->getNextFilePart($fd, true, 'files_fal'); } $this->loadInit(); + fclose($fd); return true; } $this->error('Error opening file: ' . $filename); - - fclose($fd); } return false; } @@ -1690,12 +1690,12 @@ class Import extends ImportExport $this->error('File read error: InitString had a wrong length. (' . $name . ')'); return null; } - $datString = fread($fd, (int)$initStrDat[2]); + $datString = (string)fread($fd, (int)$initStrDat[2]); fread($fd, 1); if (hash_equals($initStrDat[0], md5($datString))) { if ($initStrDat[1]) { if ($this->compress) { - $datString = gzuncompress($datString); + $datString = (string)gzuncompress($datString); } else { $this->error('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.'); return null; @@ -1717,9 +1717,9 @@ class Import extends ImportExport public function loadContent($filecontent) { $pointer = 0; - $this->dat['header'] = $this->getNextContentPart($filecontent, $pointer, 1, 'header'); - $this->dat['records'] = $this->getNextContentPart($filecontent, $pointer, 1, 'records'); - $this->dat['files'] = $this->getNextContentPart($filecontent, $pointer, 1, 'files'); + $this->dat['header'] = $this->getNextContentPart($filecontent, $pointer, true, 'header'); + $this->dat['records'] = $this->getNextContentPart($filecontent, $pointer, true, 'records'); + $this->dat['files'] = $this->getNextContentPart($filecontent, $pointer, true, 'files'); $this->loadInit(); } @@ -1743,12 +1743,12 @@ class Import extends ImportExport $this->error('Content read error: InitString had a wrong length. (' . $name . ')'); return null; } - $datString = substr($filecontent, $pointer, (int)$initStrDat[2]); + $datString = (string)substr($filecontent, $pointer, (int)$initStrDat[2]); $pointer += (int)$initStrDat[2] + 1; if (hash_equals($initStrDat[0], md5($datString))) { if ($initStrDat[1]) { if ($this->compress) { - $datString = gzuncompress($datString); + $datString = (string)gzuncompress($datString); return $unserialize ? unserialize($datString, ['allowed_classes' => false]) : $datString; } $this->error('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.'); diff --git a/typo3/sysext/impexp/Classes/ImportExport.php b/typo3/sysext/impexp/Classes/ImportExport.php index 3f02452e5211018f5180e63b07ddb6dee8f833a1..e83b462a0e0e787328950ecbaf553a8692eae77e 100644 --- a/typo3/sysext/impexp/Classes/ImportExport.php +++ b/typo3/sysext/impexp/Classes/ImportExport.php @@ -365,6 +365,7 @@ abstract class ImportExport // Subrecords: if (is_array($this->dat['header']['pid_lookup'][$k])) { foreach ($this->dat['header']['pid_lookup'][$k] as $t => $recUidArr) { + $t = (string)$t; if ($t !== 'pages') { foreach ($recUidArr as $ruid => $value) { $this->singleRecordLines($t, $ruid, $lines, $preCode . ' '); @@ -429,19 +430,19 @@ abstract class ImportExport /** * Go through remaining pages (not in tree) * - * @param array $pT Page tree array with uid/subrow (from ->dat[header][pagetree] + * @param array<int, array> $pT Page tree array with uid/subrow (from ->dat[header][pagetree] * @param array $lines Output lines array (is passed by reference and modified) */ public function traversePageRecords($pT, &$lines) { foreach ($pT as $k => $rHeader) { - $this->singleRecordLines('pages', $k, $lines, '', 1); + $this->singleRecordLines('pages', (int)$k, $lines, '', true); // Subrecords: if (is_array($this->dat['header']['pid_lookup'][$k])) { foreach ($this->dat['header']['pid_lookup'][$k] as $t => $recUidArr) { if ($t !== 'pages') { foreach ($recUidArr as $ruid => $value) { - $this->singleRecordLines($t, $ruid, $lines, ' '); + $this->singleRecordLines((string)$t, (int)$ruid, $lines, ' '); } } } @@ -463,7 +464,7 @@ abstract class ImportExport if ($t !== 'pages') { $preCode = ''; foreach ($recUidArr as $ruid => $value) { - $this->singleRecordLines($t, $ruid, $lines, $preCode, 1); + $this->singleRecordLines((string)$t, (int)$ruid, $lines, $preCode, true); } } } @@ -1133,7 +1134,7 @@ abstract class ImportExport if (isset($importRecord[$fN])) { if (trim($databaseRecord[$fN]) !== trim($importRecord[$fN])) { // Create diff-result: - $output[$fN] = $diffUtility->makeDiffDisplay(BackendUtility::getProcessedValue($table, $fN, !$inverseDiff ? $importRecord[$fN] : $databaseRecord[$fN], 0, 1, 1), BackendUtility::getProcessedValue($table, $fN, !$inverseDiff ? $databaseRecord[$fN] : $importRecord[$fN], 0, 1, 1)); + $output[$fN] = $diffUtility->makeDiffDisplay(BackendUtility::getProcessedValue($table, $fN, !$inverseDiff ? $importRecord[$fN] : $databaseRecord[$fN], 0, true, true), BackendUtility::getProcessedValue($table, $fN, !$inverseDiff ? $databaseRecord[$fN] : $importRecord[$fN], 0, true, true)); } unset($importRecord[$fN]); } @@ -1151,7 +1152,7 @@ abstract class ImportExport foreach ($output as $fN => $state) { $tRows[] = ' <tr> - <td>' . htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fN]['label'])) . ' (' . htmlspecialchars($fN) . ')</td> + <td>' . htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fN]['label'])) . ' (' . htmlspecialchars((string)$fN) . ')</td> <td>' . $state . '</td> </tr> ';