CLI and deployment

โ† CLI and deployment

Ashterix

docs(articles): English translation of From Magento to Symfony

en/articles/magento-to-symfony/infrastructure/cli.md new file +70 โˆ’0

1 + # CLI and deployment
2 +
3 + | bin/magento | bin/console | Note |
4 + |---|---|---|
5 + | cache:flush, cache:clean | cache:clear; cache:pool:clear cache.app | The system cache and data are different things. |
6 + | setup:upgrade | doctrine:migrations:migrate | Only schema and data from migrations. |
7 + | setup:db-declaration:generate-whitelist | make:migration, doctrine:migrations:diff | Generates a migration class. |
8 + | setup:di:compile | cache:warmup | In prod it runs as part of cache:clear. |
9 + | deploy:mode:set production | APP_ENV=prod, APP_DEBUG=0 | Plus composer dump-env prod. |
10 + | module:enable / module:status | config/bundles.php; about | about shows the version, environment and paths. |
11 + | dev:di:info | debug:container, debug:autowiring | Plus lint:container. |
12 + | config:show | debug:config, config:dump-reference | Actual values and all available options. |
13 + | โ€” | debug:router, router:match | Routes. |
14 + | โ€” | debug:event-dispatcher | Listeners with priorities. |
15 + | queue:consumers:start | messenger:consume async | After deployment: messenger:stop-workers. |
16 + | cron:run | messenger:consume scheduler_default | Or the system cron. |
17 + | indexer:reindex | your own command | There are no indexers. |
18 + | admin:user:create | your own command, fixtures | Users are your own entity. |
19 + | โ€” | make:controller, make:entity, make:crud, make:command | MakerBundle generates boilerplate. |
20 + | โ€” | lint:yaml, lint:container, doctrine:schema:validate | Worth running in CI. |
21 +
22 + **Magento** ยท command
23 +
24 + ```php
25 + class ImportCommand extends Command
26 + {
27 + protected function configure(): void
28 + {
29 + $this->setName('vendor:faq:import');
30 + }
31 + protected function execute(InputInterface $input, OutputInterface $output): int
32 + {
33 + return Command::SUCCESS;
34 + }
35 + }
36 + // + registration in di.xml in CommandList
37 + ```
38 +
39 + **Symfony** ยท command (the same Console component)
40 +
41 + ```php
42 + #[AsCommand(name: 'app:faq:import', description: 'Import FAQ from CSV')]
43 + final class ImportCommand extends Command
44 + {
45 + public function __construct(private Importer $importer)
46 + {
47 + parent::__construct();
48 + }
49 +
50 + protected function execute(InputInterface $input, OutputInterface $output): int
51 + {
52 + $io = new SymfonyStyle($input, $output);
53 + $io->success('Imported');
54 + return Command::SUCCESS;
55 + }
56 + }
57 + // no registration needed: autoconfigure
58 + ```
59 +
60 + ## Deploying to prod
61 +
62 + **Symfony** ยท typical sequence
63 +
64 + ```bash
65 + composer install --no-dev --optimize-autoloader
66 + composer dump-env prod
67 + APP_ENV=prod bin/console cache:clear # also warms up the cache
68 + bin/console doctrine:migrations:migrate --no-interaction
69 + bin/console messenger:stop-workers # supervisor restarts the workers with the new code
70 + ```