} } $elements = array("title_{$lang}" => 'title', 'catalogentry' => 'identifier', 'catalog' => 'remoteid', 'language' => 'lang', "description_{$lang}" => 'description', "keyword_{$lang}" => 'keywords', 'contributor' => 'Contributor', 'issuedate' => 'IssueDate', 'agefrom' => 'AgeFrom', 'ageto' => 'AgeTo', 'format' => 'mimetype', 'location' => 'url', 'file' => 'file', 'learningresourcetype' => 'LearningResourceType', 'rights' => 'Rights', 'rightsdescription' => 'RightsDescription', 'classificationpurpose' => 'ClassificationPurpose', 'classificationtaxonpath' => 'ClassificationTaxonPath'); $xml = simplexml_load_file($file); if ($result = $xml->xpath("doc")) { foreach ($result as $doc) { // check if the entry exists $exists = false; if ($el = $doc->xpath("field[@name='catalogentry']/text()")) { $identifier = $el[0]; } if (!($entry = taoresource_entry::get_by_identifier($identifier))) { $entry = new taoresource_entry(); } else { $entry->metadata_elements = array(); $exists = true; } $entry->add_element('type', 'file'); foreach ($elements as $key => $element) { if ($el = $doc->xpath("field[@name='{$key}']/text()")) { $entry->add_element($element, $el[0]); } } if ($exists) { $entry->update_instance(); } else { $entry->add_instance(); } } } exit(0);
function taoresource_restore_mods_one_index($tredata) { // restore the entry $taoresource_entry = new object(); $taoresource_entry->id = $tredata['#']['ID']['0']['#']; $taoresource_entry->title = $tredata['#']['TITLE']['0']['#']; $taoresource_entry->type = $tredata['#']['TYPE']['0']['#']; $taoresource_entry->mimetype = $tredata['#']['MIMETYPE']['0']['#']; $taoresource_entry->identifier = $tredata['#']['IDENTIFIER']['0']['#']; $taoresource_entry->remoteid = $tredata['#']['REMOTEID']['0']['#']; if ($taoresource_entry->remoteid == '$@NULL@$') { $taoresource_entry->remoteid = ''; } $taoresource_entry->file = $tredata['#']['FILE']['0']['#']; $taoresource_entry->url = $tredata['#']['URL']['0']['#']; $taoresource_entry->lang = $tredata['#']['LANG']['0']['#']; $taoresource_entry->description = $tredata['#']['DESCRIPTION']['0']['#']; $taoresource_entry->keywords = $tredata['#']['KEYWORDS']['0']['#']; $taoresource_entry->timemodified = $tredata['#']['TIMEMODIFIED']['0']['#']; $taoresource_entry = new taoresource_entry($taoresource_entry); // restore the metadata $metadata = $tredata['#']['METADATA']['0']['#']['ELEMENT']; foreach ($metadata as $element) { $entryid = $element['#']['ENTRY_ID']['0']['#']; $el = $element['#']['ELEMENT']['0']['#']; $namespace = $element['#']['NAMESPACE']['0']['#']; $value = $element['#']['VALUE']['0']['#']; $taoresource_entry->add_element($el, $value, $namespace); } $taoresource_entry->add_instance(); }