/** * */ 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); }
/** * Deletes a RegistryObject * * @param the registry object key * @return TRUE if delete was successful */ public function deleteRegistryObject($target_ro, $finalise = true) { $reenrich_queue = array(); // Check target_ro if (!$target_ro instanceof _registry_object) { $target_ro = $this->getByID($target_ro); if (!$target_ro) { throw new Exception("Registry Object targeted for delete does not exist?"); } } if ($finalise) { //delete index $this->load->library('Solr'); $this->solr->deleteByQueryCondition('id:' . $target_ro->id); } if (isPublishedStatus($target_ro->status)) { $this->load->model('data_source/data_sources', 'ds'); $data_source = $this->ds->getByID($target_ro->data_source_id); // Handle URL backup $this->db->where('registry_object_id', $target_ro->id); $this->db->update('url_mappings', array("registry_object_id" => NULL, "search_title" => $target_ro->title, "updated" => time())); //remore previous records from the deleted_registry_objects table $this->db->delete('deleted_registry_objects', array('key' => $target_ro->key)); // Add to deleted_records table $this->db->set(array('data_source_id' => $target_ro->data_source_id, 'key' => $target_ro->key, 'deleted' => time(), 'title' => $target_ro->title, 'class' => $target_ro->class, 'group' => str_replace(" ", "0x20", $target_ro->group), 'datasource' => str_replace(" ", "0x20", $data_source->slug), 'record_data' => $target_ro->getRif())); $this->db->insert('deleted_registry_objects'); // Re-enrich and reindex related $reenrich_queue = $target_ro->getRelatedKeys(); if ($finalise) { // Delete from the index $result = json_decode($this->solr->deleteByQueryCondition("id:(\"" . $target_ro->id . "\")")); if ($result->responseHeader->status != 0) { $data_source->append_log("Failed to erase from SOLR: id:" . $target_ro->id, 'error', 'registry_object'); } else { $this->solr->commit(); } } } // Also treat identifier matches as affected records which need to be enriched // (to increment their extRif:matching_identifier_count) $related_ids_by_identifier_matches = $target_ro->findMatchingRecords(); // from ro/extensions/identifiers.php $related_keys = array(); foreach ($related_ids_by_identifier_matches as $matching_record_id) { $matched_ro = $this->ro->getByID($matching_record_id); $reenrich_queue[] = $matched_ro->key; } // Delete the actual registry object $this->load->model('data_source/data_sources', 'ds'); $data_source = $this->ds->getByID($target_ro->data_source_id); $log = $target_ro->eraseFromDatabase($target_ro->id); //if($log) //$data_source->append_log("eraseFromDatabase " . $log, 'info', 'registry_object'); if ($finalise) { // And then their related records get reindexed... $this->importer->_enrichRecords($reenrich_queue); $this->importer->_reindexRecords($reenrich_queue); //log_message('debug', "Reindexed " . count($reenrich_queue) . " related record(s) when " . $target_ro->key . " was deleted."); } return $reenrich_queue; }
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); }