Skip to content
Snippets Groups Projects
Commit a0e84ddf authored by Jared Hancock's avatar Jared Hancock
Browse files

oops: Fix several small issues

* Fix warning for negative unix timestamps in Misc::db2gmtime
* Fix crash because of parser context passed to getXxx functions
* Fix inability to update email address
parent 59df5215
Branches
Tags
No related merge requests found
......@@ -117,7 +117,9 @@ class Email extends VerySimpleModel {
}
function getInfo() {
return $this->getHashtable();
$base = $this->getHashtable();
$base['mail_proto'] = $this->mail_proto;
return $base;
}
function getMailAccountInfo() {
......@@ -313,7 +315,7 @@ class Email extends VerySimpleModel {
));
if ($id)
$existing->filter(array('email_id' => $id));
$existing->exclude(array('email_id' => $id));
if ($existing->exists())
$errors['userid']=$errors['host']=__('Host/userid combination already in use.');
......
......@@ -931,13 +931,20 @@ extends FormattedLocalDate {
return (string) new FormattedLocalDate($this->date, $cfg->getTimezone(), false, $this->fromdb);
}
function getVar($what) {
function getVar($what, $context) {
global $cfg;
if ($rv = parent::getVar($what))
return $rv;
switch ($what) {
case 'user':
// Fetch $recipient from the context and find that user's time zone
if ($recipient = $context->getObj('recipient')) {
$tz = $recipient->getTimezone() ?: $cfg->getDefaultTimezone();
return new FormattedLocalDate($this->date, $tz, $recipient);
}
break;
case 'system':
return new FormattedLocalDate($this->date, $cfg->getDefaultTimezone());
}
......@@ -947,16 +954,6 @@ extends FormattedLocalDate {
return Format::relativeTime(Misc::db2gmtime($this->date));
}
function getUser($context) {
global $cfg;
// Fetch $recipient from the context and find that user's time zone
if ($recipient = $context->getObj('recipient')) {
$tz = $recipient->getTimezone() ?: $cfg->getDefaultTimezone();
return new FormattedLocalDate($this->date, $tz, $recipient);
}
}
static function getVarScope() {
return parent::getVarScope() + array(
'humanize' => 'Humanized time, e.g. about an hour ago',
......
......@@ -73,6 +73,10 @@ class Misc {
$dbtime = is_int($var) ? $var : strtotime($var);
$D = DateTime::createFromFormat('U', $dbtime);
if (!$D)
// This happens e.g. from negative timestamps
return $var;
return $dbtime - $dbtz->getOffset($D);
}
......
......@@ -70,7 +70,7 @@ class VariableReplacer {
list($v, $part) = explode('.', $var, 2);
if ($v && is_callable(array($obj, 'get'.ucfirst($v)))) {
$rv = call_user_func(array($obj, 'get'.ucfirst($v)), $this);
$rv = call_user_func(array($obj, 'get'.ucfirst($v)));
if(!$rv || !is_object($rv))
return $rv;
......@@ -374,7 +374,7 @@ class TextWithExtras {
interface TemplateVariable {
// function asVar(); — not absolutely required
// function getVar($name); — not absolutely required
// function getVar($name, $parser); — not absolutely required
static function getVarScope();
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment