/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $rootNode = new DocumentNode(); $rootNode->setName('ROOT')->setUniqRef('ROOT'); $manager->persist($rootNode); $manager->flush(); }
/** * transform * * @param \Erichard\DmsBundle\Entity\DocumentNode $node * * @return string */ public function transform($node) { if (null === $node) { return ''; } return $node->getId(); }
/** * execute * * @param InputInterface $input * @param OutputInterface $output * * @SuppressWarnings("unused") * * @return mixed */ protected function execute(InputInterface $input, OutputInterface $output) { $sourceDir = $input->getArgument('source'); $manager = $this->getContainer()->get('doctrine')->getManager(); // Trying to retrieve existing destination node. $dest = $manager->getRepository('ErichardDmsBundle:DocumentNode')->findOneBySlug($input->getOption('name')); if (!isset($dest)) { // Prepare a newly created destination node $dest = new DocumentNode(); $dest->setName($input->getOption('name')); } // Launch the importer $importer = new FilesystemImporter($this->getContainer()->get('doctrine')->getManager(), array('storage_path' => $this->getContainer()->getParameter('dms.storage.path'), 'copy' => $input->getOption('copy'))); $importer->import($sourceDir, $dest, $input->getOption('exclude')); }
/** * importDir * * @param array $currentNode * @param integer $depth * @param mixed $file * @param DocumentNodeInterface $targetNode * * @return DocumentNode */ public function importDir($currentNode, $depth, $file, $targetNode) { $node = new DocumentNode(); $node->setParent($currentNode[$depth])->setName($file->getBaseName())->setDepth($targetNode->getDepth() + $depth + 1); if (isset($this->options['node_callback']) && is_callable($this->options['node_callback'])) { call_user_func_array($this->options['node_callback'], array($node)); } $this->emn->persist($node); return $node; }
/** * deleteDocument * * @param DocumentNode $document */ public function deleteDocument($document) { $parts = preg_split('~/(?=[^/]*$)~', $document->getFilename()); $finder = new Finder(); $finder->files()->in($this->container->getParameter('dms.storage.path') . '/' . $parts[0])->name($parts[1]); foreach ($finder as $file) { $this->container->get('filesystem')->remove($file); } }
/** * isuserNode * * @param \Erichard\DmsBundle\Entity\DocumentNode $node * * @return boolean */ public function isUserNode($node) { $return = false; if (preg_match('/' . $this->container->getParameter('dms.workspace.user_pattern') . '/', $node->getUniqRef())) { $return = true; } return $return; }
/** * createAction * * @param string $node * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function createAction($node) { $emn = $this->get('doctrine')->getManager(); $parentNode = $this->findNodeOrThrowError($node); $newNode = new DocumentNode(); $newNode->setParent($parentNode); $form = $this->createForm('dms_node', $newNode); $form->bind($this->get('request')); if (!$form->isValid()) { $response = $this->render('ErichardDmsBundle:Standard/Node:add.html.twig', array('node' => $parentNode, 'form' => $form->createView())); } else { $metadatas = $form->get('metadatas')->getData(); foreach ($metadatas as $metaName => $metaValue) { if (null !== $metaValue) { $metadata = new DocumentNodeMetadataLnk($emn->getRepository('Erichard\\DmsBundle\\Entity\\Metadata')->findOneByName($metaName)); $metadata->setValue($metaValue); $newNode->addMetadata($metadata); $emn->persist($metadata); } } $emn->persist($newNode); $emn->flush(); if ($this->get('event_dispatcher')->hasListeners(DmsEvents::NODE_CREATE)) { $event = new DmsNodeEvent($newNode); $this->get('event_dispatcher')->dispatch(DmsEvents::NODE_CREATE, $event); } $this->get('session')->getFlashBag()->add('success', 'documentNode.add.successfully_created'); $response = $this->redirect($this->generateUrl('erichard_dms_node_list', array('node' => $node))); } return $response; }