1 | <?php |
||
17 | class UpdateCommand extends AbstractCommand |
||
18 | { |
||
19 | protected function configure() |
||
20 | { |
||
21 | parent::configure(); |
||
22 | |||
23 | $this |
||
24 | ->setName('odm:schema:update') |
||
25 | ->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'Document class to process (default: all classes)') |
||
26 | ->setDescription('Update indexes for your documents'); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @return int |
||
31 | */ |
||
32 | protected function execute(InputInterface $input, OutputInterface $output) |
||
33 | { |
||
34 | $class = $input->getOption('class'); |
||
35 | |||
36 | $sm = $this->getSchemaManager(); |
||
37 | $isErrored = false; |
||
38 | |||
39 | try { |
||
40 | if (is_string($class)) { |
||
41 | $this->processDocumentIndex($sm, $class, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input)); |
||
42 | $output->writeln(sprintf('Updated <comment>index(es)</comment> for <info>%s</info>', $class)); |
||
43 | } else { |
||
44 | $this->processIndex($sm, $this->getMaxTimeMsFromInput($input), $this->getWriteConcernFromInput($input)); |
||
45 | $output->writeln('Updated <comment>indexes</comment> for <info>all classes</info>'); |
||
46 | } |
||
47 | } catch (Throwable $e) { |
||
48 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
49 | $isErrored = true; |
||
50 | } |
||
51 | |||
52 | return $isErrored ? 255 : 0; |
||
53 | } |
||
54 | |||
55 | protected function processDocumentIndex(SchemaManager $sm, string $document, ?int $maxTimeMs, ?WriteConcern $writeConcern) |
||
59 | |||
60 | protected function processIndex(SchemaManager $sm, ?int $maxTimeMs, ?WriteConcern $writeConcern) |
||
64 | |||
65 | /** |
||
66 | * @throws BadMethodCallException |
||
67 | */ |
||
68 | protected function processDocumentCollection(SchemaManager $sm, string $document, ?int $maxTimeMs, ?WriteConcern $writeConcern) |
||
72 | |||
73 | /** |
||
74 | * @throws BadMethodCallException |
||
75 | */ |
||
76 | protected function processCollection(SchemaManager $sm, ?int $maxTimeMs, ?WriteConcern $writeConcern) |
||
80 | |||
81 | /** |
||
82 | * @throws BadMethodCallException |
||
83 | */ |
||
84 | protected function processDocumentDb(SchemaManager $sm, string $document, ?int $maxTimeMs, ?WriteConcern $writeConcern) |
||
88 | |||
89 | /** |
||
90 | * @throws BadMethodCallException |
||
91 | */ |
||
92 | protected function processDb(SchemaManager $sm, ?int $maxTimeMs, ?WriteConcern $writeConcern) |
||
96 | } |
||
97 |