ExecutionResult.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Migrations\Version;
  4. use DateTimeImmutable;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\Query\Query;
  7. use RuntimeException;
  8. use Throwable;
  9. use function count;
  10. /**
  11. * The ExecutionResult class is responsible for storing the result of a migration version after it executes.
  12. *
  13. * @internal
  14. */
  15. final class ExecutionResult
  16. {
  17. /** @var Query[] */
  18. private $sql = [];
  19. /**
  20. * Seconds
  21. *
  22. * @var float|null
  23. */
  24. private $time;
  25. /** @var float|null */
  26. private $memory;
  27. /** @var bool */
  28. private $skipped = false;
  29. /** @var bool */
  30. private $error = false;
  31. /** @var Throwable|null */
  32. private $exception;
  33. /** @var DateTimeImmutable|null */
  34. private $executedAt;
  35. /** @var int */
  36. private $state;
  37. /** @var Schema|null */
  38. private $toSchema;
  39. /** @var Version */
  40. private $version;
  41. /** @var string */
  42. private $direction;
  43. public function __construct(Version $version, string $direction = Direction::UP, ?DateTimeImmutable $executedAt = null)
  44. {
  45. $this->executedAt = $executedAt;
  46. $this->version = $version;
  47. $this->direction = $direction;
  48. }
  49. public function getDirection(): string
  50. {
  51. return $this->direction;
  52. }
  53. public function getExecutedAt(): ?DateTimeImmutable
  54. {
  55. return $this->executedAt;
  56. }
  57. public function setExecutedAt(DateTimeImmutable $executedAt): void
  58. {
  59. $this->executedAt = $executedAt;
  60. }
  61. public function getVersion(): Version
  62. {
  63. return $this->version;
  64. }
  65. public function hasSql(): bool
  66. {
  67. return count($this->sql) !== 0;
  68. }
  69. /**
  70. * @return Query[]
  71. */
  72. public function getSql(): array
  73. {
  74. return $this->sql;
  75. }
  76. /**
  77. * @param Query[] $sql
  78. */
  79. public function setSql(array $sql): void
  80. {
  81. $this->sql = $sql;
  82. }
  83. public function getTime(): ?float
  84. {
  85. return $this->time;
  86. }
  87. public function setTime(float $time): void
  88. {
  89. $this->time = $time;
  90. }
  91. public function getMemory(): ?float
  92. {
  93. return $this->memory;
  94. }
  95. public function setMemory(float $memory): void
  96. {
  97. $this->memory = $memory;
  98. }
  99. public function setSkipped(bool $skipped): void
  100. {
  101. $this->skipped = $skipped;
  102. }
  103. public function isSkipped(): bool
  104. {
  105. return $this->skipped;
  106. }
  107. public function setError(bool $error, ?Throwable $exception = null): void
  108. {
  109. $this->error = $error;
  110. $this->exception = $exception;
  111. }
  112. public function hasError(): bool
  113. {
  114. return $this->error;
  115. }
  116. public function getException(): ?Throwable
  117. {
  118. return $this->exception;
  119. }
  120. public function setToSchema(Schema $toSchema): void
  121. {
  122. $this->toSchema = $toSchema;
  123. }
  124. public function getToSchema(): Schema
  125. {
  126. if ($this->toSchema === null) {
  127. throw new RuntimeException('Cannot call getToSchema() when toSchema is null.');
  128. }
  129. return $this->toSchema;
  130. }
  131. public function getState(): int
  132. {
  133. return $this->state;
  134. }
  135. public function setState(int $state): void
  136. {
  137. $this->state = $state;
  138. }
  139. }