| 1: | <?php
|
| 2: | namespace Opencart\Admin\Model\Tool;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Backup extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: |
|
| 14: | public function getTables(): array {
|
| 15: | $table_data = [];
|
| 16: |
|
| 17: | $query = $this->db->query("SHOW TABLES FROM `" . DB_DATABASE . "`");
|
| 18: |
|
| 19: | foreach ($query->rows as $result) {
|
| 20: | if (isset($result['Tables_in_' . DB_DATABASE]) && substr($result['Tables_in_' . DB_DATABASE], 0, strlen(DB_PREFIX)) == DB_PREFIX) {
|
| 21: | $table_data[] = $result['Tables_in_' . DB_DATABASE];
|
| 22: | }
|
| 23: | }
|
| 24: |
|
| 25: | return $table_data;
|
| 26: | }
|
| 27: |
|
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: |
|
| 37: | public function getRecords(string $table, int $start = 0, int $limit = 100): array {
|
| 38: | if ($start < 0) {
|
| 39: | $start = 0;
|
| 40: | }
|
| 41: |
|
| 42: | if ($limit < 1) {
|
| 43: | $limit = 10;
|
| 44: | }
|
| 45: |
|
| 46: | $query = $this->db->query("SELECT * FROM `" . $table . "` LIMIT " . (int)$start . "," . (int)$limit);
|
| 47: |
|
| 48: | if ($query->num_rows) {
|
| 49: | return $query->rows;
|
| 50: | } else {
|
| 51: | return [];
|
| 52: | }
|
| 53: | }
|
| 54: |
|
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: |
|
| 62: | public function getTotalRecords(string $table): int {
|
| 63: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . $table . "`");
|
| 64: |
|
| 65: | if ($query->num_rows) {
|
| 66: | return (int)$query->row['total'];
|
| 67: | } else {
|
| 68: | return 0;
|
| 69: | }
|
| 70: | }
|
| 71: | }
|
| 72: | |