// First we check to see if there's any hosts now with the same name foreach ($_POST['selectedDevices'] as $deviceId) { $device = AutodiscoveryDevicePeer::retrieveByPK($deviceId); if (!$device) { $error = "One of the devices provided no longer exists."; continue; } $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $device->getName()); $c->setIgnoreCase(true); $host = NagiosHostPeer::doSelectOne($c); if (!$host) { $c = new Criteria(); $c->add(AutodiscoveryDevicePeer::NAME, $device->getName()); $c->setIgnoreCase(true); $host = AutodiscoveryDevicePeer::doSelectOne($c); if ($host->getId() == $device->getId()) { unset($host); } } if (!empty($host)) { $error = "A host already exists with the name of " . $device->getName() . ". Change the device's name before importing."; } } if (empty($error)) { $totalSuccess = 0; // Okay, no errors, let's create our hosts! foreach ($_POST['selectedDevices'] as $deviceId) { $device = AutodiscoveryDevicePeer::retrieveByPK($deviceId); $tempHost = new NagiosHost(); $tempHost->setAddress($device->getAddress());
/** * Get the associated AutodiscoveryDevice object * * @param PropelPDO Optional Connection object. * @return AutodiscoveryDevice The associated AutodiscoveryDevice object. * @throws PropelException */ public function getAutodiscoveryDevice(PropelPDO $con = null) { if ($this->aAutodiscoveryDevice === null && $this->device_id !== null) { $c = new Criteria(AutodiscoveryDevicePeer::DATABASE_NAME); $c->add(AutodiscoveryDevicePeer::ID, $this->device_id); $this->aAutodiscoveryDevice = AutodiscoveryDevicePeer::doSelectOne($c, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aAutodiscoveryDevice->addAutodiscoveryDeviceTemplateMatchs($this); */ } return $this->aAutodiscoveryDevice; }