BackupSchedule.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS product developed. (2016-12-13)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace MGProvision\Proxmox\v2\models;
  20. use MGProvision\Proxmox\v2 as proxmox;
  21. /**
  22. * Description of BackupSchedule
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgarden.com>
  25. * @version 1.0.0
  26. */
  27. class BackupSchedule extends AbstractObject
  28. {
  29. protected $path;
  30. protected $starttime;
  31. protected $enabled;
  32. protected $mailto;
  33. protected $dow;
  34. protected $vmid;
  35. protected $storage;
  36. protected $quiet;
  37. protected $id;
  38. protected $remove;
  39. protected $compress;
  40. protected $mode;
  41. protected $maxfiles;
  42. protected $node;
  43. protected $schedule;
  44. public function getStarttime()
  45. {
  46. return $this->starttime;
  47. }
  48. public function getEnabled()
  49. {
  50. return $this->enabled;
  51. }
  52. public function getMailto()
  53. {
  54. return $this->mailto;
  55. }
  56. public function getDow()
  57. {
  58. return $this->dow;
  59. }
  60. public function getVmid()
  61. {
  62. return $this->vmid;
  63. }
  64. public function getStorage()
  65. {
  66. return $this->storage;
  67. }
  68. public function getQuiet()
  69. {
  70. return $this->quiet;
  71. }
  72. public function getId()
  73. {
  74. return $this->id;
  75. }
  76. public function getRemove()
  77. {
  78. return $this->remove;
  79. }
  80. public function getCompress()
  81. {
  82. return $this->compress;
  83. }
  84. public function getMode()
  85. {
  86. return $this->mode;
  87. }
  88. public function getMaxfiles()
  89. {
  90. return $this->maxfiles;
  91. }
  92. public function getNode()
  93. {
  94. return $this->node;
  95. }
  96. public function setStarttime($starttime)
  97. {
  98. $this->starttime = $starttime;
  99. return $this;
  100. }
  101. public function setEnabled($enabled)
  102. {
  103. $this->enabled = $enabled;
  104. return $this;
  105. }
  106. public function setMailto($mailto)
  107. {
  108. $this->mailto = $mailto;
  109. return $this;
  110. }
  111. public function setDow($dow)
  112. {
  113. $this->dow = $dow;
  114. return $this;
  115. }
  116. public function setVmid($vmid)
  117. {
  118. $this->vmid = $vmid;
  119. return $this;
  120. }
  121. public function setStorage($storage)
  122. {
  123. $this->storage = $storage;
  124. return $this;
  125. }
  126. public function setQuiet($quiet)
  127. {
  128. $this->quiet = $quiet;
  129. return $this;
  130. }
  131. public function setId($id)
  132. {
  133. $this->id = $id;
  134. return $this;
  135. }
  136. public function setRemove($remove)
  137. {
  138. $this->remove = $remove;
  139. return $this;
  140. }
  141. public function setCompress($compress)
  142. {
  143. $this->compress = $compress;
  144. return $this;
  145. }
  146. public function setMode($mode)
  147. {
  148. $this->mode = $mode;
  149. return $this;
  150. }
  151. public function setMaxfiles($maxfiles)
  152. {
  153. $this->maxfiles = $maxfiles;
  154. return $this;
  155. }
  156. public function setNode($node)
  157. {
  158. $this->node = $node;
  159. return $this;
  160. }
  161. public function setPath($path)
  162. {
  163. $this->path = $path;
  164. return $this;
  165. }
  166. public function delete()
  167. {
  168. if (empty($this->id))
  169. throw new proxmox\ProxmoxApiException('Backup Schedule [id] - property is missing and it is not optional');
  170. return $this->api()->delete("/cluster/backup/".$this->getId());
  171. }
  172. private function fill()
  173. {
  174. $data = array(
  175. "vmid" => $this->getVmid(),
  176. "starttime" => $this->getStarttime(),
  177. );
  178. if($this->getMaxfiles()){
  179. $data['maxfiles'] = (int) $this->getMaxfiles();
  180. }
  181. if ($this->getStorage())
  182. $data['storage'] = $this->getStorage();
  183. if ($this->getRemove())
  184. $data['remove'] = $this->getRemove();
  185. if ($this->getDow())
  186. $data['dow'] = $this->getDow();
  187. if (!is_null($this->mode))
  188. $data['mode'] = $this->getMode();
  189. if (!is_null($this->compress))
  190. $data['compress'] = $this->getCompress();
  191. if ($this->getMailto())
  192. $data['mailto'] = $this->getMailto();
  193. return $data;
  194. }
  195. public function create()
  196. {
  197. $data = $this->fill();
  198. return $this->api()->post("/cluster/backup", $data);
  199. }
  200. public function update()
  201. {
  202. $data = $this->fill();
  203. return $this->api()->put("/cluster/backup/" . $this->getId(), $data);
  204. }
  205. public function getAttributes()
  206. {
  207. if($this->schedule){
  208. $ex = explode(" ", $this->schedule);
  209. $this->setDow($ex[0]);
  210. $this->setStarttime($ex[1]);
  211. }
  212. return array(
  213. 'displayId' => preg_replace('/^(.*):/', '', $this->getId()),
  214. "starttime" => $this->getStarttime(),
  215. "days" => explode(",", $this->dow),
  216. "compress" => $this->getCompress(),
  217. "mode" => $this->getMode(),
  218. "mailto" => $this->getMailto(),
  219. "id" => $this->getId(),
  220. "dow" => $this->getDow()
  221. );
  222. }
  223. /**
  224. * @return mixed
  225. */
  226. public function getSchedule()
  227. {
  228. return $this->schedule;
  229. }
  230. /**
  231. * @param mixed $schedule
  232. * @return BackupSchedule
  233. */
  234. public function setSchedule($schedule)
  235. {
  236. $this->schedule = $schedule;
  237. return $this;
  238. }
  239. }