public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('The node must have a name (use --name)'); } if (!$this->opts->connection) { throw new Zend_Console_Getopt_Exception('The node must have a connection (use --connection)'); } if (!$this->opts->schema) { throw new Zend_Console_Getopt_Exception('The node must have a schema (use --schema)'); } // Check that the name supplied is unique Meshing_Utils::initialiseDb(); $node = P2POwnNodeQuery::create()->findOneByName($this->opts->name); if ($node) { throw new Zend_Console_Getopt_Exception('A node of that name already exists'); } // Check that the connection exists $this->connection = P2PConnectionQuery::create()->findOneByName($this->opts->connection); if (!$this->connection) { throw new Zend_Console_Getopt_Exception('The specified connection is not registered'); } // Check that the schema exists $this->schema = MeshingSchemaQuery::create()->findOneByName($this->opts->schema); if (!$this->schema) { throw new Zend_Console_Getopt_Exception('The specified schema is not registered'); } }
public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('Which node would you like have send updates? (use --name)'); } Meshing_Utils::initialiseDb(); $this->node = P2POwnNodeQuery::create()->findOneByName($this->opts->name); if (!$this->node) { throw new Zend_Console_Getopt_Exception('A node of that name is not registered'); } }
/** * 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()); }
public function preRunCheck() { // Used to track bad combos e.g. local-to AND remote-to $hasToLocal = $hasToRemote = false; $localFromName = $this->opts->{'local-from'}; if (!$localFromName) { throw new Zend_Console_Getopt_Exception('A local node must be specified (use --local-from)'); } if ($localToName = $this->opts->{'local-to'}) { $hasToLocal = true; } // @todo Not implemented yet if ($remoteToName = $this->opts->{'remote-to'}) { throw new Zend_Console_Getopt_Exception('Remote nodes are not currently supported'); //$hasToRemote = true; } // Check for bad combinations if ($localToName && $remoteToName) { throw new Zend_Console_Getopt_Exception('You cannot have a local-to AND a remote-to node'); } if (!$localToName && !$remoteToName) { throw new Zend_Console_Getopt_Exception('You must have one \'to\' node (use --local-to or --remote-to)'); } // Check that the local from actually exists Meshing_Utils::initialiseDb(); $this->localFromNode = P2POwnNodeQuery::create()->findOneByName($localFromName); if (!$this->localFromNode) { throw new Zend_Console_Getopt_Exception('A local node of that (from) name is not registered'); } if ($localToName) { $this->localToNode = P2POwnNodeQuery::create()->findOneByName($localToName); if (!$this->localToNode) { throw new Zend_Console_Getopt_Exception('A local node of that (to) name is not registered'); } } // We cannot trust ourselves, so to speak ;-) if ($localFromName == $localToName) { throw new Zend_Console_Getopt_Exception('There is no point in setting a node to trust itself'); } }
public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('Which node would you like to start? (use --name)'); } Meshing_Utils::initialiseDb(); $node = P2POwnNodeQuery::create()->findOneByName($this->opts->name); if (!$node) { throw new Zend_Console_Getopt_Exception('A node of that name is not registered'); } // Connect with this node's connection, and ensure there are rows in known_nodes $conn = Propel::getConnection($node->getP2PConnection()->getName()); $schemaName = $node->getMeshingSchema()->getName(); Meshing_Utils::initialiseNodeDbs($schemaName); // Obtain the number of trusted nodes $class = Meshing_Node_Utils::getNodeClassName($schemaName, 'KnownNodePeer'); $knownNodeCount = call_user_func(array($class, 'doCount'), new Criteria(), $distinct = false, $conn); // If there are no trust rows, we cannot start if (!$knownNodeCount) { throw new Zend_Console_Getopt_Exception('A node needs to trust other nodes before it can be started'); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this MeshingSchema is new, it will return * an empty collection; or if this MeshingSchema has previously * been saved, it will retrieve related P2POwnNodes 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 MeshingSchema. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelCollection|array P2POwnNode[] List of P2POwnNode objects */ public function getP2POwnNodesJoinP2PConnection($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = P2POwnNodeQuery::create(null, $criteria); $query->joinWith('P2PConnection', $join_behavior); return $this->getP2POwnNodes($query, $con); }
/** * 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(P2POwnNodePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { P2POwnNodeQuery::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 P2POwnNode object * * @param PropelPDO Optional Connection object. * @return P2POwnNode The associated P2POwnNode object. * @throws PropelException */ public function getToOwnNode(PropelPDO $con = null) { if ($this->aToOwnNode === null && $this->to_own_node_id !== null) { $this->aToOwnNode = P2POwnNodeQuery::create()->findPk($this->to_own_node_id, $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->aToOwnNode->addMeshingTrustLocalsRelatedByToOwnNodeId($this); */ } return $this->aToOwnNode; }