function taxonomy_xml_rdf_make_term in Taxonomy import/export via XML 7
Same name and namespace in other branches
- 6.2 rdf_format.inc \taxonomy_xml_rdf_make_term()
Create the placeholder and fill in the values for this term.
NOT its relationships yet.
1 call to taxonomy_xml_rdf_make_term()
- taxonomy_xml_rdf_parse in formats/
rdf_format.inc - Read in RDF taxonomies and vocabularies. Create vocabs and terms as needed.
File
- formats/
rdf_format.inc, line 563
Code
function taxonomy_xml_rdf_make_term(&$term) {
$identifier = taxonomy_xml_get_term_guid($term);
// drupal_set_message(t("Reviewing term %identifier '%name' and analyzing its properties", array('%identifier' => $identifier, '%name' => @$term->name)));
if (empty($identifier)) {
watchdog('taxonomy_xml', "\n Attempting to make term, but no identifier is available. Can't do that. Skipping it. <pre>!term</pre>", array(
'!term' => print_r($term, 1),
), WATCHDOG_ERROR);
return NULL;
}
// When running in batch, children will have a hard time finding their
// parents if they only know them by source-localized ID (probably a URI)
// and the destination-taxonomy (here) HASN'T REMEMBERED THAT INFO.
// Because taxonomy.module just doesn't.
// We require some other method (fields on terms) to save that
// metadata for us so the child can find its target later.
// This is our 'identifier' - the REMOTE identifier not the local one.
// Build term from data.
// Convert all input predicates into attributes on the object
// the taxonomy.module will understand.
taxonomy_xml_canonicize_predicates($term);
// Ensure name is valid, this is required.
if (empty($term->name)) {
// Fallback to a name, identifier
// derived (roughly) from the URI identifier.
// Not always meaningful, but all we have in some contexts.
$term->name = taxonomy_xml_shortname($identifier);
if (empty($term->name)) {
// Still not set?
// This should be impossible - all subjects must have a URI or identifier
// But who knows what wierdness the input gave us.
drupal_set_message(t("\n A term called %identifier didn't produce any readable name to use. ", array(
'%identifier' => $identifier,
)), 'error');
watchdog('taxonomy_xml', "\n Invalid term object, not enough data : NO NAME <pre>!term</pre>", array(
'!term' => print_r($term, 1),
), WATCHDOG_ERROR);
return;
}
else {
watchdog('taxonomy_xml', "\n We were unable to find a specific label for the term\n referred to as %identifier.\n Guessing that %name will be good enough.", array(
'%identifier' => $identifier,
'%name' => $term->name,
), WATCHDOG_NOTICE);
// Still, this causes problems
// if queuing data about terms that are not yet loaded
// - such as those that are ONLY referenced by URI
// with no human name (Freenet)
// Our munged names are temporary until the full data is retrieved.
}
}
// See if a definition matching this terms name already exists in the DB.
// Build on that.
$existing_term = taxonomy_xml_get_term_by_guid($identifier, $term->vid);
if (!$existing_term) {
$force_new = variable_get('taxonomy_xml_duplicate', FALSE);
$existing_term = _taxonomy_xml_get_term_placeholder($term->name, $term->vid, $force_new);
}
// Merge the old term objects properties into this one.
// Really just want its tid, but there may be more info I should not lose.
// New input takes precedence over older data.
// Old data just fills in the gaps.
foreach ((array) $existing_term as $key => $value) {
if (!isset($term->{$key})) {
$term->{$key} = $value;
}
}
// The term object is now as tidy as it can be as a self-contained entity.
// dpm($term);
// It may be premature to save this term if we don't know its parent yet,
// The system will default to parent=0, which causes bad structure later on.
if (!isset($term->parents)) {
watchdog('taxonomy_xml', "About to save a term '%name' with no parent, this could be a problem later, but probably just means it's root-level", array(
'%name' => $term->name,
), WATCHDOG_INFO);
}
$status = taxonomy_term_save($term);
// This object is being passed around as a handle, so I don't expect to have
// lost anything important from it.
if ($status == SAVED_NEW) {
// Just remember this is fresh - for useful feedback messages.
$term->taxonomy_xml_new_term = TRUE;
}
// It's possible that not all the referenced items were available
// in the current document/loop.
// Add referred items to the import queue for later processing.
taxonomy_xml_add_all_children_to_queue($term);
$term->taxonomy_xml_presaved = TRUE;
// A flag to avoid double-processing.
return $term;
}