1<?php 2 3namespace Icinga\Module\Director\Deployment; 4 5use Icinga\Module\Director\Db; 6use Icinga\Module\Director\Objects\IcingaObject; 7 8class DeploymentInfo 9{ 10 /** @var IcingaObject */ 11 protected $object; 12 13 protected $db; 14 15 /** @var int */ 16 protected $totalChanges; 17 18 /** @var int */ 19 protected $objectChanges; 20 21 public function __construct(Db $db) 22 { 23 $this->db = $db; 24 } 25 26 public function setObject(IcingaObject $object) 27 { 28 $this->object = $object; 29 return $this; 30 } 31 32 public function getTotalChanges() 33 { 34 if ($this->totalChanges === null) { 35 $this->totalChanges = $this->db->countActivitiesSinceLastDeployedConfig(); 36 } 37 38 return $this->totalChanges; 39 } 40 41 public function getSingleObjectChanges() 42 { 43 if ($this->objectChanges === null) { 44 if ($this->object === null) { 45 $this->objectChanges = 0; 46 } else { 47 $this->objectChanges = $this->db 48 ->countActivitiesSinceLastDeployedConfig($this->object); 49 } 50 } 51 52 return $this->objectChanges; 53 } 54 55 public function hasUndeployedChanges() 56 { 57 return $this->getSingleObjectChanges() > 0 && $this->getTotalChanges() > 0; 58 } 59} 60