]> git.mxchange.org Git - hub.git/commitdiff
node_type rewritten to 'mode' element from request
authorRoland Häder <roland@mxchange.org>
Wed, 25 Mar 2009 09:13:54 +0000 (09:13 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 25 Mar 2009 09:13:54 +0000 (09:13 +0000)
application/hub/class_ApplicationHelper.php
application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php
application/hub/main/nodes/class_BaseHubNode.php

index 1c5cb9decee07740fc0790e7d70bdfdba36824a0..7dc7f51d3c819c649cd2097e71dafa81cd23603d 100644 (file)
@@ -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';
index 0cab92fce65f63782676ec09097cd6c7aec9be9f..7dccdef85bb28b4b2db7a1ad9a4e63b816b45b2d 100644 (file)
@@ -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);
index c82ca908a4d1a18686ea3f09f0b9fbf15ad57776..6ca6aacb474645cf96dfa3a1dd3c2241e858f14b 100644 (file)
@@ -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());