Update oids after create
@param $event
178508
public function afterCreate(PersistenceEvent $event) {
    if ($event->getAction() == PersistenceAction::CREATE) {
      $oldOid = $event->getOldOid();
      $oldOidStr = $oldOid != null ? $oldOid->__toString() : null;
      if ($oldOidStr != null && isset($this->createdTranslations[$oldOidStr])) {
        foreach ($this->createdTranslations[$oldOidStr] as $translation) {
          $translation->setValue('objectid', $event->getObject()->getOID()->__toString());
        }
      }
    }
  }
418919
public function afterSave($event)
    {
        if (!$event->getSubject()->success) {
            return false;
        }

        // `created` will be set for add actions, `id` for edit actions
        if (!$event->getSubject()->created && !$event->getSubject()->id) {
            return false;
        }

        // The `add`action (new Resource) MUST respond with HTTP Status Code 201,
        // see http://jsonapi.org/format/#crud-creating-responses-201
        if ($event->getSubject()->created) {
            $this->_controller()->response = $this->_controller()->response->withStatus(201);
        }

        $this->_insertBelongsToDataIntoEventFindResult($event);

        /** @var \Crud\Event\Subject $subject */
        $subject = $event->getSubject();
        $this->render($subject);
    }
1318203
public function onPostBind($event)
    {
        $form = $event->getForm();

        if ( ! $form->isRoot()) return;

        $clientData = $event->getForm()->getData();

        if ( ! is_object($clientData)) return;

        $this->filterService->filterEntity($clientData);

    }
268391
public static function onPostLoad(Event $event)
    {
        $revision = $event->getTarget();
        $dispatcher = $event->getDispatcher();
        $application = $dispatcher->getApplication();

        if (null !== $application) {
            $em = $application->getEntityManager();
            $revision
                ->setEntityManager($em)
                ->setToken($application->getBBUserToken())
            ;

            if (null === $revision->getContent()) {
                $db = $em->getConnection();
                $stmt = $db->executeQuery(
                    'SELECT `content_uid`, `classname` FROM `revision` WHERE `uid` = ?',
                    [$revision->getUid()]
                );

                $items = $stmt->fetchAll();
                if ($items) {
                    foreach ($items as $item) {
                        $content = $em->find(Revision::getFullClassname($item['classname']), $item['content_uid']);
                        if ($content) {
                            $revision->setContent($content);
                        }
                    }
                }
            }
        }

        $revision->postLoad();
    }
513289
public function preCreate(CreateEvent $event)
    {
        /** @var Group $role */
        $object = $event->getObject();
        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof User) {
            $object->setUser($user);
        } else {
            $object->setUser($this->userManager->getDefaultClarolineUser());
        }
    }
632171
public static function updateLastVisit($event)
    {
        if ($event->isValid) {
            /**
             * @var User $user
             */
            $user = $event->identity;
            $user->last_visit_at = time();
            $user->updateAttributes(['last_visit_at']);
            return true;
        }
        return false;
    }
809999
public function onPreCreate(OrderEvent $event)
    {
        if ($this->isOrderLocked($event)) {
            return;
        }

        $order = $event->getOrder();

        // Only for orders and quotes
        if (!in_array($order->getType(), [OrderTypes::TYPE_ORDER, OrderTypes::TYPE_QUOTE])) {
            return;
        }

        // Generate number and key
        $this->generateNumberAndKey($order);

        // Handle identity
        $this->handleIdentity($order);

        // Handle addresses
        $this->handleAddresses($order);
    }
868480
protected function update(Event $event)
    {
        $this->dispatch(static::EVENT_UPDATE_BEFORE, $event);
        if (!$event->isPropagationStopped()) {
            $this->updateProcess($event);
            if (!$event->isPropagationStopped()) {
                $this->dispatch(static::EVENT_UPDATE_AFTER, $event);
            }
        }
    }
792035
public function afterSave(Save $event)
    {
        /** @var Entity $entity */
        $entity = $event->getTarget();
        $entity->loadRelations = false;
        $prop = $this->getPropertyName();
        $relPrk = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getPrimaryKey();
        $entPrk = $entity->getPrimaryKey();
        
        if (isset($entity->$prop) && is_array($entity->$prop)) {
            $this->beforeDelete(new Delete(['primaryKey' => $entity->$entPrk]));
            foreach ($entity->$prop as $object) {
                $relVal = $object;
                if ($object instanceof Entity) {
                    $relVal = $object->$relPrk;
                }

                Sql::createSql($entity->getAdapter())
                    ->insert($this->getRelationTable())
                    ->set(
                        [
                            $this->getForeignKey() => $entity->$entPrk,
                            $this->getRelatedForeignKey() => $relVal
                        ]
                    )
                    ->execute();
            }
        }
        $entity->loadRelations = true;
    }
1166423
public function operation($event){
        if ($event->name == UploadImg::EVENT_AFTER_VALIDATE
            && empty($this->owner->imageFile)){
            return;
        }
        if(!$this->createTool()){
            return;
        }
        if(
            $this->owner->isthumb&&
            $this->operate==self::IMG_THUMB){
            $this->thumbImg();
        }
        if(
            $this->owner->iswater&&
            $this->operate==self::IMG_WATER){
            $this->waterImg();
        }
    }
504458
public function preCreate(CreateEvent $event)
    {
        $badge = $event->getObject();

        if ($badge->getWorkspace()) {
            $badge->setEnabled($this->parametersSerializer->serialize()['badges']['enable_default']);
        }
    }
1148441
public function afterFind($event)
    {
        foreach ($this->attributes as $attribute) {
            $this->owner->{$attribute} = $this->htmlEncode($this->owner->{$attribute});
        }
    }
1068991
public function save(IEvent $event)
    {
        if (null !== $event->getId()) {
            return $event;
        }

        $event->setId((string)Uuid::uuid4());

        $this->events[] = $event;

        return $event;
    }
453667
public function beforeApiRequestSend($event)
    {
        $request = $event->request;
        $data = $request->getData();
        $data['openid'] = $this->getOpenid();
        $request->setData($data);

        parent::beforeApiRequestSend($event);
    }
1206219
public function onPostAutoloadDump(Event $event)
    {
        $this->io->writeError('<info>Remove update lock tmp file: ' . $this->getUpdateLockFile() . '</info>');
        if (file_exists($this->getUpdateLockFile())) {
            if (!unlink($this->getUpdateLockFile())) {
                $this->io->writeError("<error>Not removed lock file: " . $this->getUpdateLockFile() . "</error>");
            }
        } else {
            $this->io->writeError("<warning>Not found lock file: " . $this->getUpdateLockFile() . "</warning>");
        }
    }
1268283
public function preCreate(CreateEvent $event)
    {
        /** @var Role $role */
        $role = $event->getObject();

        if (!$role->getWorkspace()) {
            $role->setName(strtoupper('role_'.$role->getTranslationKey()));
        }
    }
594693
public function afterCommit(TransactionEvent $event) {
    if ($this->liveUpdate && $event->getPhase() == TransactionEvent::AFTER_COMMIT) {
      $persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
      // add inserted/updated objects
      foreach (array_merge(array_values($event->getInsertedOids()), $event->getUpdatedOids()) as $oid) {
        $object = $persistenceFacade->load(ObjectId::parse($oid));
        if ($object) {
          $this->addToIndex($object);
        }
        else {
          self::$logger->warn("Could not index object with oid ".$oid." because it does not exist");
        }
      }
      // remove deleted objects
      foreach ($event->getDeletedOids() as $oid) {
        $this->deleteFromIndex(ObjectId::parse($oid));
      }
    }
  }