Exporter
1 year ago
QueryBuilder
2 years ago
DbInfo.php
6 months ago
ExcludedTables.php
5 months ago
OptionPreservationHandler.php
2 years ago
SearchReplace.php
6 months ago
SelectedTables.php
8 months ago
TableDto.php
1 year ago
TableService.php
9 months ago
TablesRenamer.php
5 months ago
WpDbInfo.php
8 months ago
WpOptionsInfo.php
1 year ago
iDbInfo.php
2 years ago
TableDto.php
188 lines
| 1 | <?php |
| 2 | |
| 3 | // TODO PHP7.x; declare(strict_types=1); |
| 4 | // TODO PHP7.x; type-hints & return types |
| 5 | |
| 6 | namespace WPStaging\Framework\Database; |
| 7 | |
| 8 | use DateTime; |
| 9 | use WPStaging\Framework\Interfaces\HydrateableInterface; |
| 10 | use WPStaging\Core\WPStaging; |
| 11 | |
| 12 | class TableDto implements HydrateableInterface |
| 13 | { |
| 14 | /** @var string */ |
| 15 | private $name; |
| 16 | |
| 17 | /** @var int */ |
| 18 | private $rows; |
| 19 | |
| 20 | /** @var int */ |
| 21 | private $size; |
| 22 | |
| 23 | /** @var int */ |
| 24 | private $autoIncrement; |
| 25 | |
| 26 | /** @var DateTime */ |
| 27 | private $createdAt; |
| 28 | |
| 29 | /** @var DateTime */ |
| 30 | private $updatedAt; |
| 31 | |
| 32 | /** @var bool */ |
| 33 | private $isView = false; |
| 34 | |
| 35 | public function hydrate(array $data = []) |
| 36 | { |
| 37 | $this->setName($data['Name']); |
| 38 | |
| 39 | $this->setRows(isset($data['Rows']) ? (int) $data['Rows'] : 0); |
| 40 | $this->setAutoIncrement(isset($data['Auto_increment']) ? $data['Auto_increment'] : null); |
| 41 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 42 | $this->setCreatedAt(new DateTime(isset($data['Create_time']) ? $data['Create_time'] : '')); |
| 43 | if (isset($data['Update_time']) && $data['Update_time']) { |
| 44 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 45 | $this->setUpdatedAt(new DateTime($data['Update_time'])); |
| 46 | } |
| 47 | |
| 48 | if (isset($data['Data_length'], $data['Index_length'])) { |
| 49 | $size = (int) $data['Data_length'] + (int) $data['Index_length']; |
| 50 | $this->setSize($size); |
| 51 | } |
| 52 | |
| 53 | if (isset($data['Comment']) && $data['Comment'] === 'VIEW') { |
| 54 | $this->setIsView(true); |
| 55 | } |
| 56 | |
| 57 | return $this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return string |
| 62 | */ |
| 63 | public function getName() |
| 64 | { |
| 65 | return $this->name; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param string $name |
| 70 | */ |
| 71 | public function setName($name) |
| 72 | { |
| 73 | $this->name = $name; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @return int |
| 78 | */ |
| 79 | public function getRows() |
| 80 | { |
| 81 | return $this->rows; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @param int $rows |
| 86 | */ |
| 87 | public function setRows($rows) |
| 88 | { |
| 89 | $this->rows = $rows; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @return int |
| 94 | */ |
| 95 | public function getSize() |
| 96 | { |
| 97 | return $this->size; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @param int $size |
| 102 | */ |
| 103 | public function setSize($size) |
| 104 | { |
| 105 | $this->size = $size; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @return int|null |
| 110 | */ |
| 111 | public function getAutoIncrement() |
| 112 | { |
| 113 | return $this->autoIncrement; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @param int|null $autoIncrement |
| 118 | */ |
| 119 | public function setAutoIncrement($autoIncrement) |
| 120 | { |
| 121 | $this->autoIncrement = $autoIncrement; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @return DateTime |
| 126 | */ |
| 127 | public function getCreatedAt() |
| 128 | { |
| 129 | return $this->createdAt; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @param DateTime $createdAt |
| 134 | */ |
| 135 | public function setCreatedAt($createdAt) |
| 136 | { |
| 137 | $this->createdAt = $createdAt; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @return DateTime|null |
| 142 | */ |
| 143 | public function getUpdatedAt() |
| 144 | { |
| 145 | return $this->updatedAt; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @param DateTime $updatedAt |
| 150 | */ |
| 151 | public function setUpdatedAt($updatedAt) |
| 152 | { |
| 153 | $this->updatedAt = $updatedAt; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @return bool |
| 158 | */ |
| 159 | public function getIsView(): bool |
| 160 | { |
| 161 | return $this->isView; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * @param bool $isView |
| 166 | * @return void |
| 167 | */ |
| 168 | public function setIsView(bool $isView) |
| 169 | { |
| 170 | $this->isView = $isView; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * @return string |
| 175 | */ |
| 176 | public function getHumanReadableSize() |
| 177 | { |
| 178 | // Note: We skip displaying the table size here if it is on WordPress Playground. |
| 179 | // To get the size of a sqlite table the php sqlite extension must be compiled |
| 180 | // with SQLITE_ENABLE_DBSTAT_VTAB which is not compiled by default. |
| 181 | if (WPStaging::isOnWordPressPlayground()) { |
| 182 | return ''; |
| 183 | } |
| 184 | |
| 185 | return size_format($this->size); |
| 186 | } |
| 187 | } |
| 188 |