doctrine.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Doctrine\ORM\Tools\Console\ConsoleRunner;
  4. use Symfony\Component\Console\Helper\HelperSet;
  5. use Doctrine\DBAL\Types\Type;
  6. /**
  7. * Very useful script in order to create a Migration file based in the
  8. * current differences of the database:
  9. *
  10. * php bin/doctrine.php migrations:diff
  11. *
  12. * This script also show doctrine basic commands:
  13. * - Create schema
  14. * - Drop schema
  15. * - Update schema,
  16. * etc
  17. *
  18. **/
  19. (@include_once __DIR__.'/../vendor/autoload.php') || @include_once __DIR__.'/../../../autoload.php';
  20. $directories = array(getcwd(), getcwd().DIRECTORY_SEPARATOR.'config');
  21. $configFile = null;
  22. foreach ($directories as $directory) {
  23. $configFile = $directory.DIRECTORY_SEPARATOR.'cli-config.php';
  24. if (file_exists($configFile)) {
  25. break;
  26. }
  27. }
  28. if (!file_exists($configFile)) {
  29. ConsoleRunner::printCliConfigTemplate();
  30. exit(1);
  31. }
  32. if (!is_readable($configFile)) {
  33. echo 'Configuration file ['.$configFile.'] does not have read permission.'."\n";
  34. exit(1);
  35. }
  36. Type::overrideType(
  37. Type::DATETIME,
  38. Database::getUTCDateTimeTypeClass()
  39. );
  40. /*Type::addType(
  41. 'json',
  42. 'Sonata\Doctrine\Types\JsonType'
  43. );*/
  44. $commands = array(
  45. new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
  46. new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
  47. new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
  48. new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(),
  49. new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
  50. new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
  51. new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
  52. );
  53. $helperSet = require $configFile;
  54. if (!($helperSet instanceof HelperSet)) {
  55. foreach ($GLOBALS as $helperSetCandidate) {
  56. if ($helperSetCandidate instanceof HelperSet) {
  57. $helperSet = $helperSetCandidate;
  58. break;
  59. }
  60. }
  61. }
  62. \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, $commands);