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\repository; use MGProvision\Proxmox\v2 as proxmox; use MGProvision\Proxmox\v2\interfaces\VmInterface; class TaskRepository extends AbstractRepository { private $nodes; private $vmids; private $limit; private $fromStartime; public function findByVm(VmInterface $vm) { $this->nodes = array($vm->getNode()); $this->vmids = array($vm->getVmid()); return $this; } public function findByNodes($nodes) { $this->nodes = $nodes; return $this; } public function findByVmids($vmids) { $this->vmids = $vmids; return $this; } public function limit($limit) { $this->limit = $limit; return $this; } public function fromStartTime($fromStartime) { $this->fromStartime = $fromStartime; return $this; } /** * * @return proxmox\models\Task[] */ public function fetch() { if (!empty($this->fetch)) { return $this->fetch; } $data = array(); $i = 0; foreach ($this->nodes as $node) { $parameters = array(); if (isset($this->vmids[$i])) { $parameters["vmid"] = $this->vmids[$i]; } if (isset($this->limit)) { $parameters["limit"] = $this->limit; } $collection = $this->api()->get("/nodes/{$node}/tasks", $parameters); foreach ($collection as $task) { if($this->fromStartime && $task['starttime'] < $this->fromStartime ){ continue; } $entityObj = new proxmox\models\Task(); $entityObj->setAttributes($task); $entityObj->setPath("/nodes/{$node}/tasks/" . $task['upid']); $data[] = $entityObj; } $i++; } return $data; } public function delete() { foreach ($this->fetch() as $task) { $task->delete(); } } }