Merge pull request #658 from arabcoders/dev
Add ValidateCommand for validating backend reference IDs.
This commit is contained in:
32
FAQ.md
32
FAQ.md
@@ -326,24 +326,28 @@ General error: 11 database disk image is malformed
|
||||
To repair the database, follow these steps:
|
||||
|
||||
```bash
|
||||
$ docker exec -ti watchstate bash
|
||||
$ sqlite3 /config/db/watchstate_v01.db '.dump' | sqlite3 /config/db/watchstate_v01-repaired.db
|
||||
$ docker exec -ti watchstate console db:repair /config/db/watchstate_v01.db
|
||||
```
|
||||
|
||||
Once the dump and rebuild are complete, perform an integrity check:
|
||||
> [!NOTE]
|
||||
> change `/config/db/watchstate_v01.db` to the path of your database file.
|
||||
|
||||
```bash
|
||||
$ sqlite3 /config/db/watchstate_v01-repaired.db 'PRAGMA integrity_check'
|
||||
You should get similar output to the following:
|
||||
|
||||
```
|
||||
INFO: Attempting to repair database '{db_name}'.
|
||||
INFO: Copied database '{db_name}' to '{db_name}.before.repair.db' as backup.
|
||||
INFO: Attempting to repair database '{db_name}'.
|
||||
INFO: Database '{db_name}' repaired successfully.
|
||||
INFO: Checking database integrity...
|
||||
INFO: SQLite3: ok
|
||||
INFO: Database '{db_name}' is valid.
|
||||
INFO: Updating database version to 1723988129.
|
||||
INFO: Renaming database '{db_name}.new.db' to '{db_name}'.
|
||||
INFO: Repair completed successfully. Database '{db_name}' is now valid.
|
||||
```
|
||||
|
||||
If the output is simply `ok`, the repaired database is valid. You can then replace the corrupted database with the
|
||||
repaired one:
|
||||
|
||||
```bash
|
||||
$ mv /config/db/watchstate_v01-repaired.db /config/db/watchstate_v01.db
|
||||
```
|
||||
|
||||
Your system should now use the repaired database without errors.
|
||||
If there are no errors, the database has been repaired successfully. And you can resume using the tool.
|
||||
|
||||
---
|
||||
|
||||
@@ -416,7 +420,7 @@ These environment variables relates to the tool itself, You should manage them v
|
||||
|
||||
> [!IMPORTANT]
|
||||
> for environment variables that has `{TASK}` tag, you **MUST** replace it with one of `IMPORT`, `EXPORT`, `BACKUP`,
|
||||
`PRUNE`, `INDEXES`.
|
||||
`PRUNE`, `INDEXES` or `VALIDATE`.
|
||||
|
||||
## Add tool specific environment variables
|
||||
|
||||
|
||||
25
composer.lock
generated
25
composer.lock
generated
@@ -3588,12 +3588,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Roave/SecurityAdvisories.git",
|
||||
"reference": "45b01f4e60c350f72a8697056674e449e053935a"
|
||||
"reference": "59be420c5cdc0c3c9cdae31804d32fefb515a918"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/45b01f4e60c350f72a8697056674e449e053935a",
|
||||
"reference": "45b01f4e60c350f72a8697056674e449e053935a",
|
||||
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/59be420c5cdc0c3c9cdae31804d32fefb515a918",
|
||||
"reference": "59be420c5cdc0c3c9cdae31804d32fefb515a918",
|
||||
"shasum": ""
|
||||
},
|
||||
"conflict": {
|
||||
@@ -3611,7 +3611,7 @@
|
||||
"airesvsg/acf-to-rest-api": "<=3.1",
|
||||
"akaunting/akaunting": "<2.1.13",
|
||||
"akeneo/pim-community-dev": "<5.0.119|>=6,<6.0.53",
|
||||
"alextselegidis/easyappointments": "<=1.5",
|
||||
"alextselegidis/easyappointments": "<=1.5.1",
|
||||
"alterphp/easyadmin-extension-bundle": ">=1.2,<1.2.11|>=1.3,<1.3.1",
|
||||
"amazing/media2click": ">=1,<1.3.3",
|
||||
"ameos/ameos_tarteaucitron": "<1.2.23",
|
||||
@@ -3715,7 +3715,7 @@
|
||||
"contao/managed-edition": "<=1.5",
|
||||
"corveda/phpsandbox": "<1.3.5",
|
||||
"cosenary/instagram": "<=2.3",
|
||||
"craftcms/cms": "<=4.14.14|>=5,<=5.6.16",
|
||||
"craftcms/cms": "<4.15.3|>=5,<5.7.5",
|
||||
"croogo/croogo": "<4",
|
||||
"cuyz/valinor": "<0.12",
|
||||
"czim/file-handling": "<1.5|>=2,<2.3",
|
||||
@@ -3948,6 +3948,7 @@
|
||||
"klaviyo/magento2-extension": ">=1,<3",
|
||||
"knplabs/knp-snappy": "<=1.4.2",
|
||||
"kohana/core": "<3.3.3",
|
||||
"koillection/koillection": "<1.6.12",
|
||||
"krayin/laravel-crm": "<=1.3",
|
||||
"kreait/firebase-php": ">=3.2,<3.8.1",
|
||||
"kumbiaphp/kumbiapp": "<=1.1.1",
|
||||
@@ -3966,7 +3967,7 @@
|
||||
"latte/latte": "<2.10.8",
|
||||
"lavalite/cms": "<=9|==10.1",
|
||||
"lcobucci/jwt": ">=3.4,<3.4.6|>=4,<4.0.4|>=4.1,<4.1.5",
|
||||
"league/commonmark": "<2.6",
|
||||
"league/commonmark": "<2.7",
|
||||
"league/flysystem": "<1.1.4|>=2,<2.1.1",
|
||||
"league/oauth2-server": ">=8.3.2,<8.4.2|>=8.5,<8.5.3",
|
||||
"leantime/leantime": "<3.3",
|
||||
@@ -4066,9 +4067,9 @@
|
||||
"nzo/url-encryptor-bundle": ">=4,<4.3.2|>=5,<5.0.1",
|
||||
"october/backend": "<1.1.2",
|
||||
"october/cms": "<1.0.469|==1.0.469|==1.0.471|==1.1.1",
|
||||
"october/october": "<=3.6.4",
|
||||
"october/october": "<3.7.5",
|
||||
"october/rain": "<1.0.472|>=1.1,<1.1.2",
|
||||
"october/system": "<1.0.476|>=1.1,<1.1.12|>=2,<2.2.34|>=3,<3.5.15",
|
||||
"october/system": "<3.7.5",
|
||||
"oliverklee/phpunit": "<3.5.15",
|
||||
"omeka/omeka-s": "<4.0.3",
|
||||
"onelogin/php-saml": "<2.10.4",
|
||||
@@ -4196,8 +4197,8 @@
|
||||
"serluck/phpwhois": "<=4.2.6",
|
||||
"sfroemken/url_redirect": "<=1.2.1",
|
||||
"sheng/yiicms": "<1.2.1",
|
||||
"shopware/core": "<6.5.8.17-dev|>=6.6,<6.6.10.3-dev|>=6.7.0.0-RC1-dev,<6.7.0.0-RC2-dev",
|
||||
"shopware/platform": "<6.5.8.17-dev|>=6.6,<6.6.10.3-dev|>=6.7.0.0-RC1-dev,<6.7.0.0-RC2-dev",
|
||||
"shopware/core": "<6.6.10.3-dev|>=6.7.0.0-RC1-dev,<6.7.0.0-RC2-dev",
|
||||
"shopware/platform": "<6.6.10.3-dev|>=6.7.0.0-RC1-dev,<6.7.0.0-RC2-dev",
|
||||
"shopware/production": "<=6.3.5.2",
|
||||
"shopware/shopware": "<=5.7.17",
|
||||
"shopware/storefront": "<=6.4.8.1|>=6.5.8,<6.5.8.7-dev",
|
||||
@@ -4240,7 +4241,7 @@
|
||||
"slim/slim": "<2.6",
|
||||
"slub/slub-events": "<3.0.3",
|
||||
"smarty/smarty": "<4.5.3|>=5,<5.1.1",
|
||||
"snipe/snipe-it": "<=7.0.13",
|
||||
"snipe/snipe-it": "<8.1",
|
||||
"socalnick/scn-social-auth": "<1.15.2",
|
||||
"socialiteproviders/steam": "<1.1",
|
||||
"spatie/browsershot": "<5.0.5",
|
||||
@@ -4510,7 +4511,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-05-01T20:05:59+00:00"
|
||||
"time": "2025-05-08T20:06:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/cli-parser",
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Commands\Events\DispatchCommand;
|
||||
use App\Commands\State\BackupCommand;
|
||||
use App\Commands\State\ExportCommand;
|
||||
use App\Commands\State\ImportCommand;
|
||||
use App\Commands\State\ValidateCommand;
|
||||
use App\Commands\System\IndexCommand;
|
||||
use App\Commands\System\PruneCommand;
|
||||
use App\Libs\Mappers\Import\MemoryMapper;
|
||||
@@ -17,13 +18,13 @@ use Monolog\Level;
|
||||
|
||||
return (function () {
|
||||
$inContainer = inContainer();
|
||||
$progressTimeCheck = fn (int $v, int $d): int => 0 === $v || $v >= 180 ? $v : $d;
|
||||
$progressTimeCheck = fn(int $v, int $d): int => 0 === $v || $v >= 180 ? $v : $d;
|
||||
|
||||
$config = [
|
||||
'name' => 'WatchState',
|
||||
'version' => '$(version_via_ci)',
|
||||
'tz' => env('WS_TZ', env('TZ', 'UTC')),
|
||||
'path' => fixPath(env('WS_DATA_PATH', fn () => $inContainer ? '/config' : __DIR__ . '/../var')),
|
||||
'path' => fixPath(env('WS_DATA_PATH', fn() => $inContainer ? '/config' : __DIR__ . '/../var')),
|
||||
'logs' => [
|
||||
'context' => (bool)env('WS_LOGS_CONTEXT', false),
|
||||
'prune' => [
|
||||
@@ -44,7 +45,7 @@ return (function () {
|
||||
'encode' => JSON_INVALID_UTF8_IGNORE | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Application-Version' => fn () => getAppVersion(),
|
||||
'X-Application-Version' => fn() => getAppVersion(),
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
],
|
||||
],
|
||||
@@ -66,11 +67,6 @@ return (function () {
|
||||
// -- Extra margin for marking item not found for backend in export mode. Default 3 days.
|
||||
'not_found' => (int)env('WS_EXPORT_NOT_FOUND', 259_200),
|
||||
],
|
||||
'episodes' => [
|
||||
'enable' => [
|
||||
'guid' => (bool)env('WS_EPISODES_ENABLE_GUID', false),
|
||||
],
|
||||
],
|
||||
'ignore' => [],
|
||||
'trust' => [
|
||||
'proxy' => (bool)env('WS_TRUST_PROXY', false),
|
||||
@@ -159,14 +155,14 @@ return (function () {
|
||||
|
||||
$config['profiler'] = [
|
||||
'save' => (bool)env('WS_PROFILER_SAVE', true),
|
||||
'path' => env('WS_PROFILER_PATH', fn () => ag($config, 'tmpDir') . '/profiler'),
|
||||
'path' => env('WS_PROFILER_PATH', fn() => ag($config, 'tmpDir') . '/profiler'),
|
||||
'collector' => env('WS_PROFILER_COLLECTOR', null),
|
||||
];
|
||||
|
||||
$config['cache'] = [
|
||||
'prefix' => env('WS_CACHE_PREFIX', null),
|
||||
'url' => env('WS_CACHE_URL', 'redis://127.0.0.1:6379'),
|
||||
'path' => env('WS_CACHE_PATH', fn () => ag($config, 'tmpDir') . '/cache'),
|
||||
'path' => env('WS_CACHE_PATH', fn() => ag($config, 'tmpDir') . '/cache'),
|
||||
];
|
||||
|
||||
$config['logger'] = [
|
||||
@@ -310,6 +306,14 @@ return (function () {
|
||||
'timer' => $checkTaskTimer((string)env('WS_CRON_INDEXES_AT', '0 3 * * 3'), '0 3 * * 3'),
|
||||
'args' => env('WS_CRON_INDEXES_ARGS', '-v'),
|
||||
],
|
||||
ValidateCommand::TASK_NAME => [
|
||||
'command' => ValidateCommand::ROUTE,
|
||||
'name' => ValidateCommand::TASK_NAME,
|
||||
'info' => 'Validate stored backends reference id against the backends.',
|
||||
'enabled' => (bool)env('WS_CRON_VALIDATE', true),
|
||||
'timer' => $checkTaskTimer((string)env('WS_CRON_VALIDATE_AT', '0 4 */14 * *'), '0 4 */14 * *'),
|
||||
'args' => env('WS_CRON_VALIDATE_ARGS', '-v'),
|
||||
],
|
||||
DispatchCommand::TASK_NAME => [
|
||||
'command' => DispatchCommand::ROUTE,
|
||||
'name' => DispatchCommand::TASK_NAME,
|
||||
|
||||
@@ -94,11 +94,6 @@ return (function () {
|
||||
'description' => 'Trigger full export mode if changes exceed this number.',
|
||||
'type' => 'int',
|
||||
],
|
||||
[
|
||||
'key' => 'WS_EPISODES_ENABLE_GUID',
|
||||
'description' => 'Enable Episodes GUID parsing.',
|
||||
'type' => 'bool',
|
||||
],
|
||||
[
|
||||
'key' => 'WS_BACKENDS_FILE',
|
||||
'description' => 'The full path to the backends file.',
|
||||
@@ -258,7 +253,7 @@ return (function () {
|
||||
};
|
||||
|
||||
// -- Do not forget to update the tasks list if you add a new task.
|
||||
$tasks = ['import', 'export', 'backup', 'prune', 'indexes'];
|
||||
$tasks = ['import', 'export', 'backup', 'prune', 'indexes', 'validate'];
|
||||
$task_env = [
|
||||
[
|
||||
'key' => 'WS_CRON_{TASK}',
|
||||
|
||||
@@ -29,6 +29,10 @@ html {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.is-text-break {
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.is-masked,
|
||||
.is-full-mask,
|
||||
.is-full-mask :not(figure) {
|
||||
|
||||
@@ -184,9 +184,20 @@ onMounted(async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (false === token.href.startsWith('#') && false === token.href.includes('/guides/')) {
|
||||
if (true === token.href.startsWith('#')) {
|
||||
return;
|
||||
}
|
||||
const urls = ['/FAQ.md', '/README.md', '/NEWS.md'];
|
||||
const list = ['/guides/', ...urls];
|
||||
if (false === list.some(l => token.href.includes(l))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (urls.some(l => token.href.includes(l))) {
|
||||
const url = new URL(token.href);
|
||||
url.pathname = `/guides${url.pathname}`;
|
||||
token.href = url.pathname;
|
||||
}
|
||||
|
||||
token.href = token.href.replace('/guides/', '/help/').replace('.md', '');
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</template>
|
||||
<template v-else>{{ title }}</template>
|
||||
</div>
|
||||
<div class="notification-content content" v-if="false === useToggle || toggle">
|
||||
<div class="notification-content content is-text-break" v-if="false === useToggle || toggle">
|
||||
<template v-if="message">{{ message }}</template>
|
||||
<slot/>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="column is-12 is-clearfix">
|
||||
<span class="title is-4">
|
||||
<span class="is-unselectable">
|
||||
<span class="icon"><i class="fas fa-history" /> </span>
|
||||
<span class="icon"><i class="fas fa-history"/> </span>
|
||||
<NuxtLink to="/history">History</NuxtLink>
|
||||
:
|
||||
</span>{{ headerTitle }}
|
||||
@@ -13,35 +13,35 @@
|
||||
<div class="field is-grouped">
|
||||
<p class="control">
|
||||
<button @click="api_show_photos = !api_show_photos" class="button is-purple"
|
||||
v-tooltip.bottom="`${api_show_photos ? 'Hide' : 'Show'} fanart`">
|
||||
<span class="icon"><i class="fas fa-image" /></span>
|
||||
v-tooltip.bottom="`${api_show_photos ? 'Hide' : 'Show'} fanart`">
|
||||
<span class="icon"><i class="fas fa-image"/></span>
|
||||
</button>
|
||||
</p>
|
||||
<p class="control" v-if="data?.files?.length > 0">
|
||||
<button @click="navigateTo(`/play/${data.id}`)" class="button has-text-white has-background-danger-50"
|
||||
v-tooltip.bottom="`${data.content_exists ? 'Play media' : 'Media is inaccessible'}`"
|
||||
:disabled="!data.content_exists">
|
||||
<span class="icon"><i class="fas fa-play" /></span>
|
||||
v-tooltip.bottom="`${data.content_exists ? 'Play media' : 'Media is inaccessible'}`"
|
||||
:disabled="!data.content_exists">
|
||||
<span class="icon"><i class="fas fa-play"/></span>
|
||||
</button>
|
||||
</p>
|
||||
<p class="control">
|
||||
<button class="button" @click="toggleWatched"
|
||||
:class="{ 'is-success': !data.watched, 'is-danger': data.watched }"
|
||||
v-tooltip.bottom="'Toggle watch state'">
|
||||
:class="{ 'is-success': !data.watched, 'is-danger': data.watched }"
|
||||
v-tooltip.bottom="'Toggle watch state'">
|
||||
<span class="icon">
|
||||
<i class="fas" :class="{ 'fa-eye-slash': data.watched, 'fa-eye': !data.watched }" />
|
||||
<i class="fas" :class="{ 'fa-eye-slash': data.watched, 'fa-eye': !data.watched }"/>
|
||||
</span>
|
||||
</button>
|
||||
</p>
|
||||
<p class="control">
|
||||
<button class="button is-danger" @click="deleteItem(data)" v-tooltip.bottom="'Delete the record'"
|
||||
:disabled="isDeleting || isLoading" :class="{ 'is-loading': isDeleting }">
|
||||
<span class="icon"><i class="fas fa-trash" /></span>
|
||||
:disabled="isDeleting || isLoading" :class="{ 'is-loading': isDeleting }">
|
||||
<span class="icon"><i class="fas fa-trash"/></span>
|
||||
</button>
|
||||
</p>
|
||||
<p class="control">
|
||||
<button class="button is-info" @click="loadContent(id)" :class="{ 'is-loading': isLoading }">
|
||||
<span class="icon"><i class="fas fa-sync" /></span>
|
||||
<span class="icon"><i class="fas fa-sync"/></span>
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
@@ -49,23 +49,23 @@
|
||||
<div class="subtitle is-5" v-if="data?.via && (data?.content_title || data?.content_overview)">
|
||||
<template v-if="data?.content_title">
|
||||
<span class="is-unselectable icon">
|
||||
<i class="fas fa-tv" :class="{ 'fa-tv': 'episode' === data.type, 'fa-film': 'movie' === data.type }" />
|
||||
<i class="fas fa-tv" :class="{ 'fa-tv': 'episode' === data.type, 'fa-film': 'movie' === data.type }"/>
|
||||
</span>
|
||||
{{ data?.content_title }}
|
||||
</template>
|
||||
<div v-if="data?.content_overview" class="is-hidden-mobile is-clickable"
|
||||
@click="expandOverview = !expandOverview" :class="{ 'is-text-overflow': !expandOverview }">
|
||||
@click="expandOverview = !expandOverview" :class="{ 'is-text-overflow': !expandOverview }">
|
||||
<span class="is-unselectable icon" v-if="!data?.content_title">
|
||||
<i class="fas fa-tv" :class="{ 'fa-tv': 'episode' === data.type, 'fa-film': 'movie' === data.type }" />
|
||||
<i class="fas fa-tv" :class="{ 'fa-tv': 'episode' === data.type, 'fa-film': 'movie' === data.type }"/>
|
||||
</span>
|
||||
{{ expandOverview ? data.content_overview : data.content_overview }}
|
||||
</div>
|
||||
<div v-if="data?.content_genres && data.content_genres.length > 0" class="is-hidden-mobile is-clickable"
|
||||
:class="{ 'is-text-overflow': !expandGenres }" @click="expandGenres = !expandGenres">
|
||||
:class="{ 'is-text-overflow': !expandGenres }" @click="expandGenres = !expandGenres">
|
||||
<span class="tag is-info is-clickable mr-1" v-for="(genre, id) in data.content_genres"
|
||||
:key="`head-genre-${id}`">
|
||||
<span class="icon"><i class="fas fa-tag" /></span>
|
||||
<span class="is-capitalized" v-text="genre" />
|
||||
:key="`head-genre-${id}`">
|
||||
<span class="icon"><i class="fas fa-tag"/></span>
|
||||
<span class="is-capitalized" v-text="genre"/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -73,23 +73,23 @@
|
||||
|
||||
<div class="column is-12" v-if="!data?.via && isLoading">
|
||||
<Message message_class="has-background-info-90 has-text-dark" title="Loading" icon="fas fa-spinner fa-spin"
|
||||
message="Loading data. Please wait..." />
|
||||
message="Loading data. Please wait..."/>
|
||||
</div>
|
||||
|
||||
<div class="column is-12" v-if="data?.not_reported_by && data.not_reported_by.length > 0">
|
||||
<Message message_class="has-background-warning-80 has-text-dark" icon="fas fa-exclamation-triangle"
|
||||
:toggle="show_history_page_warning" title="Warning" :use-toggle="true"
|
||||
@toggle="show_history_page_warning = !show_history_page_warning">
|
||||
:toggle="show_history_page_warning" title="Warning" :use-toggle="true"
|
||||
@toggle="show_history_page_warning = !show_history_page_warning">
|
||||
<p>
|
||||
<span class="icon"><i class="fas fa-exclamation" /></span>
|
||||
<span class="icon"><i class="fas fa-exclamation"/></span>
|
||||
There are no metadata regarding this <strong>{{ data.type }}</strong> from (
|
||||
<span class="tag mr-1 has-text-dark" v-for="backend in data.not_reported_by" :key="`nr-${backend}`">
|
||||
<NuxtLink :to="`/backend/${backend}`" v-text="backend" />
|
||||
<NuxtLink :to="`/backend/${backend}`" v-text="backend"/>
|
||||
</span>).
|
||||
</p>
|
||||
<h5 class="has-text-dark">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-question-circle" /></span>
|
||||
<span class="icon"><i class="fas fa-question-circle"/></span>
|
||||
<span>Possible reasons</span>
|
||||
</span>
|
||||
</h5>
|
||||
@@ -113,15 +113,15 @@
|
||||
<header class="card-header">
|
||||
<div class="card-header-title is-clickable is-unselectable" @click="data._toggle = !data._toggle">
|
||||
<span class="icon">
|
||||
<i class="fas" :class="{ 'fa-arrow-up': data?._toggle, 'fa-arrow-down': !data?._toggle }" />
|
||||
<i class="fas" :class="{ 'fa-arrow-up': data?._toggle, 'fa-arrow-down': !data?._toggle }"/>
|
||||
</span>
|
||||
<span>Latest local metadata via</span>
|
||||
</div>
|
||||
<div class="card-header-icon">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-server" /></span>
|
||||
<span class="icon"><i class="fas fa-server"/></span>
|
||||
<span>
|
||||
<NuxtLink :to="`/backend/${data.via}`" v-text="data.via" />
|
||||
<NuxtLink :to="`/backend/${data.via}`" v-text="data.via"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
@@ -130,17 +130,17 @@
|
||||
<div class="columns is-multiline is-mobile">
|
||||
<div class="column is-6">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-passport" /></span>
|
||||
<span class="icon"><i class="fas fa-passport"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">ID: </span>
|
||||
<NuxtLink :to="`/history/${data.id}`" v-text="data.id" />
|
||||
<NuxtLink :to="`/history/${data.id}`" v-text="data.id"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-6 has-text-right">
|
||||
<span class="icon-text" v-if="parseInt(data.progress)">
|
||||
<span class="icon"><i class="fas fa-bars-progress" /></span>
|
||||
<span class="icon"><i class="fas fa-bars-progress"/></span>
|
||||
<span><span class="is-hidden-mobile">Progress:</span> {{ formatDuration(data.progress) }}</span>
|
||||
</span>
|
||||
<span v-else>-</span>
|
||||
@@ -149,8 +149,8 @@
|
||||
<div class="column is-6 has-text-left">
|
||||
<span class="icon-text">
|
||||
<span class="icon">
|
||||
<i class="fas fa-eye-slash" v-if="!data.watched" />
|
||||
<i class="fas fa-eye" v-else />
|
||||
<i class="fas fa-eye-slash" v-if="!data.watched"/>
|
||||
<i class="fas fa-eye" v-else/>
|
||||
</span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Status:</span>
|
||||
@@ -160,7 +160,7 @@
|
||||
</div>
|
||||
<div class="column is-6 has-text-right">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-envelope" /></span>
|
||||
<span class="icon"><i class="fas fa-envelope"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Event:</span>
|
||||
{{ ag(data.extra, `${data.via}.event`, 'Unknown') }}
|
||||
@@ -169,11 +169,11 @@
|
||||
</div>
|
||||
<div class="column is-6 has-text-left">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-calendar" /></span>
|
||||
<span class="icon"><i class="fas fa-calendar"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Updated: </span>
|
||||
<span class="has-tooltip"
|
||||
v-tooltip="`Backend updated this record at: ${moment.unix(data.updated).format(TOOLTIP_DATE_FORMAT)}`">
|
||||
v-tooltip="`Backend updated this record at: ${moment.unix(data.updated).format(TOOLTIP_DATE_FORMAT)}`">
|
||||
{{ moment.unix(data.updated).fromNow() }}
|
||||
</span>
|
||||
</span>
|
||||
@@ -182,36 +182,36 @@
|
||||
|
||||
<div class="column is-6 has-text-right">
|
||||
<span class="icon-text">
|
||||
<span class="icon" v-if="'episode' === data.type"><i class="fas fa-tv" /></span>
|
||||
<span class="icon" v-else><i class="fas fa-film" /></span>
|
||||
<span class="icon" v-if="'episode' === data.type"><i class="fas fa-tv"/></span>
|
||||
<span class="icon" v-else><i class="fas fa-film"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Type: </span>
|
||||
<NuxtLink :to="makeSearchLink('type', data.type)" v-text="ucFirst(data.type)" />
|
||||
<NuxtLink :to="makeSearchLink('type', data.type)" v-text="ucFirst(data.type)"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-6 has-text-left" v-if="'episode' === data.type">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-tv" /></span>
|
||||
<span class="icon"><i class="fas fa-tv"/></span>
|
||||
<span><span class="is-hidden-mobile">Season: </span>
|
||||
<NuxtLink :to="makeSearchLink('season', data.season)" v-text="data.season" />
|
||||
<NuxtLink :to="makeSearchLink('season', data.season)" v-text="data.season"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-6 has-text-right" v-if="'episode' === data.type">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-tv" /></span>
|
||||
<span class="icon"><i class="fas fa-tv"/></span>
|
||||
<span><span class="is-hidden-mobile">Episode: </span>
|
||||
<NuxtLink :to="makeSearchLink('episode', data.episode)" v-text="data.episode" />
|
||||
<NuxtLink :to="makeSearchLink('episode', data.episode)" v-text="data.episode"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-12" v-if="data.guids && Object.keys(data.guids).length > 0">
|
||||
<span class="icon-text is-clickable" v-tooltip="'Globally unique identifier for this item'">
|
||||
<span class="icon"><i class="fas fa-link" /></span>
|
||||
<span class="icon"><i class="fas fa-link"/></span>
|
||||
<span>GUIDs: </span>
|
||||
</span>
|
||||
<span class="tag mr-1" v-for="(guid, source) in data.guids">
|
||||
@@ -223,7 +223,7 @@
|
||||
|
||||
<div class="column is-12" v-if="data.rguids && Object.keys(data.rguids).length > 0">
|
||||
<span class="icon-text is-clickable" v-tooltip="'Relative Globally unique identifier for this episode'">
|
||||
<span class="icon"><i class="fas fa-link" /></span>
|
||||
<span class="icon"><i class="fas fa-link"/></span>
|
||||
<span>rGUIDs: </span>
|
||||
</span>
|
||||
<span class="tag mr-1" v-for="(guid, source) in data.rguids">
|
||||
@@ -235,7 +235,7 @@
|
||||
|
||||
<div class="column is-12" v-if="data.parent && Object.keys(data.parent).length > 0">
|
||||
<span class="icon-text is-clickable" v-tooltip="'Globally unique identifier for the series'">
|
||||
<span class="icon"><i class="fas fa-link" /></span>
|
||||
<span class="icon"><i class="fas fa-link"/></span>
|
||||
<span>Series GUIDs: </span>
|
||||
</span>
|
||||
<span class="tag mr-1" v-for="(guid, source) in data.parent">
|
||||
@@ -247,27 +247,27 @@
|
||||
|
||||
<div class="column is-12" v-if="data?.content_title">
|
||||
<div class="is-text-overflow">
|
||||
<span class="icon"><i class="fas fa-heading" /></span>
|
||||
<span class="icon"><i class="fas fa-heading"/></span>
|
||||
<span class="is-hidden-mobile">Subtitle: </span>
|
||||
<NuxtLink :to="makeSearchLink('subtitle', data.content_title)" v-text="data.content_title" />
|
||||
<NuxtLink :to="makeSearchLink('subtitle', data.content_title)" v-text="data.content_title"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column is-12" v-if="data?.content_path">
|
||||
<div class="is-text-overflow">
|
||||
<span class="icon"><i class="fas fa-file" /></span>
|
||||
<span class="icon"><i class="fas fa-file"/></span>
|
||||
<span class="is-hidden-mobile">File: </span>
|
||||
<NuxtLink :to="makeSearchLink('path', data.content_path)" v-text="data.content_path" />
|
||||
<NuxtLink :to="makeSearchLink('path', data.content_path)" v-text="data.content_path"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column is-6 has-text-left" v-if="data.created_at">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-database" /></span>
|
||||
<span class="icon"><i class="fas fa-database"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Created: </span>
|
||||
<span class="has-tooltip"
|
||||
v-tooltip="`DB record created at: ${moment.unix(data.created_at).format(TOOLTIP_DATE_FORMAT)}`">
|
||||
v-tooltip="`DB record created at: ${moment.unix(data.created_at).format(TOOLTIP_DATE_FORMAT)}`">
|
||||
{{ moment.unix(data.created_at).fromNow() }}
|
||||
</span>
|
||||
</span>
|
||||
@@ -276,11 +276,11 @@
|
||||
|
||||
<div class="column is-6 has-text-right" v-if="data.updated_at">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-database" /></span>
|
||||
<span class="icon"><i class="fas fa-database"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Updated: </span>
|
||||
<span class="has-tooltip"
|
||||
v-tooltip="`DB record updated at: ${moment.unix(data.updated_at).format(TOOLTIP_DATE_FORMAT)}`">
|
||||
v-tooltip="`DB record updated at: ${moment.unix(data.updated_at).format(TOOLTIP_DATE_FORMAT)}`">
|
||||
{{ moment.unix(data.updated_at).fromNow() }}
|
||||
</span>
|
||||
</span>
|
||||
@@ -289,20 +289,20 @@
|
||||
|
||||
<div class="is-hidden-tablet column is-12" v-if="data?.content_genres && data?.content_genres.length > 0">
|
||||
<div class="is-clickable" :class="{ 'is-text-overflow': !expandGenres }"
|
||||
@click="expandGenres = !expandGenres">
|
||||
<span class="icon"><i class="fas fa-tag" /></span>
|
||||
@click="expandGenres = !expandGenres">
|
||||
<span class="icon"><i class="fas fa-tag"/></span>
|
||||
<span class="is-hidden-mobile">Genres: </span>
|
||||
<span class="tag is-info mr-1 is-capitalized" v-for="genre in data.content_genres"
|
||||
:key="`latest-${genre}`" v-text="genre" />
|
||||
:key="`latest-${genre}`" v-text="genre"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="is-hidden-tablet column is-12" v-if="data?.content_overview">
|
||||
<span class="icon"><i class="fas fa-comment" /></span>
|
||||
<span class="icon"><i class="fas fa-comment"/></span>
|
||||
<span>Content Summary</span>
|
||||
<br>
|
||||
<div class="is-clickable" :class="{ 'is-text-overflow': !expandOverview }"
|
||||
@click="expandOverview = !expandOverview">
|
||||
@click="expandOverview = !expandOverview">
|
||||
{{ data.content_overview }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -314,40 +314,62 @@
|
||||
|
||||
<div class="column is-12" v-if="data?.via && Object.keys(data.metadata).length > 0">
|
||||
<div class="card" v-for="(item, key) in data.metadata" :key="key"
|
||||
:class="{ 'is-success': parseInt(item.watched), 'transparent-bg': styleInfo }">
|
||||
:class="{ 'is-success': parseInt(item.watched), 'transparent-bg': styleInfo }">
|
||||
<header class="card-header">
|
||||
<div class="card-header-title is-clickable is-unselectable" @click="item._toggle = !item._toggle">
|
||||
<span class="icon">
|
||||
<i class="fas" :class="{ 'fa-arrow-up': item?._toggle, 'fa-arrow-down': !item?._toggle }" />
|
||||
<i class="fas" :class="{ 'fa-arrow-up': item?._toggle, 'fa-arrow-down': !item?._toggle }"/>
|
||||
</span>
|
||||
|
||||
<i class="fas" :class="{
|
||||
'fa-spinner fa-spin': undefined === item?.validated,
|
||||
'fa-check has-text-success': true === item?.validated,
|
||||
'fa-xmark has-text-danger': false === item?.validated,
|
||||
}"/>
|
||||
Metadata via
|
||||
</div>
|
||||
<div class="card-header-icon">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-server" /></span>
|
||||
<span>
|
||||
<NuxtLink :to="`/backend/${key}`" v-text="key" />
|
||||
</span>
|
||||
</span>
|
||||
<div class="field is-grouped">
|
||||
<div class="control"
|
||||
v-if="false === item?.validated">
|
||||
<NuxtLink
|
||||
@click="Object.keys(data.metadata).length > 1 ? deleteMetadata(data,key) : deleteItem(data)">
|
||||
<span class="icon-text has-text-danger">
|
||||
<span class="icon"><i class="fas fa-trash"/></span>
|
||||
<span>Delete</span>
|
||||
</span>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
<div class="control">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-server"/></span>
|
||||
<span>
|
||||
<NuxtLink :to="`/backend/${key}`" v-text="key"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="card-content" v-if="item?._toggle">
|
||||
<div class="columns is-multiline is-mobile">
|
||||
|
||||
<div class="column is-12" v-if="false === item?.validated && item.validated_message">
|
||||
<span class="has-text-danger">({{ item.validated_message }})</span>
|
||||
</div>
|
||||
<div class="column is-6">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-passport" /></span>
|
||||
<span class="icon"><i class="fas fa-passport"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">ID: </span>
|
||||
<NuxtLink :to="item?.webUrl" target="_blank" v-text="item.id" v-if="item?.webUrl" />
|
||||
<span v-else v-text="item.id" />
|
||||
<NuxtLink :to="item?.webUrl" target="_blank" v-text="item.id" v-if="item?.webUrl"/>
|
||||
<span v-else v-text="item.id"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-6 has-text-right">
|
||||
<span class="icon-text" v-if="parseInt(item?.progress)">
|
||||
<span class="icon"><i class="fas fa-bars-progress" /></span>
|
||||
<span class="icon"><i class="fas fa-bars-progress"/></span>
|
||||
<span><span class="is-hidden-mobile">Progress:</span> {{ formatDuration(item.progress) }}</span>
|
||||
</span>
|
||||
<span v-else>-</span>
|
||||
@@ -356,7 +378,7 @@
|
||||
<div class="column is-6">
|
||||
<span class="icon-text">
|
||||
<span class="icon">
|
||||
<i class="fas fa-eye-slash" :class="parseInt(item.watched) ? 'fa-eye-slash' : 'fa-eye'" />
|
||||
<i class="fas fa-eye-slash" :class="parseInt(item.watched) ? 'fa-eye-slash' : 'fa-eye'"/>
|
||||
</span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Status:</span>
|
||||
@@ -367,7 +389,7 @@
|
||||
|
||||
<div class="column is-6 has-text-right">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-envelope" /></span>
|
||||
<span class="icon"><i class="fas fa-envelope"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Event:</span>
|
||||
{{ ag(data.extra, `${key}.event`, 'Unknown') }}
|
||||
@@ -377,11 +399,11 @@
|
||||
|
||||
<div class="column is-6">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-calendar" /></span>
|
||||
<span class="icon"><i class="fas fa-calendar"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Updated: </span>
|
||||
<span class="has-tooltip"
|
||||
v-tooltip="`Backend last activity: ${getMoment(ag(data.extra, `${key}.received_at`, data.updated)).format(TOOLTIP_DATE_FORMAT)}`">
|
||||
v-tooltip="`Backend last activity: ${getMoment(ag(data.extra, `${key}.received_at`, data.updated)).format(TOOLTIP_DATE_FORMAT)}`">
|
||||
{{ getMoment(ag(data.extra, `${key}.received_at`, data.updated)).fromNow() }}
|
||||
</span>
|
||||
</span>
|
||||
@@ -390,38 +412,38 @@
|
||||
|
||||
<div class="column is-6 has-text-right">
|
||||
<span class="icon-text">
|
||||
<span class="icon" v-if="'episode' === item.type"><i class="fas fa-tv" /></span>
|
||||
<span class="icon" v-else><i class="fas fa-film" /></span>
|
||||
<span class="icon" v-if="'episode' === item.type"><i class="fas fa-tv"/></span>
|
||||
<span class="icon" v-else><i class="fas fa-film"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Type: </span>
|
||||
<NuxtLink :to="makeSearchLink('type', item.type)" v-text="ucFirst(item.type)" />
|
||||
<NuxtLink :to="makeSearchLink('type', item.type)" v-text="ucFirst(item.type)"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-6" v-if="'episode' === item.type">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-tv" /></span>
|
||||
<span class="icon"><i class="fas fa-tv"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Season: </span>
|
||||
<NuxtLink :to="makeSearchLink('season', item.season)" v-text="item.season" />
|
||||
<NuxtLink :to="makeSearchLink('season', item.season)" v-text="item.season"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-6 has-text-right" v-if="'episode' === item.type">
|
||||
<span class="icon-text">
|
||||
<span class="icon"><i class="fas fa-tv" /></span>
|
||||
<span class="icon"><i class="fas fa-tv"/></span>
|
||||
<span>
|
||||
<span class="is-hidden-mobile">Episode: </span>
|
||||
<NuxtLink :to="makeSearchLink('episode', item.episode)" v-text="item.episode" />
|
||||
<NuxtLink :to="makeSearchLink('episode', item.episode)" v-text="item.episode"/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-12" v-if="item.guids && Object.keys(item.guids).length > 0">
|
||||
<span class="icon-text is-clickable" v-tooltip="'Globally unique identifier for this item'">
|
||||
<span class="icon"><i class="fas fa-link" /></span>
|
||||
<span class="icon"><i class="fas fa-link"/></span>
|
||||
<span>GUIDs: </span>
|
||||
</span>
|
||||
<span class="tag mr-1" v-for="(guid, source) in item.guids">
|
||||
@@ -433,7 +455,7 @@
|
||||
|
||||
<div class="column is-12" v-if="item.parent && Object.keys(item.parent).length > 0">
|
||||
<span class="is-clickable icon-text" v-tooltip="'Globally unique identifier for the series'">
|
||||
<span class="icon"><i class="fas fa-link" /></span>
|
||||
<span class="icon"><i class="fas fa-link"/></span>
|
||||
<span>Series GUIDs: </span>
|
||||
</span>
|
||||
<span class="tag mr-1" v-for="(guid, source) in item.parent">
|
||||
@@ -445,37 +467,37 @@
|
||||
|
||||
<div class="column is-12" v-if="item?.extra?.title">
|
||||
<div class="is-text-overflow">
|
||||
<span class="icon"><i class="fas fa-heading" /></span>
|
||||
<span class="icon"><i class="fas fa-heading"/></span>
|
||||
<span class="is-hidden-mobile">Subtitle: </span>
|
||||
<NuxtLink :to="makeSearchLink('subtitle', item.extra.title)" v-text="item.extra.title" />
|
||||
<NuxtLink :to="makeSearchLink('subtitle', item.extra.title)" v-text="item.extra.title"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column is-12" v-if="item?.extra?.genres && item.extra.genres.length > 0">
|
||||
<div class="is-clickable" :class="{ 'is-text-overflow': !item?.expandGenres }"
|
||||
@click="item.expandGenres = !item?.expandGenres">
|
||||
<span class="icon"><i class="fas fa-tag" /></span>
|
||||
@click="item.expandGenres = !item?.expandGenres">
|
||||
<span class="icon"><i class="fas fa-tag"/></span>
|
||||
<span class="is-hidden-mobile">Genres: </span>
|
||||
<span class="tag is-info mr-1 is-capitalized" v-for="genre in item.extra.genres"
|
||||
:key="`${item.id}-${genre}`" v-text="genre" />
|
||||
:key="`${item.id}-${genre}`" v-text="genre"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column is-12" v-if="item?.extra?.overview">
|
||||
<span class="icon"><i class="fas fa-comment" /></span>
|
||||
<span class="icon"><i class="fas fa-comment"/></span>
|
||||
<span>Content Summary</span>
|
||||
<br>
|
||||
<div class="is-clickable" :class="{ 'is-text-overflow': !item?.expandOverview }"
|
||||
@click="item.expandOverview = !item?.expandOverview">
|
||||
@click="item.expandOverview = !item?.expandOverview">
|
||||
{{ item.extra.overview }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column is-12" v-if="item?.path">
|
||||
<div class="is-text-overflow">
|
||||
<span class="icon"><i class="fas fa-file" /></span>
|
||||
<span class="icon"><i class="fas fa-file"/></span>
|
||||
<span class="is-hidden-mobile">File: </span>
|
||||
<NuxtLink :to="makeSearchLink('path', item.path)" v-text="item.path" />
|
||||
<NuxtLink :to="makeSearchLink('path', item.path)" v-text="item.path"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -490,8 +512,8 @@
|
||||
<span class="title is-4 is-clickable" @click="showRawData = !showRawData">
|
||||
<span class="icon-text">
|
||||
<span class="icon">
|
||||
<i v-if="showRawData" class="fas fa-arrow-up" />
|
||||
<i v-else class="fas fa-arrow-down" />
|
||||
<i v-if="showRawData" class="fas fa-arrow-up"/>
|
||||
<i v-else class="fas fa-arrow-down"/>
|
||||
</span>
|
||||
<span>Show raw unfiltered data</span>
|
||||
</span>
|
||||
@@ -499,23 +521,23 @@
|
||||
<p class="subtitle">Useful for debugging.</p>
|
||||
<div v-if="showRawData" class="mt-2" style="position: relative; max-height: 400px; overflow-y: auto;">
|
||||
<code class="is-terminal is-block is-pre-wrap p-4">{{
|
||||
JSON.stringify(Object.keys(data)
|
||||
.filter(key => !['files', 'hardware', 'content_exists', '_toggle'].includes(key))
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = data[key];
|
||||
return obj;
|
||||
}, {}), null, 2)
|
||||
}}</code>
|
||||
JSON.stringify(Object.keys(data)
|
||||
.filter(key => !['files', 'hardware', 'content_exists', '_toggle'].includes(key))
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = data[key];
|
||||
return obj;
|
||||
}, {}), null, 2)
|
||||
}}</code>
|
||||
<button class="button m-4" v-tooltip="'Copy text'" @click="() => copyText(JSON.stringify(data, null, 2))"
|
||||
style="position: absolute; top:0; right:0;">
|
||||
<span class="icon"><i class="fas fa-copy" /></span>
|
||||
style="position: absolute; top:0; right:0;">
|
||||
<span class="icon"><i class="fas fa-copy"/></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column is-12">
|
||||
<Message message_class="has-background-info-90 has-text-dark" :toggle="show_page_tips"
|
||||
@toggle="show_page_tips = !show_page_tips" :use-toggle="true" title="Tips" icon="fas fa-info-circle">
|
||||
@toggle="show_page_tips = !show_page_tips" :use-toggle="true" title="Tips" icon="fas fa-info-circle">
|
||||
<ul>
|
||||
<li>
|
||||
To see if your media backends are reporting different metadata for the same file, click on the file link
|
||||
@@ -527,7 +549,7 @@
|
||||
</li>
|
||||
<li>
|
||||
<code>rGUIDSs</code> are relative globally unique identifiers for episodes based on <code>series
|
||||
GUID</code>. They are formatted as <code>GUID://seriesID/season_number/episode_number</code>. We use
|
||||
GUID</code>. They are formatted as <code>GUID://seriesID/season_number/episode_number</code>. We use
|
||||
<code>rGUIDs</code>, to identify specific episode. This is more reliable than using episode specific
|
||||
<code>GUID</code>, as they are often misreported in the source data.
|
||||
</li>
|
||||
@@ -563,12 +585,12 @@ import {
|
||||
ucFirst
|
||||
} from '~/utils/index'
|
||||
import moment from 'moment'
|
||||
import { useBreakpoints, useStorage } from '@vueuse/core'
|
||||
import {useBreakpoints, useStorage} from '@vueuse/core'
|
||||
import Message from '~/components/Message'
|
||||
|
||||
const id = useRoute().params.id
|
||||
|
||||
useHead({ title: `History : ${id}` })
|
||||
useHead({title: `History : ${id}`})
|
||||
|
||||
const isLoading = ref(true)
|
||||
const showRawData = ref(false)
|
||||
@@ -576,8 +598,8 @@ const show_page_tips = useStorage('show_page_tips', true)
|
||||
const api_show_photos = useStorage('api_show_photos', true)
|
||||
const show_history_page_warning = useStorage('show_history_page_warning', true)
|
||||
const isDeleting = ref(false)
|
||||
const breakpoints = useBreakpoints({ mobile: 0, desktop: 640 })
|
||||
const loadedImages = ref({ poster: null, background: null })
|
||||
const breakpoints = useBreakpoints({mobile: 0, desktop: 640})
|
||||
const loadedImages = ref({poster: null, background: null})
|
||||
const expandOverview = ref(false)
|
||||
const expandGenres = ref(false)
|
||||
|
||||
@@ -619,7 +641,7 @@ const loadContent = async (id) => {
|
||||
if (200 !== response.status) {
|
||||
notification('Error', 'Error loading data', `${json.error.code}: ${json.error.message}`);
|
||||
if (404 === response.status) {
|
||||
await navigateTo({ name: 'history' })
|
||||
await navigateTo({name: 'history'})
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -627,8 +649,10 @@ const loadContent = async (id) => {
|
||||
data.value = json
|
||||
data.value._toggle = true
|
||||
|
||||
useHead({ title: `History : ${makeName(json) ?? id}` })
|
||||
useHead({title: `History : ${makeName(json) ?? id}`})
|
||||
await loadImage()
|
||||
await nextTick();
|
||||
await validateItem()
|
||||
}
|
||||
|
||||
watch(breakpoints.active(), async () => await loadImage())
|
||||
@@ -669,14 +693,14 @@ const deleteItem = async (item) => {
|
||||
return
|
||||
}
|
||||
|
||||
if (!confirm(`Are you sure you want to delete '${makeName(item)}'?`)) {
|
||||
if (!confirm(`Delete '${makeName(item)}' local record?`)) {
|
||||
return
|
||||
}
|
||||
|
||||
isDeleting.value = true
|
||||
|
||||
try {
|
||||
const response = await request(`/history/${id}`, { method: 'DELETE' })
|
||||
const response = await request(`/history/${id}`, {method: 'DELETE'})
|
||||
|
||||
if (200 !== response.status) {
|
||||
const json = await response.json()
|
||||
@@ -685,7 +709,7 @@ const deleteItem = async (item) => {
|
||||
}
|
||||
|
||||
notification('success', 'Success!', `Deleted '${makeName(item)}'.`)
|
||||
await navigateTo({ name: 'history' })
|
||||
await navigateTo({name: 'history'})
|
||||
} catch (e) {
|
||||
notification('error', 'Error', e.message)
|
||||
} finally {
|
||||
@@ -720,6 +744,48 @@ const toggleWatched = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const validateItem = async () => {
|
||||
try {
|
||||
const response = await request(`/history/${id}/validate`)
|
||||
|
||||
if (!response.ok) {
|
||||
return
|
||||
}
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
for (const [backend, item] of Object.entries(json)) {
|
||||
if (data.value.metadata[backend] === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
data.value.metadata[backend]['validated'] = item.status
|
||||
data.value.metadata[backend]['validated_message'] = item.message
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
const deleteMetadata = async (item, backend) => {
|
||||
if (!confirm(`Remove '${backend}' metadata from '${makeName(item)}' data?`)) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await request(`/history/${id}/metadata/${backend}`, {method: 'DELETE'})
|
||||
|
||||
if (200 !== response.status) {
|
||||
const json = await parse_api_response(response)
|
||||
notification('error', 'Error', `${json.error.code}: ${json.error.message}`)
|
||||
return
|
||||
}
|
||||
|
||||
notification('success', 'Success!', `Deleted '${backend}' metadata.`)
|
||||
await loadContent(id);
|
||||
} catch (e) {
|
||||
notification('error', 'Error', `Request error. ${e}`)
|
||||
}
|
||||
}
|
||||
|
||||
const getMoment = (time) => time.toString().length < 13 ? moment.unix(time) : moment(time)
|
||||
const headerTitle = computed(() => isLoading.value ? id : makeName(data.value))
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Libs\Attributes\Route\Get;
|
||||
use App\Libs\Attributes\Route\Route;
|
||||
use App\Libs\Container;
|
||||
use App\Libs\DataUtil;
|
||||
use App\Libs\Entity\StateEntity;
|
||||
use App\Libs\Entity\StateInterface as iState;
|
||||
use App\Libs\Enums\Http\Method;
|
||||
use App\Libs\Enums\Http\Status;
|
||||
@@ -19,12 +20,15 @@ use App\Libs\Exceptions\RuntimeException;
|
||||
use App\Libs\Guid;
|
||||
use App\Libs\Mappers\Import\DirectMapper;
|
||||
use App\Libs\Mappers\ImportInterface as iImport;
|
||||
use App\Libs\Options;
|
||||
use App\Libs\Traits\APITraits;
|
||||
use DateInterval;
|
||||
use JsonException;
|
||||
use PDO;
|
||||
use Psr\Http\Message\ResponseInterface as iResponse;
|
||||
use Psr\Http\Message\ServerRequestInterface as iRequest;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Psr\SimpleCache\CacheInterface as iCache;
|
||||
use SplFileInfo;
|
||||
use Throwable;
|
||||
|
||||
@@ -689,6 +693,111 @@ final class Index
|
||||
return $this->read($request, $id);
|
||||
}
|
||||
|
||||
#[Get(self::URL . '/{id:\d+}/validate[/]', name: 'history.validate')]
|
||||
public function validate_item(iCache $cache, iRequest $request, string $id): iResponse
|
||||
{
|
||||
try {
|
||||
$userContext = $this->getUserContext(request: $request, mapper: $this->mapper, logger: $this->logger);
|
||||
} catch (RuntimeException $e) {
|
||||
return api_error($e->getMessage(), Status::NOT_FOUND);
|
||||
}
|
||||
|
||||
$entity = Container::get(iState::class)::fromArray([iState::COLUMN_ID => $id]);
|
||||
|
||||
if (null === ($item = $userContext->db->get($entity))) {
|
||||
return api_error('Item Not found', Status::NOT_FOUND);
|
||||
}
|
||||
|
||||
$cacheKey = r('validate_item_{id}_{user}_{backends}', [
|
||||
'id' => $item->id,
|
||||
'user' => $userContext->name,
|
||||
'backends' => md5(implode(',', array_keys($item->getMetadata()))),
|
||||
]);
|
||||
|
||||
try {
|
||||
if (null !== ($cached = $cache->get($cacheKey))) {
|
||||
return api_response(Status::OK, $cached, headers: ['X-Cache' => 'HIT']);
|
||||
}
|
||||
} catch (Throwable) {
|
||||
// Ignore cache errors.
|
||||
}
|
||||
|
||||
$validation = [];
|
||||
|
||||
foreach ($item->getMetadata() as $name => $metadata) {
|
||||
$id = ag($metadata, StateEntity::COLUMN_ID, null);
|
||||
$validation[$name] = [
|
||||
'id' => $id,
|
||||
'status' => false,
|
||||
'message' => 'Item not found.',
|
||||
];
|
||||
|
||||
if (null === $userContext->config->get($name)) {
|
||||
$validation[$name]['message'] = 'Backend not found.';
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null === $id) {
|
||||
$validation[$name]['message'] = 'Item ID is missing.';
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$client = $this->getClient(name: $name, userContext: $userContext);
|
||||
$item = $client->getMetadata($id, [Options::NO_LOGGING => true]);
|
||||
if (count($item) > 0) {
|
||||
$validation[$name]['status'] = true;
|
||||
$validation[$name]['message'] = 'Item found.';
|
||||
} else {
|
||||
$validation[$name]['status'] = false;
|
||||
$validation[$name]['message'] = 'Item not found.';
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$validation[$name]['message'] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$cache->set($cacheKey, $validation, new DateInterval('PT10M'));
|
||||
} catch (Throwable) {
|
||||
// Ignore cache errors.
|
||||
}
|
||||
|
||||
return api_response(Status::OK, $validation, headers: ['X-Cache' => 'MISS']);
|
||||
}
|
||||
|
||||
#[Delete(self::URL . '/{id:\d+}/metadata/{backend}[/]', name: 'history.metadata.delete')]
|
||||
public function delete_item_metadata(iRequest $request, string $id, string $backend): iResponse
|
||||
{
|
||||
try {
|
||||
$userContext = $this->getUserContext(request: $request, mapper: $this->mapper, logger: $this->logger);
|
||||
} catch (RuntimeException $e) {
|
||||
return api_error($e->getMessage(), Status::NOT_FOUND);
|
||||
}
|
||||
|
||||
$entity = Container::get(iState::class)::fromArray([iState::COLUMN_ID => $id]);
|
||||
|
||||
if (null === ($item = $userContext->db->get($entity))) {
|
||||
return api_error('Item Not found', Status::NOT_FOUND);
|
||||
}
|
||||
|
||||
if (null === ($item->getMetadata($backend) ?? null)) {
|
||||
return api_error('Item metadata not found.', Status::NOT_FOUND);
|
||||
}
|
||||
|
||||
if (count($item->removeMetadata($backend)) < 1) {
|
||||
return api_error('Item metadata not found.', Status::NOT_FOUND);
|
||||
}
|
||||
|
||||
if (count($item->getMetadata()) < 1) {
|
||||
$userContext->db->remove($item);
|
||||
return api_message('Record deleted.', Status::OK);
|
||||
}
|
||||
|
||||
$userContext->db->update($item);
|
||||
return $this->read($request, $id);
|
||||
}
|
||||
|
||||
#[Get(self::URL . '/{id:\d+}/images/{type:poster|background}[/]', name: 'history.item.images')]
|
||||
public function images(iRequest $request, string $id, string $type): iResponse
|
||||
{
|
||||
|
||||
@@ -88,7 +88,7 @@ final class ParseWebhook
|
||||
{
|
||||
return $this->tryResponse(
|
||||
context: $context,
|
||||
fn: fn () => $this->parse($context, $guid, $request),
|
||||
fn: fn() => $this->parse($context, $guid, $request),
|
||||
action: $this->action,
|
||||
);
|
||||
}
|
||||
@@ -153,7 +153,7 @@ final class ParseWebhook
|
||||
}
|
||||
|
||||
try {
|
||||
$resp = Container::get(GetMetaData::class)(context: $context, id: $id, opts:[
|
||||
$resp = Container::get(GetMetaData::class)(context: $context, id: $id, opts: [
|
||||
Options::LOG_CONTEXT => ['request' => $json],
|
||||
]);
|
||||
if (!$resp->isSuccessful()) {
|
||||
@@ -207,16 +207,8 @@ final class ParseWebhook
|
||||
],
|
||||
];
|
||||
|
||||
$enableGUID = (bool)Config::get('episodes.enable.guid');
|
||||
|
||||
if (EmbyClient::TYPE_EPISODE === $type && false === $enableGUID) {
|
||||
$guids = [];
|
||||
} else {
|
||||
$guids = $guid->get(guids: ag($json, 'Item.ProviderIds', []), context: $logContext);
|
||||
}
|
||||
|
||||
$fields = [
|
||||
iState::COLUMN_GUIDS => $guids,
|
||||
iState::COLUMN_GUIDS => $guid->get(guids: ag($json, 'Item.ProviderIds', []), context: $logContext),
|
||||
iState::COLUMN_META_DATA => [
|
||||
$context->backendName => [
|
||||
iState::COLUMN_GUIDS => $guid->parse(
|
||||
@@ -263,7 +255,7 @@ final class ParseWebhook
|
||||
context: $context,
|
||||
guid: $guid,
|
||||
item: $obj,
|
||||
opts: ['override' => $fields, Options::ENABLE_EPISODE_GUID => $enableGUID],
|
||||
opts: ['override' => $fields],
|
||||
)->setIsTainted(isTainted: true === in_array($event, self::WEBHOOK_TAINTED_EVENTS));
|
||||
|
||||
if (false === $entity->hasGuids() && false === $entity->hasRelativeGuid()) {
|
||||
|
||||
@@ -238,7 +238,6 @@ class EmbyClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: $after,
|
||||
opts: [Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid')]
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -261,10 +260,7 @@ class EmbyClient implements iClient
|
||||
context: $this->context,
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
opts: ag_sets($opts, [
|
||||
'writer' => $writer,
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid'),
|
||||
])
|
||||
opts: ag_sets($opts, ['writer' => $writer])
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -288,10 +284,7 @@ class EmbyClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: $after,
|
||||
opts: [
|
||||
'queue' => $queue,
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid'),
|
||||
],
|
||||
opts: ['queue' => $queue],
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -447,10 +440,7 @@ class EmbyClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: null,
|
||||
opts: ag_sets($opts, [
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid'),
|
||||
Options::ONLY_LIBRARY_ID => $libraryId,
|
||||
])
|
||||
opts: ag_sets($opts, [Options::ONLY_LIBRARY_ID => $libraryId])
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
|
||||
@@ -73,7 +73,7 @@ final class ParseWebhook
|
||||
*/
|
||||
public function __invoke(Context $context, iGuid $guid, iRequest $request): Response
|
||||
{
|
||||
return $this->tryResponse(context: $context, fn: fn () => $this->parse($context, $guid, $request));
|
||||
return $this->tryResponse(context: $context, fn: fn() => $this->parse($context, $guid, $request));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,8 +166,6 @@ final class ParseWebhook
|
||||
],
|
||||
];
|
||||
|
||||
$enableGUID = (bool)Config::get('episodes.enable.guid');
|
||||
|
||||
$providersId = [];
|
||||
|
||||
foreach (array_change_key_case($json, CASE_LOWER) as $key => $val) {
|
||||
@@ -177,15 +175,9 @@ final class ParseWebhook
|
||||
$providersId[after($key, 'provider_')] = $val;
|
||||
}
|
||||
|
||||
if (JFC::TYPE_EPISODE === $type && false === $enableGUID) {
|
||||
$guids = [];
|
||||
} else {
|
||||
$guids = $guid->get(guids: $providersId, context: $logContext);
|
||||
}
|
||||
|
||||
$fields = [
|
||||
iState::COLUMN_WATCHED => (int)$isPlayed,
|
||||
iState::COLUMN_GUIDS => $guids,
|
||||
iState::COLUMN_GUIDS => $guid->get(guids: $providersId, context: $logContext),
|
||||
iState::COLUMN_META_DATA => [
|
||||
$context->backendName => [
|
||||
iState::COLUMN_WATCHED => true === $isPlayed ? '1' : '0',
|
||||
@@ -227,7 +219,7 @@ final class ParseWebhook
|
||||
context: $context,
|
||||
guid: $guid,
|
||||
item: $obj,
|
||||
opts: ['override' => $fields, Options::ENABLE_EPISODE_GUID => $enableGUID],
|
||||
opts: ['override' => $fields],
|
||||
)->setIsTainted(isTainted: true === in_array($event, self::WEBHOOK_TAINTED_EVENTS));
|
||||
|
||||
if (false === $entity->hasGuids() && false === $entity->hasRelativeGuid()) {
|
||||
|
||||
@@ -93,19 +93,13 @@ trait JellyfinActionTrait
|
||||
],
|
||||
];
|
||||
|
||||
if (iState::TYPE_EPISODE === $type && false === (bool)ag($opts, Options::ENABLE_EPISODE_GUID, false)) {
|
||||
$guids = [];
|
||||
} else {
|
||||
$guids = $guid->get(guids: ag($item, 'ProviderIds', []), context: $logContext);
|
||||
}
|
||||
|
||||
$builder = [
|
||||
iState::COLUMN_TYPE => $type,
|
||||
iState::COLUMN_UPDATED => makeDate($date)->getTimestamp(),
|
||||
iState::COLUMN_WATCHED => (int)$isPlayed,
|
||||
iState::COLUMN_VIA => $context->backendName,
|
||||
iState::COLUMN_TITLE => ag($item, ['Name', 'OriginalTitle'], '??'),
|
||||
iState::COLUMN_GUIDS => $guids,
|
||||
iState::COLUMN_GUIDS => $guid->get(guids: ag($item, 'ProviderIds', []), context: $logContext),
|
||||
iState::COLUMN_META_DATA => [
|
||||
$context->backendName => [
|
||||
iState::COLUMN_ID => (string)ag($item, 'Id'),
|
||||
@@ -126,7 +120,8 @@ trait JellyfinActionTrait
|
||||
$metadata = &$builder[iState::COLUMN_META_DATA][$context->backendName];
|
||||
$metadataExtra = &$metadata[iState::COLUMN_META_DATA_EXTRA];
|
||||
|
||||
$metadataExtra[iState::COLUMN_META_DATA_EXTRA_GENRES] = array_map(fn ($v) => strtolower($v), ag($item, 'Genres', []));
|
||||
$metadataExtra[iState::COLUMN_META_DATA_EXTRA_GENRES] = array_map(fn($v) => strtolower($v),
|
||||
ag($item, 'Genres', []));
|
||||
|
||||
// -- jellyfin/emby API does not provide library ID.
|
||||
if (null !== ($library = $opts[iState::COLUMN_META_LIBRARY] ?? null)) {
|
||||
@@ -159,7 +154,7 @@ trait JellyfinActionTrait
|
||||
|
||||
if (count($metadataExtra[iState::COLUMN_META_DATA_EXTRA_GENRES]) < 1) {
|
||||
$metadataExtra[iState::COLUMN_META_DATA_EXTRA_GENRES] = array_map(
|
||||
fn ($v) => strtolower($v),
|
||||
fn($v) => strtolower($v),
|
||||
ag($this->getItemDetails(context: $context, id: $parentId), 'Genres', [])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ class JellyfinClient implements iClient
|
||||
|
||||
if (false === $response->isSuccessful()) {
|
||||
throw new HttpException(
|
||||
ag($response->extra, 'message', fn () => $response->error->format()),
|
||||
ag($response->extra, 'message', fn() => $response->error->format()),
|
||||
ag($response->extra, 'http_code', 400),
|
||||
);
|
||||
}
|
||||
@@ -265,7 +265,6 @@ class JellyfinClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: $after,
|
||||
opts: [Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid')]
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -288,10 +287,7 @@ class JellyfinClient implements iClient
|
||||
context: $this->context,
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
opts: ag_sets($opts, [
|
||||
'writer' => $writer,
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid')
|
||||
])
|
||||
opts: ag_sets($opts, ['writer' => $writer])
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -315,10 +311,7 @@ class JellyfinClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: $after,
|
||||
opts: [
|
||||
'queue' => $queue,
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid'),
|
||||
],
|
||||
opts: ['queue' => $queue],
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -498,10 +491,7 @@ class JellyfinClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: null,
|
||||
opts: ag_sets($opts, [
|
||||
Options::ONLY_LIBRARY_ID => $libraryId,
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid'),
|
||||
])
|
||||
opts: ag_sets($opts, [Options::ONLY_LIBRARY_ID => $libraryId])
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -788,7 +778,7 @@ class JellyfinClient implements iClient
|
||||
private function throwError(Response $response, string $className = RuntimeException::class, int $code = 0): void
|
||||
{
|
||||
throw new $className(
|
||||
message: ag($response->extra, 'message', fn () => $response->error->format()),
|
||||
message: ag($response->extra, 'message', fn() => $response->error->format()),
|
||||
code: $code,
|
||||
previous: $response->error->previous
|
||||
);
|
||||
|
||||
@@ -268,27 +268,19 @@ class JellyfinGuid implements iGuid
|
||||
} catch (Throwable $e) {
|
||||
if (true === $log) {
|
||||
$this->logger->error(
|
||||
message: "{class}: Exception '{error.kind}' was thrown unhandled during '{client}: {user}@{backend}' parsing '{agent}' identifier. Error '{error.message}' at '{error.file}:{error.line}'.",
|
||||
message: "{class}: Unhandled exception was thrown during '{client}: {user}@{backend}' {title}parsing '{agent}' identifier. '{error.message}' at '{error.file}:{error.line}'.",
|
||||
context: [
|
||||
'class' => afterLast(static::class, '\\'),
|
||||
'backend' => $this->context->backendName,
|
||||
'client' => $this->context->clientName,
|
||||
'user' => $this->context->userContext->name,
|
||||
'error' => [
|
||||
'kind' => $e::class,
|
||||
'line' => $e->getLine(),
|
||||
'message' => $e->getMessage(),
|
||||
'file' => after($e->getFile(), ROOT_PATH),
|
||||
],
|
||||
'agent' => $value,
|
||||
'exception' => [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'kind' => get_class($e),
|
||||
'message' => $e->getMessage(),
|
||||
'trace' => $e->getTrace(),
|
||||
],
|
||||
'title' => ag_exists($context, 'item.title') ? r(
|
||||
"'{item.id}: {item.title}'",
|
||||
$context
|
||||
) . ' ' : '',
|
||||
...$context,
|
||||
...exception_log($e),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -182,17 +182,9 @@ final class ParseWebhook
|
||||
],
|
||||
];
|
||||
|
||||
$enableGUID = (bool)Config::get('episodes.enable.guid');
|
||||
|
||||
if (PlexClient::TYPE_EPISODE === $type && false === $enableGUID) {
|
||||
$guids = [];
|
||||
} else {
|
||||
$guids = $guid->get(guids: ag($item, 'Guid', []), context: $logContext);
|
||||
}
|
||||
|
||||
$fields = [
|
||||
iState::COLUMN_WATCHED => (int)$isPlayed,
|
||||
iState::COLUMN_GUIDS => $guids,
|
||||
iState::COLUMN_GUIDS => $guid->get(guids: ag($item, 'Guid', []), context: $logContext),
|
||||
iState::COLUMN_META_DATA => [
|
||||
$context->backendName => [
|
||||
iState::COLUMN_WATCHED => true === $isPlayed ? '1' : '0',
|
||||
@@ -234,7 +226,7 @@ final class ParseWebhook
|
||||
context: $context,
|
||||
guid: $guid,
|
||||
item: $obj,
|
||||
opts: ['override' => $fields, Options::ENABLE_EPISODE_GUID => $enableGUID],
|
||||
opts: ['override' => $fields],
|
||||
)->setIsTainted(isTainted: true === in_array($event, self::WEBHOOK_TAINTED_EVENTS));
|
||||
|
||||
if (false === $entity->hasGuids() && false === $entity->hasRelativeGuid()) {
|
||||
|
||||
@@ -104,19 +104,13 @@ trait PlexActionTrait
|
||||
],
|
||||
];
|
||||
|
||||
if (iState::TYPE_EPISODE === $type && false === (bool)ag($opts, Options::ENABLE_EPISODE_GUID, false)) {
|
||||
$guids = [];
|
||||
} else {
|
||||
$guids = $guid->get(guids: ag($item, 'Guid', []), context: $logContext);
|
||||
}
|
||||
|
||||
$builder = [
|
||||
iState::COLUMN_TYPE => $type,
|
||||
iState::COLUMN_UPDATED => (int)$date,
|
||||
iState::COLUMN_WATCHED => (int)$isPlayed,
|
||||
iState::COLUMN_VIA => $context->backendName,
|
||||
iState::COLUMN_TITLE => ag($item, ['title', 'originalTitle'], '??'),
|
||||
iState::COLUMN_GUIDS => $guids,
|
||||
iState::COLUMN_GUIDS => $guid->get(guids: ag($item, 'Guid', []), context: $logContext),
|
||||
iState::COLUMN_META_DATA => [
|
||||
$context->backendName => [
|
||||
iState::COLUMN_ID => (string)ag($item, 'ratingKey'),
|
||||
@@ -139,7 +133,7 @@ trait PlexActionTrait
|
||||
|
||||
if (count(ag($item, 'Genre', [])) > 0) {
|
||||
$metadataExtra[iState::COLUMN_META_DATA_EXTRA_GENRES] = array_map(
|
||||
fn ($item) => strtolower((string)ag($item, 'tag', '??')),
|
||||
fn($item) => strtolower((string)ag($item, 'tag', '??')),
|
||||
ag($item, 'Genre', [])
|
||||
);
|
||||
}
|
||||
@@ -172,8 +166,12 @@ trait PlexActionTrait
|
||||
|
||||
if (count($metadataExtra[iState::COLUMN_META_DATA_EXTRA_GENRES]) < 1) {
|
||||
$metadataExtra[iState::COLUMN_META_DATA_EXTRA_GENRES] = array_map(
|
||||
fn ($i) => strtolower((string)ag($i, 'tag', '??')),
|
||||
ag($this->getItemDetails(context: $context, id: $parentId), 'MediaContainer.Metadata.0.Genre', [])
|
||||
fn($i) => strtolower((string)ag($i, 'tag', '??')),
|
||||
ag(
|
||||
$this->getItemDetails(context: $context, id: $parentId),
|
||||
'MediaContainer.Metadata.0.Genre',
|
||||
[]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -383,9 +381,9 @@ trait PlexActionTrait
|
||||
protected function isSupportedType(string $type): bool
|
||||
{
|
||||
return true === in_array(
|
||||
PlexClient::TYPE_MAPPER[$type] ?? PlexClient::TYPE_MAPPER[strtolower($type)] ?? $type,
|
||||
iState::TYPES_LIST,
|
||||
true
|
||||
);
|
||||
PlexClient::TYPE_MAPPER[$type] ?? PlexClient::TYPE_MAPPER[strtolower($type)] ?? $type,
|
||||
iState::TYPES_LIST,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,9 +257,6 @@ class PlexClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: $after,
|
||||
opts: [
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid'),
|
||||
]
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -282,10 +279,7 @@ class PlexClient implements iClient
|
||||
context: $this->context,
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
opts: ag_sets($opts, [
|
||||
'writer' => $writer,
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid')
|
||||
])
|
||||
opts: ag_sets($opts, ['writer' => $writer])
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -309,7 +303,7 @@ class PlexClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: $after,
|
||||
opts: ['queue' => $queue, Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid')],
|
||||
opts: ['queue' => $queue],
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -467,10 +461,7 @@ class PlexClient implements iClient
|
||||
guid: $this->guid,
|
||||
mapper: $mapper,
|
||||
after: null,
|
||||
opts: ag_sets($opts, [
|
||||
Options::ONLY_LIBRARY_ID => $libraryId,
|
||||
Options::ENABLE_EPISODE_GUID => (bool)Config::get('episodes.enable.guid'),
|
||||
]),
|
||||
opts: ag_sets($opts, [Options::ONLY_LIBRARY_ID => $libraryId]),
|
||||
);
|
||||
|
||||
if ($response->hasError()) {
|
||||
@@ -964,7 +955,7 @@ class PlexClient implements iClient
|
||||
private function throwError(Response $response, string $className = RuntimeException::class, int $code = 0): void
|
||||
{
|
||||
throw new $className(
|
||||
message: ag($response->extra, 'message', fn () => $response->error->format()),
|
||||
message: ag($response->extra, 'message', fn() => $response->error->format()),
|
||||
code: $code,
|
||||
previous: $response->error->previous
|
||||
);
|
||||
|
||||
@@ -419,25 +419,17 @@ final class PlexGuid implements iGuid
|
||||
} catch (Throwable $e) {
|
||||
if (true === $log) {
|
||||
$this->logger->error(
|
||||
message: "PlexGuid: Exception '{error.kind}' was thrown unhandled during '{client}: {backend}' parsing '{agent}' identifier. Error '{error.message}' at '{error.file}:{error.line}'.",
|
||||
message: "PlexGuid: Unhandled exception was thrown during '{client}: {backend}' {title}parsing '{agent}' identifier. '{error.message}' at '{error.file}:{error.line}'.",
|
||||
context: [
|
||||
'backend' => $this->context->backendName,
|
||||
'client' => $this->context->clientName,
|
||||
'error' => [
|
||||
'kind' => $e::class,
|
||||
'line' => $e->getLine(),
|
||||
'message' => $e->getMessage(),
|
||||
'file' => after($e->getFile(), ROOT_PATH),
|
||||
],
|
||||
'agent' => $val,
|
||||
'exception' => [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'kind' => get_class($e),
|
||||
'message' => $e->getMessage(),
|
||||
'trace' => $e->getTrace(),
|
||||
],
|
||||
'title' => ag_exists($context, 'item.title') ? r(
|
||||
"'{item.id}: {item.title}'",
|
||||
$context
|
||||
) . ' ' : '',
|
||||
...$context,
|
||||
...exception_log($e),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
154
src/Commands/Database/RepairCommand.php
Normal file
154
src/Commands/Database/RepairCommand.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Commands\Database;
|
||||
|
||||
use App\Command;
|
||||
use App\Libs\Attributes\Route\Cli;
|
||||
use PDO;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface as iOutput;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Class QueueCommand
|
||||
*
|
||||
* This command is used to show webhook queued events.
|
||||
*
|
||||
* @package YourPackageNamespace
|
||||
*/
|
||||
#[Cli(command: self::ROUTE)]
|
||||
class RepairCommand extends Command
|
||||
{
|
||||
public const string ROUTE = 'db:repair';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the command.
|
||||
*/
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Attempt to repair broken database.')
|
||||
->addArgument('db', InputOption::VALUE_REQUIRED, 'Database to repair.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param iInput $input The input object.
|
||||
* @param iOutput $output The output object.
|
||||
*
|
||||
* @return int The command's exit code.
|
||||
*/
|
||||
protected function runCommand(iInput $input, iOutput $output): int
|
||||
{
|
||||
$db = $input->getArgument('db');
|
||||
if (empty($db)) {
|
||||
$output->writeln('<error>ERROR:</error> You need to provide path to the sqlite db.');
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
if (false === file_exists($db)) {
|
||||
$output->writeln(r("<error>ERROR:</error> Database '{db}' not found.", ['db' => $db]));
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$output->writeln(r("<info>INFO:</info> Attempting to repair database '{db}'.", ['db' => $db]));
|
||||
$old_db = new PDO("sqlite:{$db}");
|
||||
$version = $old_db->query('PRAGMA user_version')->fetchColumn();
|
||||
|
||||
// -- first copy db to prevent data loss.
|
||||
$backup = $db . '.before.repair.db';
|
||||
if (false === copy($db, $backup)) {
|
||||
$output->writeln(r("<error>ERROR:</error> Failed to copy database '{db}' to '{backup}'.", [
|
||||
'db' => $db,
|
||||
'backup' => $backup,
|
||||
]));
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$output->writeln(r("<info>INFO:</info> Copied database '{db}' to '{backup}' as backup.", [
|
||||
'db' => $db,
|
||||
'backup' => $backup,
|
||||
]));
|
||||
|
||||
$output->writeln(r("<info>INFO:</info> Attempting to repair database '{db}'.", ['db' => $db]));
|
||||
|
||||
|
||||
$command = "sqlite3 '{file}' '.dump' | sqlite3 '{file}.new.db'";
|
||||
$proc = Process::fromShellCommandline(r($command, ['file' => $db]));
|
||||
$proc->setTimeout(null);
|
||||
$proc->setIdleTimeout(null);
|
||||
$proc->run(function ($type, $out) use ($output) {
|
||||
$text = trim((string)$out);
|
||||
if (empty($text)) {
|
||||
return;
|
||||
}
|
||||
if ($type == Process::ERR) {
|
||||
$output->writeln(r("<error>ERROR:</error> SQLite3: {text}", ['text' => $text]));
|
||||
} else {
|
||||
$output->writeln(r("<info>INFO:</info> SQLite3: {text}", ['text' => $text]));
|
||||
}
|
||||
});
|
||||
if ($proc->isSuccessful()) {
|
||||
$output->writeln(r("<info>INFO:</info> Database '{db}' repaired successfully.", ['db' => $db]));
|
||||
} else {
|
||||
$output->writeln(r("<error>ERROR:</error> Failed to repair database '{db}'.", ['db' => $db]));
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$command = "sqlite3 '{file}.new.db' 'PRAGMA integrity_check'";
|
||||
$proc = Process::fromShellCommandline(r($command, ['file' => $db]));
|
||||
$proc->setTimeout(null);
|
||||
$proc->setIdleTimeout(null);
|
||||
$output->writeln('<info>INFO:</info> Checking database integrity...');
|
||||
$proc->run(function ($type, $out) use ($output) {
|
||||
$text = trim((string)$out);
|
||||
if (empty($text)) {
|
||||
return;
|
||||
}
|
||||
if ($type == Process::ERR) {
|
||||
$output->writeln(r("<error>ERROR:</error> SQLite3: {text}", ['text' => $text]));
|
||||
} else {
|
||||
$output->writeln(r("<info>INFO:</info> SQLite3: {text}", ['text' => $text]));
|
||||
}
|
||||
});
|
||||
if ($proc->isSuccessful()) {
|
||||
$output->writeln(r("<info>INFO:</info> Database '{db}' is valid.", ['db' => $db]));
|
||||
} else {
|
||||
$output->writeln(r("<error>ERROR:</error> Database '{db}' is not valid.", ['db' => $db]));
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$output->writeln(r("<info>INFO:</info> Updating database version to {version}.", [
|
||||
'version' => $version,
|
||||
]));
|
||||
$pdo = new PDO("sqlite:{$db}.new.db");
|
||||
$pdo->exec(r('PRAGMA user_version = {version}', ['version' => $version]));
|
||||
|
||||
$output->writeln(r("<info>INFO:</info> Renaming database '{db}.new.db' to '{db}'.", ['db' => $db]));
|
||||
|
||||
if (!rename("{$db}.new.db", $db)) {
|
||||
$output->writeln(r("<error>ERROR:</error> Failed to rename database '{db}.new.db' to '{db}'.", [
|
||||
'db' => $db,
|
||||
]));
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$output->writeln(
|
||||
r("<info>INFO:</info> Repair completed successfully. Database '{db}' is now valid.", ['db' => $db])
|
||||
);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
407
src/Commands/State/ValidateCommand.php
Normal file
407
src/Commands/State/ValidateCommand.php
Normal file
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Commands\State;
|
||||
|
||||
use App\Command;
|
||||
use App\Libs\Attributes\DI\Inject;
|
||||
use App\Libs\Attributes\Route\Cli;
|
||||
use App\Libs\Entity\StateInterface as iState;
|
||||
use App\Libs\Extends\StreamLogHandler;
|
||||
use App\Libs\LogSuppressor;
|
||||
use App\Libs\Mappers\Import\DirectMapper;
|
||||
use App\Libs\Mappers\ImportInterface as iImport;
|
||||
use App\Libs\Stream;
|
||||
use App\Libs\UserContext;
|
||||
use Monolog\Level;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface as iOutput;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class ValidateCommand
|
||||
*
|
||||
* This command Validate local databases against the backends metadata, and validate whether the reference ID
|
||||
* is still valid and exists in the backend.
|
||||
*/
|
||||
#[Cli(command: self::ROUTE)]
|
||||
class ValidateCommand extends Command
|
||||
{
|
||||
public const string ROUTE = 'state:validate';
|
||||
|
||||
public const string TASK_NAME = 'validate';
|
||||
|
||||
/**
|
||||
* @var array<array-key,array<string,bool>> Store the status of item from backend in-case we have multiple sub-users.
|
||||
*/
|
||||
private array $cache = [];
|
||||
|
||||
private const array TO_VERBOSITY = [
|
||||
Level::Emergency->value => iOutput::VERBOSITY_SILENT,
|
||||
Level::Critical->value => iOutput::VERBOSITY_QUIET,
|
||||
Level::Alert->value => iOutput::VERBOSITY_NORMAL,
|
||||
Level::Error->value => iOutput::VERBOSITY_NORMAL,
|
||||
Level::Warning->value => iOutput::VERBOSITY_NORMAL,
|
||||
Level::Notice->value => iOutput::VERBOSITY_VERBOSE,
|
||||
Level::Info->value => iOutput::VERBOSITY_VERY_VERBOSE,
|
||||
Level::Debug->value => iOutput::VERBOSITY_DEBUG,
|
||||
];
|
||||
|
||||
private array $perRun = [];
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param iImport $mapper The import interface object.
|
||||
* @param iLogger $logger The logger interface object.
|
||||
* @param LogSuppressor $suppressor The log suppressor object.
|
||||
*
|
||||
*/
|
||||
public function __construct(
|
||||
#[Inject(DirectMapper::class)]
|
||||
private iImport $mapper,
|
||||
private iLogger $logger,
|
||||
private LogSuppressor $suppressor,
|
||||
) {
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the method.
|
||||
*/
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(self::ROUTE)
|
||||
->setDescription('Validate stored backends reference id against the backends.')
|
||||
->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'Select user. Default all users.')
|
||||
->addOption(
|
||||
'logfile',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'Save console output to file. Will not work with progress bar.'
|
||||
)
|
||||
->addOption('progress', null, InputOption::VALUE_NONE, 'Show progress bar.');
|
||||
}
|
||||
|
||||
protected function runCommand(iInput $input, iOutput $output): int
|
||||
{
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output, [
|
||||
iLogger::class => $this->logger,
|
||||
Level::class => Level::Error,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the local databases against the backends reference ID.
|
||||
*
|
||||
* @param iInput $input The input interface object.
|
||||
* @param iOutput $output The output interface object.
|
||||
*
|
||||
* @return int The return status code.
|
||||
*/
|
||||
protected function process(iInput $input, iOutput $output): int
|
||||
{
|
||||
if (null !== ($logfile = $input->getOption('logfile')) && true === ($this->logger instanceof Logger)) {
|
||||
$this->logger->setHandlers([
|
||||
$this->suppressor->withHandler(new StreamLogHandler(new Stream($logfile, 'w'), $output))
|
||||
]);
|
||||
}
|
||||
|
||||
$logIO = null;
|
||||
$io = null;
|
||||
|
||||
if ($input->getOption('progress') && method_exists($output, 'section')) {
|
||||
$logIO = new SymfonyStyle($input, $output->section());
|
||||
$io = new SymfonyStyle($input, $output->section());
|
||||
}
|
||||
|
||||
$users = getUsersContext(mapper: $this->mapper, logger: $this->logger);
|
||||
|
||||
if (null !== ($user = $input->getOption('user'))) {
|
||||
$users = array_filter($users, fn($k) => $k === $user, mode: ARRAY_FILTER_USE_KEY);
|
||||
if (empty($users)) {
|
||||
$output->writeln(r("<error>User '{user}' not found.</error>", ['user' => $user]));
|
||||
return self::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
$start_time = microtime(true);
|
||||
|
||||
foreach ($users as $userContext) {
|
||||
$userStart = microtime(true);
|
||||
|
||||
$this->output(Level::Notice, "SYSTEM: Validating '{user}' local database metadata reference ids.", [
|
||||
'user' => $userContext->name,
|
||||
], $logIO);
|
||||
|
||||
$this->validate($userContext, $io, $logIO);
|
||||
|
||||
$this->output(Level::Notice, "SYSTEM: Completed '{user}' local database validation in '{duration}'s.", [
|
||||
'user' => $userContext->name,
|
||||
'duration' => round(microtime(true) - $userStart, 4),
|
||||
], $logIO);
|
||||
}
|
||||
|
||||
$this->output(Level::Notice, "SYSTEM: Completed local databases validation in '{duration}'s.", [
|
||||
'duration' => round(microtime(true) - $start_time, 4),
|
||||
], $logIO);
|
||||
|
||||
$this->renderStatus($output);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function validate(
|
||||
UserContext $userContext,
|
||||
SymfonyStyle|null $progBar = null,
|
||||
SymfonyStyle|null $logIO = null
|
||||
): void {
|
||||
$clients = [];
|
||||
|
||||
foreach ($userContext->config->getAll() as $backend => $config) {
|
||||
$clients[$backend] = makeBackend($config, $backend, [UserContext::class => $userContext]);
|
||||
}
|
||||
|
||||
$records = $userContext->db->getTotal();
|
||||
|
||||
if (null !== $progBar) {
|
||||
$progBar->progressStart($records);
|
||||
$progBar->newLine();
|
||||
}
|
||||
|
||||
$this->perRun[$userContext->name] = [
|
||||
'updated' => 0,
|
||||
'removed' => 0,
|
||||
'no_change' => 0,
|
||||
'backends' => array_map(fn() => ['found' => 0, 'removed' => 0], $userContext->config->getAll()),
|
||||
];
|
||||
|
||||
$ref = &$this->perRun[$userContext->name];
|
||||
|
||||
$progressUpdate = 0;
|
||||
$recordsCount = number_format($records);
|
||||
foreach ($userContext->db->fetch() as $item) {
|
||||
try {
|
||||
if (count($item->getMetadata()) < 1) {
|
||||
$this->output(
|
||||
Level::Warning,
|
||||
"SYSTEM: No metadata found for item '{user}: #{id}' Removing record.",
|
||||
[
|
||||
'id' => $item->id,
|
||||
'user' => $userContext->name,
|
||||
],
|
||||
$logIO,
|
||||
);
|
||||
$userContext->db->remove($item);
|
||||
$ref['removed']++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = $item->getMetadata();
|
||||
|
||||
$this->output(
|
||||
Level::Debug,
|
||||
"SYSTEM: Validating '{user}: #{id}' - '{title}' reference ID for '{backends}'.",
|
||||
[
|
||||
'id' => $item->id,
|
||||
'user' => $userContext->name,
|
||||
'title' => $item->getName(),
|
||||
'backends' => implode(', ', array_keys($meta)),
|
||||
],
|
||||
$logIO,
|
||||
);
|
||||
|
||||
foreach ($meta as $backend => $metadata) {
|
||||
$id = ag($metadata, iState::COLUMN_ID);
|
||||
$this->output(
|
||||
Level::Debug,
|
||||
"SYSTEM: Validating '{user}@{backend}: #{id} - {item_id}' '{title}' reference ID.",
|
||||
[
|
||||
'id' => $item->id,
|
||||
'item_id' => $id,
|
||||
'user' => $userContext->name,
|
||||
'title' => $item->getName(),
|
||||
'backend' => $backend,
|
||||
],
|
||||
$logIO,
|
||||
);
|
||||
|
||||
if (null === $id) {
|
||||
$this->output(
|
||||
Level::Notice,
|
||||
"SYSTEM: No reference ID found for item '{user}@{backend}: #{id}' Removing reference ID.",
|
||||
[
|
||||
'id' => $item->id,
|
||||
'backend' => $backend,
|
||||
'user' => $userContext->name,
|
||||
],
|
||||
$logIO,
|
||||
);
|
||||
$ref['removed']++;
|
||||
$item->removeMetadata($backend);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null === ($clients[$backend] ?? null)) {
|
||||
$this->output(
|
||||
Level::Warning,
|
||||
"SYSTEM: '{user}: #{id}' has reference to '{backend}' which doesn't exists. Removing reference ID.",
|
||||
[
|
||||
'id' => $item->id,
|
||||
'user' => $userContext->name,
|
||||
'backend' => $backend,
|
||||
],
|
||||
$logIO,
|
||||
|
||||
);
|
||||
$item->removeMetadata($backend);
|
||||
continue;
|
||||
}
|
||||
|
||||
$sub_ref = &$this->perRun[$userContext->name]['backends'][$backend];
|
||||
|
||||
$cacheKey = $clients[$backend]->getContext()->backendUrl . $id;
|
||||
|
||||
try {
|
||||
if (isset($this->cache[$cacheKey])) {
|
||||
$data = $this->cache[$cacheKey];
|
||||
} else {
|
||||
$data = $clients[$backend]->getMetadata($id);
|
||||
$data = !(count($data) < 1);
|
||||
$this->cache[$cacheKey] = $data;
|
||||
}
|
||||
|
||||
if (false === $data) {
|
||||
$this->output(
|
||||
Level::Notice,
|
||||
"SYSTEM: Request for '{user}@{backend}: #{id} - {item_id}' didnt return any data. Removing reference ID.",
|
||||
[
|
||||
'id' => $item->id,
|
||||
'item_id' => $id,
|
||||
'user' => $userContext->name,
|
||||
'backend' => $backend,
|
||||
],
|
||||
$logIO,
|
||||
);
|
||||
$sub_ref['removed']++;
|
||||
$item->removeMetadata($backend);
|
||||
continue;
|
||||
}
|
||||
|
||||
$sub_ref['found']++;
|
||||
} catch (Throwable $e) {
|
||||
$this->output(
|
||||
Level::Notice,
|
||||
"SYSTEM: Request for '{user}@{backend}: #{id} - {item_id}'. returned with error. {error}. Removing reference ID.",
|
||||
[
|
||||
'id' => $item->id,
|
||||
'item_id' => $id,
|
||||
'user' => $userContext->name,
|
||||
'backend' => $backend,
|
||||
'error' => $e->getMessage(),
|
||||
],
|
||||
$logIO,
|
||||
);
|
||||
$sub_ref['removed']++;
|
||||
$this->cache[$cacheKey] = false;
|
||||
$item->removeMetadata($backend);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($item->metadata) < 1) {
|
||||
$this->output(
|
||||
Level::Notice,
|
||||
"SYSTEM: Item '{user}: #{id}' no longer have any reference ID. Removing record.",
|
||||
[
|
||||
'id' => $item->id,
|
||||
'user' => $userContext->name,
|
||||
],
|
||||
$logIO,
|
||||
);
|
||||
|
||||
$ref['removed']++;
|
||||
$userContext->db->remove($item);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item->diff()) {
|
||||
$ref['updated']++;
|
||||
$userContext->db->update($item);
|
||||
} else {
|
||||
$ref['no_change']++;
|
||||
}
|
||||
} finally {
|
||||
if (null === $progBar) {
|
||||
$progressUpdate++;
|
||||
if (0 === ($progressUpdate % 500)) {
|
||||
$this->output(Level::Info, "SYSTEM: Processed '{progress}/{total}' %{percent}.", [
|
||||
'progress' => number_format($progressUpdate),
|
||||
'total' => $recordsCount,
|
||||
'percent' => round(($progressUpdate / $records) * 100, 3),
|
||||
], $logIO);
|
||||
}
|
||||
} else {
|
||||
$progBar->progressAdvance();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $progBar) {
|
||||
$progBar->progressFinish();
|
||||
$progBar->newLine();
|
||||
}
|
||||
}
|
||||
|
||||
private function output(Level $level, string $message, array $context = [], SymfonyStyle|null $io = null): void
|
||||
{
|
||||
if (null !== $io) {
|
||||
$io->writeln(r($message, $context), self::TO_VERBOSITY[$level->value] ?? iOutput::VERBOSITY_NORMAL);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->logger->log($level, $message, $context);
|
||||
}
|
||||
|
||||
private function renderStatus(iOutput $output): void
|
||||
{
|
||||
foreach ($this->perRun as $user => $data) {
|
||||
$this->logger->notice("User '{user}' local database, had {u} updated, {r} removed, {n} no change.", [
|
||||
'user' => $user,
|
||||
'u' => $data['updated'],
|
||||
'r' => $data['removed'],
|
||||
'n' => $data['no_change'],
|
||||
]);
|
||||
|
||||
$tbl = [];
|
||||
|
||||
$total = count($data['backends']);
|
||||
$i = 0;
|
||||
foreach ($data['backends'] as $backend => $backendData) {
|
||||
$i++;
|
||||
$tbl[] = [
|
||||
'Backend' => $backend,
|
||||
'Reference Found' => $backendData['found'],
|
||||
'Reference Removed' => $backendData['removed'],
|
||||
];
|
||||
if ($i < $total) {
|
||||
$tbl[] = new TableSeparator();
|
||||
}
|
||||
}
|
||||
|
||||
$output->writeln('');
|
||||
new Table($output)->setHeaders(array_keys($tbl[0]))->setStyle('box')->setRows(array_values($tbl))->render();
|
||||
$output->writeln('');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,14 @@ namespace App\Commands\System;
|
||||
use App\Command;
|
||||
use App\Libs\Attributes\DI\Inject;
|
||||
use App\Libs\Attributes\Route\Cli;
|
||||
use App\Libs\Database\DatabaseInterface as iDB;
|
||||
use App\Libs\Mappers\Import\DirectMapper;
|
||||
use App\Libs\Mappers\ImportInterface as iImport;
|
||||
use App\Libs\Options;
|
||||
use App\Libs\UserContext;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Output\OutputInterface as iOutput;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface as iOutput;
|
||||
|
||||
/**
|
||||
* Class IndexCommand
|
||||
@@ -32,7 +31,8 @@ final class IndexCommand extends Command
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param iDB $db An instance of the iDB class.
|
||||
* @param iImport $mapper
|
||||
* @param iLogger $logger
|
||||
*/
|
||||
public function __construct(
|
||||
#[Inject(DirectMapper::class)]
|
||||
@@ -89,7 +89,7 @@ final class IndexCommand extends Command
|
||||
*/
|
||||
protected function runCommand(iInput $input, iOutput $output): int
|
||||
{
|
||||
foreach (getUsersContext(mapper:$this->mapper, logger: $this->logger) as $userContext) {
|
||||
foreach (getUsersContext(mapper: $this->mapper, logger: $this->logger) as $userContext) {
|
||||
$output->writeln(r("Ensuring user '{user}' database has correct indexes.", [
|
||||
'user' => $userContext->name
|
||||
]), iOutput::VERBOSITY_VERBOSE);
|
||||
|
||||
@@ -7,15 +7,11 @@ namespace App\Commands\System;
|
||||
use App\Command;
|
||||
use App\Libs\Attributes\DI\Inject;
|
||||
use App\Libs\Attributes\Route\Cli;
|
||||
use App\Libs\Database\DatabaseInterface as iDB;
|
||||
use App\Libs\Mappers\Import\DirectMapper;
|
||||
use App\Libs\Mappers\ImportInterface as iImport;
|
||||
use App\Libs\Options;
|
||||
use App\Libs\UserContext;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Output\OutputInterface as iOutput;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
|
||||
/**
|
||||
* Class MaintenanceCommand
|
||||
@@ -31,7 +27,8 @@ final class MaintenanceCommand extends Command
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param iDB $db An instance of the iDB class.
|
||||
* @param iImport $mapper
|
||||
* @param iLogger $logger
|
||||
*/
|
||||
public function __construct(
|
||||
#[Inject(DirectMapper::class)]
|
||||
@@ -71,8 +68,8 @@ final class MaintenanceCommand extends Command
|
||||
*/
|
||||
protected function runCommand(iInput $input, iOutput $output): int
|
||||
{
|
||||
foreach (getUsersContext(mapper:$this->mapper, logger: $this->logger) as $userContext) {
|
||||
$output->writeln(r("Optmizing user '{user}' database.", [
|
||||
foreach (getUsersContext(mapper: $this->mapper, logger: $this->logger) as $userContext) {
|
||||
$output->writeln(r("Optimizing user '{user}' database.", [
|
||||
'user' => $userContext->name
|
||||
]), iOutput::VERBOSITY_VERBOSE);
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ use App\Libs\Attributes\Route\Cli;
|
||||
use App\Libs\Database\DatabaseInterface as iDB;
|
||||
use App\Libs\Mappers\Import\DirectMapper;
|
||||
use App\Libs\Mappers\ImportInterface as iImport;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Output\OutputInterface as iOutput;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
use Symfony\Component\Console\Input\InputInterface as iInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface as iOutput;
|
||||
|
||||
/**
|
||||
* Class MigrationsCommand
|
||||
@@ -28,7 +28,8 @@ final class MigrationsCommand extends Command
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param iDB $db An instance of the iDB class.
|
||||
* @param iImport $mapper
|
||||
* @param iLogger $logger
|
||||
*/
|
||||
public function __construct(
|
||||
#[Inject(DirectMapper::class)]
|
||||
@@ -67,7 +68,7 @@ final class MigrationsCommand extends Command
|
||||
*/
|
||||
protected function runCommand(iInput $input, iOutput $output): int
|
||||
{
|
||||
return $this->single(fn (): int => $this->process($input, $output), $output);
|
||||
return $this->single(fn(): int => $this->process($input, $output), $output);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +86,7 @@ final class MigrationsCommand extends Command
|
||||
$opts['fresh'] = true;
|
||||
}
|
||||
|
||||
foreach (getUsersContext(mapper:$this->mapper, logger:$this->logger) as $userContext) {
|
||||
foreach (getUsersContext(mapper: $this->mapper, logger: $this->logger) as $userContext) {
|
||||
$output->writeln(r("Running database migrations for '{user}' database.", [
|
||||
'user' => $userContext->name
|
||||
]), iOutput::VERBOSITY_VERBOSE);
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Libs\Database;
|
||||
use App\Libs\Entity\StateInterface;
|
||||
use Closure;
|
||||
use DateTimeInterface;
|
||||
use Generator;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
|
||||
@@ -208,4 +209,22 @@ interface DatabaseInterface
|
||||
* @throws PDOException if transaction fails.
|
||||
*/
|
||||
public function transactional(Closure $callback): mixed;
|
||||
|
||||
/**
|
||||
* Fetch data from database.
|
||||
*
|
||||
* @param array $opts (Options to pass to the query)
|
||||
*
|
||||
* @return Generator<StateInterface> Yielding each row of data.
|
||||
*/
|
||||
public function fetch(array $opts = []): Generator;
|
||||
|
||||
/**
|
||||
* Get total number of items in database.
|
||||
*
|
||||
* @param array $opts (Options to pass to the query)
|
||||
*
|
||||
* @return int Total number of items.
|
||||
*/
|
||||
public function getTotal(array $opts = []): int;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ namespace App\Libs\Database\PDO;
|
||||
use App\Libs\Container;
|
||||
use App\Libs\Database\DatabaseInterface as iDB;
|
||||
use App\Libs\Database\DBLayer;
|
||||
use App\Libs\Entity\StateEntity;
|
||||
use App\Libs\Entity\StateInterface as iState;
|
||||
use App\Libs\Exceptions\DBAdapterException as DBException;
|
||||
use App\Libs\Options;
|
||||
use Closure;
|
||||
use DateTimeInterface;
|
||||
use Generator;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use PDOStatement;
|
||||
@@ -179,6 +179,7 @@ final class PDOAdapter implements iDB
|
||||
'message' => $e->getMessage(),
|
||||
'file' => after($e->getFile(), ROOT_PATH),
|
||||
],
|
||||
'last' => $this->db->getLastStatement(),
|
||||
]
|
||||
);
|
||||
return $entity;
|
||||
@@ -399,7 +400,8 @@ final class PDOAdapter implements iDB
|
||||
'trace' => $e->getTrace(),
|
||||
'message' => $e->getMessage(),
|
||||
'file' => after($e->getFile(), ROOT_PATH),
|
||||
]
|
||||
],
|
||||
'last' => $this->db->getLastStatement(),
|
||||
]
|
||||
);
|
||||
return $entity;
|
||||
@@ -629,6 +631,37 @@ final class PDOAdapter implements iDB
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function fetch(array $opts = []): Generator
|
||||
{
|
||||
$fromClass = $this->options['class'] ?? null;
|
||||
if (null === ($fromClass ?? null) || false === ($fromClass instanceof iState)) {
|
||||
$class = Container::get(iState::class);
|
||||
} else {
|
||||
$class = $fromClass;
|
||||
}
|
||||
|
||||
$stmt = $this->db->query('SELECT * FROM state');
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
yield $class::fromArray($row);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTotal($opts = []): int
|
||||
{
|
||||
$stmt = $this->db->query('SELECT COUNT(*) FROM state');
|
||||
if (false === ($row = $stmt->fetch(PDO::FETCH_NUM))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int)$row[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Destructor
|
||||
*
|
||||
|
||||
@@ -459,6 +459,22 @@ final class StateEntity implements iState
|
||||
return $this->metadata[$via] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function removeMetadata(string $backend): array
|
||||
{
|
||||
if (null === ($this->metadata[$backend] ?? null)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$metadata = $this->metadata[$backend];
|
||||
|
||||
unset($this->metadata[$backend]);
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
||||
@@ -295,6 +295,15 @@ interface StateInterface extends LoggerAwareInterface
|
||||
*/
|
||||
public function getMetadata(string|null $via = null): array;
|
||||
|
||||
/**
|
||||
* Get metadata.
|
||||
*
|
||||
* @param string $backend The backend name to remove metadata from.
|
||||
*
|
||||
* @return array Return the removed metadata. Or empty array if not found.
|
||||
*/
|
||||
public function removeMetadata(string $backend): array;
|
||||
|
||||
/**
|
||||
* Set metadata related to {$this->via} backend.
|
||||
*
|
||||
|
||||
@@ -50,7 +50,6 @@ final class Options
|
||||
public const string DELAY_BY = 'DELAY_BY';
|
||||
public const string RAW_RESPONSE_CALLBACK = 'RAW_RESPONSE_CALLBACK';
|
||||
public const string INTERNAL_REQUEST = 'INTERNAL_REQUEST';
|
||||
public const string ENABLE_EPISODE_GUID = 'ENABLE_EPISODE_GUID';
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user