コード例 #1
0
 protected function _persist(PersistentAbstract $object)
 {
     $object->userId = \App::getUserLogged()->id;
     $this->getCache()->clean(array('list'));
     $this->getCache()->remove($object->getId());
     if ($object->getId() != null) {
         $data = $object->exportData();
         if ($data) {
             if ($this->_timestamps) {
                 $data['modified'] = time();
             }
             $data = $this->_mapModelToMongoModel($data);
             try {
                 $result = $this->getCollection()->update(array("configId" => $object->id) + $this->_defaultFilter, array('$set' => $data), $this->_updateOptions);
             } catch (\Exception $e) {
                 throw new MongoException($e->getMessage());
             }
             if ($result['n'] == 1) {
                 return $object->getId();
             }
             throw new NotFoundException(get_class($this) . ': Object not found');
         }
     }
     throw new InvalidArgumentException(get_class($this) . ': Object ID not defined.');
 }
コード例 #2
0
 public static function createModelActionEvent($action, PersistentAbstract $model)
 {
     $eventData = array('action' => $action);
     try {
         if (\App::getUserLogged() && \App::getUserLogged()->id) {
             $eventData['userId'] = \App::getUserLogged()->id;
         }
     } catch (\Exception $e) {
     }
     $event = new EventModel();
     $event->namespace = 'connectivity';
     $event->entityType = $model->getResourceId();
     $event->entityId = $model->id;
     $event->action = $action;
     $event->eventData = $eventData;
     $event->pushEventData = true;
     $event->hiddenData = array('model' => $model->exportData());
     return $event;
 }
コード例 #3
0
 /**
  * @param  PersistentAbstract       $object
  * @throws NotFoundException
  * @throws InvalidArgumentException
  * @return string
  */
 public function update(PersistentAbstract $object)
 {
     if ($object->getId() != null) {
         try {
             $data = $object->exportData();
             if ($data) {
                 if ($this->_timestamps) {
                     $data['modified'] = time();
                 }
                 $data = $this->_mapModelToMongoModel($data);
                 try {
                     $result = $this->getCollection()->update(array('_id' => $object->getId()) + $this->_defaultFilter, array('$set' => $data));
                 } catch (\Exception $e) {
                     throw new MongoException($e->getMessage());
                 }
                 if ($result['n'] == 1) {
                     $this->_delete_cache($object->id);
                     return $object->getId();
                 }
                 throw new NotFoundException(get_class($this) . ': Object not found');
             }
         } catch (\Exception $e) {
             $this->_delete_cache($object->id);
             throw $e;
         }
     }
     throw new InvalidArgumentException(get_class($this) . ': Object ID not defined.');
 }
コード例 #4
0
 public function exportData()
 {
     $data = parent::exportData();
     unset($data['path']);
     return $data;
 }
コード例 #5
0
 /**
  *
  * @return array
  */
 public function exportData()
 {
     $data = parent::exportData();
     $data['type'] = static::ORG_TYPE;
     return $data;
 }