Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

GenerateChangeScript.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Core\Command\Db;
  24. use Stecman\Component\Symfony\Console\BashCompletion\Completion;
  25. use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
  26. use Stecman\Component\Symfony\Console\BashCompletion\Completion\ShellPathCompletion;
  27. use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
  28. use Symfony\Component\Console\Command\Command;
  29. use Symfony\Component\Console\Input\InputArgument;
  30. use Symfony\Component\Console\Input\InputInterface;
  31. use Symfony\Component\Console\Output\OutputInterface;
  32. class GenerateChangeScript extends Command implements CompletionAwareInterface {
  33. protected function configure() {
  34. $this
  35. ->setName('db:generate-change-script')
  36. ->setDescription('generates the change script from the current connected db to db_structure.xml')
  37. ->addArgument(
  38. 'schema-xml',
  39. InputArgument::OPTIONAL,
  40. 'the schema xml to be used as target schema',
  41. \OC::$SERVERROOT . '/db_structure.xml'
  42. )
  43. ;
  44. }
  45. protected function execute(InputInterface $input, OutputInterface $output) {
  46. $file = $input->getArgument('schema-xml');
  47. $schemaManager = new \OC\DB\MDB2SchemaManager(\OC::$server->getDatabaseConnection());
  48. try {
  49. $result = $schemaManager->updateDbFromStructure($file, true);
  50. $output->writeln($result);
  51. } catch (\Exception $e) {
  52. $output->writeln('Failed to update database structure ('.$e.')');
  53. }
  54. }
  55. /**
  56. * @param string $optionName
  57. * @param CompletionContext $context
  58. * @return string[]
  59. */
  60. public function completeOptionValues($optionName, CompletionContext $context) {
  61. return [];
  62. }
  63. /**
  64. * @param string $argumentName
  65. * @param CompletionContext $context
  66. * @return string[]
  67. */
  68. public function completeArgumentValues($argumentName, CompletionContext $context) {
  69. if ($argumentName === 'schema-xml') {
  70. $helper = new ShellPathCompletion(
  71. $this->getName(),
  72. 'schema-xml',
  73. Completion::TYPE_ARGUMENT
  74. );
  75. return $helper->run();
  76. }
  77. return [];
  78. }
  79. }