/** * Returns a list of entry IDs that are children of this folder * * If necessary, this method can act recursively to find children at all * levels under this folder * * TODO: protection against circular references * * @param SimpleXMLElement $entry The folder to get children for * @param PluginImport $importer The importer * @param boolean $recurse Whether to return children at all levels below this folder * @return array A list of the entry IDs of children in this folder */ private static function get_children_of_folder(SimpleXMLElement $entry, PluginImport $importer, $recurse = false) { $children = array(); // Get entries that this folder feels are a part of it foreach ($entry->link as $link) { if ($importer->curie_equals($link['rel'], PluginImportLeap::NS_LEAP, 'has_part') && isset($link['href'])) { $child = $importer->get_entry_by_id((string) $link['href']); if ($child) { if (self::is_file($child, $importer) || self::is_folder($child, $importer)) { $children[] = (string) $link['href']; } else { $importer->trace("NOTICE: Child {$child->id} of folder {$entry->id} won't be imported by the file plugin because it is not a file or folder"); } } else { $importer->trace("WARNING: folder {$entry->id} claims to have child {$link['href']} which does not exist"); } } } if ($recurse) { foreach ($children as $childid) { $child = $importer->get_entry_by_id($childid); if (self::is_folder($child, $importer)) { $children = array_merge($children, self::get_children_of_folder($child, $importer, true)); } } } return $children; }
/** * Attaches files to blog posts * * We look at the leap relationships to add attachments. Currently this * looks explicitly for the has_attachment relationship. * * If importing an entry resulted in importing a new file (caused by the * entry having out-of-line content), we attach that file to the entry. */ public static function setup_relationships(SimpleXMLElement $entry, PluginImport $importer, $strategy, array $otherentries) { switch ($strategy) { case self::STRATEGY_IMPORT_AS_BLOG: foreach ($otherentries as $entryid) { $blogpostentry = $importer->get_entry_by_id($entryid); // Get all attachments this blogpost things are attached to it // TODO: get all entries that think they're attached to the blogpost. // I think we can only look for files, Mahara doesn't understand // attaching something that isn't a file to a blogpost foreach ($blogpostentry->link as $blogpostlink) { $blogpost = null; if ($importer->curie_equals($blogpostlink['rel'], PluginImportLeap::NS_LEAP, 'has_attachment') && isset($blogpostlink['href'])) { if (!$blogpost) { $artefactids = $importer->get_artefactids_imported_by_entryid((string) $blogpostentry->id); $blogpost = new ArtefactTypeBlogPost($artefactids[0]); } $importer->trace("Attaching file {$blogpostlink['href']} to blog post {$blogpostentry->id}", PluginImportLeap::LOG_LEVEL_VERBOSE); $artefactids = $importer->get_artefactids_imported_by_entryid((string) $blogpostlink['href']); $blogpost->attach_file($artefactids[0]); } if ($blogpost) { $blogpost->commit(); } } self::setup_outoflinecontent_relationship($blogpostentry, $importer); } break; case self::STRATEGY_IMPORT_AS_ENTRY: self::setup_outoflinecontent_relationship($entry, $importer); break; default: throw new ImportException($importer, 'TODO: get_string: unknown strategy chosen for importing entry'); } }