public function execute(Batch $batch) { $values = $batch->getObjectCollection('tree'); if (!$values) { return; } foreach ($values->getTrees() as $t) { $name = (string) $t->getName(); $tree = Topic::getByName($name); if (is_object($tree)) { // We already have a tree. But we know we're going to have sub-nodes // of this tree in the import, so let's keep the same tree so that pointers // to attributes work, but let's clear it out. $root = $tree->getRootTreeNodeObject(); $root->populateChildren(); $children = $root->getChildNodes(); foreach ($children as $child) { $child->delete(); } } else { $tree = Topic::add($name); } $parent = $tree->getRootTreeNodeObject(); foreach ($t->getRootNodes() as $node) { $this->add($node, $parent); } } }
public function submit() { $vs = Loader::helper('validation/strings'); $sec = Loader::helper('security'); $name = $sec->sanitizeString($this->post('topicTreeName')); if (!$this->token->validate('submit')) { $this->error->add(t($this->token->getErrorMessage())); } if (!$vs->notempty($name)) { $this->error->add(t('You must specify a valid name for your tree.')); } if (!PermissionKey::getByHandle('add_topic_tree')->validate()) { $this->error->add(t('You do not have permission to add this tree.')); } if (!$this->error->has()) { $tree = TopicTree::add($name); $this->redirect('/dashboard/system/attributes/topics', 'tree_added', $tree->getTreeID()); } }