1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ODM\MongoDB\Tools\Console\Command\Schema; |
21
|
|
|
|
22
|
|
|
use Doctrine\ODM\MongoDB\SchemaManager; |
23
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
24
|
|
|
use Symfony\Component\Console\Input\InputOption; |
25
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @author Chris Jones <[email protected]> |
29
|
|
|
* @author Michał Dąbrowski <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class UpdateCommand extends AbstractCommand |
32
|
|
|
{ |
33
|
|
|
private $timeout; |
34
|
|
|
|
35
|
|
|
protected function configure() |
36
|
|
|
{ |
37
|
|
|
$this |
38
|
|
|
->setName('odm:schema:update') |
39
|
|
|
->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'Document class to process (default: all classes)') |
40
|
|
|
->addOption('timeout', 't', InputOption::VALUE_OPTIONAL, 'Timeout (ms) for acknowledged index creation') |
41
|
|
|
->setDescription('Update indexes for your documents') |
42
|
|
|
; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param InputInterface $input |
47
|
|
|
* @param OutputInterface $output |
48
|
|
|
* @return int|null|void |
49
|
|
|
*/ |
50
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
51
|
|
|
{ |
52
|
|
|
$class = $input->getOption('class'); |
53
|
|
|
|
54
|
|
|
$timeout = $input->getOption('timeout'); |
55
|
|
|
$this->timeout = isset($timeout) ? (int) $timeout : null; |
56
|
|
|
|
57
|
|
|
$sm = $this->getSchemaManager(); |
58
|
|
|
$isErrored = false; |
59
|
|
|
|
60
|
|
|
try { |
61
|
|
|
if (isset($class)) { |
62
|
|
|
$this->processDocumentIndex($sm, $class); |
63
|
|
|
$output->writeln(sprintf('Updated <comment>index(es)</comment> for <info>%s</info>', $class)); |
64
|
|
|
} else { |
65
|
|
|
$this->processIndex($sm); |
66
|
|
|
$output->writeln('Updated <comment>indexes</comment> for <info>all classes</info>'); |
67
|
|
|
} |
68
|
|
|
} catch (\Exception $e) { |
69
|
|
|
$output->writeln('<error>' . $e->getMessage() . '</error>'); |
70
|
|
|
$isErrored = true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return ($isErrored) ? 255 : 0; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param SchemaManager $sm |
78
|
|
|
* @param object $document |
79
|
|
|
*/ |
80
|
|
|
protected function processDocumentIndex(SchemaManager $sm, $document) |
81
|
|
|
{ |
82
|
|
|
$sm->updateDocumentIndexes($document, $this->timeout); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param SchemaManager $sm |
87
|
|
|
*/ |
88
|
|
|
protected function processIndex(SchemaManager $sm) |
89
|
|
|
{ |
90
|
|
|
$sm->updateIndexes($this->timeout); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param SchemaManager $sm |
95
|
|
|
* @param object $document |
96
|
|
|
* @throws \BadMethodCallException |
97
|
|
|
*/ |
98
|
|
|
protected function processDocumentCollection(SchemaManager $sm, $document) |
99
|
|
|
{ |
100
|
|
|
throw new \BadMethodCallException('Cannot update a document collection'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param SchemaManager $sm |
105
|
|
|
* @throws \BadMethodCallException |
106
|
|
|
*/ |
107
|
|
|
protected function processCollection(SchemaManager $sm) |
108
|
|
|
{ |
109
|
|
|
throw new \BadMethodCallException('Cannot update a collection'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param SchemaManager $sm |
114
|
|
|
* @param object $document |
115
|
|
|
* @throws \BadMethodCallException |
116
|
|
|
*/ |
117
|
|
|
protected function processDocumentDb(SchemaManager $sm, $document) |
118
|
|
|
{ |
119
|
|
|
throw new \BadMethodCallException('Cannot update a document database'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param SchemaManager $sm |
124
|
|
|
* @throws \BadMethodCallException |
125
|
|
|
*/ |
126
|
|
|
protected function processDb(SchemaManager $sm) |
127
|
|
|
{ |
128
|
|
|
throw new \BadMethodCallException('Cannot update a database'); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: