/** * Import a Json file (.rzt) containing node and node source. * * @param string $serializedData * @param EntityManager $em * * @return bool */ public static function importJsonFile($serializedData, EntityManager $em) { $serializer = new NodeJsonSerializer($em); $nodes = $serializer->deserialize($serializedData); $exist = $em->getRepository('RZ\\Roadiz\\Core\\Entities\\Node')->findAll(); if (empty($exist)) { foreach ($nodes as $node) { static::browseTree($node, $em); } } return true; }
/** * Export all Node in a Json file (.rzn). * * @param Symfony\Component\HttpFoundation\Request $request * * @return Symfony\Component\HttpFoundation\Response */ public function exportAllAction(Request $request) { $this->validateAccessForRole('ROLE_ACCESS_NODES'); $existingNodes = $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Node')->findBy(["parent" => null]); foreach ($existingNodes as $existingNode) { $this->getService('em')->refresh($existingNode); } $serializer = new NodeJsonSerializer($this->getService('em')); $node = $serializer->serialize($existingNodes); $response = new Response($node, Response::HTTP_OK, []); $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'node-all-' . date("YmdHis") . '.rzn')); $response->prepare($request); return $response; }
/** * Import a Json file (.rzt) containing node and node source. * * @param string $serializedData * * @return bool */ public static function importJsonFile($serializedData) { $nodes = NodeJsonSerializer::deserialize($serializedData); $exist = Kernel::getInstance()->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Node')->findAll(); if (empty($exist)) { foreach ($nodes as $node) { static::browseTree($node); } } return true; }