| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-10-11)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace MGProvision\Proxmox\v2\models;
- use MGProvision\Proxmox\v2 as proxmox;
- /**
- * Description of File
- *
- * @author Pawel Kopec <pawelk@modulesgarden.com>
- * @version 1.0.0
- */
- class File extends AbstractObject
- {
- protected $content;
- protected $size;
- protected $format;
- protected $volid;
- protected $ctime;
- private $path;
- protected $node;
- protected $vmid;
- public function getContent()
- {
- return $this->content;
- }
- public function getSize()
- {
- return $this->size;
- }
- public function getFormat()
- {
- return $this->format;
- }
- public function getVolid()
- {
- return $this->volid;
- }
- public function setContent($content)
- {
- $this->content = $content;
- return $this;
- }
- public function setSize($size)
- {
- $this->size = $size;
- return $this;
- }
- public function setFormat($format)
- {
- $this->format = $format;
- return $this;
- }
- public function setVolid($volid)
- {
- $this->volid = $volid;
- return $this;
- }
- public function getFriendlyName()
- {
- $ex = explode("/", $this->getVolid());
- $friendlyName = end($ex);
- $s = array("-", "_", ".tar.gz", ".iso", '.tar.xz');
- $r = array(" ", " ", "", "", "");
- $friendlyName = str_replace($s, $r, $friendlyName);
- $friendlyName = ucwords($friendlyName);
- return $friendlyName;
- }
- /**
- *
- * @param string $path i.e. /nodes/proxmox/storage/local/content/local:backup/vzdump-lxc-100-2017_01_18-10_33_18.tar.lzo
- * @throws proxmox\ProxmoxApiException
- */
- public function setPath($path)
- {
- if (!preg_match('/\/content\//', $path))
- {
- throw new proxmox\ProxmoxApiException(sprintf("File Path ('%s') is not valid", $path));
- }
- $this->path = $path;
- }
- public function getDate()
- {
- if($this->ctime){
- return date("Y-m-d", $this->ctime);
- }
- preg_match('/[0-9]{4}_[0-9]{2}_[0-9]{2}/', $this->volid, $matches);
- return str_replace("_", "-", $matches[0]);
- }
- public function getHour()
- {
- if($this->ctime){
- return date("H:i:s", $this->ctime);
- }
- preg_match('/-[0-9]{2}_[0-9]{2}_[0-9]{2}/', $this->volid, $matches);
- return str_replace(array("-", "_"), array("", ":"), $matches[0]);
- }
- public function getTimestamp()
- {
- return strtotime($this->getDate() . " " . $this->getHour());
- }
- public function getAttributes()
- {
- return array(
- "content" => $this->getContent(),
- "size" => $this->getSize(),
- "format" => $this->getFormat(),
- "volid" => $this->getVolid(),
- "date" => $this->getDate(),
- "hour" => $this->getHour()
- );
- }
- public function delete()
- {
- if (empty($this->path))
- throw new proxmox\ProxmoxApiException('File [path] - property is missing and it is not optional');
- return $this->api()->delete($this->path);
- }
- /**
- * @return mixed
- */
- public function getCtime()
- {
- return $this->ctime;
- }
- /**
- * @param mixed $ctime
- * @return File
- */
- public function setCtime($ctime)
- {
- $this->ctime = $ctime;
- return $this;
- }
- /**
- * @return mixed
- */
- public function getNode()
- {
- return $this->node;
- }
- /**
- * @param mixed $node
- * @return File
- */
- public function setNode($node)
- {
- $this->node = $node;
- return $this;
- }
- public function formatVolid()
- {
- $ex = explode("/", $this->getVolid());
- return end($ex);
- }
- public function getVmid()
- {
- return $this->vmid;
- }
- /**
- * @param mixed $vmid
- * @return File
- */
- public function setVmid($vmid)
- {
- $this->vmid = $vmid;
- return $this;
- }
- }
|