/** * Import all the cities from the xml. */ private function importCities($xmlElement) { // Clear them first. db_query('TRUNCATE {culturefeed_search_cities}'); // Import rows. foreach ($xmlElement->cities->city as $city) { $cityAttributes = $city->attributes(); $record = array('cid' => (string) $cityAttributes['id'], 'name' => (string) $cityAttributes['label'], 'zip' => (string) $cityAttributes['zip'], 'slug' => (string) $cityAttributes['zip'] . '-' . culturefeed_search_slug((string) $cityAttributes['label'], 251)); drupal_write_record('culturefeed_search_cities', $record); $this->logMessages[] = array('message' => 'Imported city ' . (string) $cityAttributes['label'], 'code' => 'success'); } }
/** * Import all the terms with given pids as parents. */ private function importTerms($TermsElement, $pids = array()) { $parents = array(); foreach ($TermsElement as $term) { $termAttributes = $term->attributes(); // Do not import disabled terms if ($termAttributes['enabled'] == 'false' && drupal_is_cli()) { drush_log('skipped disabled term: ' . $termAttributes['id'], 'warning'); continue; } // If it has children, also import them. if (isset($term->term)) { $child_pids = $pids; $child_pids['p' . (count($pids) + 1)] = (string) $termAttributes['id']; $this->importTerms($term->term, $child_pids); } $parentId = trim((string) $termAttributes['parentid']); $parents[(string) $termAttributes['id']] = $parentId; $record = array('tid' => (string) $termAttributes['id'], 'language' => LANGUAGE_NONE, 'name' => (string) $termAttributes['label'], 'did' => (string) $termAttributes['domain'], 'parent' => empty($parentId) ? $parentId : NULL, 'show_term' => $termAttributes['show'] == 'true' ? 1 : 0, 'slug' => culturefeed_search_slug((string) $termAttributes['label'], 128)); $record += $pids; // Get all the parent ids (p1, p2, p3...) /* if (!empty($parentId)) { $parentWasTerm = TRUE; $currTerm = $term; $termParents = array(); // Loop through parents untill we find a non-term node. while ($parentWasTerm) { // Get parent of current term, and check if it's also a term. $parent_node = $currTerm->xpath('parent::*'); $parent = $parent_node[0]; if (!$parent) { break; } if ($parent->getName() == 'term') { $termParents[] = (string) $parent->attributes()->id; $currTerm = $parent; } else { $parentWasTerm = FALSE; } } foreach ($termParents as $i => $id) { $record['p' . ($i + 1)] = $id; } } */ // Always save label as undefined language so we can fallback. $this->logMessages[] = array('message' => 'Imported term ' . $record['name'] . ' ' . $parentId . ' for domain ' . $record['did'], 'code' => 'success'); drupal_write_record('culturefeed_search_terms', $record); // Import other languages. foreach (array('nl', 'en', 'de', 'fr') as $language) { $key = 'label' . $language; if (isset($termAttributes[$key]) && !empty($termAttributes[$key])) { $record['language'] = $language; $record['name'] = (string) $termAttributes[$key]; drupal_write_record('culturefeed_search_terms', $record); $this->logMessages[] = array('message' => 'Imported term ' . $record['name'] . ' ' . $parentId . ' in language ' . $record['language'], 'code' => 'success'); } } } }