Commit r2392: https://sourceforge.net/p/mrbs/code/2392/
------------------------------------------------------------------------
r2392 | cimorrison | 2012-09-05 14:15:28 +0100 (Wed, 05 Sep 2012) | 1 line
Changed paths:
M /mrbs/trunk/web/functions_ical.inc
M /mrbs/trunk/web/systemdefaults.inc.php
Improved error handling when updating VTIMEZONE definitions. Now if MRBS is
unable to download a new definition from the web, as will happen on sites that
do not have external internet access, the last_updated field is updated anyway
so that MRBS does not attempt to retry for another 28 days (default setting).
Previously it would retry every time edit_entry_handler.php was executed. See
also SF Support Request 258.
------------------------------------------------------------------------
Index: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php (revision 2391)
+++ mrbs/trunk/web/systemdefaults.inc.php (revision 2392)
@@ -48,7 +48,9 @@
$zoneinfo_outlook_compatible = TRUE;
// The VTIMEZONE definitions are cached in the database with an expiry time
-// of $zoneinfo_expiry seconds
+// of $zoneinfo_expiry seconds. If your server does not have external
internet
+// access set $zoneinfo_expiry to PHP_INT_MAX to prevent MRBS from trying to
+// update the VTIMEZONE definitions.
$zoneinfo_expiry = 60*60*24*28; // 28 days
/*******************
Index: mrbs/trunk/web/functions_ical.inc
===================================================================
--- mrbs/trunk/web/functions_ical.inc (revision 2391)
+++ mrbs/trunk/web/functions_ical.inc (revision 2392)
@@ -35,6 +35,7 @@
// download the contents of the web page at $url and return it as a string
+// Returns the contents of the URL, or else FALSE on failure
function download($url)
{
global $proxy;
@@ -42,7 +43,7 @@
$connect_timeout = 2; // seconds
$transfer_timeout = 2; // seconds
$curlopt_timeout = 3; // seconds
-
+
// If we can we use cURL to download the page because it allows us to
// set a timeout on establishing a connection as well as on the transfer
time.
// (We can only set a timeout on transfer time with file_get_contents()).
The
@@ -56,6 +57,10 @@
curl_setopt($ch, CURLOPT_TIMEOUT, $curlopt_timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$contents = curl_exec($ch);
+ if ($contents === FALSE)
+ {
+ trigger_error(curl_error($ch), E_USER_WARNING);
+ }
curl_close($ch);
}
@@ -70,6 +75,10 @@
'timeout' =>
$transfer_timeout)));
// Suppress any timeout warnings
$contents = @file_get_contents($url);
+ if ($contents === FALSE)
+ {
+ trigger_error("MRBS: could not get contents of $url", E_USER_WARNING);
+ }
}
return $contents;
@@ -142,26 +151,42 @@
$vcalendar = download($tz_url);
- if ($vcalendar)
+ if ($vcalendar === FALSE)
{
+ trigger_error("MRBS: failed to download a new timezone definition from
$tz_url", E_USER_WARNING);
+ }
+ else
+ {
$new_vtimezone = extract_vtimezone($vcalendar);
- if (!empty($new_vtimezone))
+ if (empty($new_vtimezone))
{
+ trigger_error("MRBS: $tz_url did not contain a valid VTIMEZONE",
E_USER_WARNING);
+ }
+ else
+ {
// We've got a valid VTIMEZONE, so we can overwrite $vtimezone
$vtimezone = $new_vtimezone;
- // Update the database
- $sql = "UPDATE $tbl_zoneinfo
- SET vtimezone='" . sql_escape($vtimezone) . "',
- last_updated=" . time() . "
- WHERE timezone='" . sql_escape($tz) . "'
- AND outlook_compatible=$zoneinfo_outlook_compatible";
- if (sql_command($sql) < 0)
- {
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
}
}
+
+ // Update the database, whether we've successfully got a new VTIMEZONE
or not.
+ // If we didn't manage to get a new VTIMEZONE, updating the database
will update
+ // the last_updated field and mean that MRBS will not try again until
after the
+ // expiry interval has passed. This will mean that we don't introduce a
few
+ // seconds delay every time this file is included. (The most likely
reason that
+ // we couldn't get a new VTIMEZONE is that the site doesn't have
external internet
+ // access, so there's no point in retrying for a while).
+ $sql = "UPDATE $tbl_zoneinfo
+ SET vtimezone='" . sql_escape($vtimezone) . "',
+ last_updated=" . time() . "
+ WHERE timezone='" . sql_escape($tz) . "'
+ AND outlook_compatible=$zoneinfo_outlook_compatible";
+ if (sql_command($sql) < 0)
+ {
+ trigger_error(sql_error(), E_USER_WARNING);
+ fatal_error(FALSE, get_vocab("fatal_db_error"));
+ }
+
}
}
// There's nothing in the database, so try and get a VTIMEZONE component
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits