Fixed an oversight preventing the watch progress from being processed by backends.

This commit is contained in:
Abdulmhsen B. A. A.
2024-08-18 21:38:10 +03:00
parent a2ae3e6a33
commit a3b134b251
2 changed files with 29 additions and 17 deletions

View File

@@ -45,14 +45,28 @@ final readonly class ProcessProgressEvent
$e->stopPropagation();
$options = $e->getOptions();
$entity = Container::get(iState::class)::fromArray($e->getData());
if (null === ($item = $this->db->get(Container::get(iState::class)::fromArray($e->getData())))) {
$writer(Level::Error, "Item with id '{id}' not found.", [
'id' => ag($e->getData(), 'id', $e->getReference() ?? 'Unknown ID.')
if (null === ($item = $this->db->get($entity))) {
$writer(Level::Error, "Item '{title}' Is not referenced locally yet.", ['title' => $entity->getName()]);
return $e;
}
if ($item->isWatched() || $entity->isWatched()) {
$writer(Level::Info, "Item '{id}: {title}' is marked as watched. Not updating watch process.", [
'id' => $item->id,
'title' => $item->getName()
]);
return $e;
}
$item = $item->apply($entity);
if (!$item->hasPlayProgress()) {
$writer(Level::Notice, "Item '{title}' has no watch progress to export.", ['title' => $item->title]);
return $e;
}
$list = [];
$supported = Config::get('supported', []);

View File

@@ -74,21 +74,19 @@ final readonly class ProcessRequestEvent
$pEnabled = (bool)Config::get('sync.progress', false);
if (true === $pEnabled && true === $entity->hasPlayProgress() && !$entity->isWatched()) {
if (null !== ($newEntity = $this->mapper->get($entity))) {
$logger->notice(r("Scheduling '{title}' for watch progress update via '{backend}' event.", [
'backend' => $entity->via,
'title' => $entity->getName(),
]));
$logger->notice(r("Scheduling '{title}' for watch progress update via '{backend}' event.", [
'backend' => $entity->via,
'title' => $entity->getName(),
]));
queueEvent(ProcessProgressEvent::NAME, [iState::COLUMN_ID => $newEntity->id], [
'unique' => true,
EventsTable::COLUMN_REFERENCE => r('{type}://{id}@{backend}', [
'type' => $newEntity->type,
'backend' => $newEntity->via,
'id' => ag($newEntity->getMetadata($newEntity->via), iState::COLUMN_ID, '??'),
]),
]);
}
queueEvent(ProcessProgressEvent::NAME, $entity->getAll(), [
'unique' => true,
EventsTable::COLUMN_REFERENCE => r('{type}://{id}@{backend}', [
'type' => $entity->type,
'backend' => $entity->via,
'id' => ag($entity->getMetadata($entity->via), iState::COLUMN_ID, '??'),
]),
]);
}
$handler->close();