Commit 8fc5e696 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #356 in ZP/z-push from...

Merge pull request #356 in ZP/z-push from bugfix/ZP-983-handle-appointment-when-starttime to develop

* commit '6b62a009':
  ZP-983 Remove debug log.
  ZP-983 Log dates in WBXML mode and print them in the same format as they would appear in WBXML.
  ZP-983 Retrieve start/end time from MAPI if not set.
  ZP-983 Implement all cases of the specified cases of unset start/endtime.
  ZP-983 Allow MAPIProvider->setAppointment() to ignore start+endtime if they are not set.
  ZP-983 Set start and endtime to the next half hour if not set for appointments created on a mobile.
  ZP-983 Remove required flag for start & endtime in SyncObject check.
parents 19a6ed24 6b62a009
...@@ -1185,6 +1185,26 @@ class MAPIProvider { ...@@ -1185,6 +1185,26 @@ class MAPIProvider {
else else
$tz = false; $tz = false;
// start and end time may not be set - try to get them from the existing appointment for further calculation - see https://jira.z-hub.io/browse/ZP-983
if (!isset($appointment->starttime) || !isset($appointment->endtime)) {
$amapping = MAPIMapping::GetAppointmentMapping();
$amapping = $this->getPropIdsFromStrings($amapping);
$existingstartendpropsmap = array($amapping["starttime"], $amapping["endtime"]);
$existingstartendprops = $this->getProps($mapimessage, $existingstartendpropsmap);
if (isset($existingstartendprops[$amapping["starttime"]]) && !isset($appointment->starttime)) {
$appointment->starttime = $existingstartendprops[$amapping["starttime"]];
ZLog::Write(LOGLEVEL_WBXML, sprintf("MAPIProvider->setAppointment(): Parameter 'starttime' was not set, using value from MAPI %d (%s).", $appointment->starttime, gmstrftime("%Y%m%dT%H%M%SZ", $appointment->starttime)));
}
if (isset($existingstartendprops[$amapping["endtime"]]) && !isset($appointment->endtime)) {
$appointment->endtime = $existingstartendprops[$amapping["endtime"]];
ZLog::Write(LOGLEVEL_WBXML, sprintf("MAPIProvider->setAppointment(): Parameter 'endtime' was not set, using value from MAPI %d (%s).", $appointment->endtime, gmstrftime("%Y%m%dT%H%M%SZ", $appointment->endtime)));
}
}
if (!isset($appointment->starttime) || !isset($appointment->endtime)) {
throw new StatusException("MAPIProvider->setAppointment(): Error, start and/or end time not set and can not be retrieved from MAPI.", SYNC_STATUS_SYNCCANNOTBECOMPLETED);
}
//calculate duration because without it some webaccess views are broken. duration is in min //calculate duration because without it some webaccess views are broken. duration is in min
$localstart = $this->getLocaltimeByTZ($appointment->starttime, $tz); $localstart = $this->getLocaltimeByTZ($appointment->starttime, $tz);
$localend = $this->getLocaltimeByTZ($appointment->endtime, $tz); $localend = $this->getLocaltimeByTZ($appointment->endtime, $tz);
......
...@@ -1445,6 +1445,9 @@ class Sync extends RequestProcessor { ...@@ -1445,6 +1445,9 @@ class Sync extends RequestProcessor {
case SYNC_ADD: case SYNC_ADD:
self::$topCollector->AnnounceInformation(sprintf("Creating new message from mobile %d", $messageCount)); self::$topCollector->AnnounceInformation(sprintf("Creating new message from mobile %d", $messageCount));
try { try {
// mark the message as new message so SyncObject->Check() can differentiate
$message->flags = SYNC_NEWMESSAGE;
// ignore sms messages // ignore sms messages
if ($foldertype == "SMS") { if ($foldertype == "SMS") {
ZLog::Write(LOGLEVEL_DEBUG, "SMS sync are not supported. Ignoring message."); ZLog::Write(LOGLEVEL_DEBUG, "SMS sync are not supported. Ignoring message.");
......
...@@ -92,8 +92,7 @@ class SyncAppointment extends SyncObject { ...@@ -92,8 +92,7 @@ class SyncAppointment extends SyncObject {
SYNC_POOMCAL_STARTTIME => array ( self::STREAMER_VAR => "starttime", SYNC_POOMCAL_STARTTIME => array ( self::STREAMER_VAR => "starttime",
self::STREAMER_TYPE => self::STREAMER_TYPE_DATE, self::STREAMER_TYPE => self::STREAMER_TYPE_DATE,
self::STREAMER_CHECKS => array( self::STREAMER_CHECK_REQUIRED => self::STREAMER_CHECK_SETZERO, self::STREAMER_CHECKS => array( self::STREAMER_CHECK_CMPLOWER => SYNC_POOMCAL_ENDTIME ),
self::STREAMER_CHECK_CMPLOWER => SYNC_POOMCAL_ENDTIME ),
self::STREAMER_RONOTIFY => true ), self::STREAMER_RONOTIFY => true ),
...@@ -108,8 +107,7 @@ class SyncAppointment extends SyncObject { ...@@ -108,8 +107,7 @@ class SyncAppointment extends SyncObject {
self::STREAMER_RONOTIFY => true), self::STREAMER_RONOTIFY => true),
SYNC_POOMCAL_ENDTIME => array ( self::STREAMER_VAR => "endtime", SYNC_POOMCAL_ENDTIME => array ( self::STREAMER_VAR => "endtime",
self::STREAMER_TYPE => self::STREAMER_TYPE_DATE, self::STREAMER_TYPE => self::STREAMER_TYPE_DATE,
self::STREAMER_CHECKS => array( self::STREAMER_CHECK_REQUIRED => self::STREAMER_CHECK_SETONE, self::STREAMER_CHECKS => array( self::STREAMER_CHECK_CMPHIGHER => SYNC_POOMCAL_STARTTIME ),
self::STREAMER_CHECK_CMPHIGHER => SYNC_POOMCAL_STARTTIME ),
self::STREAMER_RONOTIFY => true ), self::STREAMER_RONOTIFY => true ),
SYNC_POOMCAL_RECURRENCE => array ( self::STREAMER_VAR => "recurrence", SYNC_POOMCAL_RECURRENCE => array ( self::STREAMER_VAR => "recurrence",
...@@ -234,6 +232,41 @@ class SyncAppointment extends SyncObject { ...@@ -234,6 +232,41 @@ class SyncAppointment extends SyncObject {
* @return boolean * @return boolean
*/ */
public function Check($logAsDebug = false) { public function Check($logAsDebug = false) {
// Fix starttime and endtime if they are not set on NEW appointments - see https://jira.z-hub.io/browse/ZP-983
if ($this->flags === SYNC_NEWMESSAGE) {
$time = time();
$calcstart = $time + 1800 - ($time % 1800); // round up to the next half hour
// Check error cases first
// Case 2: starttime not set, endtime in the past
if (!isset($this->starttime) && isset($this->endtime) && $this->endtime < $time) {
ZLog::Write(LOGLEVEL_WARN, "SyncAppointment->Check(): Parameter 'starttime' not set while 'endtime' is in the past (case 2). Aborting.");
return false;
}
// Case 3b: starttime not set, endtime in the future (3) but before the calculated starttime (3b)
elseif (!isset($this->starttime) && isset($this->endtime) && $this->endtime > $time && $this->endtime < $calcstart) {
ZLog::Write(LOGLEVEL_WARN, "SyncAppointment->Check(): Parameter 'starttime' not set while 'endtime' is in the future but before the calculated starttime (case 3b). Aborting.");
return false;
}
// Case 5: starttime in the future but no endtime set
elseif (isset($this->starttime) && $this->starttime > $time && !isset($this->endtime)) {
ZLog::Write(LOGLEVEL_WARN, "SyncAppointment->Check(): Parameter 'starttime' is in the future but 'endtime' is not set (case 5). Aborting.");
return false;
}
// Set starttime to the rounded up next half hour
// Case 1, 3a (endtime won't be changed as it's set)
if (!isset($this->starttime)) {
$this->starttime = $calcstart;
ZLog::Write(LOGLEVEL_WBXML, sprintf("SyncAppointment->Check(): Parameter 'starttime' was not set, setting it to %d (%s).", $this->starttime, gmstrftime("%Y%m%dT%H%M%SZ", $this->starttime)));
}
// Case 1, 4
if (!isset($this->endtime)) {
$this->endtime = $calcstart + 1800; // 30 min after calcstart
ZLog::Write(LOGLEVEL_WBXML, sprintf("SyncAppointment->Check(): Parameter 'endtime' was not set, setting it to %d (%s).", $this->endtime, gmstrftime("%Y%m%dT%H%M%SZ", $this->endtime)));
}
}
$ret = parent::Check($logAsDebug); $ret = parent::Check($logAsDebug);
// semantic checks general "turn off switch" // semantic checks general "turn off switch"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment