Пример #1
0
 /**
  * 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']);
     }
 }