Skip to content

Commit

Permalink
Add full support for sets
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Jan 12, 2024
1 parent c2f3e74 commit 6c700c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ public function addOrUpdateRecord(Record $newRecord, bool $bulkMode = false): vo
if ($newRecord->hasContent() || Configuration::getInstance()->deletedRecords !== 'no') {
$oldRecord->setContent($newRecord->getContent(), false);
$oldRecord->setLastChanged($newRecord->getLastChanged());
// TODO: Add full set support.
// Add new sets.
foreach (array_diff($newRecord->getSets(), $oldRecord->getSets()) as $newSet) {
$oldRecord->addSet($newSet);
}
// Remove old sets.
foreach (array_diff($oldRecord->getSets(), $newRecord->getSets()) as $oldSet) {
$oldRecord->removeSet($oldSet);
}
} else {
$this->entityManager->remove($oldRecord);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Entity/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,14 @@ public function __construct(string $spec, ?string $name = null, string $descript
throw $exception;
}
}

/**
* Get the set's string representation for comparison.
*
* @return string The set's unique spec
*/
public function __toString(): string
{
return $this->getSpec();
}
}

0 comments on commit 6c700c6

Please sign in to comment.