Merge branch '2013.03'
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 14 May 2013 12:52:47 +0000 (14:52 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 14 May 2013 12:52:47 +0000 (14:52 +0200)
1  2 
tine20/Calendar/Convert/Event/VCalendar/Abstract.php
tine20/Setup/Controller.php

@@@ -6,7 -6,7 +6,7 @@@
   * @subpackage  Frontend
   * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
   * @author      Lars Kneschke <l.kneschke@metaways.de>
-  * @copyright   Copyright (c) 2011-2012 Metaways Infosystems GmbH (http://www.metaways.de)
+  * @copyright   Copyright (c) 2011-2013 Metaways Infosystems GmbH (http://www.metaways.de)
   *
   */
  
@@@ -45,15 -45,15 +45,15 @@@ class Calendar_Convert_Event_VCalendar_
      }
      
      /**
 -     * convert Calendar_Model_Event to Sabre_VObject_Component
 +     * convert Tinebase_Record_RecordSet to Sabre_VObject_Component
       *
 -     * @param  Calendar_Model_Event  $_record
 +     * @param  Tinebase_Record_RecordSet  $_records
       * @return Sabre_VObject_Component
       */
 -    public function fromTine20Model(Tinebase_Record_Abstract $_record)
 +    public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records)
      {
          if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ 
 -            . ' event ' . print_r($_record->toArray(), true));
 +            . ' Events: ' . print_r($_records->toArray(), true));
          
          $vcalendar = new Sabre_VObject_Component('VCALENDAR');
          
          $vcalendar->VERSION  = '2.0';
          $vcalendar->CALSCALE = 'GREGORIAN';
          
 -        $vcalendar->add(new Sabre_VObject_Component_VTimezone($_record->originator_tz));
 -        
 -        $vevent = $this->_convertCalendarModelEvent($_record);
 -        $vcalendar->add($vevent);
 +        $vcalendar->add(new Sabre_VObject_Component_VTimezone($_records->getFirstRecord()->originator_tz));
          
 -        if ($_record->exdate instanceof Tinebase_Record_RecordSet) {
 -            $_record->exdate->addIndices(array('is_deleted'));
 -            $eventExceptions = $_record->exdate->filter('is_deleted', false);
 +        foreach ($_records as $_record) {
 +            $vevent = $this->_convertCalendarModelEvent($_record);
 +            $vcalendar->add($vevent);
              
 -            foreach ($eventExceptions as $eventException) {
 -                $vevent = $this->_convertCalendarModelEvent($eventException, $_record);
 -                $vcalendar->add($vevent);
 +            if ($_record->exdate instanceof Tinebase_Record_RecordSet) {
 +                $_record->exdate->addIndices(array('is_deleted'));
 +                $eventExceptions = $_record->exdate->filter('is_deleted', false);
 +                
 +                foreach ($eventExceptions as $eventException) {
 +                    $vevent = $this->_convertCalendarModelEvent($eventException, $_record);
 +                    $vcalendar->add($vevent);
 +                }
 +                
              }
 -            
          }
          
          $this->_afterFromTine20Model($vcalendar);
          
          return $vcalendar;
      }
 +
 +    /**
 +     * convert Calendar_Model_Event to Sabre_VObject_Component
 +     *
 +     * @param  Calendar_Model_Event  $_record
 +     * @return Sabre_VObject_Component
 +     */
 +    public function fromTine20Model(Tinebase_Record_Abstract $_record)
 +    {
 +        $_records = new Tinebase_Record_RecordSet(get_class($_record), array($_record), true, false);
 +        return $this->fromTine20RecordSet($_records);
 +    }
      
      /**
       * convert calendar event to Sabre_VObject_Component
              throw new Tinebase_Exception_UnexpectedValue('no main VEVENT component found in VCALENDAR');
          }
          
-         // parse the event exceptions
+         // TODO only do this for events with rrule?
+         // if (! empty($event->rrule)) {
+         
+         $this->_parseEventExceptions($event, $vcalendar);
+         $event->isValid(true);
+         
+         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' data ' . print_r($event->toArray(), true));
+         
+         return $event;
+     }
+     
+     /**
+      * parse event exceptions and add them to tine event record
+      * 
+      * @param Calendar_Model_Event $event
+      * @param Sabre_VObject_Component $vcalendar
+      */
+     protected function _parseEventExceptions($event, $vcalendar)
+     {
          $oldExdates = $event->exdate instanceof Tinebase_Record_RecordSet ? $event->exdate->filter('is_deleted', false) : new Tinebase_Record_RecordSet('Calendar_Model_Event');
          foreach ($vcalendar->VEVENT as $vevent) {
              if (isset($vevent->{'RECURRENCE-ID'}) && $event->uid == $vevent->UID) {
                  $event->exdate->addRecord($recurException);
              }
          }
+     }
+     
+     /**
+      * converts vcalendar to Tinebase_Record_RecordSet of Calendar_Model_Event
+      * 
+      * @param  mixed                 $_blob   the vcalendar to parse
+      * @return Tinebase_Record_RecordSet
+      */
+     public function toTine20RecordSet($_blob)
+     {
+         $vcalendar = self::getVcal($_blob);
          
-         $event->isValid(true);
+         $result = new Tinebase_Record_RecordSet('Calendar_Model_Event');
          
-         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' data ' . print_r($event->toArray(), true));
+         foreach ($vcalendar->VEVENT as $vevent) {
+             if (! isset($vevent->{'RECURRENCE-ID'})) {
+                 $event = new Calendar_Model_Event();
+                 $this->_convertVevent($vevent, $event);
+                 if (! empty($event->rrule)) {
+                     $this->_parseEventExceptions($event, $vcalendar);
+                 }
+                 $result->addRecord($event);
+             }
+         }
          
-         return $event;
+         return $result;
      }
      
      /**
       */
      public static function readVCalBlob($blob, $failcount = 0, $spacecount = 0, $lastBrokenLineNumber = 0, $lastLines = array())
      {
+         // convert to utf-8
+         $blob = mbConvertTo($blob);
+         
          if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ .
              ' ' . $blob);
          
@@@ -892,7 -892,6 +892,7 @@@ class Setup_Controlle
              'accounts'          => $this->_getAccountsStorageData(),
              'redirectSettings'  => $this->_getRedirectSettings(),
              'password'          => $this->_getPasswordSettings(),
 +            'saveusername'      => $this->_getReuseUsernameSettings()
          );
      }
      
              $this->_updatePasswordSettings($_authenticationData['password']);
          }
          
 +        if (isset($_authenticationData['saveusername'])) {
 +            $this->_updateReuseUsername($_authenticationData['saveusername']);
 +        }
 +        
          if (isset($_authenticationData['acceptedTermsVersion'])) {
              $this->saveAcceptedTerms($_authenticationData['acceptedTermsVersion']);
          }
              }
          }
      }
 +
 +        /**
 +     * update pw settings
 +     * 
 +     * @param array $data
 +     */
 +    protected function _updatePasswordSettings($data)
 +    {
 +        foreach ($data as $config => $value) {
 +            Tinebase_Config::getInstance()->set($config, $value);
 +        }
 +    }
      
      /**
       * update pw settings
       * 
       * @param array $data
       */
 -    protected function _updatePasswordSettings($data)
 +    protected function _updateReuseUsername($data)
      {
          foreach ($data as $config => $value) {
              Tinebase_Config::getInstance()->set($config, $value);
      }
      
      /**
 +     * get Reuse Username to login textbox
 +     * 
 +     * @return array
 +     * 
 +     * @todo should use generic mechanism to fetch setup related configs
 +     */
 +    protected function _getReuseUsernameSettings()
 +    {
 +        $configs = array(
 +            Tinebase_Config::REUSEUSERNAME_SAVEUSERNAME         => 0,
 +        );
 +
 +        $result = array();
 +        $tinebaseInstalled = $this->isInstalled('Tinebase');
 +        foreach ($configs as $config => $default) {
 +            $result[$config] = ($tinebaseInstalled) ? Tinebase_Config::getInstance()->get($config, $default) : $default;
 +        }
 +        
 +        return $result;
 +    }
 +    
 +    /**
       * get email config
       *
       * @return array
          
          foreach ($this->_emailConfigKeys as $configName => $configKey) {
              if (array_key_exists($configName, $_data)) {
-                 Tinebase_Config::getInstance()->set($configKey, $_data[$configName]);
+                 // fetch current config first and preserve all values that aren't in $_data array
+                 $currentConfig = Tinebase_Config::getInstance()->get($configKey, new Tinebase_Config_Struct(array()))->toArray();
+                 $newConfig = array_merge($_data[$configName], array_diff_key($currentConfig, $_data[$configName]));
+                 Tinebase_Config::getInstance()->set($configKey, $newConfig);
              }
          }
      }