mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add redirection to wopi after doc generation
This commit is contained in:
parent
663d484bee
commit
0f838fbb2d
@ -3,6 +3,8 @@
|
||||
namespace Chill\DocGeneratorBundle\Controller;
|
||||
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@ -54,7 +56,7 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
* )
|
||||
*/
|
||||
public function generateDocFromTemplateAction(
|
||||
TempUrlOpenstackGenerator $tempUrlGenerator,
|
||||
\ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface $tempUrlGenerator,
|
||||
DocGeneratorTemplate $template, string $entityClassName, int $entityId): Response
|
||||
{
|
||||
$getUrlGen = $tempUrlGenerator->generate(
|
||||
@ -87,7 +89,7 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
$fileContent = fopen($tmpfname2, 'r'); // the generated file content
|
||||
|
||||
$genDocName = 'doc_'.sprintf( '%010d', rand()).'.docx';
|
||||
$genDocName = 'doc_' . sprintf('%010d', rand()) . '.docx';
|
||||
|
||||
$getUrlGen = $tempUrlGenerator->generate(
|
||||
'PUT',
|
||||
@ -97,25 +99,28 @@ class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
$client = new Client();
|
||||
|
||||
$putResponse = $client->request('PUT', $getUrlGen->{'url'}, [
|
||||
'body' => $fileContent
|
||||
]);
|
||||
try {
|
||||
$putResponse = $client->request('PUT', $getUrlGen->{'url'}, [
|
||||
'body' => $fileContent
|
||||
]);
|
||||
|
||||
if ($putResponse->getStatusCode() == 201) {
|
||||
return new JsonResponse(
|
||||
array(
|
||||
"msg" => "Document créé",
|
||||
"id" => $genDocName,
|
||||
"response" => array(
|
||||
"reasonPhrase" => $putResponse->getReasonPhrase(),
|
||||
"statusCode" => $putResponse->getStatusCode())));
|
||||
if ($putResponse->getStatusCode() == 201) {
|
||||
$storedObject = new StoredObject();
|
||||
$storedObject
|
||||
// currently, only docx is supported
|
||||
->setType('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
|
||||
->setFilename($genDocName);
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($storedObject);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('chill_wopi_file_edit', [
|
||||
'fileId' => $genDocName
|
||||
]);
|
||||
}
|
||||
} catch (TransferException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new JsonResponse(
|
||||
array(
|
||||
"msg" => "PBM",
|
||||
"response" => array(
|
||||
"reasonPhrase" => $putResponse->getReasonPhrase(),
|
||||
"statusCode" => $putResponse->getStatusCode())));
|
||||
}
|
||||
}
|
||||
|
@ -37,14 +37,14 @@ class StoredObject implements AsyncFileInterface
|
||||
/**
|
||||
* @ORM\Column(type="json_array", name="key")
|
||||
*/
|
||||
private array $keyInfos;
|
||||
private array $keyInfos = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int[]
|
||||
* @ORM\Column(type="json_array", name="iv")
|
||||
*/
|
||||
private array $iv;
|
||||
private array $iv = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", name="creation_date")
|
||||
@ -59,7 +59,7 @@ class StoredObject implements AsyncFileInterface
|
||||
/**
|
||||
* @ORM\Column(type="json_array", name="datas")
|
||||
*/
|
||||
private array $datas;
|
||||
private array $datas = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ const datetimeToISO = (date) => {
|
||||
|
||||
const intervalDaysToISO = (days) => {
|
||||
if (null === days) {
|
||||
return 'PD0';
|
||||
return 'P0D';
|
||||
}
|
||||
|
||||
return `P${days}D`;
|
||||
|
@ -12,6 +12,6 @@ use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
|
||||
return static function (RoutingConfigurator $routes) {
|
||||
$routes
|
||||
->add('testtest', '/edit/{fileId}')
|
||||
->add('chill_wopi_file_edit', '/edit/{fileId}')
|
||||
->controller(Test::class);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user