Implement --dry-run for SyncCommand

This commit is contained in:
ArabCoders
2025-01-18 22:18:01 +03:00
parent bcc3c4fa7f
commit dd195b4ea4
7 changed files with 53 additions and 6 deletions

2
FAQ.md
View File

@@ -251,7 +251,7 @@ load on the backends. By default, it will sync once every 3 hours. you can ofc c
> [!NOTE]
> Known issues:
* Currently, state:sync doesn't have a way of syncing plex users that has PIN enabled.
* Currently, `state:sync` doesn't have a way of syncing plex users that has PIN enabled.
* Majority of the command flags aren't working or not implemented yet.
> [!IMPORTANT]

View File

@@ -10,6 +10,7 @@ use App\Backends\Common\Response;
use App\Backends\Jellyfin\JellyfinClient;
use App\Libs\Entity\StateInterface as iState;
use App\Libs\Extends\Date;
use App\Libs\Options;
use App\Libs\QueueRequests;
use Psr\Log\LoggerInterface as iLogger;
use Symfony\Contracts\HttpClient\HttpClientInterface as iHttp;
@@ -68,6 +69,22 @@ class UpdateState
);
}
if (true === (bool)ag($context->options, Options::DRY_RUN, false)) {
$this->logger->notice(
"Would mark '{backend}' {item.type} '{item.title}' as '{item.play_state}'.",
[
'backend' => $context->backendName,
'item' => [
'id' => $itemId,
'title' => $entity->getName(),
'type' => $entity->type == iState::TYPE_EPISODE ? 'episode' : 'movie',
'play_state' => $entity->isWatched() ? 'played' : 'unplayed',
],
]
);
return new Response(status: true);
}
$queue->add(
$this->http->request(
method: $entity->isWatched() ? 'POST' : 'DELETE',

View File

@@ -10,6 +10,7 @@ use App\Backends\Emby\EmbyClient;
use App\Libs\Config;
use App\Libs\Exceptions\Backends\InvalidArgumentException;
use App\Libs\Guid;
use App\Libs\Options;
use Psr\Log\LoggerInterface;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
@@ -242,14 +243,18 @@ class JellyfinGuid implements iGuid
}
try {
if (true === isIgnoredId($this->context->backendName, $type, $key, $value, $id)) {
if (null === ($bName = ag($this->context->options, Options::ALT_NAME))) {
$bName = $this->context->backendName;
}
if (true === isIgnoredId($bName, $type, $key, $value, $id)) {
if (true === $log) {
$this->logger->debug(
"{class}: Ignoring '{client}: {backend}' external id '{source}' for {item.type} '{item.id}: {item.title}' as requested.",
[
'class' => afterLast(static::class, '\\'),
'client' => $this->context->clientName,
'backend' => $this->context->backendName,
'backend' => $bName,
'source' => $key . '://' . $value,
'guid' => [
'source' => $key,

View File

@@ -8,6 +8,7 @@ use App\Backends\Common\CommonTrait;
use App\Backends\Common\Context;
use App\Backends\Common\Response;
use App\Libs\Entity\StateInterface as iState;
use App\Libs\Options;
use App\Libs\QueueRequests;
use Psr\Log\LoggerInterface as iLogger;
use Symfony\Contracts\HttpClient\HttpClientInterface as iHttp;
@@ -53,6 +54,22 @@ final class UpdateState
continue;
}
if (true === (bool)ag($context->options, Options::DRY_RUN, false)) {
$this->logger->notice(
"Would mark '{backend}' {item.type} '{item.title}' as '{item.play_state}'.",
[
'backend' => $context->backendName,
'item' => [
'id' => $itemId,
'title' => $entity->getName(),
'type' => $entity->type == iState::TYPE_EPISODE ? 'episode' : 'movie',
'play_state' => $entity->isWatched() ? 'played' : 'unplayed',
],
]
);
return new Response(status: true);
}
$url = $context->backendUrl->withPath($entity->isWatched() ? '/:/scrobble' : '/:/unscrobble')
->withQuery(
http_build_query([

View File

@@ -9,6 +9,7 @@ use App\Backends\Common\GuidInterface as iGuid;
use App\Libs\Config;
use App\Libs\Exceptions\Backends\InvalidArgumentException;
use App\Libs\Guid;
use App\Libs\Options;
use Psr\Log\LoggerInterface as iLogger;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
@@ -371,13 +372,17 @@ final class PlexGuid implements iGuid
continue;
}
if (true === isIgnoredId($this->context->backendName, $type, $key, $value, $id)) {
if (null === ($bName = ag($this->context->options, Options::ALT_NAME))) {
$bName = $this->context->backendName;
}
if (true === isIgnoredId($bName, $type, $key, $value, $id)) {
if (true === $log) {
$this->logger->debug(
"PlexGuid: Ignoring '{client}: {backend}' external id '{source}' for {item.type} '{item.id}: {item.title}' as requested.",
[
'client' => $this->context->clientName,
'backend' => $this->context->backendName,
'backend' => $bName,
'source' => $val,
'guid' => [
'source' => $key,

View File

@@ -272,6 +272,7 @@ class SyncCommand extends Command
$info['displayName'] = ag($user, 'name');
$info = ag_delete($info, 'options.' . Options::PLEX_USER_PIN);
$info = ag_delete($info, 'options.' . Options::ADMIN_TOKEN);
$info = ag_set($info, 'options.' . Options::ALT_NAME, ag($backend, 'name'));
unset($info['class']);
$user['backend'] = ag($backend, 'name');
@@ -312,7 +313,7 @@ class SyncCommand extends Command
'results' => arrayToString($this->usersList($users)),
]);
foreach ($users as $user) {
foreach (array_reverse($users) as $user) {
$this->queue->reset();
$this->mapper->reset();
@@ -378,6 +379,7 @@ class SyncCommand extends Command
'peak' => getPeakMemoryUsage(),
],
]);
exit(1);
}
return self::SUCCESS;

View File

@@ -41,6 +41,7 @@ final class Options
public const string PLEX_USER_PIN = 'PLEX_USER_PIN';
public const string REQUEST_ID = 'REQUEST_ID';
public const string ONLY_LIBRARY_ID = 'ONLY_LIBRARY_ID';
public const string ALT_NAME = 'ALT_NAME';
private function __construct()
{