Skip to content

Commit 987057f

Browse files
o-balolli42
authored andcommitted
[BUGFIX] Avoid $e->getPrevious() on doctrine exceptions
As sorted out with #105897, using $e->getPrevious() is a left over from much older doctrine/dbal versions. The change applies the solution core wide to prevent calling getMessage() on null. Resolves: #105565 Releases: main, 13.4, 12.4 Change-Id: I820f587d912fb75db4322a222036b49d83ff511e Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/86958 Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Oliver Bartsch <bo@cedev.de> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: core-ci <typo3@b13.com>
1 parent 533a0f8 commit 987057f

File tree

9 files changed

+49
-71
lines changed

9 files changed

+49
-71
lines changed

Build/phpstan/phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,6 @@ parameters:
252252
count: 1
253253
path: ../../typo3/sysext/backend/Classes/Form/FormDataGroup/OrderedProviderList.php
254254

255-
-
256-
message: '#^Call to function is_array\(\) with array\<TYPO3\\CMS\\Core\\Resource\\FileReference\> will always evaluate to true\.$#'
257-
identifier: function.alreadyNarrowedType
258-
count: 1
259-
path: ../../typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php
260-
261255
-
262256
message: '#^Parameter \#2 \$replace of function str_replace expects array\<string\>\|string, array\<int, int\|string\> given\.$#'
263257
identifier: argument.type

typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ protected function addItemsFromFolder(array $result, $fieldName, array $items)
290290
*/
291291
protected function addItemsFromForeignTable(array $result, $fieldName, array $items, bool $includeFullRows = false)
292292
{
293-
$databaseError = null;
294-
$queryResult = null;
295-
// Guard
296293
if (empty($result['processedTca']['columns'][$fieldName]['config']['foreign_table'])
297294
|| !is_string($result['processedTca']['columns'][$fieldName]['config']['foreign_table'])
298295
) {
@@ -315,13 +312,8 @@ protected function addItemsFromForeignTable(array $result, $fieldName, array $it
315312
try {
316313
$queryResult = $queryBuilder->executeQuery();
317314
} catch (DBALException $e) {
318-
$databaseError = $e->getPrevious()->getMessage();
319-
}
320-
321-
// Early return on error with flash message
322-
if (!empty($databaseError)) {
323-
$msg = $databaseError . '. ';
324-
$msg .= $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:error.database_schema_mismatch');
315+
// Early return on error with flash message
316+
$msg = $e->getMessage() . '. ' . $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:error.database_schema_mismatch');
325317
$msgTitle = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:error.database_schema_mismatch_title');
326318
$flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $msg, $msgTitle, ContextualFeedbackSeverity::ERROR, true);
327319
$defaultFlashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier();
@@ -364,7 +356,7 @@ protected function addItemsFromForeignTable(array $result, $fieldName, array $it
364356
$icon = '';
365357
if ($isFileReference) {
366358
$references = $this->fileRepository->findByRelation($foreignTable, $iconFieldName, $foreignRow['uid']);
367-
if (is_array($references) && !empty($references)) {
359+
if (!empty($references)) {
368360
$icon = reset($references);
369361
$icon = $icon->getPublicUrl();
370362
}

typo3/sysext/core/Classes/DataHandling/DataHandler.php

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3876,8 +3876,7 @@ public function copySpecificPage($uid, $destPid, $copyTablesArray, $first = fals
38763876
}
38773877
}
38783878
} catch (DBALException $e) {
3879-
$databaseErrorMessage = $e->getPrevious()->getMessage();
3880-
$this->log($table, $uid, SystemLogDatabaseAction::CHECK, 0, SystemLogErrorClassification::USER_ERROR, 'An SQL error occurred: {reason}', -1, ['reason' => $databaseErrorMessage]);
3879+
$this->log($table, $uid, SystemLogDatabaseAction::CHECK, 0, SystemLogErrorClassification::USER_ERROR, 'An SQL error occurred: {reason}', -1, ['reason' => $e->getMessage()]);
38813880
}
38823881
}
38833882
}
@@ -5374,7 +5373,7 @@ public function deleteRecord(string $table, int $uid, bool $noRecordCheck = fals
53745373
$this->connectionPool->getConnectionForTable($table)
53755374
->update($table, $updateFields, ['uid' => $uid]);
53765375
} catch (DBALException $e) {
5377-
$databaseErrorMessage = $e->getPrevious()->getMessage();
5376+
$databaseErrorMessage = $e->getMessage();
53785377
}
53795378
} else {
53805379
// Delete the hard way...:
@@ -5383,7 +5382,7 @@ public function deleteRecord(string $table, int $uid, bool $noRecordCheck = fals
53835382
$this->deletedRecords[$table][] = $uid;
53845383
$this->deleteL10nOverlayRecords($table, $uid);
53855384
} catch (DBALException $e) {
5386-
$databaseErrorMessage = $e->getPrevious()->getMessage();
5385+
$databaseErrorMessage = $e->getMessage();
53875386
}
53885387
}
53895388
if ($this->enableLogging) {
@@ -7656,42 +7655,35 @@ public function updateDB($table, $id, $fieldArray): void
76567655
if (!empty($fieldArray)) {
76577656
$fieldArray = $this->insertUpdateDB_preprocessBasedOnFieldType($table, $fieldArray);
76587657
$connection = $this->connectionPool->getConnectionForTable($table);
7659-
$updateErrorMessage = '';
76607658
try {
7661-
// Execute the UPDATE query:
76627659
$connection->update($table, $fieldArray, ['uid' => (int)$id]);
76637660
} catch (DBALException $e) {
7664-
$updateErrorMessage = $e->getPrevious()->getMessage();
7665-
}
7666-
// If succeeds, do...:
7667-
if ($updateErrorMessage === '') {
7668-
// Update reference index:
7669-
$this->updateRefIndex($table, $id);
7670-
// Set History data
7671-
$historyEntryId = 0;
7672-
if (isset($this->historyRecords[$table . ':' . $id])) {
7673-
$historyEntryId = $this->getRecordHistoryStore()->modifyRecord($table, $id, $this->historyRecords[$table . ':' . $id], $this->correlationId);
7674-
}
7675-
if ($this->enableLogging) {
7676-
$newRow = $fieldArray;
7677-
$newRow['uid'] = $id;
7678-
// Set log entry:
7679-
$propArr = $this->getRecordPropertiesFromRow($table, $newRow);
7680-
$isOfflineVersion = (bool)($newRow['t3ver_oid'] ?? 0);
7681-
if ($isOfflineVersion) {
7682-
$this->log($table, $id, SystemLogDatabaseAction::UPDATE, $propArr['pid'], SystemLogErrorClassification::MESSAGE, 'Record "{title}" ({table}:{uid}) was updated (Offline version)', 10, ['title' => $propArr['header'], 'table' => $table, 'uid' => $id, 'history' => $historyEntryId], $propArr['event_pid']);
7683-
} else {
7684-
$this->log($table, $id, SystemLogDatabaseAction::UPDATE, $propArr['pid'], SystemLogErrorClassification::MESSAGE, 'Record "{title}" ({table}:{uid}) was updated', 10, ['title' => $propArr['header'], 'table' => $table, 'uid' => $id, 'history' => $historyEntryId], $propArr['event_pid']);
7685-
}
7686-
}
7687-
// Clear cache for relevant pages:
7688-
$this->registerRecordIdForPageCacheClearing($table, $id);
7689-
// Unset the pageCache for the id if table was page.
7690-
if ($table === 'pages') {
7691-
unset($this->pageCache[$id]);
7661+
$this->log($table, $id, SystemLogDatabaseAction::UPDATE, 0, SystemLogErrorClassification::SYSTEM_ERROR, 'SQL error: "{reason}" ({table}:{uid})', 12, ['reason' => $e->getMessage(), 'table' => $table, 'uid' => $id]);
7662+
return;
7663+
}
7664+
$this->updateRefIndex($table, $id);
7665+
// Set History data
7666+
$historyEntryId = 0;
7667+
if (isset($this->historyRecords[$table . ':' . $id])) {
7668+
$historyEntryId = $this->getRecordHistoryStore()->modifyRecord($table, $id, $this->historyRecords[$table . ':' . $id], $this->correlationId);
7669+
}
7670+
if ($this->enableLogging) {
7671+
$newRow = $fieldArray;
7672+
$newRow['uid'] = $id;
7673+
// Set log entry:
7674+
$propArr = $this->getRecordPropertiesFromRow($table, $newRow);
7675+
$isOfflineVersion = (bool)($newRow['t3ver_oid'] ?? 0);
7676+
if ($isOfflineVersion) {
7677+
$this->log($table, $id, SystemLogDatabaseAction::UPDATE, $propArr['pid'], SystemLogErrorClassification::MESSAGE, 'Record "{title}" ({table}:{uid}) was updated (Offline version)', 10, ['title' => $propArr['header'], 'table' => $table, 'uid' => $id, 'history' => $historyEntryId], $propArr['event_pid']);
7678+
} else {
7679+
$this->log($table, $id, SystemLogDatabaseAction::UPDATE, $propArr['pid'], SystemLogErrorClassification::MESSAGE, 'Record "{title}" ({table}:{uid}) was updated', 10, ['title' => $propArr['header'], 'table' => $table, 'uid' => $id, 'history' => $historyEntryId], $propArr['event_pid']);
76927680
}
7693-
} else {
7694-
$this->log($table, $id, SystemLogDatabaseAction::UPDATE, 0, SystemLogErrorClassification::SYSTEM_ERROR, 'SQL error: "{reason}" ({table}:{uid})', 12, ['reason' => $updateErrorMessage, 'table' => $table, 'uid' => $id]);
7681+
}
7682+
// Clear cache for relevant pages:
7683+
$this->registerRecordIdForPageCacheClearing($table, $id);
7684+
// Unset the pageCache for the id if table was page.
7685+
if ($table === 'pages') {
7686+
unset($this->pageCache[$id]);
76957687
}
76967688
}
76977689
}

typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static function (string $columnName): string {
181181
$this->connection->executeStatement($statement);
182182
$result[$statement] = '';
183183
} catch (DBALException $e) {
184-
$result[$statement] = $e->getPrevious()->getMessage();
184+
$result[$statement] = $e->getMessage();
185185
}
186186
}
187187

typo3/sysext/core/Classes/Database/Schema/SchemaMigrator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function migrate(array $statements, array $selectedStatements): array
123123
try {
124124
$connection->executeStatement($statement);
125125
} catch (DBALException $e) {
126-
$result[$hash] = $e->getPrevious()->getMessage();
126+
$result[$hash] = $e->getMessage();
127127
}
128128
}
129129
}
@@ -192,7 +192,7 @@ public function importStaticData(array $statements, bool $truncate = false): arr
192192
$connection->executeStatement($statement);
193193
$result[$statement] = '';
194194
} catch (DBALException $e) {
195-
$result[$statement] = $e->getPrevious()->getMessage();
195+
$result[$statement] = $e->getMessage();
196196
}
197197
}
198198
}

typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function addRow(string $tableName, array $fieldValues, bool $isRelation =
8787
$connection = $this->connectionPool->getConnectionForTable($tableName);
8888
$connection->insert($tableName, $fieldValues);
8989
} catch (DBALException $e) {
90-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230766, $e);
90+
throw new SqlErrorException($e->getMessage(), 1470230766, $e);
9191
}
9292

9393
$uid = 0;
@@ -121,7 +121,7 @@ public function updateRow(string $tableName, array $fieldValues, bool $isRelatio
121121
$connection = $this->connectionPool->getConnectionForTable($tableName);
122122
$connection->update($tableName, $fieldValues, ['uid' => $uid]);
123123
} catch (DBALException $e) {
124-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230767, $e);
124+
throw new SqlErrorException($e->getMessage(), 1470230767, $e);
125125
}
126126

127127
if (!$isRelation) {
@@ -164,7 +164,7 @@ public function updateRelationTableRow(string $tableName, array $fieldValues): v
164164
try {
165165
$this->connectionPool->getConnectionForTable($tableName)->update($tableName, $fieldValues, $where);
166166
} catch (DBALException $e) {
167-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230768, $e);
167+
throw new SqlErrorException($e->getMessage(), 1470230768, $e);
168168
}
169169
}
170170

@@ -181,7 +181,7 @@ public function removeRow(string $tableName, array $where, bool $isRelation = fa
181181
try {
182182
$this->connectionPool->getConnectionForTable($tableName)->delete($tableName, $where);
183183
} catch (DBALException $e) {
184-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230769, $e);
184+
throw new SqlErrorException($e->getMessage(), 1470230769, $e);
185185
}
186186

187187
if (!$isRelation && isset($where['uid'])) {
@@ -225,7 +225,7 @@ public function getObjectDataByQuery(QueryInterface $query): array
225225
try {
226226
$rows = $queryBuilder->executeQuery()->fetchAllAssociative();
227227
} catch (DBALException $e) {
228-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074485, $e);
228+
throw new SqlErrorException($e->getMessage(), 1472074485, $e);
229229
}
230230
}
231231

@@ -263,7 +263,7 @@ protected function getObjectDataByRawQuery(Statement $statement): array
263263
try {
264264
$result = $realStatement->executeQuery();
265265
} catch (DBALException $e) {
266-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064721, $e);
266+
throw new SqlErrorException($e->getMessage(), 1472064721, $e);
267267
}
268268
$rows = $result->fetchAllAssociative();
269269
// Prepared Doctrine DBAL statement
@@ -274,7 +274,7 @@ protected function getObjectDataByRawQuery(Statement $statement): array
274274
}
275275
$result = $realStatement->executeQuery();
276276
} catch (DBALException $e) {
277-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1481281404, $e);
277+
throw new SqlErrorException($e->getMessage(), 1481281404, $e);
278278
}
279279
$rows = $result->fetchAllAssociative();
280280
} else {
@@ -285,7 +285,7 @@ protected function getObjectDataByRawQuery(Statement $statement): array
285285
$connection = $this->connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
286286
$statement = $connection->executeQuery($realStatement, $parameters);
287287
} catch (DBALException $e) {
288-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064775, $e);
288+
throw new SqlErrorException($e->getMessage(), 1472064775, $e);
289289
}
290290

291291
$rows = $statement->fetchAllAssociative();
@@ -338,7 +338,7 @@ public function getObjectCountByQuery(QueryInterface $query): int
338338
try {
339339
$count = $queryBuilder->executeQuery()->fetchOne();
340340
} catch (DBALException $e) {
341-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074379, $e);
341+
throw new SqlErrorException($e->getMessage(), 1472074379, $e);
342342
}
343343
if ($query->getOffset()) {
344344
$count -= $query->getOffset();
@@ -399,7 +399,7 @@ public function getUidOfAlreadyPersistedValueObject(AbstractValueObject $object)
399399
}
400400
return null;
401401
} catch (DBALException $e) {
402-
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470231748, $e);
402+
throw new SqlErrorException($e->getMessage(), 1470231748, $e);
403403
}
404404
}
405405

typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4922,7 +4922,7 @@ public function getQuery(Connection $connection, string $table, array $conf): st
49224922
$conf['begin'] = str_ireplace('total', $count, (string)$conf['begin']);
49234923
}
49244924
} catch (DBALException $e) {
4925-
$this->getTimeTracker()->setTSlogMessage($e->getPrevious()->getMessage());
4925+
$this->getTimeTracker()->setTSlogMessage($e->getMessage());
49264926
return '';
49274927
}
49284928
}

typo3/sysext/scheduler/Classes/Task/OptimizeDatabaseTableTask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function execute()
5757
} catch (DBALException $e) {
5858
throw new \RuntimeException(
5959
TableGarbageCollectionTask::class . ' failed for: ' . $tableName . ': ' .
60-
$e->getPrevious()->getMessage(),
60+
$e->getMessage(),
6161
1441390263
6262
);
6363
}

typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ protected function version_swap(string $table, int $id, int $swapWith, DataHandl
703703
['uid' => (int)$id]
704704
);
705705
} catch (DBALException $e) {
706-
$sqlErrors[] = $e->getPrevious()->getMessage();
706+
$sqlErrors[] = $e->getMessage();
707707
}
708708

709709
if (empty($sqlErrors)) {
@@ -714,7 +714,7 @@ protected function version_swap(string $table, int $id, int $swapWith, DataHandl
714714
['uid' => (int)$swapWith]
715715
);
716716
} catch (DBALException $e) {
717-
$sqlErrors[] = $e->getPrevious()->getMessage();
717+
$sqlErrors[] = $e->getMessage();
718718
}
719719
}
720720

@@ -967,7 +967,7 @@ protected function publishNewRecord(string $table, array $newRecordInWorkspace,
967967
]
968968
);
969969
} catch (DBALException $e) {
970-
$dataHandler->log($table, $id, DatabaseAction::PUBLISH, 0, SystemLogErrorClassification::SYSTEM_ERROR, 'During Publishing: SQL errors happened: {reason}', -1, ['reason' => $e->getPrevious()->getMessage()]);
970+
$dataHandler->log($table, $id, DatabaseAction::PUBLISH, 0, SystemLogErrorClassification::SYSTEM_ERROR, 'During Publishing: SQL errors happened: {reason}', -1, ['reason' => $e->getMessage()]);
971971
}
972972

973973
if ($dataHandler->enableLogging) {

0 commit comments

Comments
 (0)