Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(common/api): publish api (client/server)+ command #1080

Merged
merged 24 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bd4eab6
fix: Etag is not a key, so it was always no
theus77 Nov 25, 2024
a45a9d2
feat: loadArchiveItemsInCache
theus77 Nov 25, 2024
08e4b1e
ref: quiet option is automatically taken into account by SymfonyConsole
theus77 Nov 25, 2024
2332726
ref: quiet option is automatically taken into account by SymfonyConsole
theus77 Nov 25, 2024
34d63ae
ref: quiet option is automatically taken into account by SymfonyConsole
theus77 Nov 25, 2024
8914446
feat: progressbar on building archive
theus77 Nov 25, 2024
c3c6c35
ref: cleaner, a bit
theus77 Nov 25, 2024
04b3b99
feat: ems:storage:load-archive-in-cache command
theus77 Nov 25, 2024
9d6e504
feat: loadArchiveItemsInCache
theus77 Nov 25, 2024
e6a5d63
feat: Archive::diff
theus77 Nov 25, 2024
756ef4f
Merge branch '5.x' into feat/preload_archive_in_cache
theus77 Nov 25, 2024
8986528
fix: heads assume that files must be know by the first storage service
theus77 Nov 25, 2024
ae9c7e0
feat: skip already loaded files
theus77 Nov 25, 2024
0318454
fix: if the archive hash changes, all cache must be loaded for that b…
theus77 Nov 25, 2024
412f92b
ref: loadArchiveItemsInCache
theus77 Nov 25, 2024
4468bba
ref: kind if symlink in S3 storage services
theus77 Nov 25, 2024
ec898cd
chore: phpcs
theus77 Nov 25, 2024
8cc4708
feat: extra parameter to not try extract again if not found in cache
theus77 Nov 25, 2024
1221638
feat: extra indexResource parameter for directory path
theus77 Nov 25, 2024
81745f7
feat: better not found message
theus77 Nov 25, 2024
e30261a
feat: publish api (client&server)
theus77 Nov 26, 2024
3ff5eae
feat: publish command
theus77 Nov 26, 2024
f4dcdf2
Merge branch '5.x' into feat/preload_archive_in_cache
theus77 Nov 26, 2024
1ddd534
ref: using giveByName functions
theus77 Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions EMS/common-bundle/src/Command/Document/PublishCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace EMS\CommonBundle\Command\Document;

use EMS\CommonBundle\Common\Admin\AdminHelper;
use EMS\CommonBundle\Common\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

class PublishCommand extends AbstractCommand
{
private const ARGUMENT_CONTENT_TYPE = 'content-type';
private const ARGUMENT_OUUID = 'ouuid';
private const ARGUMENT_TARGET_ENVIRONMENT = 'target-environment';
private const ARGUMENT_REVISION_ID = 'revisison-id';
private string $contentTypeName;
private string $ouuid;
private string $targetEnvironmentName;
private ?string $revisionId;

public function __construct(private readonly AdminHelper $adminHelper)
{
parent::__construct();
}

protected function configure(): void
{
parent::configure();
$this
->addArgument(self::ARGUMENT_CONTENT_TYPE, InputArgument::REQUIRED, \sprintf('Content-type\'s name'))
->addArgument(self::ARGUMENT_OUUID, InputArgument::REQUIRED, \sprintf('OUUID of the document to publish'))
->addArgument(self::ARGUMENT_TARGET_ENVIRONMENT, InputArgument::REQUIRED, \sprintf('Environment\'s name to publish in'))
->addArgument(self::ARGUMENT_REVISION_ID, InputArgument::OPTIONAL, \sprintf('Revision ID of the revision to publish, will take the revision publish in the default environment otherwise.'))
;
}

public function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output);
$this->adminHelper->setLogger(new ConsoleLogger($output));
$this->contentTypeName = $this->getArgumentString(self::ARGUMENT_CONTENT_TYPE);
$this->targetEnvironmentName = $this->getArgumentString(self::ARGUMENT_TARGET_ENVIRONMENT);
$this->ouuid = $this->getArgumentString(self::ARGUMENT_OUUID);
$this->revisionId = $this->getArgumentStringNull(self::ARGUMENT_REVISION_ID);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io->title(\sprintf('Publish the document %s to the environment %s', $this->ouuid, $this->targetEnvironmentName));
$api = $this->adminHelper->getCoreApi()->data($this->contentTypeName);
if (!$api->publish($this->ouuid, $this->targetEnvironmentName, $this->revisionId)) {
$this->io->error('The document was not published');

return self::EXECUTE_ERROR;
}
$this->io->error('The document has been successfully published');

return self::EXECUTE_SUCCESS;
}
}
11 changes: 11 additions & 0 deletions EMS/common-bundle/src/Common/CoreApi/Endpoint/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,15 @@ private function makeResource(?string ...$path): string
{
return \implode('/', \array_merge($this->endPoint, \array_filter($path)));
}

public function publish(string $ouuid, string $environment, string $revisionId = null): bool
{
$resource = $this->makeResource('publish', $ouuid, $environment, $revisionId ?? '');
$success = $this->client->post($resource)->getData()['success'] ?? null;
if (!\is_bool($success)) {
throw new \RuntimeException('Unexpected: search must be a boolean');
}

return $success;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ public function update(string $ouuid, array $rawData): DraftInterface;
* @throws CoreApiExceptionInterface
*/
public function save(string $ouuid, array $rawData, int $mode = self::MODE_UPDATE, bool $discardDraft = true): int;

public function publish(string $ouuid, string $environment, string $revisionId = null): bool;
}
4 changes: 4 additions & 0 deletions EMS/common-bundle/src/Resources/config/commands.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<argument type="string">%kernel.project_dir%</argument>
<tag name="console.command" command="ems:document:download"/>
</service>
<service id="ems.command.document.publish" class="EMS\CommonBundle\Command\Document\PublishCommand">
<argument type="service" id="ems.helper.admin_api"/>
<tag name="console.command" command="ems:document:publish"/>
</service>
<service id="ems.command.document.update" class="EMS\CommonBundle\Command\Document\UpdateCommand">
<argument type="service" id="ems.helper.admin_api"/>
<argument type="string">%kernel.project_dir%</argument>
Expand Down
51 changes: 51 additions & 0 deletions EMS/core-bundle/src/Controller/Api/Data/PublishController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace EMS\CoreBundle\Controller\Api\Data;

use Doctrine\ORM\NonUniqueResultException;
use EMS\CoreBundle\Entity\Revision;
use EMS\CoreBundle\Service\ContentTypeService;
use EMS\CoreBundle\Service\EnvironmentService;
use EMS\CoreBundle\Service\PublishService;
use EMS\CoreBundle\Service\Revision\RevisionService;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class PublishController
{
public function __construct(
private readonly PublishService $publishService,
private readonly RevisionService $revisionService,
private readonly ContentTypeService $contentTypeService,
private readonly EnvironmentService $environmentService,
) {
}

public function publish(string $contentTypeName, string $ouuid, string $targetEnvironmentName, Revision $revision = null): JsonResponse
{
if (null === $revision) {
$contentType = $this->contentTypeService->giveByName($contentTypeName);
$revision = $this->revisionService->getCurrentRevisionForEnvironment($ouuid, $contentType, $contentType->giveEnvironment());
} elseif ($revision->giveContentType()->getName() !== $contentTypeName) {
throw new \RuntimeException(\sprintf('Content type mismatch for revision %d: Expected %s is in fact of type %s', $revision->getId(), $contentTypeName, $revision->giveContentType()->getName()));
}
if (null === $revision) {
throw new \RuntimeException(\sprintf('Revision not found for OUUID %s and Content type %s', $ouuid, $contentTypeName));
}

$targetEnvironment = $this->environmentService->giveByName($targetEnvironmentName);

try {
$publishedCounter = $this->publishService->publish($revision, $targetEnvironment);
} catch (NonUniqueResultException) {
throw new NotFoundHttpException('Document not found');
}

return new JsonResponse([
'success' => true,
'already-published' => 0 === $publishedCounter,
]);
}
}
7 changes: 7 additions & 0 deletions EMS/core-bundle/src/Resources/config/controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,13 @@
<tag name="container.service_subscriber"/>
<tag name="controller.service_arguments"/>
</service>
<service id="EMS\CoreBundle\Controller\Api\Data\PublishController">
<argument type="service" id="ems.service.publish" />
<argument type="service" id="ems.service.revision" />
<argument type="service" id="ems.service.contenttype" />
<argument type="service" id="ems.service.environment" />
<tag name="controller.service_arguments"/>
</service>

</services>
</container>
2 changes: 2 additions & 0 deletions EMS/core-bundle/src/Resources/config/routing/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
prefix="/api/meta"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/search.xml"
prefix="/api/search"/>
<import resource="@EMSCoreBundle/Resources/config/routing/api/data.xml"
prefix="/api/data"/>

</routes>
14 changes: 14 additions & 0 deletions EMS/core-bundle/src/Resources/config/routing/api/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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_data_publish" path="/{contentTypeName}/publish/{ouuid}/{targetEnvironmentName}/{revision}"
controller="EMS\CoreBundle\Controller\Api\Data\PublishController::publish"
methods="POST"
format="json">
<default key="revision" xsi:nil="true"/>
</route>

</routes>
Loading