Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the delete process #80

Merged
merged 2 commits into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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=''";
}

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -1126,6 +1130,14 @@ public function deleteChilds($table, $id, &$delete)
{
parent::deleteChilds($table, $id, $delete);

// Do not delete record if it is not a multilingual dataContainer
$drivers = ['Multilingual', __CLASS__, \DC_Multilingual::class];
$dataContainer = $GLOBALS['TL_DCA'][$table]['config']['dataContainer'] ?? null;

if (!(isset($dataContainer) && \in_array($dataContainer, $drivers, true))) {
return;
}

// Do not delete record if there is no parent table
if (empty($GLOBALS['TL_DCA'][$table]['config']['ptable'])) {
return;
Expand Down Expand Up @@ -1252,6 +1264,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 @@ -1268,6 +1292,7 @@ protected function handleLanguageOperation()

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