generatechangescript.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Core\Command\Db;
  9. use Symfony\Component\Console\Command\Command;
  10. use Symfony\Component\Console\Input\InputArgument;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Input\InputOption;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. class GenerateChangeScript extends Command {
  15. protected function configure() {
  16. $this
  17. ->setName('db:generate-change-script')
  18. ->setDescription('generates the change script from the current connected db to db_structure.xml')
  19. ->addArgument(
  20. 'schema-xml',
  21. InputArgument::OPTIONAL,
  22. 'the schema xml to be used as target schema',
  23. \OC::$SERVERROOT . '/db_structure.xml'
  24. )
  25. ;
  26. }
  27. protected function execute(InputInterface $input, OutputInterface $output) {
  28. $file = $input->getArgument('schema-xml');
  29. $schemaManager = new \OC\DB\MDB2SchemaManager(\OC_DB::getConnection());
  30. try {
  31. $result = $schemaManager->updateDbFromStructure($file, true);
  32. $output->writeln($result);
  33. } catch (\Exception $e) {
  34. $output->writeln('Failed to update database structure ('.$e.')');
  35. }
  36. }
  37. }