function _biblio_pm_create_node_from_xml in Bibliography Module 6.2
Same name and namespace in other branches
- 6 pubmed/biblio_pm.module \_biblio_pm_create_node_from_xml()
- 7 modules/pubmed/biblio_pm.module \_biblio_pm_create_node_from_xml()
- 7.2 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 183
Code
function _biblio_pm_create_node_from_xml($xml, $terms, $batch, $session_id) {
module_load_include('php', 'biblio_pm', 'EntrezPubmedArticle');
$nids = array();
$dups = array();
$node = new stdClass();
$data = new BiblioEntrezPubmedArticle();
foreach ($xml
->xpath('//PubmedArticle') as $article) {
$node = $data
->setArticle($article)
->getBiblioAsObject();
if (isset($node)) {
$dup = biblio_pm_check_md5($node->biblio_pubmed_id, $node->biblio_pubmed_md5);
$action = variable_get('biblio_pm_dup_action', 'newrev');
if (!empty($terms)) {
if (!isset($node->taxonomy)) {
$node->taxonomy = array();
}
$node->taxonomy = array_merge($terms, $node->taxonomy);
}
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.
$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
$node->nid = -$dup;
$dup = NULL;
}
if (!$dup) {
// Allows other modules to alter the node before it is being saved. (Note: $article is a SimpleXML object)
drupal_alter('biblio_pm_node', $node, $article);
biblio_save_node($node, $batch, $session_id);
if (!empty($node->nid)) {
$nids[] = $node->nid;
}
}
else {
$dups[] = $dup;
}
$node = null;
}
}
return array(
$nids,
$dups,
);
}