Respect deleted records policy

This commit is contained in:
Sebastian Meyer 2024-01-04 15:33:28 +01:00
parent 7188f37c9f
commit 00d4dc80cc
2 changed files with 18 additions and 12 deletions

View File

@ -24,7 +24,6 @@ namespace OCC\OaiPmh2\Console;
use DateTime;
use OCC\OaiPmh2\Database;
use OCC\OaiPmh2\Database\Record;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@ -160,6 +159,7 @@ class CsvImportCommand extends Command
}
}
Database::getInstance()->flush(true);
Database::getInstance()->pruneOrphanSets();
$output->writeln([
'',

View File

@ -129,21 +129,27 @@ class Database
$format = $this->entityManager->getReference(Format::class, $format);
}
$record = $this->entityManager->find(Record::class, ['identifier' => $identifier, 'format' => $format]);
if (isset($record)) {
try {
$record->setContent($data);
$record->setLastChanged($lastChanged);
} catch (ValidationFailedException $exception) {
throw $exception;
if (!isset($data) && Configuration::getInstance()->deletedRecords === 'no') {
if (isset($record)) {
$this->entityManager->remove($record);
}
} else {
try {
$record = new Record($identifier, $format, $data, $lastChanged);
} catch (ValidationFailedException $exception) {
throw $exception;
if (isset($record)) {
try {
$record->setContent($data);
$record->setLastChanged($lastChanged);
} catch (ValidationFailedException $exception) {
throw $exception;
}
} else {
try {
$record = new Record($identifier, $format, $data, $lastChanged);
} catch (ValidationFailedException $exception) {
throw $exception;
}
}
$this->entityManager->persist($record);
}
$this->entityManager->persist($record);
if (!$bulkMode) {
$this->entityManager->flush();
}