Merge a protocole independent version of spoolgen in Banana itself
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Mon, 15 Jan 2007 10:32:52 +0000 (10:32 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:20 +0000 (00:35 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@173 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
examples/spoolgen.php

index 2bab28c..df1768b 100644 (file)
@@ -445,6 +445,49 @@ class Banana
     }
 
     /**************************************************************************/
+    /* Spoolgen functions                                                     */
+    /**************************************************************************/
+
+    private function checkErrors()
+    {
+        if (Banana::$protocole->lastErrno()) {
+            echo "\nL'erreur suivante s'est produite : "
+                . Banana::$protocole->lastErrno() . " "
+                . Banana::$protocole->lastError() . "\n";
+            return false;
+        }
+        return true;
+    } 
+
+    static public function createAllSpool(array $protos)
+    {
+        foreach ($protos as $proto) {
+            $banana = new Banana(array(), $proto);
+
+            if (!$banana->checkErrors()) {
+                continue;
+            }
+            $groups = Banana::$protocole->getBoxList();
+            if (!$banana->checkErrors()) {
+                continue;
+            }
+
+            print "** $proto **\n";
+            foreach (array_keys($groups) as $g) {
+                print "Generating spool for $g : ";
+                Banana::$group = $g;
+                $spool = $banana->loadSpool($g);
+                if (!$banana->checkErrors()) {
+                    break;
+                }
+                print "done.\n";
+                unset($spool);
+            }
+            print "\n";
+        }
+    }
+
+    /**************************************************************************/
     /* Private functions                                                      */
     /**************************************************************************/
 
index 6c2c7da..16663ee 100644 (file)
@@ -20,46 +20,8 @@ EOF;
     exit;
 }
 
-class MyBanana extends Banana
-{
-    public function __construct()
-    {
-        global $opt;
-        Banana::$host = "news://{$opt['u']}:{$opt['p']}@localhost:119/\n";
-        echo Banana::$host;
-        parent::__construct();
-    }
-
-    private function checkErrors()
-    {
-        if (Banana::$protocole->lastErrno()) {
-            echo "\nL'erreur suivante s'est produite : "
-                . Banana::$protocole->lastErrno() . " "
-                . Banana::$protocole->lastError() . "\n";
-            exit;
-        }
-    }
-
-    public function createAllSpool()
-    {
-        $this->checkErrors();
-        $groups = Banana::$protocole->getBoxList();
-        $this->checkErrors();
-
-        foreach (array_keys($groups) as $g) {
-            print "Generating spool for $g : ";
-            Banana::$group = $g;
-            $spool = $this->loadSpool($g);
-            $this->checkErrors();
-            print "done.\n";
-            unset($spool);
-        }
-    }
-}
-
-
-$banana = new MyBanana();
-$banana->createAllSpool();
+Banana::$nntp_host = "news://{$opt['u']}:{$opt['p']}@localhost:119/\n";
+Banana::createAllSpool(array('NNTP'));
 
 // vim:set et sw=4 sts=4 ts=4
 ?>