/**
  * Download a set of documents
  *
  * @param  Request          $request
  * @return RedirectResponse
  */
 public function checkDownload(Request $request)
 {
     $lst = $request->request->get('lst');
     $ssttid = $request->request->get('ssttid', '');
     $subdefs = $request->request->get('obj', []);
     $download = new \set_export($this->app, $lst, $ssttid);
     if (0 === $download->get_total_download()) {
         $this->app->abort(403);
     }
     $list = $download->prepare_export($this->getAuthenticatedUser(), $this->app['filesystem'], $subdefs, $request->request->get('type') === 'title' ? true : false, $request->request->get('businessfields'));
     $list['export_name'] = sprintf('%s.zip', $download->getExportName());
     $token = $this->getTokenManipulator()->createDownloadToken($this->getAuthenticatedUser(), serialize($list));
     $this->getDispatcher()->dispatch(PhraseaEvents::EXPORT_CREATE, new ExportEvent($this->getAuthenticatedUser(), $ssttid, $lst, $subdefs, $download->getExportName()));
     return $this->app->redirectPath('prepare_download', ['token' => $token->getValue()]);
 }
Beispiel #2
0
 /**
  * Download a set of documents
  *
  * @param  Application      $app
  * @param  Request          $request
  * @return RedirectResponse
  */
 public function checkDownload(Application $app, Request $request)
 {
     $lst = $request->request->get('lst');
     $ssttid = $request->request->get('ssttid', '');
     $subdefs = $request->request->get('obj', []);
     $download = new \set_export($app, $lst, $ssttid);
     if (0 === $download->get_total_download()) {
         $app->abort(403);
     }
     $list = $download->prepare_export($app['authentication']->getUser(), $app['filesystem'], $subdefs, $request->request->get('type') === 'title' ? true : false, $request->request->get('businessfields'));
     $list['export_name'] = sprintf('%s.zip', $download->getExportName());
     $token = $app['tokens']->getUrlToken(\random::TYPE_DOWNLOAD, $app['authentication']->getUser()->getId(), new \DateTime('+3 hours'), serialize($list));
     if (!$token) {
         throw new \RuntimeException('Download token could not be generated');
     }
     $app['events-manager']->trigger('__DOWNLOAD__', ['lst' => $lst, 'downloader' => $app['authentication']->getUser()->getId(), 'subdefs' => $subdefs, 'from_basket' => $ssttid, 'export_file' => $download->getExportName()]);
     return $app->redirectPath('prepare_download', ['token' => $token]);
 }
Beispiel #3
0
 /**
  * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments
  */
 public function testTwoDocumentsDownload()
 {
     $nbRowLogsBefore = $this->getNbRowLogs(self::$DI['record_1']->get_databox());
     $thumbnail = self::$DI['record_1']->get_thumbnail();
     $thumbnail2 = self::$DI['record_2']->get_thumbnail();
     $list = ['export_name' => 'Export_2012-10-23_617.zip', 'count' => 2, 'files' => [['base_id' => self::$DI['record_1']->get_base_id(), 'record_id' => self::$DI['record_1']->get_record_id(), 'export_name' => 'my_downloads', 'original_name' => '0470', 'subdefs' => ['document' => ['ajout' => '', 'path' => $thumbnail->get_path(), 'file' => $thumbnail->get_file(), 'label' => '', 'size' => $thumbnail->get_size(), 'mime' => $thumbnail->get_mime(), 'folder' => '', 'exportExt' => pathinfo($thumbnail->get_file(), PATHINFO_EXTENSION)]]], ['base_id' => self::$DI['record_2']->get_base_id(), 'record_id' => self::$DI['record_2']->get_record_id(), 'export_name' => 'my_downloads2', 'original_name' => '0471', 'subdefs' => ['document' => ['ajout' => '', 'path' => $thumbnail2->get_path(), 'file' => $thumbnail2->get_file(), 'label' => '', 'size' => $thumbnail2->get_size(), 'mime' => $thumbnail2->get_mime(), 'folder' => '', 'exportExt' => pathinfo($thumbnail2->get_file(), PATHINFO_EXTENSION)]]]]];
     $token = $this->getToken($list);
     // Build zip
     \set_export::build_zip(self::$DI['app'], $token, $list, sprintf('%s/%s.zip', self::$DI['app']['tmp.download.path'], $token->getValue()));
     // Check response
     $url = sprintf('/download/%s/get/', $token->getValue());
     self::$DI['client']->request('POST', $url);
     $response = self::$DI['client']->getResponse();
     $this->assertTrue($response->isOk(), $response);
     $this->assertRegExp('#attachment#', $response->headers->get('content-disposition'));
     $this->assertEquals('application/zip', $response->headers->get('content-type'));
     $nbRowLogsAfter = $this->getNbRowLogs(self::$DI['record_1']->get_databox());
     $this->assertGreaterThan($nbRowLogsBefore, $nbRowLogsAfter);
     unset($response);
 }
Beispiel #4
0
 /**
  * Build a zip of downloaded documents
  *
  * @param Application $app
  * @param Request     $request
  * @param Token       $token
  *
  * @return Response
  */
 public function downloadExecute(Application $app, Request $request, Token $token)
 {
     if (false === ($list = @unserialize($token->getData()))) {
         return $app->json(['success' => false, 'message' => 'Invalid datas']);
     }
     set_time_limit(0);
     // Force the session to be saved and closed.
     $app['session']->save();
     ignore_user_abort(true);
     \set_export::build_zip($app, $token, $list, sprintf($app['tmp.download.path'] . '/%s.zip', $token->getValue()));
     return $app->json(['success' => true, 'message' => '']);
 }
 /**
  * Export document by mail
  *
  * @param  Request      $request
  * @return JsonResponse
  */
 public function exportMail(Request $request)
 {
     set_time_limit(0);
     session_write_close();
     ignore_user_abort(true);
     $lst = $request->request->get('lst', '');
     $ssttid = $request->request->get('ssttid', '');
     //prepare export
     $download = new \set_export($this->app, $lst, $ssttid);
     $list = $download->prepare_export($this->getAuthenticatedUser(), $this->getFilesystem(), (array) $request->request->get('obj'), $request->request->get("type") == "title" ?: false, $request->request->get('businessfields'));
     $separator = preg_split('//', ' ;,', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
     $separator = '/\\' . implode('|\\', $separator) . '/';
     $list['export_name'] = sprintf("%s.zip", $download->getExportName());
     $list['email'] = implode(';', preg_split($separator, $request->request->get("destmail", "")));
     $destMails = [];
     //get destination mails
     foreach (explode(";", $list['email']) as $mail) {
         if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
             $destMails[] = $mail;
         } else {
             $this->dispatch(PhraseaEvents::EXPORT_MAIL_FAILURE, new ExportFailureEvent($this->getAuthenticatedUser(), $ssttid, $lst, \eventsmanager_notify_downloadmailfail::MAIL_NO_VALID, $mail));
         }
     }
     $token = $this->getTokenManipulator()->createEmailExportToken(serialize($list));
     if (count($destMails) > 0) {
         //zip documents
         \set_export::build_zip($this->app, $token, $list, $this->app['tmp.download.path'] . '/' . $token->getValue() . '.zip');
         $remaingEmails = $destMails;
         $url = $this->app->url('prepare_download', ['token' => $token->getValue(), 'anonymous' => false, 'type' => \Session_Logger::EVENT_EXPORTMAIL]);
         $user = $this->getAuthenticatedUser();
         $emitter = new Emitter($user->getDisplayName(), $user->getEmail());
         foreach ($destMails as $key => $mail) {
             try {
                 $receiver = new Receiver(null, trim($mail));
             } catch (InvalidArgumentException $e) {
                 continue;
             }
             $mail = MailRecordsExport::create($this->app, $receiver, $emitter, $request->request->get('textmail'));
             $mail->setButtonUrl($url);
             $mail->setExpiration($token->getExpiration());
             $this->deliver($mail, !!$request->request->get('reading_confirm', false));
             unset($remaingEmails[$key]);
         }
         //some mails failed
         if (count($remaingEmails) > 0) {
             foreach ($remaingEmails as $mail) {
                 $this->dispatch(PhraseaEvents::EXPORT_MAIL_FAILURE, new ExportFailureEvent($this->getAuthenticatedUser(), $ssttid, $lst, \eventsmanager_notify_downloadmailfail::MAIL_FAIL, $mail));
             }
         }
     }
     return $this->app->json(['success' => true, 'message' => '']);
 }
 /**
  * Build a zip of downloaded documents
  *
  * @param Application $app
  * @param Request     $request
  * @param String      $token
  *
  * @return Response
  */
 public function downloadExecute(Application $app, Request $request, $token)
 {
     try {
         $datas = $app['tokens']->helloToken($token);
     } catch (NotFoundHttpException $e) {
         return $app->json(['success' => false, 'message' => 'Invalid token']);
     }
     if (false === ($list = @unserialize((string) $datas['datas']))) {
         return $app->json(['success' => false, 'message' => 'Invalid datas']);
     }
     set_time_limit(0);
     // Force the session to be saved and closed.
     $app['session']->save();
     ignore_user_abort(true);
     \set_export::build_zip($app, $token, $list, sprintf($app['root.path'] . '/tmp/download/%s.zip', $datas['value']));
     return $app->json(['success' => true, 'message' => '']);
 }
 /**
  * Build a zip of downloaded documents
  *
  * @param Token       $token
  *
  * @return Response
  */
 public function downloadExecute(Token $token)
 {
     if (false === ($list = @unserialize($token->getData()))) {
         return $this->app->json(['success' => false, 'message' => 'Invalid datas']);
     }
     set_time_limit(0);
     // Force the session to be saved and closed.
     /** @var Session $session */
     $session = $this->app['session'];
     $session->save();
     ignore_user_abort(true);
     if ($list['count'] > 1) {
         \set_export::build_zip($this->app, $token, $list, sprintf($this->app['tmp.download.path'] . '/%s.zip', $token->getValue()));
     } else {
         $list['complete'] = true;
         $token->setData(serialize($list));
         /** @var EntityManagerInterface $manager */
         $manager = $this->app['orm.em'];
         $manager->persist($token);
         $manager->flush();
     }
     return $this->app->json(['success' => true, 'message' => '']);
 }
Beispiel #8
0
 /**
  * Export document by mail
  *
  * @param  Application  $app
  * @param  Request      $request
  * @return JsonResponse
  */
 public function exportMail(Application $app, Request $request)
 {
     set_time_limit(0);
     session_write_close();
     ignore_user_abort(true);
     $lst = $request->request->get('lst', '');
     $ssttid = $request->request->get('ssttid', '');
     //prepare export
     $download = new \set_export($app, $lst, $ssttid);
     $list = $download->prepare_export($app['authentication']->getUser(), $app['filesystem'], (array) $request->request->get('obj'), $request->request->get("type") == "title" ?: false, $request->request->get('businessfields'));
     $separator = preg_split('//', ' ;,', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
     $separator = '/\\' . implode('|\\', $separator) . '/';
     $list['export_name'] = sprintf("%s.zip", $download->getExportName());
     $list['email'] = implode(';', preg_split($separator, $request->request->get("destmail", "")));
     $destMails = [];
     //get destination mails
     foreach (explode(";", $list['email']) as $mail) {
         if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
             $destMails[] = $mail;
         } else {
             $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', ['usr_id' => $app['authentication']->getUser()->getId(), 'lst' => $lst, 'ssttid' => $ssttid, 'dest' => $mail, 'reason' => \eventsmanager_notify_downloadmailfail::MAIL_NO_VALID]);
         }
     }
     //generate validation token
     $endDateObject = new \DateTime('+1 day');
     $token = $app['tokens']->getUrlToken(\random::TYPE_EMAIL, false, $endDateObject, serialize($list));
     if (count($destMails) > 0 && $token) {
         //zip documents
         \set_export::build_zip($app, $token, $list, $app['root.path'] . '/tmp/download/' . $token . '.zip');
         $remaingEmails = $destMails;
         $url = $app->url('prepare_download', ['token' => $token, 'anonymous']);
         $emitter = new Emitter($app['authentication']->getUser()->getDisplayName(), $app['authentication']->getUser()->getEmail());
         foreach ($destMails as $key => $mail) {
             try {
                 $receiver = new Receiver(null, trim($mail));
             } catch (InvalidArgumentException $e) {
                 continue;
             }
             $mail = MailRecordsExport::create($app, $receiver, $emitter, $request->request->get('textmail'));
             $mail->setButtonUrl($url);
             $mail->setExpiration($endDateObject);
             $app['notification.deliverer']->deliver($mail);
             unset($remaingEmails[$key]);
         }
         //some mails failed
         if (count($remaingEmails) > 0) {
             foreach ($remaingEmails as $mail) {
                 $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', ['usr_id' => $app['authentication']->getUser()->getId(), 'lst' => $lst, 'ssttid' => $ssttid, 'dest' => $mail, 'reason' => \eventsmanager_notify_downloadmailfail::MAIL_FAIL]);
             }
         }
     } elseif (!$token && count($destMails) > 0) {
         //couldn't generate token
         foreach ($destMails as $mail) {
             $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', ['usr_id' => $app['authentication']->getUser()->getId(), 'lst' => $lst, 'ssttid' => $ssttid, 'dest' => $mail, 'reason' => 0]);
         }
     }
     return $app->json(['success' => true, 'message' => '']);
 }