PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/Task/Pdx/Reset.php

https://github.com/ibidem/mjolnir-database
PHP | 84 lines | 62 code | 11 blank | 11 comment | 15 complexity | 544123057997132c0276af461d4e1217 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php namespace mjolnir\database;
  2. /**
  3. * @package mjolnir
  4. * @category Database
  5. * @author Ibidem Team
  6. * @copyright (c) 2013, Ibidem Team
  7. * @license https://github.com/ibidem/ibidem/blob/master/LICENSE.md
  8. */
  9. class Task_Pdx_Reset extends \app\Task_Base
  10. {
  11. /**
  12. * ...
  13. */
  14. function run()
  15. {
  16. \app\Task::consolewriter($this->writer);
  17. if (\app\CFS::config('mjolnir/base')['db:migrations'] !== 'paradox')
  18. {
  19. $this->writer
  20. ->printf('error', 'System is currently setup to use ['.\app\CFS::config('mjolnir/base')['db:migrations'].'] migrations.')
  21. ->eol()->eol();
  22. return;
  23. }
  24. $pivot = $this->get('pivot', false);
  25. $version = $this->get('version', false);
  26. $dryrun = $this->get('dry-run', false);
  27. $verbose = $this->get('verbose', false);
  28. $pivot !== false || $pivot = null;
  29. $version !== false || $version = null;
  30. $dryrun !== false || $dryrun = null;
  31. $verbose !== false || $verbose = null;
  32. if ($version !== null && $pivot === null)
  33. {
  34. $this->writer->writef(' You must provide a pivot channel.')->eol();
  35. return;
  36. }
  37. if ($version === null && $pivot !== null)
  38. {
  39. $this->writer->writef(' You must provide a version with the pivot channel. Use no parameters for complete install.')->eol();
  40. return;
  41. }
  42. $pdx = \app\Pdx::instance($this->writer, $verbose);
  43. if (($history = $pdx->reset($pivot, $version, $dryrun)) === false)
  44. {
  45. $this->writer->writef(' The database is locked and operation could not be performed in non-destructive manner.')->eol();
  46. }
  47. else # reset done
  48. {
  49. // dry run?
  50. if ($dryrun)
  51. {
  52. if ($verbose)
  53. {
  54. $this->writer->eol();
  55. }
  56. foreach ($history as $entry)
  57. {
  58. $this->writer->writef(' %9s %s %s', $entry['version'], $entry['channel'], empty($entry['hotfix']) ? '' : '/ '.$entry['hotfix'])->eol();
  59. }
  60. }
  61. else # not dry-run
  62. {
  63. if ($verbose)
  64. {
  65. $this->writer->eol();
  66. }
  67. $this->writer
  68. ->eol()->eol()
  69. ->writef(' Reset complete.')->eol();
  70. }
  71. }
  72. }
  73. } # class