Check for missing persist options.

@param PersistEvent $event
775562
public function checkOptions(PersistEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticlePageDocument) {
            return;
        }

        $autoRename = $event->getOption('auto_rename');

        if (false !== $autoRename) {
            throw new \InvalidArgumentException('Persist "ArticlePageDocument" only with option "auto_rename" set to "false" allowed');
        }
    }
818493
protected function persistResource(ResourceEvent $event)
    {
        $resource = $event->getResource();

        // TODO Validation ?

        try {
            $this->manager->persist($resource);
            $this->manager->flush();
        } catch(DBALException $e) {
            if ($this->debug) {
                throw $e;
            }
            $event->addMessage(new ResourceMessage(
                'ekyna_admin.resource.message.persist.failure',
                ResourceMessage::TYPE_ERROR
            ));
            return $event;
        }

        return $event->addMessage(new ResourceMessage(
            'ekyna_admin.resource.message.persist.success',
            ResourceMessage::TYPE_SUCCESS
        ));
    }
447946
public function checkIncrementalDate(ConstraintEventFormat $event)
    {
        $schema = $event->getSchema();

        if (!isset($schema->{'x-constraints'}) ||
            (is_array($schema->{'x-constraints'}) && !in_array('incrementalDate', $schema->{'x-constraints'}))
        ) {
            return;
        }

        // get the current record
        $path = $this->utils->getNormalizedPathFromPointer($event->getPath());
        $currentRecord = $this->utils->getCurrentEntity([$path]);

        if (is_null($currentRecord)) {
            return;
        }

        $data = $event->getElement();

        // get the current value in database
        $accessor = PropertyAccess::createPropertyAccessor();

        if (!$accessor->isReadable($currentRecord, $path)) {
            // value is not saved in db..
            return;
        }

        $storedValue = $accessor->getValue($currentRecord, $path);
        $storedDate = Rfc3339::createFromString($storedValue);
        $userDate = Rfc3339::createFromString($data);

        if ($userDate <= $storedDate) {
            $event->addError(
                sprintf('The date must be greater than the saved date %s', $storedValue)
            );
        }
    }
480851
public function handleScheduleRename(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (!$event->getOption('auto_name')
            || !$document instanceof AutoNameBehavior
            || $event->getOption('auto_name_locale') !== $event->getLocale()
            || !$event->hasNode()
            || $event->getNode()->isNew()
        ) {
            return;
        }

        $node = $event->getNode();
        $name = $this->getName($document, $event->getParentNode(), $event->getOption('auto_rename'), $node);

        if ($name === $node->getName()) {
            return;
        }

        $uuid = $event->getNode()->getIdentifier();
        $this->scheduledRename[] = ['uuid' => $uuid, 'name' => $name, 'locale' => $event->getLocale()];
    }
1308941
public function persistData()
    {
        // we sort the array first, useful for doing ris match
        if (!empty($this->userAgentsWithDeviceID)) {
            ksort($this->userAgentsWithDeviceID);
            $this->persistenceProvider->save($this->getPrefix(), $this->userAgentsWithDeviceID);
        }
    }
586225
private function validatePersisters(array $persisters)
    {
        foreach ($persisters as $name => $config) {
            $this->validateTypeAndService($config, sprintf('as3_modlr.persisters.%s', $name));
            switch ($config['type']) {
                case 'mongodb':
                    $this->validateLibClassExists('Persister\MongoDb\Persister', sprintf('as3_modlr.persisters.%s.type', $name));
                    $this->validatePersisterMongoDb($config);
                    break;
                default:
                    break;
            }
        }
    }
582804
public function postCreate(CreateEvent $event)
    {
        if (in_array(Options::USER_SELF_LOG, $event->getOptions())) {
            $this->userManager->logUser($event->getObject());
        }
    }
81418
public function canTrigger(Event $event)
    {
        $if = $this->_evaluateCondition('if', $event);
        $unless = $this->_evaluateCondition('unless', $event);

        return $if && !$unless;
    }
1051555
public function checkPermissionIsDeletable(BuildDataDefinitionEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        $container = $event->getContainer();

        if ($container->getBasicDefinition()->isDeletable()) {
            return;
        }

        $view          = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
        $modelCommands = $view->getModelCommands();

        $this->disableCommandByActionName($modelCommands, 'delete');
    }
398468
public function beforeSave(Save $event)
    {
        $entity = $event->getTarget();
        $property = $this->getPropertyName();
        $field = $this->getForeignKey();
        $data = $event->data;
        if (isset($entity->$property) && !is_null($entity->$property)) {
            /** @var Entity $object */
            $object = $entity->$property;
            $data[$field] = $object;
            $class = $this->getRelatedEntity();
            if ($object instanceof $class) {
                $pmk = $object->getPrimaryKey();
                $data[$field] = $object->$pmk;
            }
            $event->data = $data;
        }
    }
1102936
private function shouldPersistMessage(PersistentMessage $message): bool
    {
        return ($message instanceof Command && $this->persistCommands) ||
        ($message instanceof Event && $this->persistEvents);
    }
1363143
public function onRestore(RestoreEvent $event)
    {
        $plugin = $this->pluginRegistry->getPlugin($event->getOption('plugin'));

        $optionsResolver = new OptionsResolver();
        $plugin->configureOptionsResolver($optionsResolver);
        $parameter = $optionsResolver->resolve($event->getOption('parameter'));

        try {
            $plugin->restore($event->getSource(), $event->getDestination(), $event->getDatabase(), $parameter);
            $event->setStatus(BackupStatus::STATE_SUCCESS);
        } catch (\Exception $exception) {
            $event->setStatus(BackupStatus::STATE_FAILED);
            $event->setException($exception);
        }
    }
590866
public function attachPersistor(PersistorInterface $persistor, $key = '')
    {
        if (empty($key)) {
            $this->persistors[] = $persistor;
        } else {
            $this->persistors[$key] = $persistor;
        }
    }
891623
public function onPointsCollected(AbstractInfluxDbEvent $event): bool
    {
        if (!$this->isConcerned($event)) {
            return false;
        }

        $this->testUdpConnection($event);

        if ($event instanceof AbstractDeferredInfluxDbEvent) {
            $this->addEventPointsToStorage($event);

            return true;
        }

        $this->writeEventPoints($event);

        return true;
    }
924971
public function handlePersist(PersistEvent $event)
    {
        /** @var SecurityBehavior $document */
        $document = $event->getDocument();

        if (!$this->supports($document) || !$document->getPermissions()) {
            return;
        }

        $node = $event->getNode();

        foreach ($document->getPermissions() as $roleId => $permission) {
            // TODO use PropertyEncoder, once it is refactored
            $node->setProperty('sec:role-' . $roleId, $this->getAllowedPermissions($permission));
        }
    }
580156
public function handlePersistUpdateUrl(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (!$document instanceof ShadowLocaleBehavior) {
            return;
        }

        if (!$document->isShadowLocaleEnabled()) {
            return;
        }

        $node = $event->getNode();
        $structure = $this->inspector->getStructureMetadata($document);

        if (false === $structure->hasPropertyWithTagName('sulu.rlp')) {
            return;
        }

        $locatorProperty = $structure->getPropertyByTagName('sulu.rlp');

        if ($node->getPropertyValueWithDefault(
            $this->encoder->localizedSystemName(
                $locatorProperty->getName(), $document->getLocale()
            ),
            null
        )) {
            return;
        }

        $shadowLocator = $node->getPropertyValueWithDefault(
            $this->encoder->localizedSystemName(
                $locatorProperty->getName(), $document->getShadowLocale()
            ),
            null
        );

        if (!$shadowLocator) {
            return;
        }

        $event->getAccessor()->set(
          'resourceSegment',
          $shadowLocator
        );
    }
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());
        }
      }
    }
  }