From 06dd75eb1ea40a6f1d26bbf25e9b34f7b6a07459 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 15 Oct 2023 03:21:55 +0300 Subject: [PATCH] fix cyrilic keywords extraction, add reindex all torrents toolkit --- src/Service/TorrentService.php | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Service/TorrentService.php b/src/Service/TorrentService.php index 044700d..0427730 100644 --- a/src/Service/TorrentService.php +++ b/src/Service/TorrentService.php @@ -134,11 +134,11 @@ class TorrentService } public function readTorrentFileByTorrentId( - int $id + int $torrentId ): ?\Rhilip\Bencode\TorrentFile { return $this->readTorrentFileByFilepath( - $this->getStorageFilepathById($id) + $this->getStorageFilepathByTorrentId($torrentId) ); } @@ -159,7 +159,7 @@ class TorrentService '/[\s]+/', ' ', preg_replace( - '/[\W]+/', + '/[\W_]+/u', ' ', $list['path'] ) @@ -196,12 +196,12 @@ class TorrentService return array_unique($keywords); } - public function getStorageFilepathById(int $id): string + public function getStorageFilepathByTorrentId(int $torrentId): string { return sprintf( '%s/var/torrents/%s.torrent', $this->kernelInterface->getProjectDir(), - implode('/', str_split($id)) + implode('/', str_split($torrentId)) ); } @@ -248,7 +248,7 @@ class TorrentService $filesystem = new Filesystem(); $filesystem->copy( $filepath, - $this->getStorageFilepathById( + $this->getStorageFilepathByTorrentId( $torrent->getId() ) ); @@ -445,6 +445,25 @@ class TorrentService } } + public function reindexTorrentKeywordsAll(): void + { + foreach ($this->entityManagerInterface + ->getRepository(Torrent::class) + ->findAll() as $torrent) + { + $torrent->setKeywords( + $this->generateTorrentKeywordsByTorrentFilepath( + $this->getStorageFilepathByTorrentId( + $torrent->getId() + ) + ) + ); + + $this->entityManagerInterface->persist($torrent); + $this->entityManagerInterface->flush(); + } + } + public function setTorrentApprovedByTorrentId( int $torrentId, bool $value