Skip to content

Commit

Permalink
Merge pull request #186 from ArabCoders/dev
Browse files Browse the repository at this point in the history
Added backend:restore command.
  • Loading branch information
arabcoders committed Jul 1, 2022
2 parents 199500b + fe58d08 commit beb0b75
Show file tree
Hide file tree
Showing 7 changed files with 646 additions and 42 deletions.
4 changes: 2 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@
BackupCommand::TASK_NAME => [
Task::NAME => BackupCommand::TASK_NAME,
Task::ENABLED => (bool)env('WS_CRON_BACKUP', false),
Task::RUN_AT => (string)env('WS_CRON_BACKUP_AT', '0 0 */3 * *'),
Task::RUN_AT => (string)env('WS_CRON_BACKUP_AT', '0 6 */3 * *'),
Task::COMMAND => '@' . BackupCommand::ROUTE,
Task::ARGS => '-v',
Task::ARGS => env('WS_CRON_EXPORT_ARGS', '-v'),
],
],
];
Expand Down
49 changes: 34 additions & 15 deletions src/Backends/Jellyfin/Action/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Backends\Common\GuidInterface as iGuid;
use App\Backends\Jellyfin\JellyfinClient as JFC;
use App\Libs\Entity\StateInterface as iState;
use App\Libs\Guid;
use App\Libs\Mappers\ImportInterface as iImport;
use SplFileObject;
use Throwable;
Expand Down Expand Up @@ -38,6 +37,7 @@ protected function process(

try {
$logContext['item'] = [
'backend' => $context->backendName,
'id' => ag($item, 'Id'),
'title' => match ($type) {
JFC::TYPE_MOVIE => sprintf(
Expand Down Expand Up @@ -71,11 +71,10 @@ protected function process(
item: $item,
opts: $opts + ['library' => ag($logContext, 'library.id')]
);

$arr = [
iState::COLUMN_TYPE => $entity->type,
iState::COLUMN_WATCHED => $entity->isWatched(),
iState::COLUMN_UPDATED => makeDate($entity->updated),
iState::COLUMN_WATCHED => (int)$entity->isWatched(),
iState::COLUMN_UPDATED => makeDate($entity->updated)->getTimestamp(),
iState::COLUMN_META_SHOW => '',
iState::COLUMN_TITLE => trim($entity->title),
];
Expand All @@ -96,21 +95,41 @@ protected function process(
unset($arr[iState::COLUMN_META_SHOW]);
}

$guids = [];

foreach (Guid::fromArray($entity->getGuids(), false)->getAll() as $db => $val) {
$guids[after($db, 'guid_')] = $val;
}

$arr[iState::COLUMN_YEAR] = $entity->year;
$arr[iState::COLUMN_GUIDS] = $guids;


$arr[iState::COLUMN_GUIDS] = array_filter(
$entity->getGuids(),
fn($key) => str_contains($key, 'guid_'),
ARRAY_FILTER_USE_KEY
);
if ($entity->isEpisode()) {
$parents = [];
foreach (Guid::fromArray($entity->getParentGuids(), false)->getAll() as $db => $val) {
$parents[after($db, 'guid_')] = $val;
$arr[iState::COLUMN_PARENT] = array_filter(
$entity->getParentGuids(),
fn($key) => str_contains($key, 'guid_'),
ARRAY_FILTER_USE_KEY
);
}

if (true !== (bool)ag($opts, 'no_enhance') && null !== ($fromDb = $mapper->get($entity))) {
$arr[iState::COLUMN_GUIDS] = array_replace_recursive(
array_filter(
$fromDb->getGuids(),
fn($key) => str_contains($key, 'guid_'),
ARRAY_FILTER_USE_KEY
),
$arr[iState::COLUMN_GUIDS]
);
if ($entity->isEpisode()) {
$arr[iState::COLUMN_PARENT] = array_replace_recursive(
array_filter(
$fromDb->getParentGuids(),
fn($key) => str_contains($key, 'guid_'),
ARRAY_FILTER_USE_KEY
),
$arr[iState::COLUMN_PARENT]
);
}
$arr[iState::COLUMN_PARENT] = $parents;
}

$writer->fwrite(
Expand Down
47 changes: 33 additions & 14 deletions src/Backends/Plex/Action/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Backends\Common\GuidInterface as iGuid;
use App\Backends\Plex\PlexClient;
use App\Libs\Entity\StateInterface as iState;
use App\Libs\Guid;
use App\Libs\Mappers\ImportInterface as iImport;
use SplFileObject;
use Throwable;
Expand Down Expand Up @@ -43,6 +42,7 @@ protected function process(
}

$logContext['item'] = [
'backend' => $context->backendName,
'id' => ag($item, 'ratingKey'),
'title' => match ($type) {
PlexClient::TYPE_MOVIE => sprintf(
Expand Down Expand Up @@ -77,8 +77,8 @@ protected function process(

$arr = [
iState::COLUMN_TYPE => $entity->type,
iState::COLUMN_WATCHED => $entity->isWatched(),
iState::COLUMN_UPDATED => makeDate($entity->updated),
iState::COLUMN_WATCHED => (int)$entity->isWatched(),
iState::COLUMN_UPDATED => makeDate($entity->updated)->getTimestamp(),
iState::COLUMN_META_SHOW => '',
iState::COLUMN_TITLE => trim($entity->title),
];
Expand All @@ -99,21 +99,40 @@ protected function process(
unset($arr[iState::COLUMN_META_SHOW]);
}

$guids = [];

foreach (Guid::fromArray($entity->getGuids(), false)->getAll() as $db => $val) {
$guids[after($db, 'guid_')] = $val;
}

$arr[iState::COLUMN_YEAR] = $entity->year;
$arr[iState::COLUMN_GUIDS] = $guids;

$arr[iState::COLUMN_GUIDS] = array_filter(
$entity->getGuids(),
fn($key) => str_contains($key, 'guid_'),
ARRAY_FILTER_USE_KEY
);
if ($entity->isEpisode()) {
$parents = [];
foreach (Guid::fromArray($entity->getParentGuids(), false)->getAll() as $db => $val) {
$parents[after($db, 'guid_')] = $val;
$arr[iState::COLUMN_PARENT] = array_filter(
$entity->getParentGuids(),
fn($key) => str_contains($key, 'guid_'),
ARRAY_FILTER_USE_KEY
);
}

if (true !== (bool)ag($opts, 'no_enhance') && null !== ($fromDb = $mapper->get($entity))) {
$arr[iState::COLUMN_GUIDS] = array_replace_recursive(
array_filter(
$fromDb->getGuids(),
fn($key) => str_contains($key, 'guid_'),
ARRAY_FILTER_USE_KEY
),
$arr[iState::COLUMN_GUIDS]
);
if ($entity->isEpisode()) {
$arr[iState::COLUMN_PARENT] = array_replace_recursive(
array_filter(
$fromDb->getParentGuids(),
fn($key) => str_contains($key, 'guid_'),
ARRAY_FILTER_USE_KEY
),
$arr[iState::COLUMN_PARENT]
);
}
$arr[iState::COLUMN_PARENT] = $parents;
}

$writer->fwrite(
Expand Down
Loading

0 comments on commit beb0b75

Please sign in to comment.