if ($requestInstance->isRequestElementSet('mode')) {
// Then use this which overrides the config entry temporarily
$nodeMode = $requestInstance->getRequestElement('mode');
- } // END - if
+ } else {
+ // Set it for easier re-usage
+ $requestInstance->setRequestElement('mode', $nodeMode);
+ }
// Now convert the node-mode in a class name
$className = 'Hub' . $this->convertToClassName($nodeMode) . 'Node';
* 'Registers' a new node id along with data provided in the node instance.
* This may sound confusing but avoids double code very nicely...
*
- * @param $nodeInstance A node instance
+ * @param $nodeInstance A node instance
+ * @param $requestInstance An instance of a Requestable class
* @return void
*/
- public function registerNodeId (BaseHubNode $nodeInstance) {
+ public function registerNodeId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
// Get a dataset instance
$dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
$dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
// Add registration elements to the dataset
- $nodeInstance->addElementsToDataSet($dataSetInstance);
+ $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
// "Insert" this request instance completely into the database
$this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
// Search for the node number zero which is hard-coded the default
$searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
- $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->__toString());
+ $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $requestInstance->getRequestElement('mode'));
$searchInstance->setLimit(1);
// Get a result back
// Get the node id from result and set it
$this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
+
+ // Output message
+ $this->getDebugInstance()->output('Re-using found node-id: ' . $this->getNodeId() . '');
} else {
// Get an RNG instance (Random Number Generator)
$rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
// Generate a pseudo-random string
- $randomString = $rngInstance->randomString(255);
+ $randomString = $rngInstance->randomString(255) . ':' . $requestInstance->getRequestElement('mode');
// Get a crypto instance
$cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
$this->setNodeId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
// Register the node id with our wrapper
- $wrapperInstance->registerNodeId($this);
+ $wrapperInstance->registerNodeId($this, $requestInstance);
+
+ // Output message
+ $this->getDebugInstance()->output('Creating new node-id: ' . $this->getNodeId() . '');
}
}
* Adds registration elements to a given dataset instance
*
* @param $criteriaInstance An instance of a storeable criteria
+ * @param $requestInstance An instance of a Requestable class
* @return void
*/
- public function addElementsToDataSet (StoreableCriteria $criteriaInstance) {
+ public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance) {
// Add node number and type
$criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->__toString());
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $requestInstance->getRequestElement('mode'));
// Add the node id
$criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());