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

Consider super works #37

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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: 24 additions & 1 deletion Classes/Command/HealthCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ protected function removeDoubleWorks(): void
$this->io->section('Removing double works');
$publishedItems = $this->publishedItemRepository->findAll();
$this->io->progressStart(count($publishedItems));

$works = [];
foreach ($publishedItems as $publishedItem) {
$this->io->progressAdvance();
foreach ($publishedItem->getContainedWorks() as $work) {
Expand All @@ -172,7 +174,11 @@ protected function removeDoubleWorks(): void
}
foreach ($publishedItem->getPublishedSubitems() as $publishedSubitem) {
foreach ($publishedSubitem->getContainedWorks() as $work) {
if (isset($works[$work->getGndId()]) && $works[$work->getGndId()]->getUid() != $work->getUid()) {
if (
isset($works[$work->getGndId()]) &&
$works[$work->getGndId()]->getUid() != $work->getUid() &&
$work->getGndId() != 'lokal'
) {
$publishedSubitem->removeContainedWork($work);
$publishedSubitem->addContainedWork($works[$work->getGndId()]);
$this->io->text('detected double ' . $work->getGndId() . ', ' . $work->getFullTitle() . '.');
Expand Down Expand Up @@ -258,6 +264,8 @@ protected function removeUnusedWorks(): void
{
$this->io->section('Removing unused works');
$publishedItems = $this->publishedItemRepository->findAll();

// check works linked in published items and subitems
foreach ($publishedItems as $publishedItem) {
foreach ($publishedItem->getContainedWorks() as $work) {
$works[$work->getUid()] = $work;
Expand All @@ -268,6 +276,21 @@ protected function removeUnusedWorks(): void
}
}
}

// check works linked as super works
while (true) {
$initialWorkCount = count($works);
foreach ($works as $work) {
if($work->getSuperWork() != null) {
$works[$work->getSuperWork()->getUid()] = $work->getSuperWork();
}
}
$newWorkCount = count($works);
if ($initialWorkCount == $newWorkCount) {
break;
}
}

$worksFromDb = $this->workRepository->findAll();
$this->io->progressStart(count($works));
foreach ($worksFromDb as $work) {
Expand Down