123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- <?php
- namespace FTTHBundle\Entity;
- use Base\AdminBundle\Interfaces\PreRemoveInterface;
- use Base\AdminBundle\Traits\TenancyIdTrait;
- use Base\AdminBundle\Traits\TenancyIdTraitInterface;
- use Doctrine\ORM\Mapping as ORM;
- use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
- use JMS\Serializer\Annotation as JMS;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\Workflow\Exception\ExceptionInterface;
- use DeviceBundle\Validator\Constraints as ValidatorAssert;
- use DeviceBundle\Interfaces\DeviceInterface;
- use MapBundle\Entity\Interfaces\LocationInterface;
- use MapBundle\Entity\Traits\LocationTrait;
- use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
- use WorkflowBundle\Entity\Traits\WorkflowTrait;
- use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
- use Gedmo\Mapping\Annotation as Gedmo;
- use Base\AdminBundle\Interfaces\SoftDeleteInterface;
- /**
- * @ORM\Entity
- * @UniqueEntity("ip")
- * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
- *
- * @ValidatorAssert\Device
- */
- class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, PreRemoveInterface, SoftDeleteInterface
- {
- use ExtraDataTrait;
- use TenancyIdTrait;
- use LocationTrait;
- use WorkflowTrait;
- use SoftDeleteable;
- /**
- * @var bigint $id
- *
- * @ORM\Column(type="bigint", nullable=false)
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="IDENTITY")
- */
- private $id;
- /**
- * @var string $name
- *
- * @ORM\Column(type="string", length=255)
- * @Assert\NotNull
- */
- protected $name;
- /**
- * @var string $ip
- *
- * @ORM\Column(type="string", length=50, nullable=true, unique=true)
- */
- protected $ip;
- /**
- * @var string $snmpCommunity
- *
- * @ORM\Column(type="string", length=255, nullable=true, unique=false)
- */
- protected $snmpCommunity;
- /**
- * @var string $sshUser
- *
- * @ORM\Column(type="string", length=255, nullable=true, unique=false)
- */
- protected $sshUser;
- /**
- * @var string $sshPass
- *
- * @ORM\Column(type="string", length=255, nullable=true, unique=false)
- */
- protected $sshPass;
- /**
- * @var string $libraryVersion
- *
- * @ORM\Column(type="string", length=255, nullable=true, unique=false)
- */
- protected $libraryVersion;
- /**
- * @ORM\ManyToOne(targetEntity="OLTModel", inversedBy="olts", fetch="EXTRA_LAZY")
- * @ORM\JoinColumn(name="model_id", referencedColumnName="id", onDelete="SET NULL")
- *
- * @JMS\MaxDepth(1)
- */
- protected $model;
- /**
- * @ORM\OneToMany(targetEntity="ONU", mappedBy="olt", fetch="EXTRA_LAZY", cascade={"remove"})
- *
- * @JMS\MaxDepth(2)
- */
- protected $onus;
- /**
- * @ORM\OneToMany(targetEntity="NAP", mappedBy="olt", fetch="EXTRA_LAZY", cascade={"remove"})
- *
- * @JMS\MaxDepth(2)
- */
- protected $naps;
- /**
- * @ORM\Column(type="string", nullable=true)
- */
- protected $currentState = null;
- /**
- * @ORM\Column(type="string", nullable=false, options={"default": "success"})
- */
- protected $transitionState = 'success';
- /**
- * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
- * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
- *
- * @JMS\MaxDepth(1)
- */
- protected $workflow;
- /**
- * @ORM\Column(type="boolean", nullable=true, columnDefinition="BOOLEAN DEFAULT TRUE")
- */
- protected $executeSnmp = true;
- /**
- * @ORM\Column(type="integer", options={"unsigned":true, "default":10})
- */
- protected $timeScan = 10;
- /**
- * @ORM\Column(type="integer", options={"unsigned":true, "default":5})
- */
- protected $timeOltOctets = 5;
- /**
- * @ORM\Column(type="integer", options={"unsigned":true, "default":5})
- */
- protected $timePonStats = 5;
- /**
- * @ORM\Column(type="integer", options={"unsigned":true, "default":5})
- */
- protected $timeOnuStats = 5;
- /**
- * @ORM\Column(type="string", nullable=true)
- */
- protected $enable;
- /**
- * @ORM\Column(type="boolean", options={"default":true})
- */
- protected $backups;
- /**
- * @return string
- */
- public function __toString()
- {
- return (string)$this->name;
- }
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * @return string
- */
- public function getIp()
- {
- return $this->ip;
- }
- /**
- * @return string
- */
- public function getSnmpCommunity()
- {
- return $this->snmpCommunity;
- }
- /**
- * @return string
- */
- public function getSshUser()
- {
- return $this->sshUser;
- }
- /**
- * @return string
- */
- public function getSshPass()
- {
- return $this->sshPass;
- }
- /**
- * @param string $name
- * @return $this
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * @param string $ip
- * @return $this
- */
- public function setIp($ip)
- {
- $this->ip = $ip;
- return $this;
- }
- /**
- * @param string $snmpCommunity
- * @return $this
- */
- public function setSnmpCommunity($snmpCommunity)
- {
- $this->snmpCommunity = $snmpCommunity;
- return $this;
- }
- /**
- * @param string $sshUser
- * @return $this
- */
- public function setSshUser($sshUser)
- {
- $this->sshUser = $sshUser;
- return $this;
- }
- /**
- * @param string $sshPass
- * @return $this
- */
- public function setSshPass($sshPass)
- {
- $this->sshPass = $sshPass;
- return $this;
- }
- /**
- * @param ONU $onu
- * @return OLT
- */
- public function addOnu(ONU $onu)
- {
- $this->onus[] = $onu;
- return $this;
- }
- /**
- * @param ONU $onu
- * @return OLT
- */
- public function removeOnu(ONU $onu)
- {
- $this->onus->removeElement($onu);
- return $this;
- }
- /**
- * @return Doctrine\Common\Collections\Collection
- */
- public function getOnus()
- {
- return $this->onus;
- }
- /**
- * @param NAP $nap
- *
- * @return OLT
- */
- public function addNap(NAP $nap)
- {
- $this->naps[] = $nap;
- return $this;
- }
- /**
- * @param NAP $nap
- *
- * @return OLT
- */
- public function removeNap(NAP $nap)
- {
- $this->naps->removeElement($nap);
- return $this;
- }
- /**
- * @return Doctrine\Common\Collections\Collection
- */
- public function getNaps()
- {
- return $this->naps;
- }
- /**
- * @return OLTModel
- */
- public function getModel()
- {
- return $this->model;
- }
- /**
- * @param OLTModel $model
- * @return $this
- */
- public function setModel($model)
- {
- $this->model = $model;
- return $this;
- }
- /* Va a quedar deprecate */
- public function getWorkflowObject()
- {
- if ($this->model) {
- $model = $this->model;
- if ($model->getWorkflow()) {
- return $model->getWorkflow();
- }
- }
- return $this->workflow;
- }
- /**
- * @return array
- */
- public function getDeviceData()
- {
- $deviceData = array();
- $deviceData['deviceType'] = get_class($this);
- $deviceData['deviceId'] = $this->id;
- $deviceData['ip'] = $this->ip;
- $deviceData['tenancy'] = $this->tenancyId;
- $deviceExtraData = array('snmpCommunity' => $this->snmpCommunity, 'sshUser' => $this->sshUser, 'sshPass' => $this->sshPass,
- 'libraryVersion' => $this->libraryVersion, 'name' => $this->name);
- if ($this->model) {
- $model = $this->getModel();
- $deviceExtraData['modelId'] = $model->getId();
- $deviceExtraData['mark'] = $model->getMark();
- $deviceExtraData['library'] = $model->getLibrary();
- } else {
- $deviceExtraData['modelId'] = null;
- $deviceExtraData['mark'] = null;
- $deviceExtraData['library'] = null;
- }
- $deviceExtraData['executeSnmp'] = $this->executeSnmp;
- $deviceExtraData['timeScan'] = $this->timeScan;
- $deviceExtraData['timeOnuStats'] = $this->timeOnuStats;
- $deviceExtraData['timePonStats'] = $this->timePonStats;
- $deviceExtraData['timeOltOctets'] = $this->timeOltOctets;
- $deviceData['extraData'] = json_encode($deviceExtraData);
- return $deviceData;
- }
- /**
- * Set executeSnmp
- *
- * @param boolean $e
- * @return OLT
- */
- public function setExecuteSnmp($e)
- {
- $this->executeSnmp = $e;
- return $this;
- }
- /**
- * Get executeSnmp
- *
- * @return boolean
- */
- public function getExecuteSnmp()
- {
- return $this->executeSnmp;
- }
- /**
- * Set timeScan
- *
- * @param integer $timeScan
- */
- public function setTimeScan($timeScan)
- {
- $this->timeScan = $timeScan;
- }
- /**
- * Get timeScan
- *
- * @return integer
- */
- public function getTimeScan()
- {
- return $this->timeScan;
- }
- /**
- * Set timeOltOctets
- *
- * @param integer $timeOltOctets
- */
- public function setTimeOltOctets($timeOltOctets)
- {
- $this->timeOltOctets = $timeOltOctets;
- }
- /**
- * Get timeOltOctets
- *
- * @return integer
- */
- public function getTimeOltOctets()
- {
- return $this->timeOltOctets;
- }
- /**
- * Set timeOnuStats
- *
- * @param integer $timeOnuStats
- */
- public function setTimeOnuStats($timeOnuStats)
- {
- $this->timeOnuStats = $timeOnuStats;
- }
- /**
- * Get timeOnuStats
- *
- * @return integer
- */
- public function getTimeOnuStats()
- {
- return $this->timeOnuStats;
- }
- /**
- * Set timePonStats
- *
- * @param integer $timePonStats
- */
- public function setTimePonStats($timePonStats)
- {
- $this->timePonStats = $timePonStats;
- }
- /**
- * Get timePonStats
- *
- * @return integer
- */
- public function getTimePonStats()
- {
- return $this->timePonStats;
- }
- /**
- * @return string
- */
- public function getEnable()
- {
- return $this->enable;
- }
- /**
- * @param string $enable
- *
- * @return $this
- */
- public function setEnable($enable)
- {
- $this->enable = $enable;
- return $this;
- }
- /**
- * @return int
- */
- public function getLibraryVersion()
- {
- return $this->libraryVersion;
- }
- /**
- * @return array
- */
- public function getSoftDeleteCriteria()
- {
- return array('ip' => $this->ip);
- }
- /**
- * @return array
- */
- public function getEntitiesForRemove()
- {
- $entities = [];
- if ($this->onus->count() != 0) {
- $entities['onus'] = $this->onus;
- }
- if ($this->naps->count() != 0) {
- $entities['naps'] = $this->naps;
- }
- return $entities;
- }
- /**
- * @return mixed
- */
- public function getBackups()
- {
- return $this->backups;
- }
- /**
- * @param mixed $backups
- */
- public function setBackups($backups)
- {
- $this->backups = $backups;
- }
- /**
- * Obtiene los archivos de backups generados.
- * @param mixed $directory Contiene el directorio a leer.
- * @return array Retorna un array con los archivos del directorio.
- */
- public function obtainFiles($directory)
- {
- $resp = array();
- try {
- if ($this->getId()) {
- $dir = $directory . '/olt/' . $this->getId() . '/';
- $files = scandir($dir);
- rsort($files);
- $nc = 0;
- foreach ($files as $file) {
- if ($file != '.' && $file != '..') {
- if ($nc < 10) {
- $resp[$file] = $dir . $file;
- } else {
- break;
- }
- $nc++;
- }
- }
- }
- } catch (\Throwable $ignore) {
- }
- return $resp;
- }
- }
|