예제 #1
0
 /**
  * 
  */
 public function decideHarvestability($registryObject)
 {
     $reharvest = true;
     $revision_record_id = null;
     $existingRegistryObject = null;
     // If there is a draft, add to this one
     if (isDraftStatus($this->status)) {
         $existingRegistryObject = $this->CI->ro->getDraftByKey((string) $registryObject->key);
         if (!$existingRegistryObject) {
             $existingRegistryObject = $this->CI->ro->getPublishedByKey((string) $registryObject->key);
         }
     } else {
         if (isPublishedStatus($this->status)) {
             $existingRegistryObject = $this->CI->ro->getPublishedByKey((string) $registryObject->key);
             if (!$existingRegistryObject) {
                 $existingRegistryObject = $this->CI->ro->getDraftByKey((string) $registryObject->key);
             }
         }
     }
     if ($existingRegistryObject) {
         // Check for duplicates: Reject this record if it is already in the feed
         if ($existingRegistryObject->harvest_id == $this->harvestID) {
             $reharvest = false;
             $this->message_log[] = "Ignored a record received twice in this harvest: " . $registryObject->key;
             $this->ingest_duplicate_ignore++;
         }
         if ($existingRegistryObject->data_source_id == $this->dataSource->id) {
             if ($this->statusAlreadyChanged || (isDraftStatus($this->status) && isDraftStatus($existingRegistryObject->status) || isPublishedStatus($this->status) && isPublishedStatus($existingRegistryObject->status))) {
                 // Add a new revision to this existing registry object
                 $revision_record_id = $existingRegistryObject->id;
             } else {
                 $revision_record_id = null;
             }
         } else {
             // Duplicate key in alternate data source
             $reharvest = false;
             $this->message_log[] = "Ignored a record already existing in a different data source: " . $registryObject->key;
             $this->ingest_duplicate_ignore++;
         }
     } else {
         // Harvest this as a new registry object
         $revision_record_id = null;
     }
     return array($reharvest, $revision_record_id);
 }
예제 #2
0
 function handleStatusChange($target_status)
 {
     $this->_CI->load->library('Solr');
     // Changing between draft statuses, nothing to worry about:
     $this->_CI->load->model('data_source/data_sources', 'ds');
     $data_source = $this->_CI->ds->getByID($this->getAttribute('data_source_id'));
     if (isDraftStatus($this->getAttribute('original_status')) && isDraftStatus($target_status)) {
         if ($this->getAttribute('original_status') == 'ASSESSMENT_IN_PROGRESS' && $target_status == 'APPROVED') {
             $this->setAttribute("manually_assessed", 'yes');
         }
         if ($target_status == 'DRAFT') {
             $this->setAttribute("manually_assessed", 'no');
         }
     } else {
         if (isDraftStatus($this->getAttribute('original_status')) && isPublishedStatus($target_status)) {
             $xml = html_entity_decode($this->ro->getRif());
             $existingRegistryObject = $this->_CI->ro->getPublishedByKey($this->ro->key);
             if ($existingRegistryObject && $existingRegistryObject->getAttribute('data_source_id') != $this->getAttribute('data_source_id')) {
                 $otherDs = $this->_CI->ds->getByID($existingRegistryObject->getAttribute('data_source_id'));
                 throw new Exception("Registry Object with key " . $this->ro->key . " already exists in the " . NL . $otherDs->title . " Data Source");
             } else {
                 if ($existingRegistryObject) {
                     // Delete this original draft and change this object to point to the PUBLISHED (seamless changeover)
                     $manuallyAssessed = $this->getAttribute('manually_assessed');
                     $this->ro = $this->_CI->ro->getPublishedByKey($this->getAttribute("key"));
                     if ($this->getAttribute('original_status') === 'ASSESSMENT_IN_PROGRESS' || $manuallyAssessed === 'yes') {
                         $this->ro->setAttribute("manually_assessed", 'yes');
                     }
                     if ($this->ro->getAttribute('gold_status_flag') === 't') {
                         $this->ro->setAttribute("gold_status_flag", 'f');
                     }
                     $this->ro->harvest_id = $this->getAttribute('harvest_id');
                     $this->ro->save();
                     $this->_CI->ro->deleteRegistryObject($this->id);
                     $this->id = $this->ro->id;
                     $this->init();
                 }
             }
             // If the importer is already running
             if ($this->_CI->importer->isImporting) {
                 // other actions will occur in the existing importer run...
             } else {
                 // Add the XML content of this draft to the published record (and follow enrichment process, etc.)
                 $this->_CI->importer->_reset();
                 $this->_CI->importer->setXML(wrapRegistryObjects($xml));
                 $this->_CI->importer->setDatasource($data_source);
                 $this->_CI->importer->forcePublish();
                 $this->_CI->importer->statusAlreadyChanged = true;
                 $this->_CI->importer->commit();
                 if ($this->getAttribute('original_status') == 'ASSESSMENT_IN_PROGRESS' || $this->getAttribute('manually_assessed') == 'yes') {
                     $this->ro = $this->_CI->ro->getPublishedByKey($this->getAttribute("key"));
                     $this->ro->setAttribute("manually_assessed", 'yes');
                 }
                 $this->ro->index_solr();
                 if ($error_log = $this->_CI->importer->getErrors()) {
                     throw new Exception("Errors occured whilst migrating to PUBLISHED status: " . NL . $error_log);
                 }
             }
         } else {
             $existingRegistryObject = $this->_CI->ro->getDraftByKey($this->ro->key);
             if ($existingRegistryObject) {
                 // Delete any existing drafts (effectively overwriting them)
                 $this->_CI->ro->deleteRegistryObject($existingRegistryObject->id);
             }
             // Reenrich related records (reindexes affected records)
             // XXX: REENRICH RECORDS RELATED TO ME WHEN I CHANGE STATUS
             /*
             $reenrich_queue = $target_ro->getRelatedKeys();
             $this->_CI->importer->_enrichRecords($reenrich_queue);
             $this->_CI->importer->_reindexRecords($reenrich_queue);
             */
             $this->ro->slug = DRAFT_RECORD_SLUG . $this->ro->id;
             //remove the record from the index
             $this->_CI->solr->deleteByQueryCondition('id:' . $this->ro->id);
         }
     }
     $this->_initAttribute("original_status", $target_status);
 }