Skip to content

Commit

Permalink
Команды композера. Права на папки кэша на проде.
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Aug 4, 2021
1 parent 40c69fe commit 2dd7a51
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,47 @@ mklink "upload" "../../upload" /j

Далее необходимо настроить веб-сервер для работы с новым сайтом.

## Composer scripts

Приложено пару примеров скриптов для composer, запускающимся по событиям `post-update` и `post-install`.

- `Local\ComposerScript\RunMigrationsHandler` - запускает миграции.

- `Local\ComposerScript\CacheWarmerHandler` - убивает и прогревает кэш.

Добавить в секцию `scripts` файла `composer.json`:

```json
"scripts": {
"post-update-cmd": [
"Local\\ComposerScript\\RunMigrationsHandler::doInstall",
"Local\\ComposerScript\\CacheWarmerHandler::doInstall"
],
"post-install-cmd": [
"Local\\ComposerScript\\RunMigrationsHandler::doInstall",
"Local\\ComposerScript\\CacheWarmerHandler::doInstall"
],
"cache:warm": "Local\\ComposerScript\\CacheWarmerHandler::doInstall",
"migrations:run": "Local\\ComposerScript\\RunMigrationsHandler::doInstall"
},
```

Появятся команды:

```sh
composer cache:warm
```

и

```sh
composer migrations:run
```

## Прочее

- Пришлось залочить пакет `psr/container` на версию 1.0. Без этого ставился 1.1.1 (по запросу Symfony DI)
и конструкция падала из-за несоответствия интерфейсов.

Последствия: DI компонент пока версии 5.2, а не актуальной 5.3.
Последствия: DI компонент пока версии 5.2, а не актуальной 5.3.

30 changes: 30 additions & 0 deletions local/classes/ComposerScript/CacheWarmerHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Local\ComposerScript;

use Composer\Script\Event;

/**
* Class CacheWarmerHandler
* @package Local\ComposerScript
*
* @since 04.08.2021
*/
class CacheWarmerHandler
{
/**
* @param Event $event
*
* @return void
*/
public static function doInstall(Event $event): void
{
$io = $event->getIO();

$output = shell_exec('php bin/console cache:clear');
$io->write($output);

$output = shell_exec('php bin/console cache:warm');
$io->write($output);
}
}
25 changes: 25 additions & 0 deletions local/classes/ComposerScript/RunMigrationsHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Local\ComposerScript;

use Composer\Script\Event;

/**
* Class RunMigrationsHandler
* @package Local\ComposerScript
*/
class RunMigrationsHandler
{
/**
* @param Event $event
*
* @return void
*/
public static function doInstall(Event $event): void
{
$io = $event->getIO();

$output = shell_exec('php migrator migrate');
$io->write($output);
}
}
4 changes: 4 additions & 0 deletions local/php_interface/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
Arrilot\BitrixModels\ServiceProvider::register();
Arrilot\BitrixModels\ServiceProvider::registerEloquent();

// Во избежании проблем с созданием кэша на проде
// @see https://symfony.com/doc/current/setup/file_permissions.html
umask(0000);

// Symfony сервис-провайдер
$symfonyServiceProvider = new ServiceProvider(
'local/configs/services.yaml'
Expand Down

0 comments on commit 2dd7a51

Please sign in to comment.