Ejemplo n.º 1
0
function isPublishedStatus($status)
{
    return in_array($status, getPublishedStatusGroup());
}
Ejemplo n.º 2
0
 /**
  * 
  */
 public function _ingestRecord($registryObject)
 {
     $this->CI->load->model('registry_object/registry_objects', 'ro');
     $this->CI->load->model('data_source/data_sources', 'ds');
     foreach ($this->valid_classes as $class) {
         if (property_exists($registryObject, $class)) {
             $ro_xml =& $registryObject->{$class}[0];
             // Choose whether or not to harvest this record and whether this should overwrite
             // the existing entry or just create a new revision
             list($reharvest, $revision_record_id) = $this->decideHarvestability($registryObject);
             if ($reharvest) {
                 // Clean up crosswalk XML if applicable
                 $ro_xml->registerXPathNamespace("ro", RIFCS_NAMESPACE);
                 $nativeHarvestIdx = null;
                 $idx = 0;
                 foreach ($ro_xml->relatedInfo as $relatedInfo) {
                     if ((string) $relatedInfo['type'] == NATIVE_HARVEST_FORMAT_TYPE) {
                         $nativeHarvestIdx = $idx;
                     }
                     $idx++;
                 }
                 // This is a post-crosswalk record, lets extract the native data and store it!
                 if (!is_null($nativeHarvestIdx)) {
                     // Extract
                     $nativeSchemaFormat = (string) $ro_xml->relatedInfo[$nativeHarvestIdx]->identifier[0];
                     $nativeData = trim((string) $ro_xml->relatedInfo[$nativeHarvestIdx]->notes[0]);
                     // Delete the temporary node from the registry object
                     unset($ro_xml->relatedInfo[$nativeHarvestIdx]);
                 }
                 //  Record owner should only be system if this is a harvest
                 $record_owner = "SYSTEM";
                 if ($this->CI->user->isLoggedIn()) {
                     $record_owner = $this->CI->user->name() . " (" . $this->CI->user->localIdentifier() . ")";
                 }
                 if (is_null($revision_record_id)) {
                     // We are creating a new registryObject
                     $ro = $this->CI->ro->create($this->dataSource, (string) $registryObject->key, $class, "", $this->status, "temporary_slug-" . md5((string) $registryObject->key) . "-" . time(), $record_owner, $this->harvestID);
                     // if this is ds has the qa flag set we need to check if this is the first submitted for assesmment record and if so email the notify address
                     if ($this->dataSource->qa_flag === DB_TRUE && $this->ingest_new_record < 1 && !$this->forceDraft && $this->dataSource->assessment_notify_email_addr) {
                         $this->CI->ro->emailAssessor($this->dataSource);
                     }
                     $this->ingest_new_record++;
                 } else {
                     // The registryObject exists, just add a new revision to it?
                     $ro = $this->CI->ro->getByID($revision_record_id);
                     if (!$this->maintainStatus) {
                         // GEt rid of status change recursion on DRAFT->PUBLISHED
                         if ($this->statusAlreadyChanged) {
                             $ro->original_status = $this->status;
                         }
                         // Records which have already progressed through the QA workflow will be reharvested back to existing status
                         // i.e. if the record already exists, leave it's status unchanged
                         $ro->status = $this->status;
                         // Trigger a save on the new registryObject (to make handleStatusChange get called here)
                         $ro->save();
                         // this will cause the $ro pointer to be updated to the "active" version of the record
                     }
                     $ro->record_owner = $record_owner;
                     $this->ingest_new_revision++;
                 }
                 $ro->class = $class;
                 $ro->created_who = $record_owner;
                 $ro->data_source_key = $this->dataSource->key;
                 $ro->group = (string) $registryObject['group'];
                 $ro->type = (string) $ro_xml['type'];
                 if ($this->filePath) {
                     $ro->file_path = $this->filePath;
                 }
                 if ($this->nativePath) {
                     $ro->native_path = $this->nativePath;
                 }
                 // Clean up all previous versions (set = FALSE, "prune" extRif)
                 $ro->cleanupPreviousVersions();
                 // Store the native format, if we had one
                 if (isset($nativeSchemaFormat) && isset($nativeData)) {
                     $ro->updateXML($nativeData, TRUE, $nativeSchemaFormat);
                     unset($nativeSchemaFormat);
                     unset($nativeData);
                 }
                 // Order is important here!
                 $changed = $ro->updateXML(wrapRegistryObjects($registryObject->asXML()));
                 // Generate the list and display titles first, then the SLUG
                 $ro->updateTitles($ro->getSimpleXML());
                 // Only generate SLUGs for published records
                 $ro->setAttribute("harvest_id", $this->harvestID);
                 $ro->generateSlug();
                 if (in_array($this->status, getPublishedStatusGroup())) {
                     $ro->generateSlug();
                 } else {
                     $ro->slug = DRAFT_RECORD_SLUG . $ro->id;
                     $ro->setAttribute("manually_assessed", 'no');
                 }
                 // Save all our attributes to the object
                 //TODO:
                 $ro->save($changed);
                 /*
                 					//All related objects by any means are affected regardless
                 					$related_objects = $ro->getAllRelatedObjects(false, true, true);
                 					$related_keys = array();
                 					foreach($related_objects as $rr){
                 						$related_keys[] = $rr['key'];
                 					}
                 					$this->addToAffectedList($related_keys);
                 
                 					// Also treat identifier matches as affected records which need to be enriched
                 					// (to increment their extRif:matching_identifier_count)
                 					$related_ids_by_identifier_matches = $ro->findMatchingRecords(); // from ro/extensions/identifiers.php
                 					$related_keys = array();
                 					foreach($related_ids_by_identifier_matches AS $matching_record_id){
                 						$matched_ro = $this->CI->ro->getByID($matching_record_id);
                 						$related_keys[] = $matched_ro->key;
                 					}
                 					if (count($related_keys)){
                 						$this->addToAffectedList($related_keys);
                 					}
                 */
                 // if the rif-cs didn't change we don't need to enrich record.
                 if ($changed) {
                     $ro->processIdentifiers();
                     // Add this record to our counts, etc.
                     $this->importedRecords[] = $ro->id;
                 }
                 $this->ingest_successes++;
                 // Memory management...
                 unset($ro);
                 clean_cycles();
             }
         }
     }
     unset($sxml);
     unset($xml);
     //gc_collect_cycles();
 }