/** * Selects a collection of AutodiscoveryDeviceTemplateMatch objects pre-filled with all related objects except NagiosHostTemplate. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of AutodiscoveryDeviceTemplateMatch objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptNagiosHostTemplate(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } AutodiscoveryDeviceTemplateMatchPeer::addSelectColumns($c); $startcol2 = AutodiscoveryDeviceTemplateMatchPeer::NUM_COLUMNS - AutodiscoveryDeviceTemplateMatchPeer::NUM_LAZY_LOAD_COLUMNS; AutodiscoveryDevicePeer::addSelectColumns($c); $startcol3 = $startcol2 + (AutodiscoveryDevicePeer::NUM_COLUMNS - AutodiscoveryDevicePeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(AutodiscoveryDeviceTemplateMatchPeer::DEVICE_ID), array(AutodiscoveryDevicePeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = AutodiscoveryDeviceTemplateMatchPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = AutodiscoveryDeviceTemplateMatchPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = AutodiscoveryDeviceTemplateMatchPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); AutodiscoveryDeviceTemplateMatchPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined AutodiscoveryDevice rows $key2 = AutodiscoveryDevicePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = AutodiscoveryDevicePeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = AutodiscoveryDevicePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); AutodiscoveryDevicePeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (AutodiscoveryDeviceTemplateMatch) to the collection in $obj2 (AutodiscoveryDevice) $obj2->addAutodiscoveryDeviceTemplateMatch($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(AutodiscoveryDevicePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(AutodiscoveryDevicePeer::DATABASE_NAME); $criteria->add(AutodiscoveryDevicePeer::ID, $pks, Criteria::IN); $objs = AutodiscoveryDevicePeer::doSelect($criteria, $con); } return $objs; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this NagiosHost is new, it will return * an empty collection; or if this NagiosHost has previously * been saved, it will retrieve related AutodiscoveryDevices from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in NagiosHost. */ public function getAutodiscoveryDevicesJoinNagiosHostTemplate($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(NagiosHostPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collAutodiscoveryDevices === null) { if ($this->isNew()) { $this->collAutodiscoveryDevices = array(); } else { $criteria->add(AutodiscoveryDevicePeer::PROPOSED_PARENT, $this->id); $this->collAutodiscoveryDevices = AutodiscoveryDevicePeer::doSelectJoinNagiosHostTemplate($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(AutodiscoveryDevicePeer::PROPOSED_PARENT, $this->id); if (!isset($this->lastAutodiscoveryDeviceCriteria) || !$this->lastAutodiscoveryDeviceCriteria->equals($criteria)) { $this->collAutodiscoveryDevices = AutodiscoveryDevicePeer::doSelectJoinNagiosHostTemplate($criteria, $con, $join_behavior); } } $this->lastAutodiscoveryDeviceCriteria = $criteria; return $this->collAutodiscoveryDevices; }
$c1->addOr($c2); $c->add($c1); $host = NagiosHostPeer::doSelectOne($c); if ($host) { // Found parent $autodiscoveryJob->addNotice("Found parent: " . $host->getName()); $device->setProposedParent($host->getId()); $device->save(); $found = true; } } if (!$found) { $autodiscoveryJob->addNotice("Could not find a suitable parent. Setting as a top-level device."); } } else { $autodiscoveryJob->addNotce("Failed to run Traceroute. Not using it."); } } } // Okay, now we start doing the magic. $c = new Criteria(); $c->add(AutodiscoveryDevicePeer::JOB_ID, $autodiscoveryJob->getId()); $devices = AutodiscoveryDevicePeer::doSelect($c); foreach ($devices as $device) { $autodiscoveryJob->addNotice("Performing template matching for device: " . $device->getAddress()); AutodiscoveryMatchMaker::match($device, $defaultTemplate); } $autodiscoveryJob->addNotice("Completed Auto Discovery."); $autodiscoveryJob->setStatus("Finished."); $autodiscoveryJob->setStatusCode(AutodiscoveryJob::STATUS_FINISHED); $autodiscoveryJob->save();
/** * Method perform a DELETE on the database, given a NagiosHost or Criteria object OR a primary key value. * * @param mixed $values Criteria or NagiosHost object or primary key or array of primary keys * which is used to create the DELETE statement * @param PropelPDO $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows * if supported by native driver or if emulated using Propel. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doDelete($values, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(NagiosHostPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { // invalidate the cache for all objects of this type, since we have no // way of knowing (without running a query) what objects should be invalidated // from the cache based on this Criteria. NagiosHostPeer::clearInstancePool(); // rename for clarity $criteria = clone $values; } elseif ($values instanceof NagiosHost) { // invalidate the cache for this single object NagiosHostPeer::removeInstanceFromPool($values); // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it must be the primary key $criteria = new Criteria(self::DATABASE_NAME); $criteria->add(NagiosHostPeer::ID, (array) $values, Criteria::IN); foreach ((array) $values as $singleval) { // we can invalidate the cache for this single object NagiosHostPeer::removeInstanceFromPool($singleval); } } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows try { // use transaction because $criteria could contain info // for more than one table or we could emulating ON DELETE CASCADE, etc. $con->beginTransaction(); $affectedRows += NagiosHostPeer::doOnDeleteCascade($criteria, $con); NagiosHostPeer::doOnDeleteSetNull($criteria, $con); // Because this db requires some delete cascade/set null emulation, we have to // clear the cached instance *after* the emulation has happened (since // instances get re-added by the select statement contained therein). if ($values instanceof Criteria) { NagiosHostPeer::clearInstancePool(); } else { // it's a PK or object NagiosHostPeer::removeInstanceFromPool($values); } $affectedRows += BasePeer::doDelete($criteria, $con); // invalidate objects in NagiosServicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServicePeer::clearInstancePool(); // invalidate objects in NagiosHostContactMemberPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostContactMemberPeer::clearInstancePool(); // invalidate objects in NagiosDependencyPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosDependencyPeer::clearInstancePool(); // invalidate objects in NagiosDependencyTargetPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosDependencyTargetPeer::clearInstancePool(); // invalidate objects in NagiosEscalationPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosEscalationPeer::clearInstancePool(); // invalidate objects in NagiosHostContactgroupPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostContactgroupPeer::clearInstancePool(); // invalidate objects in NagiosHostgroupMembershipPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostgroupMembershipPeer::clearInstancePool(); // invalidate objects in NagiosHostCheckCommandParameterPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostCheckCommandParameterPeer::clearInstancePool(); // invalidate objects in NagiosHostParentPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostParentPeer::clearInstancePool(); // invalidate objects in NagiosHostParentPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostParentPeer::clearInstancePool(); // invalidate objects in NagiosHostTemplateInheritancePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostTemplateInheritancePeer::clearInstancePool(); // invalidate objects in AutodiscoveryDevicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. AutodiscoveryDevicePeer::clearInstancePool(); $con->commit(); return $affectedRows; } catch (PropelException $e) { $con->rollBack(); throw $e; } }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = AutodiscoveryDevicePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setJobId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setAddress($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setName($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setHostname($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setDescription($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setOsvendor($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setOsfamily($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setOsgen($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setHostTemplate($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setProposedParent($arr[$keys[10]]); } }
/** * 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; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = AutodiscoveryJobPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related AutodiscoveryLogEntry objects $c = new Criteria(AutodiscoveryLogEntryPeer::DATABASE_NAME); $c->add(AutodiscoveryLogEntryPeer::JOB, $obj->getId()); $affectedRows += AutodiscoveryLogEntryPeer::doDelete($c, $con); // delete related AutodiscoveryDevice objects $c = new Criteria(AutodiscoveryDevicePeer::DATABASE_NAME); $c->add(AutodiscoveryDevicePeer::JOB_ID, $obj->getId()); $affectedRows += AutodiscoveryDevicePeer::doDelete($c, $con); } return $affectedRows; }