Skip to content

Commit

Permalink
fix playlist limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
ahilles107 committed Feb 25, 2015
1 parent aea8a61 commit af301b9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions newscoop/library/Newscoop/Services/PlaylistsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ private function positionPlaylistArticle($playlist, $playlistArticle, $position)
$playlistArticle->setOrder($position);
$this->em->flush();

if ($oldOrder == 0 && $playlist->getMaxItems() !== null && (int) $maxPosition+1 >= $playlist->getMaxItems()) {
$this->removeLeftItems($playlist);
}
$this->removeLeftItems($playlist);

$this->em->getConnection()->exec('UNLOCK TABLES;');
} catch (\Exception $e) {
Expand All @@ -206,10 +204,12 @@ private function positionPlaylistArticle($playlist, $playlistArticle, $position)

public function removeLeftItems($playlist)
{
$this->em
->createQuery('DELETE FROM Newscoop\Entity\PlaylistArticle pa WHERE pa.order > :maxPosition AND pa.idPlaylist = :playlistId')
->setParameter('maxPosition', $playlist->getMaxItems())
->setParameter('playlistId', $playlist->getId())
->execute();
if ($playlist->getMaxItems() != null) {
$this->em
->createQuery('DELETE FROM Newscoop\Entity\PlaylistArticle pa WHERE pa.order > :maxPosition AND pa.idPlaylist = :playlistId')
->setParameter('maxPosition', $playlist->getMaxItems())
->setParameter('playlistId', $playlist->getId())
->execute();
}
}
}

0 comments on commit af301b9

Please sign in to comment.