Merge branch '2013.10' into 2014.11
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 13 Jul 2015 11:07:18 +0000 (13:07 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 13 Jul 2015 11:07:18 +0000 (13:07 +0200)
Conflicts:
tine20/Calendar/Controller/Event.php

Change-Id: I3a162ebb12ebe5fa544d630f791bf0116a8f72b7

tests/tine20/Calendar/Controller/EventTests.php
tests/tine20/Calendar/Convert/Event/VCalendar/GenericTest.php
tine20/Calendar/Controller/Event.php
tine20/Calendar/Convert/Event/VCalendar/Abstract.php
tine20/Tinebase/WebDav/PrincipalBackend.php

index 941680d..8e31c14 100644 (file)
@@ -1487,4 +1487,19 @@ class Calendar_Controller_EventTests extends Calendar_TestCase
         $ownAttender = Calendar_Model_Attender::getOwnAttender($repairedEvent->attendee);
         $this->assertTrue($ownAttender !== null);
     }
+
+    /**
+     * @see 0011130: handle bad originator timzone in VCALENDAR converter
+     */
+    public function testBrokenTimezoneInEvent()
+    {
+        $event = $this->_getEvent(true);
+        $event->originator_tz = 'AWST';
+        try {
+            $event = $this->_controller->create($event);
+            $this->fail('should throw Tinebase_Exception_Record_Validation because of bad TZ: ' . print_r($event->toArray(), true));
+        } catch (Tinebase_Exception_Record_Validation $terv) {
+            $this->assertEquals('Bad Timezone: AWST', $terv->getMessage());
+        }
+    }
 }
index 5f2ccdc..78dd6c3 100644 (file)
@@ -758,4 +758,22 @@ class Calendar_Convert_Event_VCalendar_GenericTest extends PHPUnit_Framework_Tes
         
         $this->assertEquals('Telko axel', $savedEvent->summary);
     }
+
+    /**
+     * @see 0011130: handle bad originator timzone in VCALENDAR converter
+     */
+    public function testBrokenTimezoneInTineEvent()
+    {
+        $event = $this->testConvertRepeatingAllDayDailyEventToTine20Model();
+        $event->originator_tz = 'AWST'; // Australian Western Standard Time
+
+        $this->_converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
+
+        try {
+            $vevent = $this->_converter->fromTine20Model($event)->serialize();
+            $this->fail('should throw Tinebase_Exception_Record_Validation because of bad TZ');
+        } catch (Tinebase_Exception_Record_Validation $terv) {
+            $this->assertEquals('Bad Timezone: AWST', $terv->getMessage());
+        }
+    }
 }
index c46391d..58153c2 100644 (file)
@@ -1468,10 +1468,11 @@ class Calendar_Controller_Event extends Tinebase_Controller_Record_Abstract impl
     protected function _inspectEvent($_record)
     {
         $_record->uid = $_record->uid ? $_record->uid : Tinebase_Record_Abstract::generateUID();
-        $_record->originator_tz = $_record->originator_tz ? $_record->originator_tz : Tinebase_Core::getUserTimezone();
         $_record->organizer = $_record->organizer ? $_record->organizer : Tinebase_Core::getUser()->contact_id;
         $_record->transp = $_record->transp ? $_record->transp : Calendar_Model_Event::TRANSP_OPAQUE;
-        
+
+        $this->_inspectOriginatorTZ($_record);
+
         if ($_record->hasExternalOrganizer()) {
             // assert calendarUser as attendee. This is important to keep the event in the loop via its displaycontianer(s)
             try {
@@ -1525,6 +1526,23 @@ class Calendar_Controller_Event extends Tinebase_Controller_Record_Abstract impl
             $_record->rrule = NULL;
         }
     }
+
+    /**
+     * checks/sets originator timezone
+     *
+     * @param $record
+     * @throws Tinebase_Exception_Record_Validation
+     */
+    protected function _inspectOriginatorTZ($record)
+    {
+        $record->originator_tz = $record->originator_tz ? $record->originator_tz : Tinebase_Core::getUserTimezone();
+
+        try {
+            new DateTimeZone($record->originator_tz);
+        } catch (Exception $e) {
+            throw new Tinebase_Exception_Record_Validation('Bad Timezone: ' . $record->originator_tz);
+        }
+    }
     
     /**
      * inspects delete action
index 941d655..6cd11f0 100644 (file)
@@ -81,8 +81,13 @@ class Calendar_Convert_Event_VCalendar_Abstract extends Tinebase_Convert_VCalend
         if (empty($originatorTz)) {
             throw new Tinebase_Exception_Record_Validation('originator_tz needed for conversion to Sabre\VObject\Component');
         }
-        
-        $vcalendar->add(new Sabre_VObject_Component_VTimezone($originatorTz));
+
+        try {
+            $vcalendar->add(new Sabre_VObject_Component_VTimezone($originatorTz));
+        } catch (Exception $e) {
+            Tinebase_Exception::log($e);
+            throw new Tinebase_Exception_Record_Validation('Bad Timezone: ' . $originatorTz);
+        }
         
         foreach ($_records as $_record) {
             $this->_convertCalendarModelEvent($vcalendar, $_record);
index 3dc6bf1..a4cdb01 100644 (file)
@@ -347,7 +347,6 @@ class Tinebase_WebDav_PrincipalBackend implements \Sabre\DAVACL\PrincipalBackend
                         
                         return $result;
                     }
-                    
                     $result = array();
                     
                     $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('contactId', $contactId);
@@ -390,9 +389,8 @@ class Tinebase_WebDav_PrincipalBackend implements \Sabre\DAVACL\PrincipalBackend
                             }
                         }
                     }
-                    
                     Tinebase_Cache_PerRequest::getInstance()->save(__CLASS__, __FUNCTION__, $classCacheId, $result);
-                    $cache->save($result, $cacheId, array(), 60);
+                    $cache->save($result, $cacheId, array(), 60 * 3);
                 }
                 
                 break;
@@ -524,8 +522,8 @@ class Tinebase_WebDav_PrincipalBackend implements \Sabre\DAVACL\PrincipalBackend
                     )));
                 }
                 
-                #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(
-                #    __METHOD__ . '::' . __LINE__ . ' path: ' . $prefixPath . ' properties: ' . print_r($filter->toArray(), true));
+                if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ .
+                    ' path: ' . $prefixPath . ' properties: ' . print_r($filter->toArray(), true));
                 
                 $result = Addressbook_Controller_Contact::getInstance()->search($filter, null, false, true);