| 1: | <?php
|
| 2: | namespace Opencart\Admin\Model\Setting;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Cron extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: |
|
| 20: | public function addCron(string $code, string $description, string $cycle, string $action, bool $status): int {
|
| 21: | $this->db->query("INSERT INTO `" . DB_PREFIX . "cron` SET `code` = '" . $this->db->escape($code) . "', `description` = '" . $this->db->escape($description) . "', `cycle` = '" . $this->db->escape($cycle) . "', `action` = '" . $this->db->escape($action) . "', `status` = '" . (int)$status . "', `date_added` = NOW(), `date_modified` = NOW()");
|
| 22: |
|
| 23: | return $this->db->getLastId();
|
| 24: | }
|
| 25: |
|
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: |
|
| 33: | public function deleteCron(int $cron_id): void {
|
| 34: | $this->db->query("DELETE FROM `" . DB_PREFIX . "cron` WHERE `cron_id` = '" . (int)$cron_id . "'");
|
| 35: | }
|
| 36: |
|
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: |
|
| 44: | public function deleteCronByCode(string $code): void {
|
| 45: | $this->db->query("DELETE FROM `" . DB_PREFIX . "cron` WHERE `code` = '" . $this->db->escape($code) . "'");
|
| 46: | }
|
| 47: |
|
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: |
|
| 55: | public function editCron(int $cron_id): void {
|
| 56: | $this->db->query("UPDATE `" . DB_PREFIX . "cron` SET `date_modified` = NOW() WHERE `cron_id` = '" . (int)$cron_id . "'");
|
| 57: | }
|
| 58: |
|
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: |
|
| 67: | public function editStatus(int $cron_id, bool $status): void {
|
| 68: | $this->db->query("UPDATE `" . DB_PREFIX . "cron` SET `status` = '" . (bool)$status . "' WHERE `cron_id` = '" . (int)$cron_id . "'");
|
| 69: | }
|
| 70: |
|
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: |
|
| 78: | public function getCron(int $cron_id): array {
|
| 79: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "cron` WHERE `cron_id` = '" . (int)$cron_id . "'");
|
| 80: |
|
| 81: | return $query->row;
|
| 82: | }
|
| 83: |
|
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: |
|
| 91: | public function getCronByCode(string $code): array {
|
| 92: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "cron` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
|
| 93: |
|
| 94: | return $query->row;
|
| 95: | }
|
| 96: |
|
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: |
|
| 104: | public function getCrons(array $data = []): array {
|
| 105: | $sql = "SELECT * FROM `" . DB_PREFIX . "cron`";
|
| 106: |
|
| 107: | $sort_data = [
|
| 108: | 'code',
|
| 109: | 'cycle',
|
| 110: | 'action',
|
| 111: | 'status',
|
| 112: | 'date_added',
|
| 113: | 'date_modified'
|
| 114: | ];
|
| 115: |
|
| 116: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
| 117: | $sql .= " ORDER BY " . $data['sort'];
|
| 118: | } else {
|
| 119: | $sql .= " ORDER BY `date_added`";
|
| 120: | }
|
| 121: |
|
| 122: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
| 123: | $sql .= " DESC";
|
| 124: | } else {
|
| 125: | $sql .= " ASC";
|
| 126: | }
|
| 127: |
|
| 128: | if (isset($data['start']) || isset($data['limit'])) {
|
| 129: | if ($data['start'] < 0) {
|
| 130: | $data['start'] = 0;
|
| 131: | }
|
| 132: |
|
| 133: | if ($data['limit'] < 1) {
|
| 134: | $data['limit'] = 20;
|
| 135: | }
|
| 136: |
|
| 137: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
| 138: | }
|
| 139: |
|
| 140: | $query = $this->db->query($sql);
|
| 141: |
|
| 142: | return $query->rows;
|
| 143: | }
|
| 144: |
|
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: |
|
| 150: | public function getTotalCrons(): int {
|
| 151: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "cron`");
|
| 152: |
|
| 153: | return (int)$query->row['total'];
|
| 154: | }
|
| 155: | }
|
| 156: | |