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 / JetBackupLinux / JetBackupLinuxObject.php
backup / src / JetBackup / JetBackupLinux Last commit date
.htaccess 1 year ago JetBackupLinux.php 1 month ago JetBackupLinuxObject.php 1 year ago Query.php 1 year ago QueueItem.php 1 year ago index.html 1 year ago web.config 1 year ago
JetBackupLinuxObject.php
102 lines
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 }