Skip to content

Commit a3b134b

Browse files
committed
Fixed an oversight preventing the watch progress from being processed by backends.
1 parent a2ae3e6 commit a3b134b

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/Listeners/ProcessProgressEvent.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,28 @@ public function __invoke(DataEvent $e): DataEvent
4545
$e->stopPropagation();
4646

4747
$options = $e->getOptions();
48+
$entity = Container::get(iState::class)::fromArray($e->getData());
4849

49-
if (null === ($item = $this->db->get(Container::get(iState::class)::fromArray($e->getData())))) {
50-
$writer(Level::Error, "Item with id '{id}' not found.", [
51-
'id' => ag($e->getData(), 'id', $e->getReference() ?? 'Unknown ID.')
50+
if (null === ($item = $this->db->get($entity))) {
51+
$writer(Level::Error, "Item '{title}' Is not referenced locally yet.", ['title' => $entity->getName()]);
52+
return $e;
53+
}
54+
55+
if ($item->isWatched() || $entity->isWatched()) {
56+
$writer(Level::Info, "Item '{id}: {title}' is marked as watched. Not updating watch process.", [
57+
'id' => $item->id,
58+
'title' => $item->getName()
5259
]);
5360
return $e;
5461
}
5562

63+
$item = $item->apply($entity);
64+
65+
if (!$item->hasPlayProgress()) {
66+
$writer(Level::Notice, "Item '{title}' has no watch progress to export.", ['title' => $item->title]);
67+
return $e;
68+
}
69+
5670
$list = [];
5771

5872
$supported = Config::get('supported', []);

src/Listeners/ProcessRequestEvent.php

+12-14
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,19 @@ public function __invoke(DataEvent $e): DataEvent
7474

7575
$pEnabled = (bool)Config::get('sync.progress', false);
7676
if (true === $pEnabled && true === $entity->hasPlayProgress() && !$entity->isWatched()) {
77-
if (null !== ($newEntity = $this->mapper->get($entity))) {
78-
$logger->notice(r("Scheduling '{title}' for watch progress update via '{backend}' event.", [
77+
$logger->notice(r("Scheduling '{title}' for watch progress update via '{backend}' event.", [
78+
'backend' => $entity->via,
79+
'title' => $entity->getName(),
80+
]));
81+
82+
queueEvent(ProcessProgressEvent::NAME, $entity->getAll(), [
83+
'unique' => true,
84+
EventsTable::COLUMN_REFERENCE => r('{type}://{id}@{backend}', [
85+
'type' => $entity->type,
7986
'backend' => $entity->via,
80-
'title' => $entity->getName(),
81-
]));
82-
83-
queueEvent(ProcessProgressEvent::NAME, [iState::COLUMN_ID => $newEntity->id], [
84-
'unique' => true,
85-
EventsTable::COLUMN_REFERENCE => r('{type}://{id}@{backend}', [
86-
'type' => $newEntity->type,
87-
'backend' => $newEntity->via,
88-
'id' => ag($newEntity->getMetadata($newEntity->via), iState::COLUMN_ID, '??'),
89-
]),
90-
]);
91-
}
87+
'id' => ag($entity->getMetadata($entity->via), iState::COLUMN_ID, '??'),
88+
]),
89+
]);
9290
}
9391

9492
$handler->close();

0 commit comments

Comments
 (0)