function import_folder($folder, $parent_id) { $qb = midcom_db_topic::new_query_builder(); $qb->add_constraint('up', '=', (int) $parent_id); $qb->add_constraint('name', '=', $folder->name); $existing = $qb->execute(); if (count($existing) > 0 && $existing[0]->up == $parent_id) { $topic = $existing[0]; echo "Using existing topic {$topic->name} (#{$topic->id}) from #{$topic->up}\n"; } else { $topic = new midcom_db_topic(); $topic->up = $parent_id; $topic->name = $folder->name; if (!$topic->create()) { echo "Failed to create folder {$folder->name}: " . midcom_connection::get_error_string() . "\n"; return false; } echo "Created folder {$topic->name} (#{$topic->id}) under #{$topic->up}\n"; } $topic->extra = $folder->title; $topic->update(); $topic->parameter('midcom', 'component', $folder->component); if ($folder->component == 'net.nehmer.static') { if (!$folder->has_index) { $topic->parameter('net.nehmer.static', 'autoindex', 1); } else { $topic->parameter('net.nehmer.static', 'autoindex', ''); } } foreach ($folder->files as $file) { $this->import_file($file, $topic->id); } foreach ($folder->folders as $subfolder) { $this->import_folder($subfolder, $topic->id); } return true; }