Skip to content

Commit

Permalink
Consider super works
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Oct 9, 2024
1 parent fe23ff0 commit cf93d7c
Showing 1 changed file with 24 additions and 1 deletion.
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

0 comments on commit cf93d7c

Please sign in to comment.