Skip to content

Commit

Permalink
Do not delete relations if a language record is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Feb 12, 2024
1 parent 809ec03 commit 86b965c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"require-dev": {
"contao/manager-plugin": "^2.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"terminal42/dc_multilingual": "^4.0"
},
"conflict": {
"contao/manager-plugin": "<2.0 || >=3.0"
Expand Down
13 changes: 11 additions & 2 deletions src/DcaRelationsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
use Symfony\Component\String\UnicodeString;
use Terminal42\DcMultilingualBundle\Driver;

class DcaRelationsManager
{
Expand Down Expand Up @@ -180,9 +181,13 @@ public function updateRelatedRecords(mixed $value, DataContainer $dc): mixed
/**
* Delete the records in related table.
*/
public function deleteRelatedRecords(DataContainer $dc, int $undoId): void
public function deleteRelatedRecords(DataContainer $dc, int|string $undoId): void
{
$this->deleteRelatedRecordsWithUndo($dc->table, $dc->id, $undoId);
if (!$undoId || ($dc instanceof Driver && '' !== $dc->getCurrentLanguage())) {
return;
}

$this->deleteRelatedRecordsWithUndo($dc->table, $dc->id, (int) $undoId);
}

/**
Expand Down Expand Up @@ -321,6 +326,10 @@ public function cleanRelatedRecords(): void
throw new \RuntimeException('There seems to be no valid DataContainer instance!');
}

if ($dc instanceof Driver && '' !== $dc->getCurrentLanguage()) {
return;
}

$this->loadDataContainers();

foreach ($GLOBALS['TL_DCA'] as $table => $dca) {
Expand Down

0 comments on commit 86b965c

Please sign in to comment.