gunnar: server/php-kolab/Kolab_Freebusy/Freebusy Cache.php,1.1,1.2
cvs at kolab.org
cvs at kolab.org
Fri Nov 23 14:39:34 CET 2007
Author: gunnar
Update of /kolabrepository/server/php-kolab/Kolab_Freebusy/Freebusy
In directory doto:/tmp/cvs-serv15550/php-kolab/Kolab_Freebusy/Freebusy
Modified Files:
Cache.php
Log Message:
kolab/issue898 (pfbs from several servers, are not combined into .ifb) + some minor fixes to kolab-freebusy.
Index: Cache.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Freebusy/Freebusy/Cache.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Cache.php 22 Nov 2007 16:53:05 -0000 1.1
+++ Cache.php 23 Nov 2007 13:39:32 -0000 1.2
@@ -161,6 +161,8 @@
function &load(&$access, $extended)
{
+ global $conf;
+
/* Which files will we access? */
$aclcache = &FreeBusyCacheDB_acl::singleton('acl', $this->_cache_dir);
$files = array();
@@ -228,7 +230,19 @@
$vFb->merge($pvFb);
/* Store last modification time */
- $mtimes[$file] = $c_pvcal->getMtime();
+ $mtimes[$file] = array($c_pvcal->getFile(), $c_pvcal->getMtime());
+ }
+
+ if (!empty($conf['fb']['remote_servers'])) {
+ $remote_vfb = $this->_fetchRemote($conf['fb']['remote_servers'],
+ $access);
+ if (is_a($remote_vfb, 'PEAR_Error')) {
+ Horde::logMessage(sprintf(_("Ignoring remote free/busy files: %s)"),
+ $remote_vfb->getMessage()),
+ __FILE__, __LINE__, PEAR_LOG_INFO);
+ } else {
+ $vFb->merge($remote_vfb);
+ }
}
if (!(boolean)$vFb->getBusyPeriods()) {
@@ -309,6 +323,58 @@
}
return $folder;
}
+
+ function &_fetchRemote($servers, $access)
+ {
+ $vFb = null;
+
+ foreach ($servers as $server) {
+
+ $url = 'https://' . urlencode($access->user) . ':' . urlencode($access->pass)
+ . '@' . $server . $_SERVER['REQUEST_URI'];
+ $remote = @file_get_contents($url);
+ if (!$remote) {
+ $message = sprintf(_("Unable to read free/busy information from %s"),
+ 'https://' . urlencode($access->user) . ':XXX'
+ . '@' . $server . $_SERVER['REQUEST_URI']);
+ Horde::logMessage($message, __FILE__, __LINE__, PEAR_LOG_INFO);
+ }
+
+ $rvCal = &new Horde_iCalendar();
+ $result = $rvCal->parsevCalendar($remote);
+
+ if (is_a($result, 'PEAR_Error')) {
+ $message = sprintf(_("Unable to parse free/busy information from %s: %s"),
+ 'https://' . urlencode($access->user) . ':XXX'
+ . '@' . $server . $_SERVER['REQUEST_URI'],
+ $result->getMessage());
+ Horde::logMessage($message, __FILE__, __LINE__, PEAR_LOG_INFO);
+ }
+
+ $rvFb = &$rvCal->findComponent('vfreebusy');
+ if (!$pvFb) {
+ $message = sprintf(_("Unable to find free/busy information in data from %s."),
+ 'https://' . urlencode($access->user) . ':XXX'
+ . '@' . $server . $_SERVER['REQUEST_URI']);
+ Horde::logMessage($message, __FILE__, __LINE__, PEAR_LOG_INFO);
+ }
+ if ($ets = $rvFb->getAttributeDefault('DTEND', false) !== false) {
+ // PENDING(steffen): Make value configurable
+ if ($ets < time()) {
+ $message = sprintf(_("free/busy information from %s is too old."),
+ 'https://' . urlencode($access->user) . ':XXX'
+ . '@' . $server . $_SERVER['REQUEST_URI']);
+ Horde::logMessage($message, __FILE__, __LINE__, PEAR_LOG_INFO);
+ }
+ }
+ if (!empty($vFb)) {
+ $vFb->merge($rvFb);
+ } else {
+ $vFb = $rvFb;
+ }
+ }
+ return $vFb;
+ }
};
class FreeBusyCacheDB {
@@ -545,6 +611,11 @@
$this->_file = $this->_cache_dir . '/' . $this->_filename . '.' . $this->_suffix;
}
+ function getFile()
+ {
+ return $this->_file;
+ }
+
function purge()
{
if (file_exists($this->_file)) {
@@ -594,6 +665,7 @@
return PEAR::raiseError(sprintf(_("Cache file %s lacks version data!"),
$this->_file));
}
+ $this->_version = $cache['version'];
if (!isset($cache['data'])) {
return PEAR::raiseError(sprintf(_("Cache file %s lacks data!"),
$this->_file));
@@ -660,6 +732,8 @@
var $_suffix = 'vc';
+ var $_version = 2;
+
var $_data;
function storeVcal(&$vcal, &$mtimes)
@@ -692,18 +766,23 @@
return $result;
}
+ /* Check the cache version */
+ if ($this->_version < 2) {
+ return true;
+ }
+
$this->_data = $result['vcal'];
/* Files changed? */
$keys = array_keys($result['mtimes']);
$changes = array_diff($keys, $files);
- if (!empty($changes)) {
+ if (count($keys) != count($files) || !empty($changes)) {
return true;
}
/* Check the file ctimes */
foreach ($files as $file) {
- if (filemtime($this->_cache_dir . '/' . $file) != $result['mtimes'][$file]) {
+ if (filemtime($result['mtimes'][$file][0]) != $result['mtimes'][$file][1]) {
return true;
}
}
More information about the commits
mailing list