Esempio n. 1
0
 /**
  * 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;
 }
 /**
  * Transforms sold doc to the editor model concept.
  * May be used to refactor all the code. But may miss some things.
  * @param OpenSKOS_Solr_Document $solrDocument
  * @return \Editor_Models_Concept\
  */
 protected function docToEditorConcept(OpenSKOS_Solr_Document $solrDocument)
 {
     $data = $solrDocument->toArray();
     if (!empty($data['tenant']) && is_array($data['tenant'])) {
         $data['tenant'] = $data['tenant'][0];
     }
     if (!empty($data['uuid']) && is_array($data['uuid'])) {
         $data['uuid'] = $data['uuid'][0];
     }
     return new Editor_Models_Concept(new Api_Models_Concept($data));
 }