src/Contao/View/Contao2BackendView/ActionHandler/EditHandler.php
private function checkRestoreVersion(EnvironmentInterface $environment, ModelId $modelId)
    {
        $inputProvider = $environment->getInputProvider();

        $dataProviderDefinition = $environment->getDataDefinition()->getDataProviderDefinition();
        $dataProvider           = $environment->getDataProvider($modelId->getDataProviderName());

        if (!((null !== ($modelVersion = $inputProvider->getValue('version')))
            && ('tl_version' === $inputProvider->getValue('FORM_SUBMIT'))
            && $dataProviderDefinition->getInformation($modelId->getDataProviderName())->isVersioningEnabled())
        ) {
            return;
        }

        if (null === ($model = $dataProvider->getVersion($modelId->getId(), $modelVersion))) {
            $message = \sprintf(
                'Could not load version %s of record ID %s from %s',
                $modelVersion,
                $modelId->getId(),
                $modelId->getDataProviderName()
            );

            $environment->getEventDispatcher()->dispatch(
                ContaoEvents::SYSTEM_LOG,
                new LogEvent($message, TL_ERROR, 'DC_General - checkRestoreVersion()')
            );

            throw new DcGeneralRuntimeException($message);
        }

        $dataProvider->save($model);
        $dataProvider->setVersionActive($modelId->getId(), $modelVersion);
        $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_RELOAD, new ReloadEvent());
    }
private function checkRestoreVersion(EnvironmentInterface $environment, ModelId $modelId)
    {
        $inputProvider = $environment->getInputProvider();

        $dataProviderDefinition = $environment->getDataDefinition()->getDataProviderDefinition();
        $dataProvider           = $environment->getDataProvider($modelId->getDataProviderName());

        if (!((null !== ($modelVersion = $inputProvider->getValue('version')))
            && ('tl_version' === $inputProvider->getValue('FORM_SUBMIT'))
            && $dataProviderDefinition->getInformation($modelId->getDataProviderName())->isVersioningEnabled())
        ) {
            return;
        }

        if (null === ($model = $dataProvider->getVersion($modelId->getId(), $modelVersion))) {
            $message = \sprintf(
                'Could not load version %s of record ID %s from %s',
                $modelVersion,
                $modelId->getId(),
                $modelId->getDataProviderName()
            );

            $environment->getEventDispatcher()->dispatch(
                ContaoEvents::SYSTEM_LOG,
                new LogEvent($message, TL_ERROR, 'DC_General - checkRestoreVersion()')
            );

            throw new DcGeneralRuntimeException($message);
        }

        $dataProvider->save($model);
        $dataProvider->setVersionActive($modelId->getId(), $modelVersion);
        $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_RELOAD, new ReloadEvent());
    }
private function checkRestoreVersion ( EnvironmentInterface $ environment , ModelId $ modelId ) { $ inputProvider = $ environment -> getInputProvider ( ) ; $ dataProviderDefinition = $ environment -> getDataDefinition ( ) -> getDataProviderDefinition ( ) ; $ dataProvider = $ environment -> getDataProvider ( $ modelId -> getDataProviderName ( ) ) ; if ( ! ( ( null !== ( $ modelVersion = $ inputProvider -> getValue ( 'version' ) ) ) && ( 'tl_version' === $ inputProvider -> getValue ( 'FORM_SUBMIT' ) ) && $ dataProviderDefinition -> getInformation ( $ modelId -> getDataProviderName ( ) ) -> isVersioningEnabled ( ) ) ) { return ; } if ( null === ( $ model = $ dataProvider -> getVersion ( $ modelId -> getId ( ) , $ modelVersion ) ) ) { $ message = \ sprintf ( 'Could not load version %s of record ID %s from %s' , $ modelVersion , $ modelId -> getId ( ) , $ modelId -> getDataProviderName ( ) ) ; $ environment -> getEventDispatcher ( ) -> dispatch ( ContaoEvents :: SYSTEM_LOG , new LogEvent ( $ message , TL_ERROR , 'DC_General - checkRestoreVersion()' ) ) ; throw new DcGeneralRuntimeException ( $ message ) ; } $ dataProvider -> save ( $ model ) ; $ dataProvider -> setVersionActive ( $ modelId -> getId ( ) , $ modelVersion ) ; $ environment -> getEventDispatcher ( ) -> dispatch ( ContaoEvents :: CONTROLLER_RELOAD , new ReloadEvent ( ) ) ; }
Check the submitted data if we want to restore a previous version of a model.

If so, the model will get loaded and marked as active version in the data provider and the client will perform a
reload of the page.

@param EnvironmentInterface $environment The environment.
@param ModelId              $modelId     The model id.

@return void

@throws DcGeneralRuntimeException When the requested version could not be located in the database.

@SuppressWarnings(PHPMD.LongVariable)
Check the submitted data if we want to restore a previous version of a model .