Exemplo n.º 1
0
 /**
  * Генерация zip архива с лендингом
  *
  * @param $slug
  * @return Response
  */
 public function generateHtmlAction($slug)
 {
     $repository_project = $this->getDoctrine()->getRepository('SiteMainBundle:Project');
     $project = $repository_project->findOneBySlug($slug);
     $fs = new Filesystem();
     // Имя временного каталога
     $tmpName = mt_rand();
     $dir = 'export/src/' . $tmpName . '/';
     // Создание временного каталога для экспорта
     try {
         $fs->mkdir($dir);
     } catch (IOExceptionInterface $e) {
         echo "An error occurred while creating your directory at " . $e->getPath();
     }
     // Сохранение html файла во временный каталог
     $htmlContentFile = $this->renderView('SiteMainBundle:Frontend/Project:index.local.html.twig', array('project' => $project));
     file_put_contents($dir . 'index.html', $htmlContentFile);
     // Сохранение стилей, скриптов и картинок во временный каталог
     Export::rcopy('bundles/sitemain/frontend/', $dir);
     Export::rcopy('uploads/images/', $dir . 'uploads/images/');
     Export::rcopy('cache/', $dir . 'cache/');
     Export::rcopy('uploads/' . $project->getSlug() . '/', $dir . 'uploads/' . $project->getSlug() . '/');
     // Создание zip архива
     $dirZip = 'export/zip/';
     Export::zip($dir, $dirZip . $project->getSlug() . '.zip');
     // Удаление временного каталога
     Export::rrmdir($dir);
     $response = new Response(file_get_contents($dirZip . $project->getSlug() . '.zip'));
     $d = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $project->getSlug() . '.zip');
     $response->headers->set('Content-Disposition', $d);
     return $response;
 }
Exemplo n.º 2
0
 /**
  * Deletes a Project entity.
  *
  */
 public function deleteAction(Request $request, $id)
 {
     $form = $this->createDeleteForm($id);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('SiteMainBundle:Project')->find($id);
         if (!$entity) {
             throw $this->createNotFoundException($this->get('translator')->trans('backend.project.not_found'));
         }
         // Remove directory project
         if (is_dir($entity->getProjectDirectory())) {
             Export::rrmdir($entity->getProjectDirectory());
         }
         $em->remove($entity);
         $em->flush();
     }
     return $this->redirect($this->generateUrl('backend_project_index'));
 }