|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Content\Media\Infrastructure\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Content\Media\Core\Application\MediaPathUpdater; |
|
6
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\IteratorFactory; |
|
7
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
8
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @internal |
|
16
|
|
|
*/ |
|
17
|
|
|
#[AsCommand( |
|
18
|
|
|
name: 'media:update-path', |
|
19
|
|
|
description: 'Iterates over the media and updates the path column.', |
|
20
|
|
|
)] |
|
21
|
|
|
#[Package('content')] |
|
22
|
|
|
class UpdatePathCommand extends Command |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @internal |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct( |
|
28
|
|
|
private readonly MediaPathUpdater $updater, |
|
29
|
|
|
private readonly IteratorFactory $factory |
|
30
|
|
|
) { |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function configure(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->setDescription('Update media paths') |
|
37
|
|
|
->addOption('force', 'f', null, 'Force update of all media paths'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
41
|
|
|
{ |
|
42
|
|
|
$output->writeln('Updating media paths...'); |
|
43
|
|
|
|
|
44
|
|
|
$iterator = $this->factory->createIterator('media'); |
|
45
|
|
|
if (!$input->getOption('force')) { |
|
46
|
|
|
$iterator->getQuery()->andWhere('path IS NULL'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$progressBar = new ProgressBar($output, $iterator->fetchCount()); |
|
50
|
|
|
$progressBar->start(); |
|
51
|
|
|
|
|
52
|
|
|
while ($ids = $iterator->fetch()) { |
|
53
|
|
|
$this->updater->updateMedia($ids); |
|
54
|
|
|
$progressBar->advance(\count($ids)); |
|
55
|
|
|
} |
|
56
|
|
|
$progressBar->finish(); |
|
57
|
|
|
|
|
58
|
|
|
$output->writeln(''); |
|
59
|
|
|
$output->writeln('Updating thumbnail paths...'); |
|
60
|
|
|
$output->writeln(''); |
|
61
|
|
|
|
|
62
|
|
|
$iterator = $this->factory->createIterator('media_thumbnail'); |
|
63
|
|
|
|
|
64
|
|
|
if (!$input->getOption('force')) { |
|
65
|
|
|
$iterator->getQuery()->andWhere('path IS NULL'); |
|
66
|
|
|
} |
|
67
|
|
|
$progressBar = new ProgressBar($output, $iterator->fetchCount()); |
|
68
|
|
|
|
|
69
|
|
|
$progressBar->start(); |
|
70
|
|
|
while ($ids = $iterator->fetch()) { |
|
71
|
|
|
$this->updater->updateThumbnails($ids); |
|
72
|
|
|
$progressBar->advance(\count($ids)); |
|
73
|
|
|
} |
|
74
|
|
|
$progressBar->finish(); |
|
75
|
|
|
|
|
76
|
|
|
return 0; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|