-
-
Notifications
You must be signed in to change notification settings - Fork 509
/
Copy pathShardCommand.php
120 lines (107 loc) · 3.77 KB
/
ShardCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ODM\MongoDB\Tools\Console\Command\Schema;
use Doctrine\ODM\MongoDB\SchemaManager;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ShardCommand extends AbstractCommand
{
protected function configure()
{
$this
->setName('odm:schema:shard')
->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'Document class to process (default: all classes)')
->setDescription('Enable sharding for selected documents')
;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$class = $input->getOption('class');
$sm = $this->getSchemaManager();
$isErrored = false;
try {
if (isset($class)) {
$this->processDocumentIndex($sm, $class);
$output->writeln(sprintf('Enabled sharding for <info>%s</info>', $class));
} else {
$this->processIndex($sm);
$output->writeln('Enabled sharding for <info>all classes</info>');
}
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$isErrored = true;
}
return $isErrored ? 255 : 0;
}
/**
* @param SchemaManager $sm
* @param object $document
*/
protected function processDocumentIndex(SchemaManager $sm, $document)
{
$sm->ensureDocumentSharding($document);
}
/**
* @param SchemaManager $sm
*/
protected function processIndex(SchemaManager $sm)
{
$sm->ensureSharding();
}
/**
* @param SchemaManager $sm
* @param object $document
* @throws \BadMethodCallException
*/
protected function processDocumentCollection(SchemaManager $sm, $document)
{
throw new \BadMethodCallException('Cannot update a document collection');
}
/**
* @param SchemaManager $sm
* @throws \BadMethodCallException
*/
protected function processCollection(SchemaManager $sm)
{
throw new \BadMethodCallException('Cannot update a collection');
}
/**
* @param SchemaManager $sm
* @param object $document
* @throws \BadMethodCallException
*/
protected function processDocumentDb(SchemaManager $sm, $document)
{
throw new \BadMethodCallException('Cannot update a document database');
}
/**
* @param SchemaManager $sm
* @throws \BadMethodCallException
*/
protected function processDb(SchemaManager $sm)
{
throw new \BadMethodCallException('Cannot update a database');
}
}