]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/dht/class_BaseDht.php
Added unfinished support for XML-based publishing of DHT entries.
[hub.git] / application / hub / main / dht / class_BaseDht.php
index 9f5cb4c799cfdc03295d231fec9db6599e46d5ba..fecc18cd76c8a0d6f7d03e5416aebc010d528b7b 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseDht extends BaseHubSystem {
+       /**
+        * "Cached" instance of a publish helper
+        */
+       private $publishHelperInstance = NULL;
+
        /**
         * Stacker name for "INSERT" node data
         */
@@ -162,6 +167,47 @@ abstract class BaseDht extends BaseHubSystem {
                        $this->getStackerInstance()->pushNamed(self::STACKER_NAME_PENDING_PUBLISHING, $current);
                } // END - while
        }
+
+       /**
+        * Checks whether there are entries pending publication
+        *
+        * @return      $isPending      Whether there are entries pending publication
+        */
+       public function hasEntriesPendingPublication () {
+               // Determine it if it is not empty
+               $isPending = ($this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_PENDING_PUBLISHING) === FALSE);
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] isPending=' . intval($isPending));
+               return $isPending;
+       }
+
+       /**
+        * Publishes next entry found in stack. This method shall also update the
+        * corresponding dabase entry.
+        *
+        * @return      void
+        * @todo        Find out if loadDescriptorXml() can be called only once to avoid a lot methods working.
+        */
+       public function publishEntry () {
+               // This test must not fail
+               assert($this->hasEntriesPendingPublication());
+
+               // Is there an instance?
+               if (!$this->publishHelperInstance instanceof HelpableDht) {
+                       // Get a helper instance
+                       $this->publishHelperInstance = ObjectFactory::createObjectByConfiguredName('dht_publish_entry_helper_class');
+               } // END - if
+
+               // Load the announcement descriptor
+               $this->publishHelperInstance->loadDescriptorXml($this);
+
+               // Compile all variables
+               $this->publishHelperInstance->getTemplateInstance()->compileConfigInVariables();
+
+               // "Publish" the descriptor by sending it to the bootstrap/list nodes
+               $this->publishHelperInstance->sendPackage($this);
+       }
 }
 
 // [EOF]