/**
  * Creates new objects from import
  *
  * @param \OCA\Calendar\IObjectCollection $collection
  * @throws \OCA\Calendar\BusinessLayer\Exception
  * @return \OCA\Calendar\IObjectCollection
  */
 public function createCollection(IObjectCollection $collection)
 {
     $className = get_class($collection);
     /** @var IObjectCollection $createdObjects */
     $createdObjects = new $className();
     $this->checkCalendarSupports(Permissions::CREATE);
     if (!$this->api instanceof BackendUtils\IObjectAPICreate) {
         throw new Exception('Backend does not support creating objects');
     }
     foreach ($collection as $object) {
         try {
             if ($object->getUri() === null) {
                 $randomURI = ObjectUtility::randomURI();
                 $object->setUri($randomURI);
             }
             $object->setCalendar($this->calendar);
             $object->getEtag(true);
             $this->checkObjectIsValid($object);
             Util::emitHook('\\OCA\\Calendar', 'preCreateObject', array($object));
             $object = $this->api->create($object);
             Util::emitHook('\\OCA\\Calendar', 'postCreateObject', array($object));
             $createdObjects[] = $object;
         } catch (BackendUtils\Exception $ex) {
             $this->logger->debug($ex->getMessage());
         } catch (Exception $ex) {
             $this->logger->debug($ex->getMessage());
         } catch (CorruptDataException $ex) {
             $this->logger->debug($ex->getMessage());
         }
     }
     if ($this->isCachingEnabled) {
         $this->calendar->checkUpdate();
     }
     return $createdObjects;
 }
 /**
  * Creates an new object
  *
  * @param \OCA\Calendar\IObject $object
  * @throws \OCA\Calendar\BusinessLayer\Exception
  * @return \OCA\Calendar\IObject
  */
 public function create(IObject $object)
 {
     try {
         if (is_null($object->getUri())) {
             $object->setUri(ObjectUtility::randomURI());
         }
         $object->setCalendar($this->calendar);
         // generate an provisional etag, backends can overwrite it if necessary
         $object->getEtag(true);
         $this->checkCalendarSupports(Permissions::CREATE);
         if (!$this->api instanceof BackendUtils\IObjectAPICreate) {
             throw new Exception('Backend does not support creating objects');
         }
         $this->checkObjectIsValid($object);
         Util::emitHook('\\OCA\\Calendar', 'preCreateObject', array($object));
         $object = $this->api->create($object);
         if ($this->isCachingEnabled) {
             $this->updater->propagate($object->getUri());
         }
         Util::emitHook('\\OCA\\Calendar', 'postCreateObject', array($object));
         return $object;
     } catch (BackendUtils\Exception $ex) {
         throw Exception::fromException($ex);
     }
 }
Example #3
0
 /**
  * get UTC date for database
  * @param \DateTime $datetime
  * @return string
  */
 private function getUTCforMDB(\DateTime $datetime)
 {
     return ObjectUtility::getUTCforMDB($datetime);
 }