From 1fdf7e3b8d063f240306c1e6908170f1b6e1fff2 Mon Sep 17 00:00:00 2001 From: skellamp Date: Mon, 25 Dec 2023 01:23:27 -0500 Subject: [PATCH] migrated tag related methods --- .../VuFind/Controller/Plugin/Favorites.php | 7 +- .../VuFind/src/VuFind/Db/Entity/Ratings.php | 93 ++++++++++++++ .../VuFind/src/VuFind/Db/Entity/Resource.php | 20 +++ module/VuFind/src/VuFind/Db/Row/Resource.php | 117 ------------------ module/VuFind/src/VuFind/Db/Row/User.php | 36 ------ .../src/VuFind/Db/Service/RatingsService.php | 79 +++++++++++- .../src/VuFind/Db/Service/ResourceService.php | 28 ----- .../src/VuFind/Db/Service/TagService.php | 56 +++++++++ .../src/VuFind/Db/Service/UserService.php | 22 ++-- .../src/VuFind/Favorites/FavoritesService.php | 14 +-- .../FallbackLoader/AbstractFallbackLoader.php | 16 +-- .../AbstractFallbackLoaderFactory.php | 3 +- .../VuFind/Record/FallbackLoader/Summon.php | 4 +- .../src/VuFind/RecordDriver/AbstractBase.php | 19 +-- .../src/VuFind/RecordDriver/Missing.php | 9 +- 15 files changed, 292 insertions(+), 231 deletions(-) diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Favorites.php b/module/VuFind/src/VuFind/Controller/Plugin/Favorites.php index 94c08d16bb1..2a334ee5f44 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/Favorites.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/Favorites.php @@ -150,13 +150,14 @@ public function saveBulk($params, $user) [$source, $id] = explode('|', $current, 2); // Get or create a resource object as needed: - $resourceTable = $this->getController()->getTable('Resource'); - $resource = $resourceTable->findResource($id, $source); + $resourceService = $this->getController()->getDbService(\VuFind\Db\Service\ResourceService::class); + $resource = $resourceService->findResource($id, $source); // Add the information to the user's account: $tags = isset($params['mytags']) ? $this->tags->parse($params['mytags']) : []; - $user->saveResource($resource, $list->getId(), $tags, '', false); + $userService = $this->getController()->getDbService(\VuFind\Db\Service\UserService::class); + $userService->saveResource($resource, $user->id, $list, $tags, '', false); // Collect record IDs for caching if ($this->cache->isCachable($resource->source)) { diff --git a/module/VuFind/src/VuFind/Db/Entity/Ratings.php b/module/VuFind/src/VuFind/Db/Entity/Ratings.php index f078eca5f40..5ee8a68e8c4 100644 --- a/module/VuFind/src/VuFind/Db/Entity/Ratings.php +++ b/module/VuFind/src/VuFind/Db/Entity/Ratings.php @@ -29,6 +29,7 @@ namespace VuFind\Db\Entity; +use DateTime; use Doctrine\ORM\Mapping as ORM; /** @@ -107,6 +108,16 @@ class Ratings implements EntityInterface */ protected $created = '2000-01-01 00:00:00'; + /** + * Id getter + * + * @return ?int + */ + public function getId(): ?int + { + return $this->id; + } + /** * Get user. * @@ -116,4 +127,86 @@ public function getUser() { return $this->user; } + + /** + * User setter + * + * @param User $user + * + * @return Ratings + */ + public function setUser(User $user): Ratings + { + $this->user = $user; + return $this; + } + + /** + * Rating setter + * + * @param int $rating + * + * @return Ratings + */ + public function setRating(int $rating): Ratings + { + $this->rating = $rating; + return $this; + } + + /** + * Rating getter + * + * @return int + */ + public function getRating(): int + { + return $this->rating; + } + + /** + * Resource setter + * + * @param Resource $resource + * + * @return Ratings + */ + public function setResource(Resource $resource): Ratings + { + $this->resource = $resource; + return $this; + } + + /** + * Resource getter + * + * @return Resource + */ + public function getResource(): Resource + { + return $this->resource; + } + + /** + * Created setter. + * + * @param Datetime $dateTime Created date + * + * @return UserList + */ + public function setCreated(DateTime $dateTime): Ratings + { + $this->created = $dateTime; + return $this; + } + + /** + * Created getter + * + * @return Datetime + */ + public function getCreated(): Datetime + { + return $this->created; + } } diff --git a/module/VuFind/src/VuFind/Db/Entity/Resource.php b/module/VuFind/src/VuFind/Db/Entity/Resource.php index 2ee8b579a55..28fe3cdf9e2 100644 --- a/module/VuFind/src/VuFind/Db/Entity/Resource.php +++ b/module/VuFind/src/VuFind/Db/Entity/Resource.php @@ -170,6 +170,16 @@ public function setTitle(string $title): Resource return $this; } + /** + * Title getter + * + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + /** * Author setter * @@ -231,4 +241,14 @@ public function setExtraMetadata(?string $extraMetadata): Resource $this->extraMetadata = $extraMetadata; return $this; } + + /** + * Extra Metadata getter + * + * @return ?string + */ + public function getExtraMetadata(): ?string + { + return $this->extraMetadata; + } } diff --git a/module/VuFind/src/VuFind/Db/Row/Resource.php b/module/VuFind/src/VuFind/Db/Row/Resource.php index 5a6f30bd713..bdfa9a49980 100644 --- a/module/VuFind/src/VuFind/Db/Row/Resource.php +++ b/module/VuFind/src/VuFind/Db/Row/Resource.php @@ -30,10 +30,8 @@ namespace VuFind\Db\Row; use VuFind\Date\DateException; -use VuFind\Exception\LoginRequired as LoginRequiredException; use function intval; -use function is_object; use function strlen; /** @@ -70,121 +68,6 @@ public function __construct($adapter) parent::__construct('id', 'resource', $adapter); } - /** - * Remove tags from the current resource. - * - * @param \VuFind\Db\Row\User $user The user deleting the tags. - * @param string $list_id The list associated with the tags - * (optional -- omitting this will delete ALL of the user's tags). - * - * @return void - */ - public function deleteTags($user, $list_id = null) - { - $unlinker = $this->getDbService(\VuFind\Db\Service\TagService::class); - $unlinker->destroyResourceLinks($this->id, $user->id, $list_id); - } - - /** - * Add a tag to the current resource. - * - * @param string $tagText The tag to save. - * @param \VuFind\Db\Row\User $user The user posting the tag. - * @param string $list_id The list associated with the tag - * (optional). - * - * @return void - */ - public function addTag($tagText, $user, $list_id = null) - { - $tagText = trim($tagText); - if (!empty($tagText)) { - $tagService = $this->getDbService(\VuFind\Db\Service\TagService::class); - $tag = $tagService->getByText($tagText); - - $tagService->createLink( - $tag, - $this->id, - is_object($user) ? $user->id : null, - $list_id - ); - } - } - - /** - * Remove a tag from the current resource. - * - * @param string $tagText The tag to delete. - * @param \VuFind\Db\Row\User $user The user deleting the tag. - * @param string $list_id The list associated with the tag - * (optional). - * - * @return void - */ - public function deleteTag($tagText, $user, $list_id = null) - { - $tagText = trim($tagText); - $tagService = $this->getDbService(\VuFind\Db\Service\TagService::class); - if (!empty($tagText)) { - $tagIds = []; - foreach ($tagService->getByText($tagText, false, false) as $tag) { - $tagIds[] = $tag->getId(); - } - if (!empty($tagIds)) { - $tagService->destroyResourceLinks( - $this->id, - $user->id, - $list_id, - $tagIds - ); - } - } - } - - /** - * Add or update user's rating for the current resource. - * - * @param int $userId User ID - * @param ?int $rating Rating (null to delete) - * - * @throws LoginRequiredException - * @throws \Exception - * @return int ID of rating added, deleted or updated - */ - public function addOrUpdateRating(int $userId, ?int $rating): int - { - if (null !== $rating && ($rating < 0 || $rating > 100)) { - throw new \Exception('Rating value out of range'); - } - - $ratings = $this->getDbTable('Ratings'); - $callback = function ($select) use ($userId) { - $select->where->equalTo('ratings.resource_id', $this->id); - $select->where->equalTo('ratings.user_id', $userId); - }; - if ($existing = $ratings->select($callback)->current()) { - if (null === $rating) { - $existing->delete(); - } else { - $existing->rating = $rating; - $existing->save(); - } - return $existing->id; - } - - if (null === $rating) { - return 0; - } - - $row = $ratings->createRow(); - $row->user_id = $userId; - $row->resource_id = $this->id; - $row->rating = $rating; - $row->created = date('Y-m-d H:i:s'); - $row->save(); - return $row->id; - } - /** * Use a record driver to assign metadata to the current row. Return the * current object to allow fluent interface. diff --git a/module/VuFind/src/VuFind/Db/Row/User.php b/module/VuFind/src/VuFind/Db/Row/User.php index 1bbc6a9caad..a59333a5550 100644 --- a/module/VuFind/src/VuFind/Db/Row/User.php +++ b/module/VuFind/src/VuFind/Db/Row/User.php @@ -324,42 +324,6 @@ public function getSavedData( return $table->getSavedData($resourceId, $source, $listId, $this->id); } - /** - * Add/update a resource in the user's account. - * - * @param \VuFind\Db\Row\Resource $resource The resource to add/update - * @param int $list The list to store the resource in. - * @param array $tagArray An array of tags to associate with the resource. - * @param string $notes User notes about the resource. - * @param bool $replaceExisting Whether to replace all - * existing tags (true) or append to the existing list (false). - * - * @return void - */ - public function saveResource( - $resource, - $list, - $tagArray, - $notes, - $replaceExisting = true - ) { - // Create the resource link if it doesn't exist and update the notes in any - // case: - $linkTable = $this->getDbTable('UserResource'); - $linkTable->createOrUpdateLink($resource->id, $this->id, $list, $notes); - - // If we're replacing existing tags, delete the old ones before adding the - // new ones: - if ($replaceExisting) { - $resource->deleteTags($this, $list); - } - - // Add the new tags: - foreach ($tagArray as $tag) { - $resource->addTag($tag, $this, $list); - } - } - /** * Given an array of item ids, remove them from all lists * diff --git a/module/VuFind/src/VuFind/Db/Service/RatingsService.php b/module/VuFind/src/VuFind/Db/Service/RatingsService.php index c24862e8187..53de08c3bd8 100644 --- a/module/VuFind/src/VuFind/Db/Service/RatingsService.php +++ b/module/VuFind/src/VuFind/Db/Service/RatingsService.php @@ -29,7 +29,14 @@ namespace VuFind\Db\Service; +use Laminas\Log\LoggerAwareInterface; use VuFind\Db\Entity\Ratings; +use VuFind\Db\Entity\Resource; +use VuFind\Db\Entity\User; +use VuFind\Exception\LoginRequired as LoginRequiredException; +use VuFind\Log\LoggerAwareTrait; + +use function is_object; /** * Database service for Ratings. @@ -40,9 +47,10 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development:plugins:database_gateways Wiki */ -class RatingsService extends AbstractService implements \VuFind\Db\Service\ServiceAwareInterface +class RatingsService extends AbstractService implements \VuFind\Db\Service\ServiceAwareInterface, LoggerAwareInterface { use \VuFind\Db\Service\ServiceAwareTrait; + use LoggerAwareTrait; /** * Get average rating and rating count associated with the specified resource. @@ -179,4 +187,73 @@ public function getStatistics(): array $stats = current($query->getResult()); return $stats; } + + /** + * Add or update user's rating for a resource. + * + * @param Resource $resource Resource to add or update rating. + * @param int|User $user User + * @param ?int $rating Rating (null to delete) + * + * @throws LoginRequiredException + * @throws \Exception + * @return int ID of rating added, deleted or updated + */ + public function addOrUpdateRating($resource, $user, $rating): int + { + if (null !== $rating && ($rating < 0 || $rating > 100)) { + throw new \Exception('Rating value out of range'); + } + + $dql = 'SELECT r ' + . 'FROM ' . $this->getEntityClass(Ratings::class) . ' r ' + . 'WHERE r.user = :user AND r.resource = :resource'; + $parameters = compact('resource', 'user'); + $query = $this->entityManager->createQuery($dql); + $query->setParameters($parameters); + + if ($existing = current($query->getResult())) { + if (null === $rating) { + $this->entityManager->remove($existing); + } else { + $existing->setRating($rating); + } + $updatedRatingId = $existing->getId(); + try { + $this->entityManager->flush(); + } catch (\Exception $e) { + $this->logError('Rating update failed: ' . $e->getMessage()); + throw $e; + } + return $updatedRatingId; + } + + if (null === $rating) { + return 0; + } + + $row = $this->createRatings() + ->setResource($resource) + ->setUser(is_object($user) ? $user : $this->entityManager->getReference(User::class, $user)) + ->setRating($rating) + ->setCreated(new \DateTime()); + try { + $this->persistEntity($row); + } catch (\Exception $e) { + $this->logError('Could not save rating: ' . $e->getMessage()); + return 0; + } + return $row->getId(); + } + + /** + * Create a ratings entity. + * + * @return Ratings + */ + public function createRatings(): Ratings + { + $class = $this->getEntityClass(Ratings::class); + return new $class(); + } } diff --git a/module/VuFind/src/VuFind/Db/Service/ResourceService.php b/module/VuFind/src/VuFind/Db/Service/ResourceService.php index 8d7f58e394d..c8619dad777 100644 --- a/module/VuFind/src/VuFind/Db/Service/ResourceService.php +++ b/module/VuFind/src/VuFind/Db/Service/ResourceService.php @@ -36,7 +36,6 @@ use VuFind\Db\Entity\PluginManager as EntityPluginManager; use VuFind\Db\Entity\Resource; use VuFind\Db\Entity\User; -use VuFind\Db\Entity\UserList; use VuFind\Exception\LoginRequired as LoginRequiredException; use VuFind\Log\LoggerAwareTrait; use VuFind\Record\Loader; @@ -366,31 +365,4 @@ public function findResources($ids, $source = DEFAULT_SEARCH_BACKEND) ]; return $repo->findBy($criteria); } - - /** - * Add a tag to the current resource. - * - * @param Resource|int $resource Resource associated. - * @param string $tagText The tag to save. - * @param User|int $user The user posting the tag. - * @param ?UserList $list The list associated with the tag - * (optional). - * - * @return void - */ - public function addTag($resource, $tagText, $user, $list = null) - { - $tagText = trim($tagText); - if (!empty($tagText)) { - $tagService = $this->getDbService(\VuFind\Db\Service\TagService::class); - $tag = $tagService->getByText($tagText); - - $tagService->createLink( - $tag, - $resource, - $user, - $list - ); - } - } } diff --git a/module/VuFind/src/VuFind/Db/Service/TagService.php b/module/VuFind/src/VuFind/Db/Service/TagService.php index 796ef881ee0..2f746e42aac 100644 --- a/module/VuFind/src/VuFind/Db/Service/TagService.php +++ b/module/VuFind/src/VuFind/Db/Service/TagService.php @@ -1179,4 +1179,60 @@ public function fixDuplicateTags() $this->fixDuplicateTag($dupe['tag']); } } + + /** + * Remove a tag from the resource. + * + * @param Resource $resource Resource from which tag should be deleted. + * @param string $tagText The tag to delete. + * @param int|User $user The user deleting the tag. + * @param string $list_id The list associated with the tag + * (optional). + * + * @return void + */ + public function deleteTag($resource, $tagText, $user, $list_id = null) + { + $tagText = trim($tagText); + if (!empty($tagText)) { + $tagIds = []; + foreach ($this->getByText($tagText, false, false) as $tag) { + $tagIds[] = $tag->getId(); + } + if (!empty($tagIds)) { + $this->destroyResourceLinks( + $resource, + $user, + $list_id, + $tagIds + ); + } + } + } + + /** + * Add a tag to the resource. + * + * @param Resource|int $resource Resource associated. + * @param string $tagText The tag to save. + * @param User|int $user The user posting the tag. + * @param ?UserList $list The list associated with the tag + * (optional). + * + * @return void + */ + public function addTag($resource, $tagText, $user, $list = null) + { + $tagText = trim($tagText); + if (!empty($tagText)) { + $tag = $this->getByText($tagText); + + $this->createLink( + $tag, + $resource, + $user, + $list + ); + } + } } diff --git a/module/VuFind/src/VuFind/Db/Service/UserService.php b/module/VuFind/src/VuFind/Db/Service/UserService.php index 90e35d30418..990a4af3cc8 100644 --- a/module/VuFind/src/VuFind/Db/Service/UserService.php +++ b/module/VuFind/src/VuFind/Db/Service/UserService.php @@ -192,15 +192,11 @@ public function encryptOrDecrypt($text, $encrypt = true) * * @param Resource|int $resource The resource to add/update * @param User|int $user Logged in user - * @param UserList|int $list The list to store the resource - * in. - * @param array $tagArray An array of tags to associate - * with the resource. + * @param UserList|int $list The list to store the resource in. + * @param array $tagArray An array of tags to associate with the resource. * @param string $notes User notes about the resource. - * @param bool $replaceExisting Whether to replace all - * existing tags (true) - * or append to the - * existing list (false). + * @param bool $replaceExisting Whether to replace all existing tags (true) or append to the + * existing list (false). * * @return void */ @@ -212,13 +208,11 @@ public function saveResource( $notes, $replaceExisting = true ) { - // Create the resource link if it doesn't exist and update the notes in any - // case: + // Create the resource link if it doesn't exist and update the notes in any case: $linkService = $this->getDbService(\VuFind\Db\Service\UserResourceService::class); $linkService->createOrUpdateLink($resource, $user, $list, $notes); - // If we're replacing existing tags, delete the old ones before adding the - // new ones: + // If we're replacing existing tags, delete the old ones before adding the new ones: if ($replaceExisting) { $unlinker = $this->getDbService(\VuFind\Db\Service\TagService::class); $unlinker->destroyResourceLinks($resource, $user, $list); @@ -226,8 +220,8 @@ public function saveResource( // Add the new tags: foreach ($tagArray as $tag) { - $resourceService = $this->getDbService(\VuFind\Db\Service\ResourceService::class); - $resourceService->addTag($resource, $tag, $user, $list); + $tagService = $this->getDbService(\VuFind\Db\Service\TagService::class); + $tagService->addTag($resource, $tag, $user, $list); } } } diff --git a/module/VuFind/src/VuFind/Favorites/FavoritesService.php b/module/VuFind/src/VuFind/Favorites/FavoritesService.php index fc0c48d87a6..a71aea04ec6 100644 --- a/module/VuFind/src/VuFind/Favorites/FavoritesService.php +++ b/module/VuFind/src/VuFind/Favorites/FavoritesService.php @@ -109,20 +109,20 @@ public function getListObject($listId, \VuFind\Db\Row\User $user) /** * Persist a resource to the record cache (if applicable). * - * @param RecordDriver $driver Record driver to persist - * @param \VuFind\Db\Row\Resource $resource Resource row + * @param RecordDriver $driver Record driver to persist + * @param \VuFind\Db\Entity\Resource $resource Resource object * * @return void */ protected function persistToCache( RecordDriver $driver, - \VuFind\Db\Row\Resource $resource + \VuFind\Db\Entity\Resource $resource ) { if ($this->recordCache) { $this->recordCache->setContext(RecordCache::CONTEXT_FAVORITE); $this->recordCache->createOrUpdate( - $resource->record_id, - $resource->source, + $resource->getRecordId(), + $resource->getSource(), $driver->getRawData() ); } @@ -159,7 +159,7 @@ public function save( ); // Get or create a resource object as needed: - $resource = $this->resourceTable->findResource( + $resource = $this->getDbService(\VuFind\Db\Service\ResourceService::class)->findResource( $driver->getUniqueId(), $driver->getSourceIdentifier(), true, @@ -172,7 +172,7 @@ public function save( // Add the information to the user's account: $userService = $this->getDbService(\VuFind\Db\Service\UserService::class); $userService->saveResource( - $resource->id, + $resource, $user->id, $list, $params['mytags'] ?? [], diff --git a/module/VuFind/src/VuFind/Record/FallbackLoader/AbstractFallbackLoader.php b/module/VuFind/src/VuFind/Record/FallbackLoader/AbstractFallbackLoader.php index 5818d2adc28..5ce379324db 100644 --- a/module/VuFind/src/VuFind/Record/FallbackLoader/AbstractFallbackLoader.php +++ b/module/VuFind/src/VuFind/Record/FallbackLoader/AbstractFallbackLoader.php @@ -29,7 +29,7 @@ namespace VuFind\Record\FallbackLoader; -use VuFind\Db\Table\Resource; +use VuFind\Db\Service\ResourceService as ResourceService; use VuFind\RecordDriver\AbstractBase as RecordDriver; use VuFind\RecordDriver\Feature\PreviousUniqueIdInterface; use VuFindSearch\Service; @@ -53,11 +53,11 @@ abstract class AbstractFallbackLoader implements FallbackLoaderInterface protected $source = DEFAULT_SEARCH_BACKEND; /** - * Resource table + * Resource database service * - * @var Resource + * @var ResourceService */ - protected $table; + protected $resourceService; /** * Search service @@ -69,12 +69,12 @@ abstract class AbstractFallbackLoader implements FallbackLoaderInterface /** * Constructor * - * @param Resource $table Resource database table object - * @param Service $searchService Search service + * @param ResourceService $resourceService Resource database service + * @param Service $searchService Search service */ - public function __construct(Resource $table, Service $searchService) + public function __construct(ResourceService $resourceService, Service $searchService) { - $this->table = $table; + $this->resourceService = $resourceService; $this->searchService = $searchService; } diff --git a/module/VuFind/src/VuFind/Record/FallbackLoader/AbstractFallbackLoaderFactory.php b/module/VuFind/src/VuFind/Record/FallbackLoader/AbstractFallbackLoaderFactory.php index 0f7033ce48e..1bafe3a0fc2 100644 --- a/module/VuFind/src/VuFind/Record/FallbackLoader/AbstractFallbackLoaderFactory.php +++ b/module/VuFind/src/VuFind/Record/FallbackLoader/AbstractFallbackLoaderFactory.php @@ -66,7 +66,8 @@ public function __invoke( array $options = null ) { return new $requestedName( - $container->get(\VuFind\Db\Table\PluginManager::class)->get('resource'), + $container->get(\VuFind\Db\Service\PluginManager::class) + ->get(\VuFind\Db\Service\ResourceService::class), $container->get(\VuFindSearch\Service::class), ...$options ?? [] ); diff --git a/module/VuFind/src/VuFind/Record/FallbackLoader/Summon.php b/module/VuFind/src/VuFind/Record/FallbackLoader/Summon.php index 9ebe0beecf9..124f8536f53 100644 --- a/module/VuFind/src/VuFind/Record/FallbackLoader/Summon.php +++ b/module/VuFind/src/VuFind/Record/FallbackLoader/Summon.php @@ -62,8 +62,8 @@ class Summon extends AbstractFallbackLoader */ protected function fetchSingleRecord($id) { - $resource = $this->table->findResource($id, 'Summon'); - if ($resource && ($extra = json_decode($resource->extra_metadata, true))) { + $resource = $this->resourceService->findResource($id, 'Summon'); + if ($resource && ($extra = json_decode($resource->getExtraMetadata(), true))) { $bookmark = $extra['bookmark'] ?? ''; if (strlen($bookmark) > 0) { $params = new ParamBag( diff --git a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php index b502344ef47..ea3cdd92003 100644 --- a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php +++ b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php @@ -214,13 +214,14 @@ public function getTags( */ public function addTags($user, $tags) { - $resources = $this->getDbTable('Resource'); - $resource = $resources->findResource( + $resourceService = $this->getDbService(\VuFind\Db\Service\ResourceService::class); + $resource = $resourceService->findResource( $this->getUniqueId(), $this->getSourceIdentifier() ); + $tagService = $this->getDbService(\VuFind\Db\Service\TagService::class); foreach ($tags as $tag) { - $resource->addTag($tag, $user); + $tagService->addTag($resource, $tag, $user->id); } } @@ -234,13 +235,14 @@ public function addTags($user, $tags) */ public function deleteTags($user, $tags) { - $resources = $this->getDbTable('Resource'); - $resource = $resources->findResource( + $resourceService = $this->getDbService(\VuFind\Db\Service\ResourceService::class); + $resource = $resourceService->findResource( $this->getUniqueId(), $this->getSourceIdentifier() ); + $tagService = $this->getDbService(\VuFind\Db\Service\TagService::class); foreach ($tags as $tag) { - $resource->deleteTag($tag, $user); + $tagService->deleteTag($resource, $tag, $user->id); } } @@ -311,12 +313,11 @@ public function addOrUpdateRating(int $userId, ?int $rating): void { // Clear rating cache: $this->ratingCache = []; - $resources = $this->getDbTable('Resource'); - $resource = $resources->findResource( + $resource = $this->getDbService(\VuFind\Db\Service\ResourceService::class)->findResource( $this->getUniqueId(), $this->getSourceIdentifier() ); - $resource->addOrUpdateRating($userId, $rating); + $this->getDbService(\VuFind\Db\Service\RatingsService::class)->addOrUpdateRating($resource, $userId, $rating); } /** diff --git a/module/VuFind/src/VuFind/RecordDriver/Missing.php b/module/VuFind/src/VuFind/RecordDriver/Missing.php index 9bad5900a27..455c1b3040f 100644 --- a/module/VuFind/src/VuFind/RecordDriver/Missing.php +++ b/module/VuFind/src/VuFind/RecordDriver/Missing.php @@ -72,11 +72,10 @@ public function determineMissingTitle() // If available, load title from database: $id = $this->getUniqueId(); if ($id) { - $table = $this->getDbTable('Resource'); - $resource = $table - ->findResource($id, $this->getSourceIdentifier(), false); - if (!empty($resource) && !empty($resource->title)) { - return $resource->title; + $resourceService = $this->getDbService(\VuFind\Db\Service\ResourceService::class); + $resource = $resourceService->findResource($id, $this->getSourceIdentifier(), false); + if (!empty($resource) && !empty($resource->getTitle())) { + return $resource->getTitle(); } }