Skip to content

Commit

Permalink
Merge branch '5.x' into feat/deprecrated-search-index-view
Browse files Browse the repository at this point in the history
  • Loading branch information
coppee committed Mar 29, 2024
2 parents 4ca12d2 + 2a4ea4d commit 7b6b773
Show file tree
Hide file tree
Showing 107 changed files with 64,556 additions and 71,485 deletions.
17 changes: 17 additions & 0 deletions EMS/common-bundle/src/Common/CoreApi/Endpoint/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ public function __construct(private readonly Client $client)
{
}

public function submit(array $data): string
{
$resource = $this->makeResource('submissions');

$data = $this->client->post($resource, $data)->getData();

return $data['submission_id'];
}

public function getSubmission(string $submissionId, ?string $property = null): array
{
$resource = $this->makeResource('submissions/'.$submissionId);
$query = \array_filter(['property' => $property]);

return $this->client->get($resource, $query)->getData();
}

public function createVerification(string $value): string
{
$resource = $this->makeResource('verifications');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@

interface FormInterface
{
/**
* @param array{
* form_name: string,
* instance: string,
* locale: string,
* data: array<string, mixed>,
* files?: array<int, array{filename: string, mimeType: string, size: int, form_field:string, base64: string}>,
* label: string,
* expire_date: string
* } $data
*/
public function submit(array $data): string;

/**
* @return array<string, mixed>
*/
public function getSubmission(string $submissionId, ?string $property = null): array;

public function createVerification(string $value): string;

public function getVerification(string $value): string;
Expand Down
12 changes: 12 additions & 0 deletions EMS/common-bundle/src/Storage/File/FileInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace EMS\CommonBundle\Storage\File;

interface FileInterface
{
public function getContent(): string;

public function getFilename(): string;
}
24 changes: 24 additions & 0 deletions EMS/common-bundle/src/Storage/File/LocalFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace EMS\CommonBundle\Storage\File;

use EMS\CommonBundle\Common\Standard\Type;

class LocalFile implements FileInterface
{
public function __construct(private readonly string $filename)
{
}

public function getContent(): string
{
return Type::string(\file_get_contents($this->filename));
}

public function getFilename(): string
{
return $this->filename;
}
}
41 changes: 41 additions & 0 deletions EMS/common-bundle/src/Storage/File/StorageFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace EMS\CommonBundle\Storage\File;

use EMS\Helpers\File\TempFile;
use Psr\Http\Message\StreamInterface;

class StorageFile implements FileInterface
{
private ?TempFile $tempFile = null;

public function __construct(private readonly string $hash, private readonly StreamInterface $stream)
{
}

public function __destruct()
{
if (null === $this->tempFile) {
return;
}

$this->tempFile->clean();
}

public function getContent(): string
{
return $this->stream->getContents();
}

public function getFilename(): string
{
if (null === $this->tempFile) {
$this->tempFile = TempFile::createNamed($this->hash);
$this->tempFile->loadFromStream($this->stream);
}

return $this->tempFile->path;
}
}
15 changes: 15 additions & 0 deletions EMS/common-bundle/src/Storage/StorageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use EMS\CommonBundle\Helper\EmsFields;
use EMS\CommonBundle\Storage\Factory\StorageFactoryInterface;
use EMS\CommonBundle\Storage\File\FileInterface;
use EMS\CommonBundle\Storage\File\LocalFile;
use EMS\CommonBundle\Storage\File\StorageFile;
use EMS\CommonBundle\Storage\Service\StorageInterface;
use EMS\Helpers\Standard\Json;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -390,6 +393,18 @@ public function saveConfig(array $config): string
return $this->saveContents($normalizedArray, 'assetConfig.json', 'application/json', StorageInterface::STORAGE_USAGE_CONFIG);
}

public function getFile(string $filenameOrHash): FileInterface
{
if (\file_exists($filenameOrHash)) {
return new LocalFile($filenameOrHash);
}
if (1 === \preg_match('/[0-9a-fA-F]/', $filenameOrHash)) {
return new StorageFile($filenameOrHash, $this->getStream($filenameOrHash));
}

throw new \RuntimeException(\sprintf('File %s not found', $filenameOrHash));
}

private function isUsageSupported(StorageInterface $adapter, int $usageRequested): bool
{
if ($adapter->getUsage() >= StorageInterface::STORAGE_USAGE_EXTERNAL) {
Expand Down
18 changes: 18 additions & 0 deletions EMS/core-bundle/assets/js/EmsListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class EmsListeners {
this.addFileUploaderListerners();
this.addA2LixLibSfCollection();
this.addDisabledButtonTreatListeners();
this.addDateRangeListeners();
tooltipDataLinks(this.target);
}

Expand Down Expand Up @@ -737,4 +738,21 @@ export default class EmsListeners {
});
}
}

addDateRangeListeners() {
const self = this;
jquery(this.target).find('.ems_daterangepicker').each(function( ) {

const options = $(this).data('display-option');
$(this).unbind('change');

if ($(this).not('.ignore-ems-update')) {
if (typeof self.onChangeCallback === "function") {
$(this).daterangepicker(options, function() { self.onChangeCallback(); });
}
} else {
$(this).daterangepicker(options);
}
});
}
}
14 changes: 0 additions & 14 deletions EMS/core-bundle/assets/js/editRevisionEventListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,6 @@ function editRevisionEventListeners(target, onChangeCallback = null){
}
});

target.find('.ems_daterangepicker').each(function( ) {

const options = $(this).data('display-option');
$(this).unbind('change');

if ($(this).not('.ignore-ems-update')) {
if (onChangeCallback) {
$(this).daterangepicker(options, function() { onChangeCallback(); });
}
} else {
$(this).daterangepicker(options);
}
});

target.find('textarea,input').each(function( ) {
const counterSpan = this.parentNode.querySelector('.text-counter');
if (null === counterSpan || !counterSpan.hasAttribute('data-counter-label') || counterSpan.parentNode !== this.parentNode) {
Expand Down
9 changes: 6 additions & 3 deletions EMS/core-bundle/src/Command/Xliff/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace EMS\CoreBundle\Command\Xliff;

use EMS\CommonBundle\Common\Command\AbstractCommand;
use EMS\CommonBundle\Storage\StorageManager;
use EMS\CoreBundle\Commands;
use EMS\CoreBundle\Entity\Environment;
use EMS\CoreBundle\Exception\XliffException;
Expand Down Expand Up @@ -43,15 +44,16 @@ public function __construct(
private readonly EnvironmentService $environmentService,
private readonly XliffService $xliffService,
private readonly PublishService $publishService,
private readonly RevisionService $revisionService
private readonly RevisionService $revisionService,
private readonly StorageManager $storageManager
) {
parent::__construct();
}

protected function configure(): void
{
$this
->addArgument(self::ARGUMENT_XLIFF_FILE, InputArgument::REQUIRED, 'Input XLIFF file')
->addArgument(self::ARGUMENT_XLIFF_FILE, InputArgument::REQUIRED, 'Input XLIFF file (filename or hash)')
->addOption(self::OPTION_PUBLISH_TO, null, InputOption::VALUE_OPTIONAL, 'If defined the revision will be published in the defined environment')
->addOption(self::OPTION_ARCHIVE, null, InputOption::VALUE_NONE, 'If set another revision will be flagged as archived')
->addOption(self::OPTION_LOCALE_FIELD, null, InputOption::VALUE_OPTIONAL, 'Field containing the locale', null)
Expand Down Expand Up @@ -90,7 +92,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
\sprintf('Starting the XLIFF update from file %s', $this->xliffFilename),
]);

$inserter = Inserter::fromFile($this->xliffFilename);
$fileGetter = $this->storageManager->getFile($this->xliffFilename);
$inserter = Inserter::fromFile($fileGetter->getFilename());
$this->io->progressStart($inserter->count());
$insertReport = new InsertReport();
foreach ($inserter->getDocuments() as $document) {
Expand Down
24 changes: 21 additions & 3 deletions EMS/core-bundle/src/Controller/Api/Form/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use EMS\CoreBundle\Service\Form\Submission\FormSubmissionException;
use EMS\CoreBundle\Service\Form\Submission\FormSubmissionService;
use EMS\Helpers\Standard\Json;
use EMS\Helpers\Standard\Type;
use EMS\SubmissionBundle\Request\DatabaseRequest;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -16,11 +17,13 @@

final class SubmissionController extends AbstractController
{
public function __construct(private readonly FormSubmissionService $formSubmissionService, private readonly LoggerInterface $logger)
{
public function __construct(
private readonly FormSubmissionService $formSubmissionService,
private readonly LoggerInterface $logger
) {
}

public function submit(Request $request): Response
public function submit(Request $request): JsonResponse
{
try {
$json = Json::decode(\strval($request->getContent()));
Expand All @@ -34,4 +37,19 @@ public function submit(Request $request): Response
return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}

public function detail(Request $request, string $submissionId): JsonResponse
{
if (null === $submission = $this->formSubmissionService->findById($submissionId)) {
return new JsonResponse([], Response::HTTP_NOT_FOUND);
}

if ($request->query->has('property')) {
$property = Type::string($request->query->get('property'));

return new JsonResponse([$property => $this->formSubmissionService->getProperty($submission, $property)]);
}

return new JsonResponse($submission);
}
}
1 change: 1 addition & 0 deletions EMS/core-bundle/src/Resources/config/command.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<argument type="service" id="ems.service.internationalization.xliff"/>
<argument type="service" id="ems.service.publish"/>
<argument type="service" id="ems.service.revision"/>
<argument type="service" id="ems_common.storage.manager"/>
<tag name="console.command"/>
</service>
<service id="ems.command.revision.discard-drafts" class="EMS\CoreBundle\Command\Revision\DiscardDraftCommand">
Expand Down
13 changes: 1 addition & 12 deletions EMS/core-bundle/src/Resources/config/routing/all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<import resource="@EMSCoreBundle/Resources/config/routing/data.xml"
prefix="/data"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api.xml" />
<import resource="@EMSCoreBundle/Resources/config/routing/public.xml"/>
<import resource="@EMSCoreBundle/Resources/config/routing/dashboard.xml"/>
<import resource="@EMSCoreBundle/Resources/config/routing/form.xml"/>
Expand Down Expand Up @@ -35,22 +36,10 @@
prefix="/data"/>
<import resource="@EMSCoreBundle/Resources/config/routing/search.xml"/>
<import resource="@EMSCoreBundle/Resources/config/routing/task.xml"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/search.xml"
prefix="/api/search"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/extract-data.xml"
prefix="/api/extract-data"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/admin.xml"
prefix="/api/admin"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/meta.xml"
prefix="/api/meta"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/file.xml"
prefix="/api/file"/>
<import resource="@EMSCoreBundle/Resources/config/routing/admin/view.xml"
prefix="/admin/view"/>
<import resource="@EMSCoreBundle/Resources/config/routing/admin/file.xml"
prefix="/admin/file"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/images.xml"
prefix="/api/images"/>
<import resource="@EMSCoreBundle/Resources/config/routing/views.xml"
prefix="/views"/>
<import resource="@EMSCoreBundle/Resources/config/routing/admin/job.xml"
Expand Down
27 changes: 27 additions & 0 deletions EMS/core-bundle/src/Resources/config/routing/api.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">

<route id="emsco_auth_token_login" path="/auth-token"
controller="EMS\CoreBundle\Controller\Api\AuthTokenLoginController::login"
methods="POST"
format="json"/>

<import resource="@EMSCoreBundle/Resources/config/routing/api/admin.xml"
prefix="/api/admin"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/extract-data.xml"
prefix="/api/extract-data"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/file.xml"
prefix="/api/file"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/forms.xml"
prefix="/api/forms"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/images.xml"
prefix="/api/images"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/meta.xml"
prefix="/api/meta"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/search.xml"
prefix="/api/search"/>

</routes>
26 changes: 26 additions & 0 deletions EMS/core-bundle/src/Resources/config/routing/api/forms.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">

<route id="emsco_api_forms_submissions" path="/submissions"
controller="EMS\CoreBundle\Controller\Api\Form\SubmissionController::submit"
methods="POST"
format="json"/>
<route id="emsco_api_forms_submissions_detail" path="/submissions/{submissionId}"
controller="EMS\CoreBundle\Controller\Api\Form\SubmissionController::detail"
methods="GET"
format="json">
<requirement key="submissionId">.*</requirement>
</route>
<route id="emsco_api_forms_post_verifications" path="/verifications"
controller="EMS\CoreBundle\Controller\Api\Form\VerificationController::createVerification"
methods="POST"
format="json"/>
<route id="emsco_api_forms_get_verifications" path="/verifications"
controller="EMS\CoreBundle\Controller\Api\Form\VerificationController::getVerification"
methods="GET"
format="json"/>

</routes>
Loading

0 comments on commit 7b6b773

Please sign in to comment.