gunnar: server/kolab-freebusy/freebusy generatefb.php,NONE,1.1

cvs at kolab.org cvs at kolab.org
Tue Feb 5 18:00:54 CET 2008


Author: gunnar

Update of /kolabrepository/server/kolab-freebusy/freebusy
In directory doto:/tmp/cvs-serv28530/freebusy

Added Files:
	generatefb.php 
Log Message:
A first draft of the free/busy regeneration script.

--- NEW FILE: generatefb.php ---
#!/kolabrelease/bin/php -c /kolabrelease/etc/apache/php.ini
<?php
/*
 *  COPYRIGHT
 *  ---------
 *
 *  See docs/AUTHORS file
 *
 *
 *  LICENSE
 *  -------
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Revision: 1.1 $
 *
 *  ABOUT
 *  -----
 *
 *  This script regenerates the cached free/busy information.
 *
 */

error_reporting(E_ALL);
ini_set('memory_limit', -1); /* requires safe_mode to be turned off */

/* Load the required free/busy libraries - this also loads Horde:: and
 Util:: as well as the PEAR constants*/ 
require_once 'Kolab/Freebusy/Page.php';

/* Load the configuration */ 
require_once '../../kolab/www/freebusy/config.php';

require_once('Console/Getopt.php');

$imaphost = $conf['kolab']['imap']['server'];
$imapport = $conf['kolab']['imap']['port'];
$imapoptions = '/notls';
$imapuser = 'manager';
$imappw = false;

/* Print out usage info */
function usage()
{
    global $imaphost,$imapport,$imapuser,$imappw;
    echo "Script for updating freebusy information on a kolab server.\n";
    echo "Normal usage is:\n";
    echo "\tsudo -u kolab-n ./generatefb.php [--help] [--imaphost=<imap hostname>] [--imapport=<imap port>] [--user=<manager user>] --password=<manager password>\n";
    echo "Defaults:\n";
    echo "\t--imaphost:\t$imaphost\n";
    echo "\t--imapport:\t$imapport\n";
    echo "\t--user:\t$imapuser\n";
    echo "\t--password:\t<no default>\n";
    exit(-1);
}

/* Parse command line options */
list($options,$args) = Console_Getopt::getopt(Console_Getopt::readPHPArgv(),'h',array('help','imaphost=','imapport=','user=','password='));
foreach( $options as $o ) {
    $a = $o[1];
    $o = $o[0];
    switch($o) {
	case 'h':
	case '--help':       usage(); break;
	case '--imaphost': $imaphost = $a; break;
	case '--imapport': $imapport = $a; break;
	case '--user':       $imapuser = $a; break;
	case '--password': $imappw   = $a; break;
    }
}

/* Password must be supplied */
if(!$imappw) usage();

$access = &new FolderAccess($imapuser, $imappw);
$result = $access->authenticate();
if (is_a($result, 'PEAR_Error')) {
    echo "Failed to authenticate!\n";
    echo $result->getMessage();
    exit(-1);
 }

/* Load the required Kolab libraries */ 
require_once "Horde/Kolab.php";
require_once "Horde/Kolab/IMAP.php";

$imap = new Kolab_IMAP();
$folders = $imap->listFolders();

if (is_a($folders, 'PEAR_Error')) {
    echo "Failed to fetch the IMAP folders!\n";
    echo $folders->getMessage();
    exit(-1);
 }

if (!is_array($folders)) {
    echo "Expected list of IMAP folders but got:\n";
    var_dump($folders);
    exit(-1);
 }

$calendars = array();

foreach ($folders as $folder) {

    if ($folder[1] == 'event' && (substr($folder[0], 0, 6) != 'shared')) {
        $calendars[] = $folder[0];
    }
}

/* Load the cache class now */
require_once('Kolab/Freebusy/Cache.php');

/* Where is the cache data stored? */
if (!empty($conf['fb']['cache_dir'])) {
    $cache_dir = $conf['fb']['cache_dir'];
} else {
    /* This default is not recommended so make sure you set a 
     * cache dir outside of the apache document root.
     */
    $cache_dir = dirname(__FILE__) . '/cache';
}

$cache = &new FreeBusyCache($cache_dir);

foreach ($calendars as $calendar) {

    /* Validate folder access */
    $result = $access->parseFolder($calendar);
    if (is_a($result, 'PEAR_Error')) {
        echo "Failed accessing calendar \"" . $calendar . "\"!\n";
        var_dump($result);
        exit(-1);
    }

    echo "Regenerating calendar \"" . $calendar . "\"!\n";

    /* Update the cache */
    $result = $cache->store($access);
    if (is_a($result, 'PEAR_Error')) {
        echo "Failed regenerating cache for calendar \"" . $calendar . "\"!\n";
        echo $result->getMessage();
        exit(-1);
    }
}
?>





More information about the commits mailing list