From 33ef0a3a1e0a6a1bfe01c5b0f67fb9856d5a7c7d Mon Sep 17 00:00:00 2001 From: Ralf Baussenwein Date: Thu, 19 Jan 2023 14:39:10 +0100 Subject: [PATCH 1/2] Optimize the delete process --- src/Driver.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Driver.php b/src/Driver.php index 903b57a..8003e25 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -1126,6 +1126,11 @@ public function deleteChilds($table, $id, &$delete) { parent::deleteChilds($table, $id, $delete); + // Do not delete record if it is not a multilingual dataContainer + if ('Multilingual' !== $GLOBALS['TL_DCA'][$table]['config']['dataContainer']) { + return; + } + // Do not delete record if there is no parent table if (empty($GLOBALS['TL_DCA'][$table]['config']['ptable'])) { return; @@ -1252,6 +1257,18 @@ protected function handleLanguageOperation() } elseif ($this->strTable === $request->request->get('FORM_SUBMIT') && $request->request->has('deleteLanguage') ) { + // Trigger the ondelete_callback + if (\is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['ondelete_callback'])) { + foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['ondelete_callback'] as $callback) { + if (\is_array($callback)) { + $this->import($callback[0]); + $this->{$callback[0]}->{$callback[1]}($this, ''); + } elseif (\is_callable($callback)) { + $callback($this, ''); + } + } + } + Database::getInstance() ->prepare( "DELETE FROM " . $this->strTable . " @@ -1268,6 +1285,7 @@ protected function handleLanguageOperation() if ($needsReload) { $_SESSION['TL_INFO'] = ''; + Message::reset(); Controller::reload(); } } From bf8668d15d55b43183b11ab8383af263ef441ffd Mon Sep 17 00:00:00 2001 From: Ralf Baussenwein Date: Fri, 17 Mar 2023 12:04:29 +0100 Subject: [PATCH 2/2] Support config of dataContainer driver as classes --- src/Driver.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Driver.php b/src/Driver.php index 8003e25..396118a 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -740,8 +740,10 @@ public function treeView() // Child mode if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6) { $table = $GLOBALS['TL_DCA'][$this->strTable]['config']['ptable']; + $drivers = ['Multilingual', __CLASS__, \DC_Multilingual::class]; + $dataContainer = $GLOBALS['TL_DCA'][$table]['config']['dataContainer'] ?? null; - if ($GLOBALS['TL_DCA'][$table]['config']['dataContainer'] == 'Multilingual') { + if (isset($dataContainer) && \in_array($dataContainer, $drivers, true)) { $where[] = "$this->langColumnName=''"; } @@ -866,8 +868,10 @@ protected function generateTree($table, $id, $arrPrevNext, $blnHasSorting, $intM // Check whether there are child records if (!$blnNoRecursion) { Controller::loadDataContainer($table); + $drivers = ['Multilingual', __CLASS__, \DC_Multilingual::class]; + $dataContainer = $GLOBALS['TL_DCA'][$table]['config']['dataContainer'] ?? null; - if ($GLOBALS['TL_DCA'][$table]['config']['dataContainer'] === 'Multilingual' + if (isset($dataContainer) && \in_array($dataContainer, $drivers, true) && ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] === 5 || $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] === 6 || $this->strTable != $table) ) { $langColumn = $GLOBALS['TL_DCA'][$table]['config']['langColumnName'] ?? 'language'; @@ -1127,7 +1131,10 @@ public function deleteChilds($table, $id, &$delete) parent::deleteChilds($table, $id, $delete); // Do not delete record if it is not a multilingual dataContainer - if ('Multilingual' !== $GLOBALS['TL_DCA'][$table]['config']['dataContainer']) { + $drivers = ['Multilingual', __CLASS__, \DC_Multilingual::class]; + $dataContainer = $GLOBALS['TL_DCA'][$table]['config']['dataContainer'] ?? null; + + if (!(isset($dataContainer) && \in_array($dataContainer, $drivers, true))) { return; }