// Check if this set is already defined, to prevent auto increment in the database.
$existing = $this->getExistingConfigSet( $template->getConfigSets(), $item->getName() );
// If the set isn't defined, create a new one
if(!$existing instanceof Set){ $existing = newSet(); $template->getConfigSets()->add($existing); }