public function update(Taxonomy $collection)
{
$updated = [];
// First give priority to already existing entities
foreach ($collection as $entity) {
$entity->setSlug(str_replace('/', '', $entity->getSlug()));
$master = $this->getOriginal($entity);
$master->setSortorder($entity->getSortorder());
$updated[] = $master;
}
$deleted = [];
foreach ($this as $old) {
if (!in_array($old, $updated)) {
$deleted[] = $old;
}
}
// Clear the collection so that we re-add only the updated elements
$this->clear();
foreach ($updated as $new) {
$this->add($new);
}
return $deleted;
}