Exemplo n.º 1
0
 /**
  * Updates an addressbook's properties
  *
  * See \Sabre\DAV\IProperties for a description of the mutations array, as
  * well as the return value.
  *
  * @param mixed $addressbookid
  * @see \Sabre\DAV\IProperties::updateProperties
  * @return bool|array
  */
 public function updateAddressBook($addressbookid, PropPatch $propPatch)
 {
     $changes = array();
     $mutations = $propPatch->getRemainingMutations();
     foreach ($mutations as $property => $newvalue) {
         switch ($property) {
             case '{DAV:}displayname':
                 $changes['displayname'] = $newvalue;
                 break;
             case '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV . '}addressbook-description':
                 $changes['description'] = $newvalue;
                 break;
             default:
                 // If any unsupported values were being updated, we must
                 // let the entire request fail.
                 return false;
         }
     }
     list($id, $backend) = $this->getBackendForAddressBook($addressbookid);
     return $backend->updateAddressBook($id, $changes);
 }
Exemplo n.º 2
0
 /**
  * Updates a calendars properties
  *
  * The properties array uses the propertyName in clark-notation as key,
  * and the array value for the property value. In the case a property
  * should be deleted, the property value will be null.
  *
  * This method must be atomic. If one property cannot be changed, the
  * entire operation must fail.
  *
  * If the operation was successful, true can be returned.
  * If the operation failed, false can be returned.
  *
  * Deletion of a non-existant property is always succesful.
  *
  * Lastly, it is optional to return detailed information about any
  * failures. In this case an array should be returned with the following
  * structure:
  *
  * array(
  *   403 => array(
  *	  '{DAV:}displayname' => null,
  *   ),
  *   424 => array(
  *	  '{DAV:}owner' => null,
  *   )
  * )
  *
  * In this example it was forbidden to update {DAV:}displayname.
  * (403 Forbidden), which in turn also caused {DAV:}owner to fail
  * (424 Failed Dependency) because the request needs to be atomic.
  *
  * @param string $calendarId
  * @param PropPatch $propPatch
  * @return bool|array
  */
 public function updateCalendar($calendarId, PropPatch $propPatch)
 {
     $newValues = array();
     $result = array(200 => array(), 403 => array(), 424 => array());
     $hasError = false;
     $properties = $propPatch->getRemainingMutations();
     foreach ($properties as $propertyName => $propertyValue) {
         // We don't know about this property.
         if (!isset($this->propertyMap[$propertyName])) {
             $hasError = true;
             $result[403][$propertyName] = null;
             unset($properties[$propertyName]);
             continue;
         }
         $fieldName = $this->propertyMap[$propertyName];
         $newValues[$fieldName] = $propertyValue;
     }
     // If there were any errors we need to fail the request
     if ($hasError) {
         // Properties has the remaining properties
         foreach ($properties as $propertyName => $propertyValue) {
             $result[424][$propertyName] = null;
         }
         // Removing unused statuscodes for cleanliness
         foreach ($result as $status => $properties) {
             if (is_array($properties) && count($properties) === 0) {
                 unset($result[$status]);
             }
         }
         return $result;
     }
     // Success
     if (!isset($newValues['displayname'])) {
         $newValues['displayname'] = null;
     }
     if (!isset($newValues['timezone'])) {
         $newValues['timezone'] = null;
     }
     if (!isset($newValues['calendarorder'])) {
         $newValues['calendarorder'] = null;
     }
     if (!isset($newValues['calendarcolor'])) {
         $newValues['calendarcolor'] = null;
     }
     if (!is_null($newValues['calendarcolor']) && strlen($newValues['calendarcolor']) == 9) {
         $newValues['calendarcolor'] = substr($newValues['calendarcolor'], 0, 7);
     }
     OC_Calendar_Calendar::editCalendar($calendarId, $newValues['displayname'], null, $newValues['timezone'], $newValues['calendarorder'], $newValues['calendarcolor']);
     return true;
 }