Handle the action.

@param EnvironmentInterface $environment The environment.

@return string|null
489147
protected function process(EnvironmentInterface $environment)
    {
        $input      = $environment->getInputProvider();
        $clipboard  = $environment->getClipboard();
        $definition = $environment->getDataDefinition()->getBasicDefinition();

        // Tree mode needs special handling.
        if ($this->needTreeModeShowAll($definition, $input)) {
            return $this->callAction($environment, 'showAll');
        }

        // Check if it is a simple create-paste of a single model, if so, redirect to edit view.
        if ($this->isSimpleCreatePaste(
            $clipboard,
            $environment->getDataDefinition()->getBasicDefinition()->getDataProvider()
        )) {
            return $this->callAction($environment, 'create');
        }

        $source        = $this->modelIdFromParameter($input, 'source');
        $after         = $this->modelIdFromParameter($input, 'after');
        $into          = $this->modelIdFromParameter($input, 'into');
        $parentModelId = $this->modelIdFromParameter($input, 'pid');
        $items         = [];

        $environment->getController()->applyClipboardActions($source, $after, $into, $parentModelId, null, $items);

        foreach ($items as $item) {
            $clipboard->remove($item);
        }
        $clipboard->saveTo($environment);

        // If we use paste all handler don´t redirect yet.
        if ($input->getParameter('pasteAll')) {
            return null;
        }

        ViewHelpers::redirectHome($environment);

        return null;
    }
867084
protected function renderBreadcrumb(EnvironmentInterface $environment)
    {
        $event = new GetBreadcrumbEvent($environment);
        $environment->getEventDispatcher()->dispatch($event::NAME, $event);
        $elements = $event->getElements();
        if (empty($elements)) {
            return null;
        }

        $GLOBALS['TL_CSS']['cca.dc-general.breadcrumb'] = 'system/modules/dc-general/html/css/generalBreadcrumb.css';

        $template = new ContaoBackendViewTemplate('dcbe_general_breadcrumb');
        $template->set('elements', $elements);

        return $template->parse();
    }
61068
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->requireConfig();

        $output->writeln('Starting <fg=blue>Magallanes</>');
        $output->writeln('');

        try {
            $this->runtime->setEnvironment($input->getArgument('environment'));

            $strategy = $this->runtime->guessStrategy();
            $this->taskFactory = new TaskFactory($this->runtime);

            $output->writeln(sprintf('    Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
            $this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));

            if ($this->runtime->getEnvOption('releases', false)) {
                $this->runtime->generateReleaseId();
                $output->writeln(sprintf('    Release ID: <fg=green>%s</>', $this->runtime->getReleaseId()));
                $this->log(sprintf('Release ID: %s', $this->runtime->getReleaseId()));
            }

            if ($this->runtime->getConfigOption('log_file', false)) {
                $output->writeln(sprintf('    Logfile: <fg=green>%s</>', $this->runtime->getConfigOption('log_file')));
            }

            $output->writeln(sprintf('    Strategy: <fg=green>%s</>', $strategy->getName()));

            if ($input->getOption('branch') !== false) {
                $this->runtime->setEnvOption('branch', $input->getOption('branch'));
            }

            if ($this->runtime->getEnvOption('branch', false)) {
                $output->writeln(sprintf('    Branch: <fg=green>%s</>', $this->runtime->getEnvOption('branch')));
            }

            $output->writeln('');
            $this->runDeployment($output, $strategy);
        } catch (RuntimeException $exception) {
            $output->writeln('');
            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
            $output->writeln('');
            $this->statusCode = 7;
        }

        $output->writeln('Finished <fg=blue>Magallanes</>');

        return $this->statusCode;
    }
884417
private function process(Action $action, EnvironmentInterface $environment)
    {
        $actionMethod = \sprintf(
            'handle%sAllAction',
            \ucfirst($this->getSubmitAction($environment, $this->regardSelectMode($environment)))
        );

        if (false !== ($response = $this->{$actionMethod}($environment, $action))) {
            return $response;
        }

        return null;
    }
1289991
public function run( $environment ) {
        $application = NULL;
        if ( class_exists('\App\Application') ) {
            $application = new \App\Application( $this->_container );
            $application->initialize();
        }
        
        $this->_environment = $environment === self::DEVELOPMENT ? self::DEVELOPMENT : self::PRODUCTION;
        
        /* @var $dispatcher \PowerOn\Routing\Dispatcher */
        $dispatcher = $this->_container['Dispatcher'];
        
        /* @var $request \PowerOn\Network\Request */
        $request = $this->_container['Request'];
        
        /* @var $response \PowerOn\Network\Response */
        $response = $this->_container['Response'];
        
        try {
            try {
                //Obtenemos el View del container
                /* @var $view \PowerOn\View\View */
                $view = $this->_container['View'];
                
                //Lanzamos el metodo beforeDispatch de la clase application solo si existe
                !$application ?: $application->beforeDispatch();
                
                //El dispatcher entrega el controlador en caso de que lo encuentre utilizando AltoRouter
                $controller = $dispatcher->handle( $this->_container['AltoRouter'], $request );
                
                //Lanzamos el metodo afterDispatch de la clase application solo si existe
                !$application ?: $application->afterDispatch();
                
                //Obtenemos el layout de la aplicación desde la configuración
                $layout = Config::get('View.layout');
                
                //Establecemos el layout obtenido, si no fue especificado se utilizará el default.phtml
                $view->setLayout($layout ? $layout : 'default');
                
                //Establecemos el template a utilizar por el controlador seleccionado
                $view->setTemplate($dispatcher->action, $dispatcher->controller);
                
                //Inicializamos el View cargando los helpers predefinidos y demás operaciones
                $view->initialize();
                
                //Registramos el container en el controlador cargado
                $controller->registerContainer($this->_container);
                
                //Lanzamos la acción capturada por el dispatcher y altorouter
                $controller->{ $dispatcher->action }();
                
                //Lanzamos el metodo beforeRender de la clase application solo si existe
                !$application ?: $application->beforeRender();
                
                //Renderizamos la respuesta luego de realizar el negocio
                $response->render( $view->getRenderedTemplate() );
                
                //Lanzamos el metodo afterRender de la clase application solo si existe
                !$application ?: $application->afterRender();
            } catch (PowerOnException $e) {
                
                $e->log( $this->_container['Logger'] );
                
                if ( $this->_environment == self::DEVELOPMENT ) {
                    $this->handleDevError($e);
                } else {
                    $message = $e instanceof LogicException ? 'Error interno' : $e->getMessage();
                    throw new InternalErrorException($message, $e->getCode() ? $e->getCode() : NULL, $e);
                }
                
            } catch (\Exception $e) {
                
                if ( $this->_environment == self::DEVELOPMENT ) {
                    $this->handleExternalError($e);
                } else {
                    $reflection = new \ReflectionClass($e);
                    $logger = $this->_container['Logger'];
                    $logger->error($e->getMessage(), [
                        'type' => $reflection->getShortName(),
                        'code' => $e->getCode(),
                        'line' => $e->getLine(),
                        'file' => $e->getFile(),
                        'trace' => $e->getTrace()
                    ]);
                    throw new InternalErrorException('Error interno', $e->getCode() ? $e->getCode() : NULL, $e);
                }
                
            }
        } catch (InternalErrorException $e) {
            $this->handleProdError($e);
        }
    }
469917
public function remove(Model\EnvironmentInterface $environment)
    {
        $this->pmProxyClient->delete('/environments/' . $environment->getNormalizedName());
        if ($environment->hasChildren()) {
            foreach ($environment->getChildren() as $child) {
                /** @var Model\EnvironmentInterface $child */
                $this->remove($child);
            }
        }
        return $this;
    }
505476
public function setEnvironment($environment = '')
    {
        // Set the application environment
        $environment = ($environment ?: strtolower(getenv('APPLICATION_ENV')));
        $environment = ($environment ?: 'default');

        // Set the application environment
        $this->set('env', $environment);

        return $this;
    }
304948
private function handleCutAllAction(EnvironmentInterface $environment, Action $action)
    {
        $inputProvider = $environment->getInputProvider();
        foreach ($this->getModelIds($environment, $action, $this->getSubmitAction($environment)) as $modelId) {
            $inputProvider->setParameter('source', $modelId->getSerialized());

            $this->callAction($environment, 'cut');

            $inputProvider->unsetParameter('source');
        }

        ViewHelpers::redirectHome($environment);

        return null;
    }
1211733
protected function handleGlobalCommands(EnvironmentInterface $environment)
    {
        $dataDefinition = $environment->getDataDefinition();
        $backendView    = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
        $globalCommands = $backendView->getGlobalCommands();

        $globalCommands->clearCommands();

        $backCommand = new BackCommand();
        $backCommand->setDisabled(false);
        $globalCommands->addCommand($backCommand);
    }
128860
private function clearClipboard(EnvironmentInterface $environment)
    {
        $basicDefinition = $environment->getDataDefinition()->getBasicDefinition();

        $filter = new Filter();
        $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
        if ($basicDefinition->getParentDataProvider()) {
            $filter->andParentIsFromProvider($basicDefinition->getParentDataProvider());
        } else {
            $filter->andHasNoParent();
        }

        $clipboard = $environment->getClipboard();

        $items = $clipboard->fetch($filter);
        if (\count($items) < 1) {
            return;
        }

        foreach ($items as $item) {
            $clipboard->remove($item);
        }
    }
570279
public static function getGroupingMode(EnvironmentInterface $environment)
    {
        $sorting = static::getCurrentSorting($environment);

        // If no sorting defined, exit.
        if ((!$sorting)
            || (!$sorting->getCount())
            || $sorting->get(0)->getSortingMode() === GroupAndSortingInformationInterface::SORT_RANDOM
        ) {
            return null;
        }
        $firstSorting = $sorting->get(0);

        // Use the information from the property, if given.
        if ('' !== $firstSorting->getGroupingMode()) {
            $groupMode   = $firstSorting->getGroupingMode();
            $groupLength = $firstSorting->getGroupingLength();
        } else {
            // No sorting? No grouping!
            $groupMode   = GroupAndSortingInformationInterface::GROUP_NONE;
            $groupLength = 0;
        }

        return [
            'mode'     => $groupMode,
            'length'   => $groupLength,
            'property' => $firstSorting->getProperty(),
            'sorting'  => $sorting
        ];
    }
249656
public function handle(EventInterface $event)
    {

        try {
            // load the application server, naming directory and system configuration instance
            /** @var \AppserverIo\Psr\ApplicationServer\ApplicationServerInterface $applicationServer */
            $applicationServer = $this->getApplicationServer();
            /** @var \AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory */
            $namingDirectory = $applicationServer->getNamingDirectory();
            /** @var \AppserverIo\Psr\ApplicationServer\Configuration\SystemConfigurationInterface $systemConfiguration */
            $systemConfiguration = $applicationServer->getSystemConfiguration();

            // initialize the loggers
            $loggers = array();
            foreach ($systemConfiguration->getLoggers() as $loggerNode) {
                $loggers[$loggerNode->getName()] = LoggerFactory::factory($loggerNode);
            }

            // register the logger callbacks in the naming directory
            foreach ($loggers as $name => $logger) {
                $namingDirectory->bind(sprintf('php:global/log/%s', $name), $logger);
            }

            // set the initialized loggers finally
            $applicationServer->setLoggers($loggers);

        } catch (\Exception $e) {
            $applicationServer->getSystemLogger()->error($e->__toString());
        }
    }
604327
protected function getSelectButtons(EnvironmentInterface $environment)
    {
        $languageDomain = 'contao_' . $environment->getDataDefinition()->getName();

        $confirmMessage = \htmlentities(
            \sprintf(
                '<h2 class="tl_error">%s</h2>' .
                '<p></p>' .
                '<div class="tl_submit_container">' .
                '<input class="%s" value="%s" onclick="%s">' .
                '</div>',
                StringUtil::specialchars($this->translate('MSC.nothingSelect', $languageDomain)),
                'tl_submit',
                StringUtil::specialchars($this->translate('MSC.close', $languageDomain)),
                'BackendGeneral.hideMessage(); return false;'
            )
        );
        $onClick        = 'BackendGeneral.confirmSelectOverrideEditAll(this, \'properties[]\', \'' .
                          $confirmMessage . '\'); return false;';

        $continueName        = $environment->getInputProvider()->getParameter('mode');
        $buttons['continue'] = \sprintf(
            '<input type="submit" name="%s" id="%s" class="tl_submit" accesskey="%s" value="%s" onclick="%s">',
            $continueName,
            $continueName,
            'c',
            StringUtil::specialchars($this->translate('MSC.continue', $languageDomain)),
            $onClick
        );

        return $buttons;
    }
800352
public function populateController(EnvironmentInterface $environment)
    {
        $definition = $environment->getDataDefinition();

        if (!$definition->getBasicDefinition()->getParentDataProvider()) {
            return;
        }

        $parentDefinition = (new DcGeneralFactory())
            ->setEventDispatcher($environment->getEventDispatcher())
            ->setTranslator($environment->getTranslator())
            ->setContainerName($definition->getBasicDefinition()->getParentDataProvider())
            ->createDcGeneral()
            ->getEnvironment()
            ->getDataDefinition();

        $environment->setParentDataDefinition($parentDefinition);
    }
284078
public function handle(EventInterface $event)
    {

        try {
            // load the application server and the naming directory instance
            /** @var \AppserverIo\Psr\ApplicationServer\ApplicationServerInterface $applicationServer */
            $applicationServer = $this->getApplicationServer();
            /** @var \AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory */
            $namingDirectory = $applicationServer->getNamingDirectory();

            // write a log message that the event has been invoked
            $applicationServer->getSystemLogger()->info($event->getName());

            // deploy the applications for all containers
            /** @var \AppserverIo\Psr\ApplicationServer\Configuration\ContainerConfigurationInterface $containerNode */
            foreach ($applicationServer->getSystemConfiguration()->getContainers() as $containerNode) {
                // load the container instance to deploy the applications for
                /** @var \AppserverIo\Psr\ApplicationServer\ContainerInterface $container */
                $container = $namingDirectory->search(
                    sprintf(
                        'php:services/%s/%s',
                        $applicationServer->runlevelToString(ApplicationServerInterface::NETWORK),
                        $containerNode->getName()
                    )
                );

                // load the containers deployment
                /** @var \AppserverIo\Psr\Deployment\DeploymentInterface $deployment */
                $deployment = $container->getDeployment();
                $deployment->injectContainer($container);

                // deploy and initialize the container's applications
                $deployment->deploy();
            }

        } catch (\Exception $e) {
            $applicationServer->getSystemLogger()->error($e->__toString());
        }
    }
1211893
public function populateController(EnvironmentInterface $environment)
    {
        // Already populated, get out then.
        if ($environment->getController()) {
            return;
        }

        $definition = $environment->getDataDefinition();

        // If we encounter an extended definition, that one may override.
        if (!$definition->hasDefinition(ExtendedDca::NAME)) {
            return;
        }

        if (!($class = $definition->getDefinition(ExtendedDca::NAME)->getControllerClass())) {
            return;
        }

        /** @var ControllerInterface $controller */
        $controller = (new \ReflectionClass($class))->newInstance();

        $controller->setEnvironment($environment);
        $environment->setController($controller);
    }
216255
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->bootstrap($input, $output);

        $environment = $input->getOption('environment');
        $version = $input->getOption('target');
        $removeAll = $input->getOption('remove-all');

        if ($environment === null) {
            $environment = $this->getConfig()->getDefaultEnvironment();
            $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment);
        } else {
            $output->writeln('<info>using environment</info> ' . $environment);
        }

        if ($version && $removeAll) {
            throw new \InvalidArgumentException('Cannot toggle a breakpoint and remove all breakpoints at the same time.');
        }

        // Remove all breakpoints
        if ($removeAll) {
            $this->getManager()->removeBreakpoints($environment);
        } else {
            // Toggle the breakpoint.
            $this->getManager()->toggleBreakpoint($environment, $version);
        }
    }