public function catalogAction()

in pp3/module/Application/src/Application/Controller/AdminController.php [173:229]


    public function catalogAction() {
        $this->_checkAdminUser();
        $version = $this->params()->fromQuery('version');
        $experimental = $this->params()->fromQuery('experimental');
        if (!empty($version)) {        
            $nbv = $this->_nbVersionRepository->findOneBy('version', $version);
            if ($nbv) {
                $items = $experimental ? $this->_pluginVersionRepository->getNonVerifiedVersionsByNbVersion($version) : $this->_pluginVersionRepository->getVerifiedVersionsByNbVersion($version);
                if (count($items)) {                
                    $catalog = new Catalog(
                            $this->_pluginVersionRepository,
                            $version,
                            $items,
                            $experimental,
                            $this->_config['pp3']['dtdPath'],
                            $this->getDownloadBaseUrl(),
                            $this->_config['pp3']['catalogSavepath']);
                    try {
                        $errors = array();
                        $catalog->storeXml(true, $errors);
                        if(count($errors) == 0) {
                            $this->flashMessenger()->setNamespace('success')->addMessage('Catalog for NB '.$version.' published. Found '.count($items).' plugins.');
                        } else {
                            $message = 'Catalog for NB '.$version.' published. Found '.count($items).' plugins, not all plugins were valid:<ul style="margin-top: 1ex">';
                            foreach($errors as $pluginVersionId => $errorList) {
                                $plugin = $this->_pluginVersionRepository->find($pluginVersionId)->getPlugin();
                                $message .= '<li>';
                                $message .= htmlentities($plugin->getName() . ' (ID: ' . $plugin->getId() . ')', ENT_COMPAT | ENT_HTML401, 'UTF-8');
                                $message .= "<ul>";
                                foreach($errorList as $errorEntry) {
                                    $message .= '<li>';
                                    $message .= htmlentities(sprintf("%s (Code: %d)", $errorEntry->message, $errorEntry->code), ENT_COMPAT | ENT_HTML401, 'UTF-8');
                                    $message .= '</li>';
                                }
                                $message .= "</ul>";
                                $message .= '</li>';
                            }
                            $message .= '</ul>';
                            $this->flashMessenger()->setNamespace('warning')->addMessage($message);
                        }
                    } catch (\Exception $e){
                        $this->flashMessenger()->setNamespace('error')->addMessage($e->getMessage());                        
                    }                
                } else {
                    $this->flashMessenger()->setNamespace('info')->addMessage('No plugins foud for version NB '.$version);
                }
                return $this->redirect()->toRoute('admin', array(
                    'action' => 'catalog'
                ));
            }    
        }

        return new ViewModel([
            'catalUrlPath' => $this->_config['pp3']['catalogUrlPath'],
            'nbVersions' => $this->_nbVersionRepository->findAll(),            
        ]);
    }