|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) shopware AG <[email protected]> |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace ShopwarePlugins\Connect\Commands; |
|
9
|
|
|
|
|
10
|
|
|
use Shopware\Commands\ShopwareCommand; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
15
|
|
|
use ShopwarePlugins\Connect\Components\ImageImport; |
|
16
|
|
|
use ShopwarePlugins\Connect\Components\Logger; |
|
17
|
|
|
use ShopwarePlugins\Connect\Components\Helper; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
class ImageImportCommand extends ShopwareCommand |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var Helper |
|
24
|
|
|
*/ |
|
25
|
|
|
private $helper; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(Helper $helper) { |
|
28
|
|
|
parent::__construct(); |
|
29
|
|
|
$this->helper = $helper; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function configure() |
|
33
|
|
|
{ |
|
34
|
|
|
$this |
|
35
|
|
|
->setName('connect:image:import') |
|
36
|
|
|
->setDescription('Import images from connect') |
|
37
|
|
|
->addArgument( |
|
38
|
|
|
'limit', |
|
39
|
|
|
InputArgument::OPTIONAL, |
|
40
|
|
|
'Amount of Images to import at once' |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param InputInterface $input |
|
46
|
|
|
* @param OutputInterface $output |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
49
|
|
|
{ |
|
50
|
|
|
$symfonyStyle = new SymfonyStyle($input, $output); |
|
51
|
|
|
$limit = $input->getArgument('limit') | 10; |
|
52
|
|
|
|
|
53
|
|
|
$this->getImageImport()->import($limit); |
|
54
|
|
|
|
|
55
|
|
|
$symfonyStyle->success('Images were imported.'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return ImageImport |
|
60
|
|
|
*/ |
|
61
|
|
View Code Duplication |
private function getImageImport() |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
// do not use thumbnail_manager as a dependency!!! |
|
|
|
|
|
|
64
|
|
|
// MediaService::__construct uses Shop entity |
|
65
|
|
|
// this also could break the session in backend when it's used in subscriber |
|
66
|
|
|
return new ImageImport( |
|
67
|
|
|
Shopware()->Models(), |
|
68
|
|
|
$this->helper, |
|
69
|
|
|
$this->container->get('thumbnail_manager'), |
|
70
|
|
|
new Logger(Shopware()->Db()) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.