Some improvements, and fix spoolgen.php
[banana.git] / examples / spoolgen.php
CommitLineData
0e25d15d 1#!/usr/bin/php5
4cc7f778 2<?php
3/********************************************************************************
4 * spoolgen.php : spool generation
5 * --------------
6 *
7 * This file is part of the banana distribution
8 * Copyright: See COPYING files that comes with this distribution
9 ********************************************************************************/
10
11require_once("banana/banana.inc.php");
12
13$opt = getopt('u:p:h');
14
15if(isset($opt['h'])) {
16 echo <<<EOF
f8af7e38 17usage: spoolgen.php [ -u user ] [ -p pass ]
4cc7f778 18 create all spools, using user user and pass pass
19EOF;
20 exit;
21}
22
23class MyBanana extends Banana
24{
0e25d15d 25 public function __construct()
4cc7f778 26 {
27 global $opt;
0e25d15d 28 Banana::$host = "news://{$opt['u']}:{$opt['p']}@localhost:119/\n";
29 echo Banana::$host;
30 parent::__construct();
4cc7f778 31 }
32
0e25d15d 33 private function checkErrors()
4cc7f778 34 {
0e25d15d 35 if (Banana::$protocole->lastErrno()) {
36 echo "\nL'erreur suivante s'est produite : "
37 . Banana::$protocole->lastErrno() . " "
38 . Banana::$protocole->lastError() . "\n";
39 exit;
40 }
41 }
4cc7f778 42
0e25d15d 43 public function createAllSpool()
44 {
45 $this->checkErrors();
46 $groups = Banana::$protocole->getBoxList();
47 $this->checkErrors();
4cc7f778 48
0e25d15d 49 foreach (array_keys($groups) as $g) {
4cc7f778 50 print "Generating spool for $g : ";
0e25d15d 51 Banana::$group = $g;
52 $spool = $this->loadSpool($g);
53 $this->checkErrors();
4cc7f778 54 print "done.\n";
55 unset($spool);
56 }
4cc7f778 57 }
58}
59
60
61$banana = new MyBanana();
62$banana->createAllSpool();
d5588318 63
64// vim:set et sw=4 sts=4 ts=4
4cc7f778 65?>