PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Data / DBObject.php
backup / src / JetBackup / Data Last commit date
.htaccess 1 year ago ArrayData.php 1 year ago DBObject.php 1 year ago Engine.php 1 year ago Mysqldump.php 5 months ago ReflectionObject.php 1 year ago SleekStore.php 1 year ago index.html 1 year ago web.config 1 year ago
DBObject.php
122 lines
1 <?php
2
3 namespace JetBackup\Data;
4
5 use JetBackup\Exception\DBException;
6 use JetBackup\JetBackup;
7 use SleekDB\Exceptions\InvalidArgumentException;
8 use SleekDB\Exceptions\IOException;
9
10 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
11
12 class DBObject extends ArrayData {
13
14 private array $_data=[];
15 private array $_find=[];
16 private SleekStore $_db;
17
18 /**
19 * @throws DBException
20 * @throws InvalidArgumentException
21 * @throws IOException
22 */
23 public function __construct($collection) {
24 $this->_db = new SleekStore($collection);
25 }
26
27 public function getDB():SleekStore {
28 return $this->_db;
29 }
30
31 public function margeData($data=[]):void {
32 parent::margeData($data);
33 $this->_data = array_merge($this->_data, $data);
34 }
35
36 public function setData($data=[]):void {
37 parent::setData($data);
38 $this->_data = [];
39 }
40
41 public function set($key, $value):void {
42 parent::set($key, $value);
43 $this->_data[$key] = $value;
44 }
45
46 private function _save_new():void {
47 if(!($data = $this->getData())) return;
48 unset($data[JetBackup::ID_FIELD]);
49 $this->getDB()->clearCache();
50 $ret = $this->getDB()->insert($data);
51 $this->setId($ret[JetBackup::ID_FIELD]);
52 $this->setFind([[JetBackup::ID_FIELD, '=', $ret[JetBackup::ID_FIELD]]]);
53 $this->_data = [];
54 }
55
56 /**
57 * @throws InvalidArgumentException
58 */
59 public function delete():void {
60 if(!$this->getId()) return;
61 $this->getDB()->clearCache();
62 $this->getDB()->deleteById($this->getId());
63 $this->setData();
64 }
65
66 /**
67 * @throws IOException
68 * @throws InvalidArgumentException
69 */
70 public function save():void {
71 if($this->getId()) $this->setFind([[JetBackup::ID_FIELD, '=', $this->getId()]]);
72
73 if(!$this->_find) {
74 $this->_save_new();
75 return;
76 }
77
78 if(!$this->_data) return;
79 $this->getDB()->clearCache();
80 $this->getDB()->createQueryBuilder()->where($this->_find)->getQuery()->update($this->_data);
81 $this->_data = [];
82 }
83
84 public function setId(int $id):void { $this->set(JetBackup::ID_FIELD, $id); }
85 public function getId():int { return (int) $this->get(JetBackup::ID_FIELD, 0); }
86
87 public function setFind(array $find):void { $this->_find = $find; }
88
89 /**
90 * @throws InvalidArgumentException
91 */
92 protected function _loadById(int $id):void {
93 $data = $this->getDB()->findById($id);
94 if(!$data) return;
95 $this->setData($data);
96 //$this->_load([[JetBackup::ID_FIELD, '=', $id]]);
97 }
98
99 /**
100 * @throws InvalidArgumentException
101 * @throws IOException
102 */
103 public function load():void {
104 $query = $this->_db->createQueryBuilder();
105 if($this->_find) foreach($this->_find as $where) $query->where($where);
106 $data = $query->getQuery()->first();
107 if(!$data) return;
108 $this->setData($data);
109 }
110
111 /**
112 * @throws InvalidArgumentException
113 * @throws IOException
114 */
115 protected function _load(array $find):void {
116 $this->setFind($find);
117 $this->load();
118 if($this->getId()) $this->setFind([[JetBackup::ID_FIELD, '=', $this->getId()]]);
119 else $this->setFind([]);
120 }
121
122 }