Admin
4 years ago
Helpers
4 years ago
Migrations
4 years ago
MigrationLogFactory.php
4 years ago
MigrationLogModel.php
4 years ago
MigrationLogRepository.php
4 years ago
MigrationLogServiceProvider.php
4 years ago
MigrationLogStatus.php
4 years ago
MigrationLogModel.php
126 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\MigrationLog; |
| 4 | |
| 5 | /** |
| 6 | * Class MigrationLogModel |
| 7 | * @package Give\MigrationLog |
| 8 | * |
| 9 | * @since 2.10.0 |
| 10 | */ |
| 11 | class MigrationLogModel |
| 12 | { |
| 13 | /** |
| 14 | * @var string |
| 15 | */ |
| 16 | private $id; |
| 17 | |
| 18 | /** |
| 19 | * @var string |
| 20 | */ |
| 21 | private $status; |
| 22 | |
| 23 | /** |
| 24 | * @var string|null |
| 25 | */ |
| 26 | private $last_run; |
| 27 | |
| 28 | /** |
| 29 | * @var mixed|null |
| 30 | */ |
| 31 | private $error; |
| 32 | |
| 33 | /** |
| 34 | * MigrationModel constructor. |
| 35 | * |
| 36 | * @param string $id |
| 37 | * @param string $status |
| 38 | * @param mixed|null $error |
| 39 | * @param string|null $lastRun |
| 40 | */ |
| 41 | public function __construct($id, $status = '', $error = null, $lastRun = null) |
| 42 | { |
| 43 | $this->id = $id; |
| 44 | $this->last_run = $lastRun; |
| 45 | $this->setError($error); |
| 46 | $this->setStatus($status); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Set migration status |
| 51 | * |
| 52 | * @see MigrationLogStatus::STATUS_NAME |
| 53 | * |
| 54 | * @param string $status |
| 55 | * |
| 56 | * @return MigrationLogModel |
| 57 | * @uses MigrationLogStatus |
| 58 | */ |
| 59 | public function setStatus($status) |
| 60 | { |
| 61 | $this->status = array_key_exists($status, MigrationLogStatus::getAll()) |
| 62 | ? $status |
| 63 | : MigrationLogStatus::getDefault(); |
| 64 | |
| 65 | return $this; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Add migration error notice |
| 70 | * |
| 71 | * @param mixed $error |
| 72 | * |
| 73 | * @return MigrationLogModel |
| 74 | */ |
| 75 | public function setError($error) |
| 76 | { |
| 77 | if (is_array($error) || is_object($error)) { |
| 78 | $error = print_r($error, true); |
| 79 | } |
| 80 | |
| 81 | $this->error = $error; |
| 82 | |
| 83 | return $this; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @return int |
| 88 | */ |
| 89 | public function getId() |
| 90 | { |
| 91 | return $this->id; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @return string |
| 96 | */ |
| 97 | public function getStatus() |
| 98 | { |
| 99 | return $this->status; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @return string |
| 104 | */ |
| 105 | public function getLastRunDate() |
| 106 | { |
| 107 | return $this->last_run; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @return string|null |
| 112 | */ |
| 113 | public function getError() |
| 114 | { |
| 115 | return $this->error; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Save migration |
| 120 | */ |
| 121 | public function save() |
| 122 | { |
| 123 | give(MigrationLogRepository::class)->save($this); |
| 124 | } |
| 125 | } |
| 126 |