diff --git a/lib/Entity/Layout.php b/lib/Entity/Layout.php index ce6d09cdd6..af00614bf8 100644 --- a/lib/Entity/Layout.php +++ b/lib/Entity/Layout.php @@ -2681,29 +2681,34 @@ public function managePlaylistClosureTable() $child = $assignedPlaylistIds; } } - } - } - if (isset($parentId) && isset($child)) { - foreach ($child as $childId) { - $this->getLog()->debug('Manage closure table for parent ' . $parentId . ' and child ' . $childId); - - if ($this->getStore()->exists('SELECT parentId, childId, depth FROM lkplaylistplaylist WHERE childId = :childId AND parentId = :parentId ', [//phpcs:ignore - 'parentId' => $parentId, - 'childId' => $childId - ])) { - throw new InvalidArgumentException(__('Cannot add the same SubPlaylist twice.'), 'playlistId'); - } + if (isset($parentId) && isset($child)) { + foreach ($child as $childId) { + $this->getLog()->debug( + 'Manage closure table for parent ' . $parentId . ' and child ' . $childId + ); + + if ($this->getStore()->exists('SELECT parentId, childId, depth FROM lkplaylistplaylist WHERE childId = :childId AND parentId = :parentId ', [//phpcs:ignore + 'parentId' => $parentId, + 'childId' => $childId + ])) { + throw new InvalidArgumentException( + __('Cannot add the same SubPlaylist twice.'), + 'playlistId' + ); + } - $this->getStore()->insert(' + $this->getStore()->insert(' INSERT INTO `lkplaylistplaylist` (parentId, childId, depth) SELECT p.parentId, c.childId, p.depth + c.depth + 1 FROM lkplaylistplaylist p, lkplaylistplaylist c WHERE p.childId = :parentId AND c.parentId = :childId ', [ - 'parentId' => $parentId, - 'childId' => $childId - ]); + 'parentId' => $parentId, + 'childId' => $childId + ]); + } + } } } }