PluginProbe
JetBackup – Backup, Restore & Migrate / 3.1.21.3
JetBackup – Backup, Restore & Migrate v3.1.21.3
3.1.23.6 3.1.23.5 3.1.23.3 3.1.22.4 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 All 82 releases
backup / src / JetBackup / JetBackupLinux / JetBackupLinuxObject.php
JetBackupLinuxObject.php
102 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace JetBackup\JetBackupLinux;
4
5 use JetBackup\Data\ArrayData;
6 use JetBackup\Exception\JetBackupLinuxException;
7 use JetBackup\SocketAPI\Exception\SocketAPIException;
8 use JetBackup\SocketAPI\SocketAPI;
9
10 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
11
12 class JetBackupLinuxObject extends ArrayData {
13
14 const ID_FIELD = '_id';
15
16 private string $_item;
17 private array $_data=[];
18
19 public function __construct($item) {
20 $this->_item = $item;
21 }
22
23 public function set($key, $value):void {
24 parent::set($key, $value);
25 $this->_data[$key] = $value;
26 }
27
28 public function setData($data=[]):void {
29 parent::setData($data);
30 $this->_data = [];
31 }
32
33 public function setId(string $id):void { $this->set(self::ID_FIELD, $id); }
34 public function getId():string { return $this->get(self::ID_FIELD); }
35
36 /**
37 * @param string $id
38 *
39 * @return void
40 * @throws JetBackupLinuxException
41 * @throws SocketAPIException
42 */
43 protected function load(string $id):void {
44 if(!JetBackupLinux::isEnabled()) return;
45
46 $query = SocketAPI::api( 'get' . $this->_item);
47 $query->arg(self::ID_FIELD, $id);
48
49 try {
50 $response = $query->execute();
51 } catch(SocketAPIException $e) {
52 throw new JetBackupLinuxException($e->getMessage());
53 }
54
55 if(!$response['success']) throw new JetBackupLinuxException($response['message']);
56 $this->setData($response['data']);
57 }
58
59 /**
60 * @return void
61 * @throws JetBackupLinuxException
62 * @throws SocketAPIException
63 */
64 public function save():void {
65 if(!JetBackupLinux::isEnabled()) return;
66
67 $query = SocketAPI::api( 'manage' . $this->_item);
68 if($this->getId()) $query->arg(self::ID_FIELD, $this->getId());
69 $query->arg('action', $this->getId() ? 'modify' : 'create');
70
71 foreach($this->_data as $key => $value) $query->arg($key, $value);
72
73 try {
74 $response = $query->execute();
75 } catch(SocketAPIException $e) {
76 throw new JetBackupLinuxException($e->getMessage());
77 }
78
79 if(!$response['success']) throw new JetBackupLinuxException($response['message']);
80 $this->setData($response['data']);
81 }
82
83 /**
84 * @return void
85 * @throws JetBackupLinuxException
86 * @throws SocketAPIException
87 */
88 public function delete():void {
89 if(!JetBackupLinux::isEnabled() || !$this->getId()) return;
90
91 $query = SocketAPI::api( 'delete' . $this->_item);
92 $query->arg(self::ID_FIELD, $this->getId());
93
94 try {
95 $query->execute();
96 } catch(SocketAPIException $e) {
97 throw new JetBackupLinuxException($e->getMessage());
98 }
99
100 $this->setData();
101 }
102 }