Clone schedule entries when cloning a station.

This commit is contained in:
Buster "Silver Eagle" Neece 2021-07-14 19:06:47 -05:00
parent 2d1836e66e
commit b1d358c924
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
3 changed files with 50 additions and 14 deletions

View File

@ -51,7 +51,7 @@ return [
StationCloneForm::CLONE_PERMISSIONS => __('User Permissions'),
StationCloneForm::CLONE_WEBHOOKS => __('Web Hooks'),
],
'form_group_class' => 'col - sm - 12',
'form_group_class' => 'col-sm-12',
],
],

View File

@ -72,11 +72,23 @@ class StationSchedule
return $this->playlist;
}
public function setPlaylist(StationPlaylist $playlist): void
{
$this->playlist = $playlist;
$this->streamer = null;
}
public function getStreamer(): ?StationStreamer
{
return $this->streamer;
}
public function setStreamer(StationStreamer $streamer): void
{
$this->streamer = $streamer;
$this->playlist = null;
}
public function getStartTime(): int
{
return $this->start_time;

View File

@ -134,14 +134,23 @@ class StationCloneForm extends StationForm
$this->em->clear();
if (in_array(self::CLONE_PLAYLISTS, $toClone, true)) {
if (in_array(self::CLONE_MEDIA_STORAGE, $toClone, true)) {
$afterCloning = function (
Entity\StationPlaylist $oldPlaylist,
Entity\StationPlaylist $newPlaylist,
Entity\Station $newStation
) use (
$copier
): void {
$afterCloning = function (
Entity\StationPlaylist $oldPlaylist,
Entity\StationPlaylist $newPlaylist,
Entity\Station $newStation
) use (
$copier,
$toClone
): void {
foreach ($oldPlaylist->getScheduleItems() as $oldScheduleItem) {
/** @var Entity\StationSchedule $newScheduleItem */
$newScheduleItem = $copier->copy($oldScheduleItem);
$newScheduleItem->setPlaylist($newPlaylist);
$this->em->persist($newScheduleItem);
}
if (in_array(self::CLONE_MEDIA_STORAGE, $toClone, true)) {
foreach ($oldPlaylist->getFolders() as $oldPlaylistFolder) {
/** @var Entity\StationPlaylistFolder $newPlaylistFolder */
$newPlaylistFolder = $copier->copy($oldPlaylistFolder);
@ -157,10 +166,8 @@ class StationCloneForm extends StationForm
$newMediaItem->setPlaylist($newPlaylist);
$this->em->persist($newMediaItem);
}
};
} else {
$afterCloning = null;
}
}
};
$record = $this->reloadableEm->refetch($record);
$this->cloneCollection($record->getPlaylists(), $newStation, $copier, $afterCloning);
@ -184,7 +191,24 @@ class StationCloneForm extends StationForm
if (in_array(self::CLONE_STREAMERS, $toClone, true)) {
$record = $this->reloadableEm->refetch($record);
$this->cloneCollection($record->getStreamers(), $newStation, $copier);
$afterCloning = function (
Entity\StationStreamer $oldStreamer,
Entity\StationStreamer $newStreamer,
Entity\Station $station
) use (
$copier
): void {
foreach ($oldStreamer->getScheduleItems() as $oldScheduleItem) {
/** @var Entity\StationSchedule $newScheduleItem */
$newScheduleItem = $copier->copy($oldScheduleItem);
$newScheduleItem->setStreamer($newStreamer);
$this->em->persist($newScheduleItem);
}
};
$this->cloneCollection($record->getStreamers(), $newStation, $copier, $afterCloning);
}
if (in_array(self::CLONE_PERMISSIONS, $toClone, true)) {