implement torrent statuses management #28

This commit is contained in:
ghost 2023-10-27 01:36:50 +03:00
parent 3cbc6ea90f
commit 989f2f3311
64 changed files with 1051 additions and 282 deletions

View file

@ -560,6 +560,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
@ -606,6 +607,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
@ -652,6 +654,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
@ -699,6 +702,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
@ -745,6 +749,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
@ -783,6 +788,102 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
],
'session' =>
[
'user' =>
[
'id' => $user->getId(),
'sensitive' => $user->isSensitive(),
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrent->getUserId(),
]
]
]
);
break;
// Torrent Status
case $activity::EVENT_TORRENT_STATUS_ADD:
// Init torrent
if (!$torrent = $torrentService->getTorrent($activity->getTorrentId()))
{
throw $this->createNotFoundException();
}
return $this->render(
'default/activity/event/torrent/status/add' . $extension,
[
'id' => $activity->getId(),
'added' => $activity->getAdded(),
'user' =>
[
'id' => $activity->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$activity->getUserId()
)->getAddress()
)
],
'torrent' =>
[
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
],
'session' =>
[
'user' =>
[
'id' => $user->getId(),
'sensitive' => $user->isSensitive(),
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrent->getUserId(),
]
]
]
);
break;
case $activity::EVENT_TORRENT_STATUS_DELETE:
// Init torrent
if (!$torrent = $torrentService->getTorrent($activity->getTorrentId()))
{
throw $this->createNotFoundException();
}
return $this->render(
'default/activity/event/torrent/status/delete' . $extension,
[
'id' => $activity->getId(),
'added' => $activity->getAdded(),
'user' =>
[
'id' => $activity->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$activity->getUserId()
)->getAddress()
)
],
'torrent' =>
[
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
@ -830,6 +931,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
@ -882,6 +984,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
@ -934,6 +1037,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
@ -986,6 +1090,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
@ -1039,6 +1144,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
@ -1091,6 +1197,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
@ -1143,6 +1250,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
@ -1195,6 +1303,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
@ -1248,6 +1357,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
@ -1294,6 +1404,7 @@ class ActivityController extends AbstractController
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()

View file

@ -62,8 +62,9 @@ class TorrentController extends AbstractController
throw $this->createNotFoundException();
}
// Approved filter
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && !$torrent->isApproved())
// Access filter
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() &&
(!$torrent->isStatus() || !$torrent->isApproved()))
{
throw $this->createNotFoundException();
}
@ -110,9 +111,10 @@ class TorrentController extends AbstractController
[
'session' =>
[
'user' => $user,
'user' => $user,
'id' => $user->getId(),
'moderator' => $user->isModerator()
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrent->getUserId(),
],
'torrent' =>
[
@ -129,6 +131,7 @@ class TorrentController extends AbstractController
'locales' => $torrent->getLocales(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'download' =>
[
'file' =>
@ -226,24 +229,30 @@ class TorrentController extends AbstractController
$activityService
);
//
// Init request
$query = $request->get('query') ? explode(' ', urldecode($request->get('query'))) : [];
$page = $request->get('page') ? (int) $request->get('page') : 1;
// Get total torrents
$total = $torrentService->findTorrentsTotal(
$user->getId(),
$query,
$user->getLocales(),
!$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
!$user->isModerator() ? true : null, // show approved content only for regular users
!$user->isModerator() && $user->isSensitive() ? false : null,
!$user->isModerator() ? true : null,
!$user->isModerator() ? true : null,
);
$torrents = [];
foreach ($torrentService->findTorrents(
$user->getId(),
$query,
$user->getLocales(),
!$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
!$user->isModerator() ? true : null, // show approved content only for regular users
!$user->isModerator() && $user->isSensitive() ? false : null,
!$user->isModerator() ? true : null,
!$user->isModerator() ? true : null,
$this->getParameter('app.pagination'),
($page - 1) * $this->getParameter('app.pagination')
) as $torrent)
@ -254,18 +263,6 @@ class TorrentController extends AbstractController
throw $this->createNotFoundException(); // @TODO exception
}
// Generate keywords
/* @TODO deprecated, based on active search result
$keywords = [];
foreach ($torrent->getKeywords() as $keyword)
{
if (in_array($keyword, $query))
{
$keywords[] = $keyword;
}
}
*/
// Generate keywords by extension
$keywords = [];
@ -296,6 +293,7 @@ class TorrentController extends AbstractController
'added' => $torrent->getAdded(),
'approved' => $torrent->isApproved(),
'sensitive' => $torrent->isSensitive(),
'status' => $torrent->isStatus(),
'file' =>
[
'name' => $file->getName(),
@ -401,19 +399,23 @@ class TorrentController extends AbstractController
// Get total torrents
$total = $torrentService->findTorrentsTotal(
$user->getId(),
[],
$user->getLocales(),
!$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
!$user->isModerator() ? true : null, // show approved content only for regular users
!$user->isModerator() && $user->isSensitive() ? false : null,
!$user->isModerator() ? true : null,
!$user->isModerator() ? true : null,
);
// Create torrents list
$torrents = [];
foreach ($torrentService->findTorrents(
$user->getId(),
[],
$user->getLocales(),
!$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
!$user->isModerator() ? true : null, // show approved content only for regular users
!$user->isModerator() && $user->isSensitive() ? false : null,
!$user->isModerator() ? true : null,
!$user->isModerator() ? true : null,
$this->getParameter('app.pagination'),
($page - 1) * $this->getParameter('app.pagination')
) as $torrent)
@ -454,6 +456,7 @@ class TorrentController extends AbstractController
'added' => $torrent->getAdded(),
'approved' => $torrent->isApproved(),
'sensitive' => $torrent->isSensitive(),
'status' => $torrent->isStatus(),
'file' =>
[
'name' => $file->getName(),
@ -558,19 +561,23 @@ class TorrentController extends AbstractController
// Get total torrents
$total = $torrentService->findTorrentsTotal(
$user->getId(),
$query,
$user->getLocales(),
!$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
!$user->isModerator() ? true : null // show approved content only for regular users
!$user->isModerator() && $user->isSensitive() ? false : null,
!$user->isModerator() ? true : null,
!$user->isModerator() ? true : null,
);
// Create torrents list
$torrents = [];
foreach ($torrentService->findTorrents(
$user->getId(),
$query,
$user->getLocales(),
!$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all
!$user->isModerator() ? true : null, // show approved content only for regular users
!$user->isModerator() && $user->isSensitive() ? false : null,
!$user->isModerator() ? true : null,
!$user->isModerator() ? true : null,
$this->getParameter('app.pagination'),
($page - 1) * $this->getParameter('app.pagination')
) as $torrent)
@ -583,9 +590,9 @@ class TorrentController extends AbstractController
$torrents[] =
[
'id' => $torrent->getId(),
'added' => $torrent->getAdded(),
'file' =>
'id' => $torrent->getId(),
'added' => $torrent->getAdded(),
'file' =>
[
'name' => $file->getName(),
],
@ -624,6 +631,13 @@ class TorrentController extends AbstractController
ActivityService $activityService
): Response
{
// Init user
$user = $this->initUser(
$request,
$userService,
$activityService
);
// Init request
$query = $request->get('query') ? explode(' ', urldecode($request->get('query'))) : [];
$page = $request->get('page') ? (int) $request->get('page') : 1;
@ -638,19 +652,23 @@ class TorrentController extends AbstractController
// Get total torrents
$total = $torrentService->findTorrentsTotal(
$user->getId(),
$query,
$locales,
$sensitive,
true, // approved only
!$user->isModerator() ? $sensitive : null,
!$user->isModerator() ? true : null,
!$user->isModerator() ? true : null,
);
// Create torrents list
$torrents = [];
foreach ($torrentService->findTorrents(
$user->getId(),
$query,
$locales,
$sensitive,
true, // approved only
!$user->isModerator() ? $sensitive : null,
!$user->isModerator() ? true : null,
!$user->isModerator() ? true : null,
$this->getParameter('app.pagination'),
($page - 1) * $this->getParameter('app.pagination')
) as $torrent)
@ -867,7 +885,8 @@ class TorrentController extends AbstractController
time(),
(array) $locales,
(bool) $request->get('sensitive'),
$user->isApproved()
$user->isApproved(),
$user->isStatus()
);
// Add activity event
@ -898,7 +917,7 @@ class TorrentController extends AbstractController
);
}
// Torrent moderation
#[Route(
'/{_locale}/torrent/{torrentId}/approve/toggle',
name: 'torrent_approve_toggle',
@ -975,6 +994,82 @@ class TorrentController extends AbstractController
);
}
#[Route(
'/{_locale}/torrent/{torrentId}/status/toggle',
name: 'torrent_status_toggle',
requirements:
[
'_locale' => '%app.locales%',
'torrentId' => '\d+',
],
methods:
[
'GET'
]
)]
public function status(
Request $request,
UserService $userService,
TorrentService $torrentService,
ActivityService $activityService
): Response
{
// Init user
$user = $this->initUser(
$request,
$userService,
$activityService
);
// Init torrent
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
{
throw $this->createNotFoundException();
}
// Check permissions
if (!($user->isModerator() || $user->getId() == $torrent->getUserId()))
{
// @TODO
throw new \Exception(
$translator->trans('Access denied')
);
}
// Register activity event
if (!$torrent->isStatus())
{
$activityService->addEventTorrentStatusAdd(
$user->getId(),
$torrent->getId(),
time()
);
}
else
{
$activityService->addEventTorrentStatusDelete(
$user->getId(),
$torrent->getId(),
time()
);
}
// Update status
$torrentService->toggleTorrentStatus(
$torrent->getId()
);
// Redirect back to form
return $this->redirectToRoute(
'torrent_info',
[
'_locale' => $request->get('_locale'),
'torrentId' => $torrent->getId()
]
);
}
// Torrent locales
#[Route(
'/{_locale}/torrent/{torrentId}/edit/locales/{torrentLocalesId}',
@ -1807,14 +1902,9 @@ class TorrentController extends AbstractController
throw $this->createNotFoundException();
}
// Sensitive filter
if (!$user->isModerator() && $user->isSensitive())
{
throw $this->createNotFoundException();
}
// Approved filter
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && !$torrent->isApproved())
// Access filter
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() &&
(!$torrent->isStatus() || !$torrent->isApproved()))
{
throw $this->createNotFoundException();
}
@ -1934,14 +2024,9 @@ class TorrentController extends AbstractController
throw $this->createNotFoundException();
}
// Sensitive filter
if (!$user->isModerator() && $user->isSensitive())
{
throw $this->createNotFoundException();
}
// Approved filter
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && !$torrent->isApproved())
// Access filter
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() &&
(!$torrent->isStatus() || !$torrent->isApproved()))
{
throw $this->createNotFoundException();
}
@ -2058,14 +2143,9 @@ class TorrentController extends AbstractController
throw $this->createNotFoundException();
}
// Sensitive filter
if (!$user->isModerator() && $user->isSensitive())
{
throw $this->createNotFoundException();
}
// Approved filter
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() && !$torrent->isApproved())
// Access filter
if (!$user->isModerator() && $user->getId() != $torrent->getUserId() &&
(!$torrent->isStatus() || !$torrent->isApproved()))
{
throw $this->createNotFoundException();
}
@ -2389,10 +2469,12 @@ class TorrentController extends AbstractController
'locale' => $locale,
'locales' => $locales,
'torrents' => $torrentService->findTorrents(
0, // no user session init, pass 0
[], // without keywords filter
$locales, // all system locales
null, // all sensitive levels
true, // approved only
true, // enabled only
1000, // @TODO limit
0 // offset
)

View file

@ -59,6 +59,9 @@ class Activity
public const EVENT_TORRENT_WANTED_ADD = 2700;
public const EVENT_TORRENT_STATUS_ADD = 1800;
public const EVENT_TORRENT_STATUS_DELETE = 1801;
// ...
#[ORM\Column]

View file

@ -33,6 +33,9 @@ class Torrent
#[ORM\Column]
private ?bool $approved = null;
#[ORM\Column]
private ?bool $status = null;
#[ORM\Column(length: 32)]
private ?string $md5file = null;
@ -156,6 +159,18 @@ class Torrent
return $this;
}
public function isStatus(): ?bool
{
return $this->status;
}
public function setStatus(bool $status): static
{
$this->status = $status;
return $this;
}
public function getSeeders(): ?int
{
return $this->seeders;

View file

@ -22,38 +22,46 @@ class TorrentRepository extends ServiceEntityRepository
}
public function findTorrentsTotal(
int $userId,
array $keywords,
array $locales,
?bool $sensitive = null,
?bool $approved = null,
int $limit = 10,
int $offset = 0
?bool $approved = null,
?bool $status = null,
int $limit = 10,
int $offset = 0
): int
{
return $this->getTorrentsQueryByFilter(
$userId,
$keywords,
$locales,
$sensitive,
$approved,
$status,
)->select('count(t.id)')
->getQuery()
->getSingleScalarResult();
}
public function findTorrents(
int $userId,
array $keywords,
array $locales,
?bool $sensitive = null,
?bool $approved = null,
?bool $approved = null,
?bool $status = null,
int $limit = 10,
int $offset = 0
): array
{
return $this->getTorrentsQueryByFilter(
$userId,
$keywords,
$locales,
$sensitive,
$approved,
$status,
)->setMaxResults($limit)
->setFirstResult($offset)
->orderBy('t.id', 'DESC') // same as t.added
@ -62,54 +70,85 @@ class TorrentRepository extends ServiceEntityRepository
}
private function getTorrentsQueryByFilter(
int $userId,
array $keywords,
array $locales,
?bool $sensitive = null,
?bool $approved = null,
?bool $approved = null,
?bool $status = null,
): \Doctrine\ORM\QueryBuilder
{
$query = $this->createQueryBuilder('t');
if ($keywords) // @TODO ANY or DTS
if ($keywords)
{
$andX = $query->expr()->andX();
$andKeywords = $query->expr()->andX();
foreach ($keywords as $i => $keyword)
{
$keyword = mb_strtolower($keyword); // all keywords stored in lowercase
$andX->add("t.keywords LIKE :keyword{$i}");
$andKeywords->add("t.keywords LIKE :keyword{$i}");
$query->setParameter(":keyword{$i}", "%{$keyword}%");
}
$query->andWhere($andX);
$query->andWhere($andKeywords);
}
if ($locales) // @TODO ANY or DTS
if ($locales)
{
//$orX = $query->expr()->orX();
$orX = $query->expr()->orX();
$orLocales = $query->expr()->orX();
foreach ($locales as $i => $locale)
{
$orX->add("t.locales LIKE :locale{$i}");
$orLocales->add("t.locales LIKE :locale{$i}");
$orLocales->add("t.userId = :userId");
$query->setParameter(":locale{$i}", "%{$locale}%");
$query->setParameter('userId', $userId);
}
$query->andWhere($orX);
$query->andWhere($orLocales);
}
if (is_bool($sensitive))
{
$query->andWhere('t.sensitive = :sensitive')
->setParameter('sensitive', $sensitive);
$orSensitive = $query->expr()->orX();
$orSensitive->add("t.sensitive = :sensitive");
$orSensitive->add("t.userId = :userId");
$query->setParameter('sensitive', $sensitive);
$query->setParameter('userId', $userId);
$query->andWhere($orSensitive);
}
if (is_bool($approved))
{
$query->andWhere('t.approved = :approved')
->setParameter('approved', $approved);
$orApproved = $query->expr()->orX();
$orApproved->add("t.approved = :approved");
$orApproved->add("t.userId = :userId");
$query->setParameter('approved', $approved);
$query->setParameter('userId', $userId);
$query->andWhere($orApproved);
}
if (is_bool($status))
{
$orStatus = $query->expr()->orX();
$orStatus->add("t.status = :status");
$orStatus->add("t.userId = :userId");
$query->setParameter('status', $status);
$query->setParameter('userId', $userId);
$query->andWhere($orStatus);
}
return $query;

View file

@ -62,6 +62,9 @@ class ActivityService
Activity::EVENT_TORRENT_DOWNLOAD_FILE_ADD,
Activity::EVENT_TORRENT_DOWNLOAD_MAGNET_ADD,
Activity::EVENT_TORRENT_STATUS_ADD,
Activity::EVENT_TORRENT_STATUS_DELETE,
Activity::EVENT_TORRENT_WANTED_ADD,
];
}
@ -379,6 +382,30 @@ class ActivityService
] = $code;
break;
case Activity::EVENT_TORRENT_STATUS_ADD:
$events
[
$this->translatorInterface->trans('Torrents')
]
[
$this->translatorInterface->trans('Enabled')
] = $code;
break;
case Activity::EVENT_TORRENT_STATUS_DELETE:
$events
[
$this->translatorInterface->trans('Torrents')
]
[
$this->translatorInterface->trans('Disabled')
] = $code;
break;
}
}
@ -861,6 +888,65 @@ class ActivityService
return $activity;
}
public function addEventTorrentStatusAdd(
int $userId,
int $torrentId,
int $added
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_STATUS_ADD
);
$activity->setUserId(
$userId
);
$activity->setTorrentId(
$torrentId
);
$activity->setAdded(
$added
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
public function addEventTorrentStatusDelete(
int $userId,
int $torrentId,
int $added
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_STATUS_DELETE
);
$activity->setUserId(
$userId
);
$activity->setTorrentId(
$torrentId
);
$activity->setAdded(
$added
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
public function addEventTorrentWantedAdd(
int $userId,

View file

@ -192,7 +192,8 @@ class TorrentService
int $added,
array $locales,
bool $sensitive,
bool $approved
bool $approved,
bool $status
): ?Torrent
{
$torrent = $this->addTorrent(
@ -204,7 +205,8 @@ class TorrentService
),
$locales,
$sensitive,
$approved
$approved,
$status
);
$filesystem = new Filesystem();
@ -249,7 +251,8 @@ class TorrentService
array $keywords,
array $locales,
bool $sensitive,
bool $approved
bool $approved,
bool $status
): ?Torrent
{
$torrent = new Torrent();
@ -261,6 +264,7 @@ class TorrentService
$torrent->setLocales($locales);
$torrent->setSensitive($sensitive);
$torrent->setApproved($approved);
$torrent->setStatus($status);
$this->entityManagerInterface->persist($torrent);
$this->entityManagerInterface->flush();
@ -292,6 +296,30 @@ class TorrentService
return $torrent;
}
public function toggleTorrentStatus(
int $torrentId
): ?Torrent
{
$torrent = $this->getTorrent($torrentId);
$torrent->setStatus(
!$torrent->isStatus() // toggle current value
);
$this->entityManagerInterface->persist($torrent);
$this->entityManagerInterface->flush();
$this->updateTorrentLocales(
$torrent->getId()
);
$this->updateTorrentSensitive(
$torrent->getId()
);
return $torrent;
}
public function getTorrentScrapeQueue(): ?Torrent
{
return $this->entityManagerInterface
@ -305,40 +333,48 @@ class TorrentService
}
public function findTorrents(
int $userId,
array $keywords,
array $locales,
?bool $sensitive,
?bool $approved,
int $limit,
int $offset
?bool $status,
int $limit,
int $offset
) : array
{
return $this->entityManagerInterface
->getRepository(Torrent::class)
->findTorrents(
$userId,
$keywords,
$locales,
$sensitive,
$approved,
$status,
$limit,
$offset
);
}
public function findTorrentsTotal(
int $userId,
array $keywords,
array $locales,
?bool $sensitive,
?bool $approved
?bool $approved,
?bool $status
) : int
{
return $this->entityManagerInterface
->getRepository(Torrent::class)
->findTorrentsTotal(
$userId,
$keywords,
$locales,
$sensitive,
$approved
$approved,
$status
);
}