function _biblio_pm_create_node_from_xml in Bibliography Module 7.2
Same name and namespace in other branches
- 6.2 modules/pubmed/biblio_pm.module \_biblio_pm_create_node_from_xml()
- 6 pubmed/biblio_pm.module \_biblio_pm_create_node_from_xml()
- 7 modules/pubmed/biblio_pm.module \_biblio_pm_create_node_from_xml()
2 calls to _biblio_pm_create_node_from_xml()
- biblio_pm_import_ids in modules/
pubmed/ biblio_pm.module - biblio_pm_xml_biblio_import in modules/
pubmed/ biblio_pm.module
File
- modules/
pubmed/ biblio_pm.module, line 207
Code
function _biblio_pm_create_node_from_xml($xml, $terms, $batch, $session_id) {
module_load_include('php', 'biblio_pm', 'EntrezPubmedArticle');
$bids = array();
$dups = array();
$data = new BiblioEntrezPubmedArticle();
foreach ($xml
->xpath('//PubmedArticle') as $article) {
$raw_biblio = $data
->setArticle($article)
->getBiblioAsObject();
$biblio = biblio_create($raw_biblio->biblio_type, (array) $raw_biblio);
$biblio->biblio_keywords = $raw_biblio->biblio_keywords;
$wrapper = biblio_wrapper($biblio);
if (isset($biblio)) {
$dup = biblio_pm_check_md5($biblio->biblio_pubmed_id, $biblio->biblio_pubmed_md5);
$action = variable_get('biblio_pm_dup_action', 'replace');
if ($dup < 0 && $action == 'newrev') {
//entry has be imported before, but may have changed
// Load the node in order to preserve all its data and merge the new
// data from pubmed.
// Entity API doesn't support revisions at time of current Biblio 7.x-2.x development
// $node = (object) array_merge((array)node_load(-$dup), (array)$node);
// $node->nid = -$dup;
// $node->revision = 1;
// $curr_date = format_date(time());
// $node->log = t("Automatically updated on !date due to changes at source", array('!date' => $curr_date));
// $dup = NULL;
}
if ($dup < 0 && $action == 'replace') {
//entry has be imported before, but may have changed
$biblio->bid = -$dup;
$dup = NULL;
}
if (!$dup) {
// Allows other modules to alter the biblio before it is being saved. (Note: $article is a SimpleXML object)
drupal_alter('biblio_pm_biblio', $biblio, $article);
biblio_save_node($biblio, $terms, $batch, $session_id);
if (!empty($biblio->bid)) {
$bids[] = $biblio->bid;
}
}
else {
$dups[] = $dup;
}
$biblio = NULL;
}
}
return array(
$bids,
$dups,
);
}