Пример #1
0
 /**
  * Export a Group in a Json file (.rzt).
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  * @param int                                      $groupId
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function exportAction(Request $request, $groupId)
 {
     $this->validateAccessForRole('ROLE_ACCESS_GROUPS');
     $existingGroup = $this->getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Group', (int) $groupId);
     $serializer = new GroupCollectionJsonSerializer($this->getService('em'));
     $group = $serializer->serialize([$existingGroup]);
     $response = new Response($group, Response::HTTP_OK, []);
     $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'group-' . $existingGroup->getName() . '-' . date("YmdHis") . '.rzt'));
     // Rezo-Zero Type
     $response->prepare($request);
     return $response;
 }
Пример #2
0
 /**
  * Import a Json file (.rzt) containing group.
  *
  * @param string $serializedData
  * @param EntityManager $em
  *
  * @return bool
  */
 public static function importJsonFile($serializedData, EntityManager $em)
 {
     $serializer = new GroupCollectionJsonSerializer($em);
     $groups = $serializer->deserialize($serializedData);
     foreach ($groups as $group) {
         $existingGroup = $em->getRepository('RZ\\Roadiz\\Core\\Entities\\Group')->findOneBy(['name' => $group->getName()]);
         if (null === $existingGroup) {
             foreach ($group->getRolesEntities() as $role) {
                 /*
                  * then persist each role
                  */
                 $role = $em->getRepository('RZ\\Roadiz\\Core\\Entities\\Role')->findOneByName($role->getName());
             }
             $em->persist($group);
             // Flush before creating group's roles.
             $em->flush($group);
         } else {
             $existingGroup->getHandler()->diff($group);
             $em->flush($existingGroup);
         }
     }
     return true;
 }
Пример #3
0
 /**
  * Import a Json file (.rzt) containing group.
  *
  * @param string $serializedData
  *
  * @return bool
  */
 public static function importJsonFile($serializedData)
 {
     $groups = GroupCollectionJsonSerializer::deserialize($serializedData);
     foreach ($groups as $group) {
         $existingGroup = Kernel::getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Group')->findOneBy(['name' => $group->getName()]);
         if (null === $existingGroup) {
             foreach ($group->getRolesEntities() as $role) {
                 /*
                  * then persist each role
                  */
                 $role = Kernel::getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Role')->findOneByName($role->getName());
             }
             Kernel::getService('em')->persist($group);
             // Flush before creating group's roles.
             Kernel::getService('em')->flush();
         } else {
             $existingGroup->getHandler()->diff($group);
         }
         Kernel::getService('em')->flush();
     }
     return true;
 }