/** * Validate if the scheme is unique in the given tenant. * If not - checks if it should be perged. If not adds it to the _duplicateConceptSchemes and return false. * * @param OpenSKOS_Solr_Document $schemeDoc * @param int $byUserId, optional * @return bool If the document can be inserted */ protected function handleUniqueConceptScheme(OpenSKOS_Solr_Document $schemeDoc, $byUserId = null) { $canInsertDocument = true; $schemeUri = $schemeDoc->offsetGet('uri'); $schemesCheck = $this->_solr()->limit(1)->search('uri:"' . $schemeUri[0] . '" ' . 'AND tenant:"' . $this->getOpt('tenant') . '" ' . 'AND deleted:false ' . 'AND collection:' . $this->getCollection()->id); if ($schemesCheck['response']['numFound'] > 0) { if (!$this->getOpt('purge')) { $this->_duplicateConceptSchemes[] = $schemeUri[0]; $canInsertDocument = false; } else { $conceptScheme = new Editor_Models_ConceptScheme(new Api_Models_Concept(array_shift($schemesCheck['response']['docs']))); $conceptScheme->delete(true, $byUserId); } } return $canInsertDocument; }