Skip to content

Commit

Permalink
Respect deleted records policy
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Jan 4, 2024
1 parent 7188f37 commit 00d4dc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Console/CsvImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

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;
Expand Down Expand Up @@ -160,6 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}
Database::getInstance()->flush(true);
Database::getInstance()->pruneOrphanSets();

$output->writeln([
'',
Expand Down
28 changes: 17 additions & 11 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,27 @@ public function addOrUpdateRecord(
$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();
}
Expand Down

0 comments on commit 00d4dc8

Please sign in to comment.