/**
  * @param integer $action
  * @throws Exception
  */
 protected function checkCalendarSupports($action)
 {
     if (!$this->calendar->doesAllow($action)) {
         switch ($action) {
             case Permissions::CREATE:
                 throw new Exception('Calendar does not allow creating objects');
                 break;
             case Permissions::UPDATE:
                 throw new Exception('Calendar does not allow updating objects');
                 break;
             case Permissions::DELETE:
                 throw new Exception('Calendar does not allow deleting objects');
                 break;
             default:
                 throw new Exception('Calendar does not support wanted action');
                 break;
         }
     }
 }
 public function testTouch()
 {
     $this->calendar->setCtag(41);
     $this->calendar->touch();
     $this->assertSame($this->calendar->getCtag(), 42);
 }
 /**
  * @param mixed $data
  * @param int $format
  * @return \OCA\Calendar\Db\Calendar
  * @throws CorruptDataException
  * @throws TemporarilyNotAvailableException
  * @throws \InvalidArgumentException
  */
 public function createEntity($data, $format = self::FORMAT_PARAM)
 {
     if (!is_array($data) || empty($data)) {
         throw new CorruptDataException('CalendarFactory::createEntity() - Calendardata is empty');
     }
     if (isset($data['backend'])) {
         if ($data['backend'] instanceof IBackend) {
             if (!$this->backends->inCollection($data['backend'])) {
                 unset($data['backend']);
             }
         } else {
             $backend = $this->backends->find($data['backend']);
             if (!$backend instanceof IBackend) {
                 throw new TemporarilyNotAvailableException('CalendarFactory::createEntity() - Calendardata references unknown backend');
             }
             //replace backend-identifier with IBackend instance
             $data['backend'] = $backend;
         }
     }
     //replace timezone-identifier with ITimezone instance
     if (isset($data['timezone']) && isset($data['user_id'])) {
         try {
             $timezone = $this->timezones->find($data['timezone'], $data['user_id']);
             $row['timezone'] = $timezone;
         } catch (DoesNotExistException $ex) {
             unset($data['timezone']);
         }
     }
     //TODO - fix me
     unset($data['last_properties_update']);
     unset($data['last_object_update']);
     switch ($format) {
         case self::FORMAT_PARAM:
             return Calendar::fromParams($data);
             break;
         case self::FORMAT_ROW:
             return Calendar::fromRow($data);
             break;
         default:
             throw new \InvalidArgumentException('CalendarFactory::createEntity() - Unknown format given');
             break;
     }
 }