Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to generate Relative GUIDs on demand. #92

Merged
merged 3 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/Commands/Database/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ protected function runCommand(InputInterface $input, OutputInterface $output): i
if ($input->getOption('parent')) {
foreach (array_keys(Guid::SUPPORTED) as $guid) {
$guid = afterLast($guid, 'guid_');
if (!$input->getOption($guid)) {
if (null === ($val = $input->getOption($guid))) {
continue;
}
$where[] = "json_extract(meta,'$.parent.guid_{$guid}') = :{$guid}";
$params[$guid] = $input->getOption($guid);
$params[$guid] = $val;
}
} else {
foreach (array_keys(Guid::SUPPORTED) as $guid) {
$guid = afterLast($guid, 'guid_');
if (!$input->getOption($guid)) {
if (null === ($val = $input->getOption($guid))) {
continue;
}
$where[] = "guid_{$guid} LIKE '%' || :{$guid} || '%'";
$params[$guid] = $input->getOption($guid);
$params[$guid] = $val;
}
}

Expand All @@ -145,8 +145,21 @@ protected function runCommand(InputInterface $input, OutputInterface $output): i

if (0 === $rowCount) {
$output->writeln('<error>No Results. Probably invalid filters values were used.</error>');
$output->writeln('<info>Filters:</info>');
$output->writeln(print_r([$where, $params, $sql, $rows, $stmt->errorInfo()], true));
if (count($params) > 1) {
array_shift($params);
if ('json' === $input->getOption('output')) {
$output->writeln(
json_encode(
[
'Filters' => $params
],
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
)
);
} else {
$output->writeln(Yaml::dump(['Filters' => $params], 8, 2));
}
}
return self::FAILURE;
}

Expand Down
36 changes: 36 additions & 0 deletions src/Libs/Entity/StateEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,42 @@ public function hasGuids(): bool
return false;
}

public function hasRelativeGuids(): bool
{
if (StateInterface::TYPE_EPISODE !== $this->type) {
return false;
}

$parents = ag($this->meta, 'parent', []);
$season = ag($this->meta, 'season', null);
$episode = ag($this->meta, 'episode', null);

return !(null === $season || null === $episode || empty($parents));
}

public function getRelativeGuids(): array
{
if (StateInterface::TYPE_EPISODE !== $this->type) {
return [];
}

$parents = ag($this->meta, 'parent', []);
$season = ag($this->meta, 'season', null);
$episode = ag($this->meta, 'episode', null);

if (null === $season || null === $episode) {
return [];
}

$list = [];

foreach ($parents as $key => $val) {
$list[afterLast($key, 'guid_')] = $val . '/' . $season . '/' . $episode;
}

return $list;
}

public function apply(StateInterface $entity, bool $guidOnly = false): self
{
if ($this->isEqual($entity)) {
Expand Down
14 changes: 14 additions & 0 deletions src/Libs/Entity/StateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ public function isChanged(): bool;
*/
public function hasGuids(): bool;

/**
* Does the entity have Relative GUIDs?
*
* @return bool
*/
public function hasRelativeGuids(): bool;

/**
* Get Relative GUIDs.
*
* @return array
*/
public function getRelativeGuids(): array;

/**
* Get GUID Pointers.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Libs/Servers/JellyfinServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ protected function processShow(StdClass $item, string $library): void
if (!$this->hasSupportedIds($providersId)) {
$message = sprintf('Ignoring %s. No valid/supported GUIDs.', $iName);
if (empty($providersId)) {
$message .= 'Most likely unmatched TV show.';
$message .= ' Most likely unmatched TV show.';
}
$this->logger->info($message, ['guids' => empty($providersId) ? 'None' : $providersId]);
return;
Expand Down Expand Up @@ -1501,7 +1501,7 @@ protected function processImport(
$message = sprintf('Ignoring %s. No valid/supported GUIDs.', $iName);

if (empty($guids)) {
$message .= 'Most likely unmatched item.';
$message .= ' Most likely unmatched item.';
}

$this->logger->info($message, ['guids' => empty($guids) ? 'None' : $guids]);
Expand Down
4 changes: 2 additions & 2 deletions src/Libs/Servers/PlexServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ protected function processShow(StdClass $item, string $library): void
if (!$this->hasSupportedIds($item->Guid)) {
$message = sprintf('Ignoring %s. No valid/supported GUIDs.', $iName);
if (empty($item->Guid)) {
$message .= 'Possibly unmatched show';
$message .= ' Most likely unmatched TV show.';
}
$this->logger->info($message, ['guids' => empty($item->Guid) ? 'None' : $item->Guid]);
return;
Expand Down Expand Up @@ -1554,7 +1554,7 @@ protected function processImport(
$message = sprintf('Ignoring %s. No valid/supported GUIDs.', $iName);

if (empty($item->Guid)) {
$message .= 'Most likely unmatched item.';
$message .= ' Most likely unmatched item.';
}

$this->logger->info($message, ['guids' => empty($item->Guid) ? 'None' : $item->Guid]);
Expand Down
6 changes: 2 additions & 4 deletions src/Libs/Storage/PDO/PDOAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,15 @@ public function matchAnyId(array $ids, StateInterface|null $class = null): State
if (null === ($ids[$key] ?? null)) {
continue;
}

$where[] = "{$key} = :{$key}";
$cond[$key] = $ids[$key];
}

if (empty($cond)) {
return null;
}

foreach ($cond as $key => $_) {
$where[] = $key . ' = :' . $key;
}

$sqlWhere = implode(' OR ', $where);

$cachedKey = md5($sqlWhere);
Expand Down