Skip to content

Commit

Permalink
add README.md about Migrating between strategies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Warxcell committed Sep 18, 2020
1 parent 8feab1a commit a2193d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
18 changes: 5 additions & 13 deletions Command/MigrateNamingStrategyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

use Arxy\FilesBundle\Manager;
use Arxy\FilesBundle\Model\File;
use Arxy\FilesBundle\NamingStrategy;
use Doctrine\Common\Persistence\ManagerRegistry;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand All @@ -19,25 +18,18 @@ class MigrateNamingStrategyCommand extends Command

private Manager $fileManager;
private ManagerRegistry $doctrine;
private ContainerInterface $container;
private NamingStrategy $oldNamingStrategy;

public function __construct(Manager $fileManager, ManagerRegistry $registry, ContainerInterface $container)
public function __construct(Manager $fileManager, ManagerRegistry $registry, NamingStrategy $oldNamingStrategy)
{
parent::__construct();
$this->fileManager = $fileManager;
$this->doctrine = $registry;
$this->container = $container;
}

protected function configure()
{
$this->addArgument('old-naming-strategy', InputArgument::REQUIRED);
$this->oldNamingStrategy = $oldNamingStrategy;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$oldNamingStrategy = $this->container->get($input->getArgument('old-naming-strategy'));

$io = new SymfonyStyle($input, $output);
$progressBar = $io->createProgressBar();

Expand All @@ -54,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
/** @var File $file */
$file = $row[0];

$migrated = $this->fileManager->migrate($file, $oldNamingStrategy);
$migrated = $this->fileManager->migrate($file, $this->oldNamingStrategy);
if ($migrated) {
$totalMigrated++;
$io->success('File '.$file->getId().' migrated');
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,24 @@ You will receive following json as response:
"squared_thumbnail":"https:\/\/host.com\/media\/cache\/resolve\/squared_thumbnail\/1\/4\/5\/145"
}
}
```
```

## Migrating between naming strategy.

First configure the new naming strategy, but keep the old one as service.
Then register the command for migration:
```yaml
services:
Arxy\FilesBundle\Command\MigrateNamingStrategyCommand:
arguments:
$oldNamingStrategy: 'old_naming_strategy_service_id'
```
then run it.
```shell script
bin/console arxy:files:migrate-naming-strategy
```

Please note that until files are migrated - if some file is requested - it will throw error.


0 comments on commit a2193d8

Please sign in to comment.