Пример #1
0
 /**
  * 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";
     }
 }
Пример #2
0
 /**
  * Gets mixed array of MeshingOwnNode and *KnownNode objects to send to
  */
 protected function getLocalAndRemoteReceiverNodes(P2POwnNode $node)
 {
     // Rewrite the above from the perspective of the local 'to' node
     $localNodes = P2POwnNodeQuery::create()->joinMeshingTrustLocalRelatedByToOwnNodeId('TrustLocal')->useQuery('TrustLocal')->joinMeshingTrustType()->endUse()->where('TrustLocal.FromOwnNodeId = ?', $node->getId())->where('MeshingTrustType.Name LIKE ?', 'write%')->find();
     // Get array of node ids in remote database (we can't join between system and node dbs)
     $remoteNodeIds = MeshingTrustRemoteQuery::create()->joinMeshingTrustType()->where('MeshingTrustRemote.FromOwnNodeId = ?', $node->getId())->where('MeshingTrustType.Name LIKE ?', 'write%')->select('MeshingTrustRemote.KnownNodeId')->find()->getArrayCopy();
     // Initialise remote node models
     $schemaName = $node->getMeshingSchema()->getName();
     Meshing_Utils::initialiseNodeDbs($schemaName);
     $con = Meshing_Node_Utils::getConnectionForNode($node);
     // Do select in node database for remote node ids
     $className = Meshing_Node_Utils::getNodeClassName($schemaName, 'KnownNodeQuery');
     /* @var $query JobsKnownNodeQuery */
     // (This is just an example - can be of any *KnownNodeQuery class)
     $query = call_user_func(array($className, 'create'), 'KnownNode');
     $remoteNodes = $query->where('KnownNode.Id IN ?', $remoteNodeIds)->find($con);
     /* @var $localNodes PropelObjectCollection */
     /* @var $remoteNodes PropelObjectCollection */
     return array_merge($localNodes->getArrayCopy(), $remoteNodes->getArrayCopy());
 }
Пример #3
0
 /**
  * Filter the query by a related P2POwnNode object
  *
  * @param     P2POwnNode|PropelCollection $p2POwnNode The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return    MeshingTrustLocalQuery The current query, for fluid interface
  */
 public function filterByToOwnNode($p2POwnNode, $comparison = null)
 {
     if ($p2POwnNode instanceof P2POwnNode) {
         return $this->addUsingAlias(MeshingTrustLocalPeer::TO_OWN_NODE_ID, $p2POwnNode->getId(), $comparison);
     } elseif ($p2POwnNode instanceof PropelCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(MeshingTrustLocalPeer::TO_OWN_NODE_ID, $p2POwnNode->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByToOwnNode() only accepts arguments of type P2POwnNode or PropelCollection');
     }
 }
Пример #4
0
 /**
  * Filter the query by a related P2POwnNode object
  *
  * @param     P2POwnNode $p2POwnNode  the related object to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return    MeshingSchemaQuery The current query, for fluid interface
  */
 public function filterByP2POwnNode($p2POwnNode, $comparison = null)
 {
     if ($p2POwnNode instanceof P2POwnNode) {
         return $this->addUsingAlias(MeshingSchemaPeer::ID, $p2POwnNode->getSchemaId(), $comparison);
     } elseif ($p2POwnNode instanceof PropelCollection) {
         return $this->useP2POwnNodeQuery()->filterByPrimaryKeys($p2POwnNode->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByP2POwnNode() only accepts arguments of type P2POwnNode or PropelCollection');
     }
 }
Пример #5
0
 /**
  * Declares an association between this object and a P2POwnNode object.
  *
  * @param      P2POwnNode $v
  * @return     MeshingTrustLocal The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setToOwnNode(P2POwnNode $v = null)
 {
     if ($v === null) {
         $this->setToOwnNodeId(NULL);
     } else {
         $this->setToOwnNodeId($v->getId());
     }
     $this->aToOwnNode = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the P2POwnNode object, it will not be re-added.
     if ($v !== null) {
         $v->addMeshingTrustLocalRelatedByToOwnNodeId($this);
     }
     return $this;
 }
Пример #6
0
 public static function getConnectionForNode(P2POwnNode $node)
 {
     $conName = $node->getP2PConnection()->getName();
     return Propel::getConnection($conName);
 }
Пример #7
0
 /**
  * Labels the node db with a link back to the system table
  * 
  * Requires node autoloaders to be set up (Meshing_Utils::initialiseNodeDbs)
  */
 protected function writeNodeIdentityRecord(P2POwnNode $ownNode, PDO $conn)
 {
     // Save an ID record in the node
     $class = Meshing_Node_Utils::getIdentityClassName($this->opts->schema);
     $node = new $class();
     $node->setNodeId($ownNode->getId());
     $node->setSchemaName($this->opts->schema);
     $node->setBuiltAt(time());
     $node->save($conn);
     return $node;
 }
Пример #8
0
 /**
  * Exclude object from result
  *
  * @param     P2POwnNode $p2POwnNode Object to remove from the list of results
  *
  * @return    P2POwnNodeQuery The current query, for fluid interface
  */
 public function prune($p2POwnNode = null)
 {
     if ($p2POwnNode) {
         $this->addUsingAlias(P2POwnNodePeer::ID, $p2POwnNode->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }