/** * Returns a new MeshingTrustTypeQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return MeshingTrustTypeQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof MeshingTrustTypeQuery) { return $criteria; } $query = new MeshingTrustTypeQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(MeshingTrustTypePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { MeshingTrustTypeQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (PropelException $e) { $con->rollBack(); throw $e; } }
/** * Get the associated MeshingTrustType object * * @param PropelPDO Optional Connection object. * @return MeshingTrustType The associated MeshingTrustType object. * @throws PropelException */ public function getMeshingTrustType(PropelPDO $con = null) { if ($this->aMeshingTrustType === null && $this->type !== null) { $this->aMeshingTrustType = MeshingTrustTypeQuery::create()->findPk($this->type, $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->aMeshingTrustType->addMeshingTrustLocals($this); */ } return $this->aMeshingTrustType; }
/** * Adds trust between the two local nodes i.e. FROM trusts TO * * @param P2POwnNode $from * @param P2POwnNode $to */ protected function runLocal(P2POwnNode $from, P2POwnNode $to) { // Look up the trust type, using default if necessary $typeName = $this->opts->{'trust-type'}; $typeName = $typeName ? $typeName : MeshingTrustLocalPeer::TYPE_DEFAULT; $trustType = MeshingTrustTypeQuery::create()->findOneByName(strtolower($typeName)); if (!$trustType) { throw new Meshing_Console_RunException('The specified trust type is not found'); } // If a trust already exists, require force else an exception is thrown $trust = MeshingTrustLocalPeer::retrieveByPK($from->getId(), $to->getId()); if ($trust) { if ($this->opts->force) { $trust->delete(); } else { throw new Meshing_Console_RunException('A trust relationship already exists between this node pair (use --force to overwrite)'); } } $trust = new MeshingTrustLocal(); $trust->setFromOwnNode($from); $trust->setToOwnNode($to); $trust->setMeshingTrustType($trustType); $trust->save(); if (!$this->opts->quiet) { echo "trust:add -> set up trust '{$typeName}' by node '{$from->getName()}' to '{$to->getName()}'.\n"; } }