|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SyncFS\Command; |
|
4
|
|
|
|
|
5
|
|
|
use SyncFS\Configuration\Configuration; |
|
6
|
|
|
use SyncFS\Configuration\Reader; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use SyncFS\Syncer; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class SyncCommand |
|
14
|
|
|
* |
|
15
|
|
|
* @package SyncFS\Command |
|
16
|
|
|
* @author Matej Velikonja <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class SyncCommand extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
const COMMAND_NAME = 'sync'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Configure command. |
|
24
|
|
|
*/ |
|
25
|
6 |
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
$this |
|
28
|
6 |
|
->setName(self::COMMAND_NAME) |
|
29
|
6 |
|
->setDescription("Run synchronization.") |
|
30
|
6 |
|
->addArgument( |
|
31
|
6 |
|
self::ARG_CONFIG_PATH, |
|
32
|
6 |
|
InputArgument::OPTIONAL, |
|
33
|
6 |
|
'Path to config file.', |
|
34
|
6 |
|
$this->getDefaultConfiguration() |
|
35
|
|
|
); |
|
36
|
6 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param InputInterface $input |
|
40
|
|
|
* @param OutputInterface $output |
|
41
|
|
|
* |
|
42
|
|
|
* @throws \Exception |
|
43
|
|
|
* |
|
44
|
|
|
* @return int|null|void |
|
45
|
|
|
*/ |
|
46
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
47
|
|
|
{ |
|
48
|
2 |
|
$configPath = $input->getArgument('config-path'); |
|
49
|
|
|
|
|
50
|
2 |
|
if (! file_exists($configPath)) { |
|
51
|
|
|
throw new \Exception(sprintf('Configuration file %s does not exists.', $configPath)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
$configPath = realpath($configPath); |
|
55
|
|
|
|
|
56
|
2 |
|
$output->writeln(sprintf('Reading configuration from file %s.', $configPath)); |
|
57
|
|
|
|
|
58
|
2 |
|
$reader = new Reader(new Configuration()); |
|
59
|
2 |
|
$config = $reader->read($configPath); |
|
60
|
|
|
|
|
61
|
2 |
|
$output->writeln(sprintf('<info>Configuration read.</info>')); |
|
62
|
|
|
|
|
63
|
2 |
|
$syncer = new Syncer($config); |
|
64
|
|
|
|
|
65
|
2 |
|
$output->writeln('<info>Syncing folders...</info>' . PHP_EOL); |
|
66
|
|
|
|
|
67
|
2 |
|
$syncer->sync($output); |
|
68
|
|
|
|
|
69
|
2 |
|
$output->writeln( |
|
70
|
2 |
|
'<info>Syncing folders succeeded!</info>' |
|
71
|
|
|
); |
|
72
|
2 |
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|