1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TechDivision\Import\Cli\Command\ImportClearPidFileCommand |
4
|
|
|
* |
5
|
|
|
* PHP version 7 |
6
|
|
|
* |
7
|
|
|
* @author [email protected] |
8
|
|
|
* @copyright 2023 TechDivision GmbH <[email protected]> |
9
|
|
|
* @license https://opensource.org/licenses/MIT |
10
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
11
|
|
|
* @link http://www.techdivision.com |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace TechDivision\Import\Cli\Command; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
use TechDivision\Import\Configuration\ConfigurationInterface; |
19
|
|
|
use TechDivision\Import\Utils\CommandNames; |
20
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The import command implementation. |
24
|
|
|
* |
25
|
|
|
* @author [email protected] |
26
|
|
|
* @copyright 2023 TechDivision GmbH <[email protected]> |
27
|
|
|
* @license https://opensource.org/licenses/MIT |
28
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
29
|
|
|
* @link http://www.techdivision.com |
30
|
|
|
*/ |
31
|
|
|
class ImportCreateDefaultConfigCommand extends AbstractSimpleImportCommand |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Configures the current command. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
* @see \Symfony\Component\Console\Command\Command::configure() |
38
|
|
|
*/ |
39
|
|
|
protected function configure(): void |
40
|
|
|
{ |
41
|
|
|
// initialize the command with the required/optional options |
42
|
|
|
$this->setName(CommandNames::IMPORT_CREATE_CONFIG) |
|
|
|
|
43
|
|
|
->setDescription('Create the default config file which is used by the diff command'); |
44
|
|
|
|
45
|
|
|
// invoke the parent method |
46
|
|
|
parent::configure(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Finally executes the simple command. |
51
|
|
|
* |
52
|
|
|
* @param ConfigurationInterface $configuration The configuration instance |
53
|
|
|
* @param InputInterface $input An InputInterface instance |
54
|
|
|
* @param OutputInterface $output An OutputInterface instance |
55
|
|
|
* |
56
|
|
|
* @return int |
57
|
|
|
*/ |
58
|
|
|
protected function executeSimpleCommand( |
59
|
|
|
ConfigurationInterface $configuration, |
60
|
|
|
InputInterface $input, |
61
|
|
|
OutputInterface $output |
62
|
|
|
): int |
63
|
|
|
{ |
64
|
|
|
$serializer = $this->createSerializer(); |
65
|
|
|
$configValues = $serializer->serialize($configuration, 'json'); |
66
|
|
|
|
67
|
|
|
// create new default json file |
68
|
|
|
$fs = new Filesystem(); |
69
|
|
|
$fs->remove(ImportConfigDiffCommand::DEFAULT_FILE); |
70
|
|
|
$fs->appendToFile(ImportConfigDiffCommand::DEFAULT_FILE, $configValues); |
71
|
|
|
|
72
|
|
|
$output->writeln('[*] successfully created default file'); |
73
|
|
|
return 0; |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|