Skip to content

Sylius 2.x and Symfony 7.x #102

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 39 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,55 @@
"description": "Plugin to generate feeds within the Sylius ecommerce platform",
"license": "MIT",
"type": "symfony-bundle",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/tuxes3/DoctrineORMBatcherBundle.git"
},
{
"type": "vcs",
"url": "https://github.com/tuxes3/symfony-main-request-trait.git"
}
],
"require": {
"php": ">=8.1",
"ext-json": "*",
"doctrine/collections": "^1.6",
"doctrine/collections": "^2.0",
"doctrine/orm": "^2.7",
"doctrine/persistence": "^1.3 || ^2.0 || ^3.0",
"knplabs/knp-menu": "^3.1",
"league/flysystem": "^1.1 || ^2.1",
"league/flysystem-bundle": "^1.1 || ^2.4",
"league/flysystem": "^2.1 || ^3.0",
"league/flysystem-bundle": "^2.4 || ^3.0",
"liip/imagine-bundle": "^2.4",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"setono/doctrine-orm-batcher": "^0.6",
"setono/doctrine-orm-batcher-bundle": "^0.3.4",
"setono/symfony-main-request-trait": "^1.0",
"setono/doctrine-orm-batcher-bundle": "dev-master as 0.3.4",
"setono/symfony-main-request-trait": "dev-master as 1.0.0",
"spatie/enum": "^3.7",
"sylius/resource-bundle": "^1.6",
"symfony/config": "^5.4 || ^6.3",
"symfony/console": "^5.4 || ^6.3",
"symfony/dependency-injection": "^5.4 || ^6.3",
"symfony/event-dispatcher": "^5.4 || ^6.3",
"symfony/config": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/event-dispatcher": "^6.4 || ^7.0",
"symfony/event-dispatcher-contracts": "^1.1 || ^2.2 || ^3.0",
"symfony/form": "^5.4 || ^6.3",
"symfony/http-foundation": "^5.4.7 || ^6.3",
"symfony/http-kernel": "^5.4 || ^6.3",
"symfony/messenger": "^5.4 || ^6.3",
"symfony/mime": "^5.4 || ^6.3",
"symfony/options-resolver": "^5.4 || ^6.3",
"symfony/routing": "^5.4 || ^6.3",
"symfony/serializer": "^5.4 || ^6.3",
"symfony/form": "^6.4 || ^7.0",
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/messenger": "^6.4 || ^7.0",
"symfony/mime": "^6.4 || ^7.0",
"symfony/options-resolver": "^6.4 || ^7.0",
"symfony/routing": "^6.4 || ^7.0",
"symfony/serializer": "^6.4 || ^7.0",
"symfony/translation-contracts": "^1.1 || ^2.3 || ^3.0",
"symfony/uid": "^5.4 || ^6.3",
"symfony/validator": "^5.4 || ^6.3",
"symfony/workflow": "^5.4 || ^6.3",
"symfony/uid": "^6.4 || ^7.0",
"symfony/validator": "^6.4 || ^7.0",
"symfony/workflow": "^6.4 || ^7.0",
"twig/twig": "^2.14 || ^3.0",
"webmozart/assert": "^1.1"
},
"require-dev": {
"api-platform/core": "^2.6",
"lexik/jwt-authentication-bundle": "^2.15",
"lexik/jwt-authentication-bundle": "^3.1",
"php-http/message-factory": "^1.1",
"phpspec/phpspec": "^7.2",
"phpunit/phpunit": "^9.5",
Expand All @@ -51,14 +60,15 @@
"psalm/plugin-symfony": "^5.0",
"setono/code-quality-pack": "^2.4",
"setono/sylius-behat-pack": "^0.2",
"sylius/sylius": "^1.11",
"sylius/sylius": "^2.0",
"symfony/debug-bundle": "^5.4 || ^6.3",
"symfony/dotenv": "^5.4 || ^6.3",
"symfony/intl": "^5.4 || ^6.3",
"symfony/web-profiler-bundle": "^5.4 || ^6.3",
"symfony/webpack-encore-bundle": "^1.17",
"symfony/webpack-encore-bundle": "^2.2",
"weirdan/doctrine-psalm-plugin": "^2.2"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
Expand All @@ -77,9 +87,13 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"ergebnis/composer-normalize": true,
"php-http/discovery": true,
"symfony/thanks": false
},
"sort-packages": true
"sort-packages": true,
"platform": {
"php": "8.3.99"
}
},
"extra": {
"branch-alias": {
Expand Down
16 changes: 6 additions & 10 deletions src/Command/ProcessFeedsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
namespace Setono\SyliusFeedPlugin\Command;

use Setono\SyliusFeedPlugin\Processor\FeedProcessorInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'setono:sylius-feed:process',
description: 'Processes all enabled feeds',
)]
final class ProcessFeedsCommand extends Command
{
protected static $defaultName = 'setono:sylius-feed:process';

private FeedProcessorInterface $feedProcessor;

public function __construct(FeedProcessorInterface $feedProcessor)
Expand All @@ -23,18 +26,11 @@ public function __construct(FeedProcessorInterface $feedProcessor)
$this->feedProcessor = $feedProcessor;
}

protected function configure(): void
{
$this
->setDescription('Processes all enabled feeds')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->feedProcessor->setLogger(new ConsoleLogger($output));
$this->feedProcessor->process();

return 0;
return self::SUCCESS;
}
}
27 changes: 8 additions & 19 deletions src/Message/Handler/FinishGenerationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\Persistence\ObjectManager;
use InvalidArgumentException;
use League\Flysystem\DirectoryListing;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\StorageAttributes;
use Psr\Log\LoggerInterface;
Expand All @@ -22,8 +21,8 @@
use Setono\SyliusFeedPlugin\Workflow\FeedGraph;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Workflow\Registry;
use Throwable;
use Twig\Environment;
Expand All @@ -35,13 +34,14 @@
* @psalm-suppress DeprecatedInterface
* @psalm-suppress InternalMethod
*/
final class FinishGenerationHandler implements MessageHandlerInterface
#[AsMessageHandler]
final class FinishGenerationHandler
{
use GetFeedTrait;

private ObjectManager $feedManager;

/** @var FilesystemInterface|FilesystemOperator */
/** @var FilesystemOperator */
private $filesystem;

private Registry $workflowRegistry;
Expand Down Expand Up @@ -71,14 +71,12 @@ public function __construct(
) {
$this->feedRepository = $feedRepository;
$this->feedManager = $feedManager;
if (interface_exists(FilesystemInterface::class) && $filesystem instanceof FilesystemInterface) {
$this->filesystem = $filesystem;
} elseif ($filesystem instanceof FilesystemOperator) {

if ($filesystem instanceof FilesystemOperator) {
$this->filesystem = $filesystem;
} else {
throw new InvalidArgumentException(sprintf(
'The filesystem must be an instance of %s or %s',
FilesystemInterface::class,
'The filesystem must be an instance of %s',
FilesystemOperator::class,
));
}
Expand Down Expand Up @@ -152,16 +150,7 @@ public function __invoke(FinishGeneration $message): void

fwrite($batchStream, $feedEnd);

if (interface_exists(FilesystemInterface::class) && $filesystem instanceof FilesystemInterface) {
/** @var resource|false $res */
$res = $filesystem->writeStream((string) TemporaryFeedPathGenerator::getBaseFile($dir), $batchStream);

if (false === $res) {
throw new RuntimeException('An error occurred when trying to write the finished feed write');
}
} else {
$filesystem->writeStream((string) TemporaryFeedPathGenerator::getBaseFile($dir), $batchStream);
}
$filesystem->writeStream((string) TemporaryFeedPathGenerator::getBaseFile($dir), $batchStream);

// tries to close the file pointer although it may already have been closed by flysystem
fclose($batchStream);
Expand Down
34 changes: 11 additions & 23 deletions src/Message/Handler/GenerateBatchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use const JSON_PRETTY_PRINT;
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\FilesystemOperator;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
Expand All @@ -31,8 +30,8 @@
use Sylius\Component\Channel\Model\ChannelInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Serializer\Encoder\JsonEncode;
Expand All @@ -41,17 +40,18 @@
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\Workflow;
use Symfony\Component\Workflow\WorkflowInterface;
use Throwable;
use Twig\Environment;
use Webmozart\Assert\Assert;

/**
* @psalm-suppress UndefinedDocblockClass
* @psalm-suppress UndefinedClass
* @psalm-suppress DeprecatedInterface
* @psalm-suppress InternalMethod
*/
final class GenerateBatchHandler implements MessageHandlerInterface
#[AsMessageHandler]
final class GenerateBatchHandler
{
use GetChannelTrait;
use GetFeedTrait;
Expand All @@ -65,7 +65,7 @@ final class GenerateBatchHandler implements MessageHandlerInterface

private Environment $twig;

/** @var FilesystemInterface|FilesystemOperator */
/** @var FilesystemOperator */
private $filesystem;

private FeedPathGeneratorInterface $temporaryFeedPathGenerator;
Expand Down Expand Up @@ -112,14 +112,11 @@ public function __construct(
$this->feedManager = $feedManager;
$this->feedTypeRegistry = $feedTypeRegistry;
$this->twig = $twig;
if (interface_exists(FilesystemInterface::class) && $filesystem instanceof FilesystemInterface) {
$this->filesystem = $filesystem;
} elseif ($filesystem instanceof FilesystemOperator) {
if ($filesystem instanceof FilesystemOperator) {
$this->filesystem = $filesystem;
} else {
throw new InvalidArgumentException(sprintf(
'The filesystem must be an instance of %s or %s',
FilesystemInterface::class,
'The filesystem must be an instance of %s',
FilesystemOperator::class,
));
}
Expand Down Expand Up @@ -231,15 +228,8 @@ public function __invoke(GenerateBatch $message): void
$filesystem = $this->filesystem;
$path = TemporaryFeedPathGenerator::getPartialFile($dir, $filesystem);

if (interface_exists(FilesystemInterface::class) && $filesystem instanceof FilesystemInterface) {
$res = $filesystem->writeStream((string) $path, $stream);
fclose($stream);

Assert::true($res, 'An error occurred when trying to write a feed item');
} else {
$filesystem->writeStream((string) $path, $stream);
fclose($stream);
}
$filesystem->writeStream((string) $path, $stream);
fclose($stream);

$this->feedManager->flush();
$this->feedManager->clear();
Expand Down Expand Up @@ -300,19 +290,17 @@ private function resetRequestContext(): void
$this->urlGenerator->setContext($this->initialRequestContext);
}

private function getWorkflow(FeedInterface $feed): Workflow
private function getWorkflow(FeedInterface $feed): WorkflowInterface
{
try {
$workflow = $this->workflowRegistry->get($feed, FeedGraph::GRAPH);
return $this->workflowRegistry->get($feed, FeedGraph::GRAPH);
} catch (InvalidArgumentException $e) {
throw new UnrecoverableMessageHandlingException(
'An error occurred when trying to get the workflow for the feed',
0,
$e,
);
}

return $workflow;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Message/Handler/GenerateFeedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
use Setono\SyliusFeedPlugin\Repository\FeedRepositoryInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Messenger\MessageBusInterface;

/**
* @psalm-suppress DeprecatedInterface
*/
final class GenerateFeedHandler implements MessageHandlerInterface
#[AsMessageHandler]
final class GenerateFeedHandler
{
use GetChannelTrait;
use GetFeedTrait;
Expand Down
5 changes: 3 additions & 2 deletions src/Message/Handler/ProcessFeedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
use Setono\SyliusFeedPlugin\Validator\TemplateValidatorInterface;
use Setono\SyliusFeedPlugin\Workflow\FeedGraph;
use Sylius\Component\Core\Model\ChannelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Workflow\Registry;

/**
* @psalm-suppress DeprecatedInterface
* @psalm-suppress InternalMethod
*/
final class ProcessFeedHandler implements MessageHandlerInterface
#[AsMessageHandler]
final class ProcessFeedHandler
{
use GetFeedTrait;

Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/routing/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ setono_sylius_feed_admin_feed:
resource: |
alias: setono_sylius_feed.feed
section: admin
templates: '@SyliusAdmin\\Crud'
templates: "@SyliusAdmin/shared/crud"
redirect: show
grid: setono_sylius_feed_admin_feed
permission: true
Expand Down Expand Up @@ -39,7 +39,7 @@ setono_sylius_feed_admin_feed_violations_index:
route:
parameters:
id: $id
template: '@SyliusAdmin/Crud/index.html.twig'
template: '@SyliusAdmin/shared/crud/index.html.twig'
grid: setono_sylius_feed_admin_violation
section: admin
permission: true
2 changes: 1 addition & 1 deletion src/Resources/config/services/feed_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class="Setono\SyliusFeedPlugin\FeedContext\Google\Shopping\ProductItemContext">
<argument type="service" id="router"/>
<argument type="service" id="liip_imagine.cache.manager"/>
<argument type="service" id="sylius.availability_checker"/>
<argument type="service" id="sylius.checker.inventory.availability"/>
</service>
</services>
</container>
Loading