Skip to content

Commit

Permalink
Optimize the delete process
Browse files Browse the repository at this point in the history
  • Loading branch information
rabauss committed Jan 19, 2023
1 parent 1af3379 commit 01f35cd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 . "
Expand All @@ -1249,6 +1267,7 @@ protected function handleLanguageOperation()

if ($needsReload) {
$_SESSION['TL_INFO'] = '';
Message::reset();
\Controller::reload();
}
}
Expand Down

0 comments on commit 01f35cd

Please sign in to comment.