From 01f35cd163f33bec8e716193a8cf8158cf8ae7e3 Mon Sep 17 00:00:00 2001 From: Ralf Baussenwein Date: Thu, 19 Jan 2023 14:39:10 +0100 Subject: [PATCH] Optimize the delete process --- src/Driver.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Driver.php b/src/Driver.php index 4fbb6c1..d1fd82d 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -13,6 +13,7 @@ use Contao\CoreBundle\Exception\AccessDeniedException; use Contao\CoreBundle\Exception\InternalServerErrorException; +use Contao\Message; use Contao\System; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -1107,6 +1108,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; @@ -1233,6 +1239,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 . " @@ -1249,6 +1267,7 @@ protected function handleLanguageOperation() if ($needsReload) { $_SESSION['TL_INFO'] = ''; + Message::reset(); \Controller::reload(); } }