1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\MediaBundle\Command; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @final since sonata-project/media-bundle 3.21.0 |
23
|
|
|
*/ |
24
|
|
|
class AddMediaCommand extends BaseCommand |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
protected $quiet = false; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* NEXT_MAJOR: remove this property. |
33
|
|
|
* |
34
|
|
|
* @deprecated This property is deprecated since sonata-project/media-bundle 2.4 and will be removed in 4.0 |
35
|
|
|
*/ |
36
|
|
|
protected $output; |
37
|
|
|
|
38
|
|
|
public function configure(): void |
39
|
|
|
{ |
40
|
|
|
$this->setName('sonata:media:add') |
41
|
|
|
->setDescription('Add a media into the database') |
42
|
|
|
->setDefinition([ |
43
|
|
|
new InputArgument('providerName', InputArgument::REQUIRED, 'The provider'), |
44
|
|
|
new InputArgument('context', InputArgument::REQUIRED, 'The context'), |
45
|
|
|
new InputArgument('binaryContent', InputArgument::REQUIRED, 'The content'), |
46
|
|
|
|
47
|
|
|
new InputOption('description', null, InputOption::VALUE_OPTIONAL, 'The media description field', null), |
48
|
|
|
new InputOption('copyright', null, InputOption::VALUE_OPTIONAL, 'The media copyright field', null), |
49
|
|
|
new InputOption('author', null, InputOption::VALUE_OPTIONAL, 'The media author name field', null), |
50
|
|
|
new InputOption('enabled', null, InputOption::VALUE_OPTIONAL, 'The media enabled field', true), |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int |
55
|
|
|
{ |
56
|
|
|
$provider = $input->getArgument('providerName'); |
57
|
|
|
$context = $input->getArgument('context'); |
58
|
|
|
$binaryContent = $input->getArgument('binaryContent'); |
59
|
|
|
|
60
|
|
|
$output->writeln(sprintf('Add a new media - context: %s, provider: %s, content: %s', $context, $provider, $binaryContent)); |
61
|
|
|
|
62
|
|
|
$media = $this->getMediaManager()->create(); |
63
|
|
|
$media->setBinaryContent($binaryContent); |
64
|
|
|
|
65
|
|
|
if ($input->getOption('description')) { |
66
|
|
|
$media->setDescription($input->getOption('description')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($input->getOption('copyright')) { |
70
|
|
|
$media->setCopyright($input->getOption('copyright')); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if ($input->getOption('author')) { |
74
|
|
|
$media->setAuthorName($input->getOption('author')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (\in_array($input->getOption('enabled'), [1, true, 'true'], true)) { |
78
|
|
|
$media->setEnabled(true); |
79
|
|
|
} else { |
80
|
|
|
$media->setEnabled(false); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->getMediaManager()->save($media, $context, $provider); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$output->writeln('done!'); |
86
|
|
|
|
87
|
|
|
return 0; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.