|
|
@ -150,7 +150,7 @@ class TorrentService |
|
|
|
public function generateTorrentKeywordsByTorrentFilepath( |
|
|
|
public function generateTorrentKeywordsByTorrentFilepath( |
|
|
|
string $filepath, |
|
|
|
string $filepath, |
|
|
|
int $minLength = 3 |
|
|
|
int $minLength = 3 |
|
|
|
): string |
|
|
|
): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
$keywords = []; |
|
|
|
$keywords = []; |
|
|
|
|
|
|
|
|
|
|
@ -175,17 +175,17 @@ class TorrentService |
|
|
|
{ |
|
|
|
{ |
|
|
|
unset($words[$key]); |
|
|
|
unset($words[$key]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$words[$key] = mb_strtolower($value); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$keywords = array_merge($keywords, $words); |
|
|
|
$keywords = array_merge($keywords, $words); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return mb_strtolower( |
|
|
|
return array_unique($keywords); |
|
|
|
implode( |
|
|
|
|
|
|
|
',', |
|
|
|
|
|
|
|
array_unique($keywords) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getStorageFilepathById(int $id): string |
|
|
|
public function getStorageFilepathById(int $id): string |
|
|
@ -197,6 +197,25 @@ class TorrentService |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getTorrentContributors(Torrent $torrent): array |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$contributors = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->findTorrentLocalesByTorrentId($torrent->getUserId()) as $torrentLocale) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$contributors[] = $torrentLocale->getUserId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->findTorrentSensitiveByTorrentId($torrent->getUserId()) as $torrentSensitive) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$contributors[] = $torrentSensitive->getUserId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$contributors[] = $torrent->getUserId(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return array_unique($contributors); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function add( |
|
|
|
public function add( |
|
|
|
string $filepath, |
|
|
|
string $filepath, |
|
|
|
int $userId, |
|
|
|
int $userId, |
|
|
@ -213,6 +232,8 @@ class TorrentService |
|
|
|
$this->generateTorrentKeywordsByTorrentFilepath( |
|
|
|
$this->generateTorrentKeywordsByTorrentFilepath( |
|
|
|
$filepath |
|
|
|
$filepath |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
$locales, |
|
|
|
|
|
|
|
$sensitive, |
|
|
|
$approved |
|
|
|
$approved |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -224,8 +245,6 @@ class TorrentService |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($locales)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->addTorrentLocales( |
|
|
|
$this->addTorrentLocales( |
|
|
|
$torrent->getId(), |
|
|
|
$torrent->getId(), |
|
|
|
$userId, |
|
|
|
$userId, |
|
|
@ -233,7 +252,6 @@ class TorrentService |
|
|
|
$locales, |
|
|
|
$locales, |
|
|
|
$approved |
|
|
|
$approved |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->addTorrentSensitive( |
|
|
|
$this->addTorrentSensitive( |
|
|
|
$torrent->getId(), |
|
|
|
$torrent->getId(), |
|
|
@ -258,7 +276,9 @@ class TorrentService |
|
|
|
int $userId, |
|
|
|
int $userId, |
|
|
|
int $added, |
|
|
|
int $added, |
|
|
|
string $md5file, |
|
|
|
string $md5file, |
|
|
|
string $keywords, |
|
|
|
array $keywords, |
|
|
|
|
|
|
|
array $locales, |
|
|
|
|
|
|
|
bool $sensitive, |
|
|
|
bool $approved |
|
|
|
bool $approved |
|
|
|
): ?Torrent |
|
|
|
): ?Torrent |
|
|
|
{ |
|
|
|
{ |
|
|
@ -268,6 +288,8 @@ class TorrentService |
|
|
|
$torrent->setAdded($added); |
|
|
|
$torrent->setAdded($added); |
|
|
|
$torrent->setMd5File($md5file); |
|
|
|
$torrent->setMd5File($md5file); |
|
|
|
$torrent->setKeywords($keywords); |
|
|
|
$torrent->setKeywords($keywords); |
|
|
|
|
|
|
|
$torrent->setLocales($locales); |
|
|
|
|
|
|
|
$torrent->setSensitive($sensitive); |
|
|
|
$torrent->setApproved($approved); |
|
|
|
$torrent->setApproved($approved); |
|
|
|
|
|
|
|
|
|
|
|
$this->entityManagerInterface->persist($torrent); |
|
|
|
$this->entityManagerInterface->persist($torrent); |
|
|
@ -288,12 +310,41 @@ class TorrentService |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function searchTorrents(string $query) : array |
|
|
|
public function findTorrents( |
|
|
|
|
|
|
|
array $keywords, |
|
|
|
|
|
|
|
array $locales, |
|
|
|
|
|
|
|
?bool $sensitive, |
|
|
|
|
|
|
|
?bool $approved, |
|
|
|
|
|
|
|
int $limit, |
|
|
|
|
|
|
|
int $offset |
|
|
|
|
|
|
|
) : array |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->entityManagerInterface |
|
|
|
return $this->entityManagerInterface |
|
|
|
->getRepository(Torrent::class) |
|
|
|
->getRepository(Torrent::class) |
|
|
|
->searchByKeywords( |
|
|
|
->findTorrents( |
|
|
|
explode(' ', $query) |
|
|
|
$keywords, |
|
|
|
|
|
|
|
$locales, |
|
|
|
|
|
|
|
$sensitive, |
|
|
|
|
|
|
|
$approved, |
|
|
|
|
|
|
|
$limit, |
|
|
|
|
|
|
|
$offset |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function findTorrentsTotal( |
|
|
|
|
|
|
|
array $keywords, |
|
|
|
|
|
|
|
array $locales, |
|
|
|
|
|
|
|
?bool $sensitive, |
|
|
|
|
|
|
|
?bool $approved |
|
|
|
|
|
|
|
) : int |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->entityManagerInterface |
|
|
|
|
|
|
|
->getRepository(Torrent::class) |
|
|
|
|
|
|
|
->findTorrentsTotal( |
|
|
|
|
|
|
|
$keywords, |
|
|
|
|
|
|
|
$locales, |
|
|
|
|
|
|
|
$sensitive, |
|
|
|
|
|
|
|
$approved |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -308,6 +359,74 @@ class TorrentService |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function updateTorrentSensitive( |
|
|
|
|
|
|
|
int $torrentId, |
|
|
|
|
|
|
|
): void |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($torrent = $this->getTorrent($torrentId)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($torrentSensitive = $this->entityManagerInterface |
|
|
|
|
|
|
|
->getRepository(TorrentSensitive::class) |
|
|
|
|
|
|
|
->findOneBy( |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'torrentId' => $torrentId, |
|
|
|
|
|
|
|
'approved' => true, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'id' => 'DESC' |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$torrent->setSensitive( |
|
|
|
|
|
|
|
$torrentSensitive->isValue() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->entityManagerInterface->persist($torrent); |
|
|
|
|
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function updateTorrentLocales( |
|
|
|
|
|
|
|
int $torrentId |
|
|
|
|
|
|
|
): void |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($torrent = $this->getTorrent($torrentId)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($torrentLocales = $this->entityManagerInterface |
|
|
|
|
|
|
|
->getRepository(TorrentLocales::class) |
|
|
|
|
|
|
|
->findOneBy( |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'torrentId' => $torrentId, |
|
|
|
|
|
|
|
'approved' => true, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'id' => 'DESC' |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$torrent->setLocales($torrentLocales->getValue()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->entityManagerInterface->persist($torrent); |
|
|
|
|
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function setTorrentApprovedByTorrentId( |
|
|
|
|
|
|
|
int $torrentId, |
|
|
|
|
|
|
|
bool $value |
|
|
|
|
|
|
|
): void |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($torrent = $this->getTorrent($torrentId)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$torrent->setApproved($value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->entityManagerInterface->persist($torrent); |
|
|
|
|
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function setTorrentsApprovedByUserId( |
|
|
|
public function setTorrentsApprovedByUserId( |
|
|
|
int $userId, |
|
|
|
int $userId, |
|
|
|
bool $value |
|
|
|
bool $value |
|
|
@ -355,24 +474,6 @@ class TorrentService |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function findLastTorrentLocalesByTorrentIdApproved( |
|
|
|
|
|
|
|
int $torrentId, |
|
|
|
|
|
|
|
bool $approved = true |
|
|
|
|
|
|
|
): ?TorrentLocales |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->entityManagerInterface |
|
|
|
|
|
|
|
->getRepository(TorrentLocales::class) |
|
|
|
|
|
|
|
->findOneBy( |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'torrentId' => $torrentId, |
|
|
|
|
|
|
|
'approved' => $approved |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'id' => 'DESC' |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function findTorrentLocalesByTorrentId(int $torrentId): array |
|
|
|
public function findTorrentLocalesByTorrentId(int $torrentId): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->entityManagerInterface |
|
|
|
return $this->entityManagerInterface |
|
|
@ -400,6 +501,10 @@ class TorrentService |
|
|
|
$this->entityManagerInterface->persist($torrentLocales); |
|
|
|
$this->entityManagerInterface->persist($torrentLocales); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->updateTorrentLocales( |
|
|
|
|
|
|
|
$torrentLocales->getTorrentId() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return $torrentLocales; |
|
|
|
return $torrentLocales; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -412,6 +517,10 @@ class TorrentService |
|
|
|
$this->entityManagerInterface->remove($torrentLocales); |
|
|
|
$this->entityManagerInterface->remove($torrentLocales); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->updateTorrentLocales( |
|
|
|
|
|
|
|
$torrentLocales->getTorrentId() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return $torrentLocales; |
|
|
|
return $torrentLocales; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -434,6 +543,10 @@ class TorrentService |
|
|
|
$this->entityManagerInterface->persist($torrentLocales); |
|
|
|
$this->entityManagerInterface->persist($torrentLocales); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->updateTorrentLocales( |
|
|
|
|
|
|
|
$torrentId |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return $torrentLocales; |
|
|
|
return $torrentLocales; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -484,24 +597,6 @@ class TorrentService |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function findLastTorrentSensitiveByTorrentIdApproved( |
|
|
|
|
|
|
|
int $torrentId, |
|
|
|
|
|
|
|
bool $approved = true |
|
|
|
|
|
|
|
): ?TorrentSensitive |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->entityManagerInterface |
|
|
|
|
|
|
|
->getRepository(TorrentSensitive::class) |
|
|
|
|
|
|
|
->findOneBy( |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'torrentId' => $torrentId, |
|
|
|
|
|
|
|
'approved' => $approved, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'id' => 'DESC' |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function findTorrentSensitiveByTorrentId(int $torrentId): array |
|
|
|
public function findTorrentSensitiveByTorrentId(int $torrentId): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->entityManagerInterface |
|
|
|
return $this->entityManagerInterface |
|
|
@ -531,6 +626,10 @@ class TorrentService |
|
|
|
$this->entityManagerInterface->persist($torrentSensitive); |
|
|
|
$this->entityManagerInterface->persist($torrentSensitive); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->updateTorrentSensitive( |
|
|
|
|
|
|
|
$torrentSensitive->getTorrentId() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return $torrentSensitive; |
|
|
|
return $torrentSensitive; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -545,6 +644,10 @@ class TorrentService |
|
|
|
$this->entityManagerInterface->remove($torrentSensitive); |
|
|
|
$this->entityManagerInterface->remove($torrentSensitive); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->updateTorrentSensitive( |
|
|
|
|
|
|
|
$torrentSensitive->getTorrentId() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return $torrentSensitive; |
|
|
|
return $torrentSensitive; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -567,6 +670,10 @@ class TorrentService |
|
|
|
$this->entityManagerInterface->persist($torrentSensitive); |
|
|
|
$this->entityManagerInterface->persist($torrentSensitive); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
$this->entityManagerInterface->flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->updateTorrentSensitive( |
|
|
|
|
|
|
|
$torrentId |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return $torrentSensitive; |
|
|
|
return $torrentSensitive; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|