/** * The profile importer tries to import raw profile fields using the * strategy mechanism, but most of the useful profile information is stored * in the person entry corresponding to the author. * * The persondata entry is not actually imported using a strategy, because * we need to be able to import basic data from the <author> element if * it's not present too. So all the person importing is handled in import_author_data() */ public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer) { if (self::$personcontentblank === null) { self::$personcontentblank = true; if ($persondataid = $importer->get('persondataid')) { self::$personcontentblank = !(string) $importer->get_entry_by_id($persondataid)->content; } } $isentry = PluginImportLeap::is_rdf_type($entry, $importer, 'entry'); if ($isentry && self::$personcontentblank && PluginImportLeap::is_correct_category_scheme($entry, $importer, 'common_item', 'Personalstatement')) { return array(array('strategy' => self::STRATEGY_IMPORT_AS_INTRODUCTION, 'score' => 100, 'other_required_entries' => array())); } // If it's a raw entry with the right mahara:plugin and mahara:type // we should be able to import it $correctplugintype = count($entry->xpath('mahara:artefactplugin[@mahara:plugin="internal"]')) == 1; if ($isentry && $correctplugintype) { return array(array('strategy' => self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'score' => 100, 'other_required_entries' => array())); } return array(); }
/** * The profile importer has two strategies it can use for certain entries. * * The profile importer attempts to "reserve" the persondata entry * representing the user being imported (if one exists). * * The persondata entry is not actually imported using a strategy, because * we need to be able to import basic data from the <author> element if * it's not present too. So all the importing is handled in one custom hook * - import_author_data() * * The importer also tries to reserve raw entries with mahara:plugin="internal" * - these can be used to populate some of our profile fields that aren't * explicitly mapped in LEAP2A. */ public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImport $importer) { $strategies = array(); if (is_null(self::$persondataid)) { $author = $importer->get('xml')->xpath('//a:feed/a:author[1]'); $author = $author[0]; if (isset($author->uri) && $importer->get_entry_by_id((string) $author->uri)) { self::$persondataid = (string) $author->uri; } else { self::$persondataid = false; } } // TODO: also check other element has the right leaptype (person) //$correctrdftype = count($entry->xpath('rdf:type[' // . $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'selection') . ']')) == 1; if ((string) $entry->id == self::$persondataid) { $strategies[] = array('strategy' => self::STRATEGY_DUMMY, 'score' => 100, 'other_required_entries' => array()); } else { // If it's a raw entry with the right mahara:plugin and mahara:type // we should be able to import it $correctrdftype = count($entry->xpath('rdf:type[' . $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'entry') . ']')) == 1; $correctplugintype = count($entry->xpath('mahara:artefactplugin[@mahara:plugin="internal"]')) == 1; if ($correctrdftype && $correctplugintype) { $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'score' => 100, 'other_required_entries' => array()); } } return $strategies; }
/** * Import entries using our load mapping. See: * http://wiki.mahara.org/Developer_Area/Import%2f%2fExport/Import%3a_Implementation_Plan#second_pass.3a_load_all_entries_into_mahara_as_per_load_mapping */ private function import_from_load_mapping() { $this->trace("--------------------------\nimport_from_load_mapping()"); // TODO: do both usedlists as by key instead of by value for faster checks $usedlist = $loadedentries = array(); uksort($this->loadmapping, create_function('$a, $b', 'return $a["score"] < $b["score"];')); foreach ($this->loadmapping as $entryid => $strategydata) { if (in_array($entryid, $usedlist)) { // TODO: what should we do in this case? $this->trace("WARNING: {$entryid} has already been imported as part of a previous entry"); continue; } if (isset($strategydata['other_required_entries'])) { foreach ($strategydata['other_required_entries'] as $otherentryid) { if (in_array($otherentryid, $usedlist)) { $this->trace("WARNING: {$entryid} has already been imported as part of a previous entry"); continue 2; } } } $this->trace("Importing {$entryid} using strategy {$strategydata['strategy']} of plugin {$strategydata['artefactplugin']}"); safe_require('artefact', $strategydata['artefactplugin']); $entry = $this->get_entry_by_id($entryid); $classname = 'LeapImport' . ucfirst($strategydata['artefactplugin']); // TODO: this throws ImportException if it can't be imported, need // to decide if this exception can bubble up or whether it should // be caught here $artefactmapping = call_static_method($classname, 'import_using_strategy', $entry, $this, $strategydata['strategy'], $strategydata['other_required_entries']); if (!is_array($artefactmapping)) { throw new SystemException("import_from_load_mapping(): {$classname}::import_using_strategy has not return a list"); } $this->artefactids = array_merge($this->artefactids, $artefactmapping); $usedlist[] = $entryid; if (isset($strategydata['other_required_entries'])) { foreach ($strategydata['other_required_entries'] as $otherentryid) { $usedlist[] = $otherentryid; } } $loadedentries[] = $entryid; } // The internal artefact plugin needs to deal with the <author> tag // plus persondata for the author. // Note: I don't feel guilty doing this in this way because a) internal // artefact plugin is required and b) it's the only one that needs this // TODO: this should return an artefact mapping so things can create // links to profile fields, but nothing actually needs it yet LeapImportInternal::import_author_data($this); // Now all artefacts are loaded, allow each plugin to load // relationships for them if they need to foreach ($loadedentries as $entryid) { $strategydata = $this->loadmapping[$entryid]; $classname = 'LeapImport' . ucfirst($strategydata['artefactplugin']); $entry = $this->get_entry_by_id($entryid); call_static_method($classname, 'setup_relationships', $entry, $this, $strategydata['strategy'], $strategydata['other_required_entries']); } }