1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ODM\MongoDB\Tools\Console\Command\Schema; |
6
|
|
|
|
7
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
8
|
|
|
use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory; |
9
|
|
|
use Doctrine\ODM\MongoDB\SchemaManager; |
10
|
|
|
use MongoDB\Driver\WriteConcern; |
11
|
|
|
use Symfony\Component\Console\Command\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
14
|
|
|
|
15
|
|
|
abstract class AbstractCommand extends Command |
16
|
|
|
{ |
17
|
|
|
public const DB = 'db'; |
18
|
|
|
public const COLLECTION = 'collection'; |
19
|
|
|
public const INDEX = 'index'; |
20
|
|
|
|
21
|
|
|
protected function configure() |
22
|
|
|
{ |
23
|
|
|
parent::configure(); |
24
|
|
|
|
25
|
|
|
$this |
26
|
|
|
->addOption('maxTimeMs', null, InputOption::VALUE_REQUIRED, 'An optional maxTimeMs that will be used for all schema operations.') |
27
|
|
|
->addOption('w', null, InputOption::VALUE_REQUIRED, 'An optional w option for the write concern that will be used for all schema operations.') |
28
|
|
|
->addOption('wTimeout', null, InputOption::VALUE_REQUIRED, 'An optional wTimeout option for the write concern that will be used for all schema operations.') |
29
|
|
|
->addOption('journal', null, InputOption::VALUE_REQUIRED, 'An optional journal option for the write concern that will be used for all schema operations.'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
abstract protected function processDocumentCollection(SchemaManager $sm, string $document, ?int $maxTimeMs, ?WriteConcern $writeConcern); |
33
|
|
|
|
34
|
|
|
abstract protected function processCollection(SchemaManager $sm, ?int $maxTimeMs, ?WriteConcern $writeConcern); |
35
|
|
|
|
36
|
|
|
abstract protected function processDocumentDb(SchemaManager $sm, string $document, ?int $maxTimeMs, ?WriteConcern $writeConcern); |
37
|
|
|
|
38
|
|
|
abstract protected function processDb(SchemaManager $sm, ?int $maxTimeMs, ?WriteConcern $writeConcern); |
39
|
|
|
|
40
|
|
|
abstract protected function processDocumentIndex(SchemaManager $sm, string $document, ?int $maxTimeMs, ?WriteConcern $writeConcern); |
41
|
|
|
|
42
|
|
|
abstract protected function processIndex(SchemaManager $sm, ?int $maxTimeMs, ?WriteConcern $writeConcern); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return SchemaManager |
46
|
|
|
*/ |
47
|
|
|
protected function getSchemaManager() |
48
|
|
|
{ |
49
|
|
|
return $this->getDocumentManager()->getSchemaManager(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return DocumentManager |
54
|
|
|
*/ |
55
|
|
|
protected function getDocumentManager() |
56
|
|
|
{ |
57
|
|
|
return $this->getHelper('documentManager')->getDocumentManager(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return ClassMetadataFactory |
62
|
|
|
*/ |
63
|
|
|
protected function getMetadataFactory() |
64
|
|
|
{ |
65
|
|
|
return $this->getDocumentManager()->getMetadataFactory(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function getMaxTimeMsFromInput(InputInterface $input) : ?int |
69
|
|
|
{ |
70
|
|
|
$maxTimeMs = $input->getOption('maxTimeMs'); |
71
|
|
|
|
72
|
|
|
return $maxTimeMs !== null ? (int) $maxTimeMs : null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function getWriteConcernFromInput(InputInterface $input) : ?WriteConcern |
76
|
|
|
{ |
77
|
|
|
$w = $input->getOption('w'); |
78
|
|
|
$wTimeout = $input->getOption('wTimeout'); |
79
|
|
|
$journal = $input->getOption('journal'); |
80
|
|
|
|
81
|
|
|
if ($w === null && $wTimeout === null && $journal === null) { |
82
|
|
|
return null; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return new WriteConcern($w, (int) $wTimeout, (bool) $journal); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|