From: Roland Häder Date: Wed, 25 Mar 2009 09:13:54 +0000 (+0000) Subject: node_type rewritten to 'mode' element from request X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7a0d723bf2119162895f34ece6464571781d57de;p=hub.git node_type rewritten to 'mode' element from request --- diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 1c5cb9dec..7dc7f51d3 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -164,7 +164,10 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica 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'; diff --git a/application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php b/application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php index 0cab92fce..7dccdef85 100644 --- a/application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php @@ -69,10 +69,11 @@ class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper { * '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)); @@ -80,7 +81,7 @@ class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper { $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); diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index c82ca908a..6ca6aacb4 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -78,7 +78,7 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { // 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 @@ -91,12 +91,15 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { // 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'); @@ -105,7 +108,10 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { $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() . ''); } } @@ -113,12 +119,13 @@ class BaseHubNode extends BaseFrameworkSystem implements Updateable { * 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());