Newscoop\NewscoopBundle\Controller\PluginsController::indexAction PHP Метод

indexAction() публичный Метод

public indexAction ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function indexAction(Request $request)
    {
        $user = $this->container->get('user')->getCurrentUser();
        $translator = $this->container->get('translator');
        if (!$user->hasPermission('plugin_manager')) {
            throw new AccessDeniedException($translator->trans("You do not have the right to manage plugins.", array(), 'plugins'));
        }
        $pluginService = $this->container->get('newscoop.plugins.service');
        $allAvailablePlugins = array();
        // show only modern plugins
        foreach ($pluginService->getAllAvailablePlugins() as $key => $value) {
            if (strpos($value->getName(), '/') !== false) {
                $allAvailablePlugins[] = $value;
            }
        }
        $form = $this->container->get('form.factory')->create(new PrivatePluginUploadType(), array());
        $this->createFolderStructure($pluginService);
        // handle private plugin upload
        if ($request->getMethod() == 'POST') {
            $form->handleRequest($request);
            if ($form->isValid()) {
                $file = $form['package']->getData();
                $extension = $file->guessExtension();
                if ($extension != 'zip') {
                    $request->getSession()->getFlashBag()->add('error', $translator->trans('newscoop.plugins_manager.form.package_must_be_zip', array(), 'plugins_manager'));
                    return $this->redirect($this->generateUrl('newscoop_newscoop_plugins_index'));
                }
                $file->move($pluginService->getPluginsDir() . self::PRIVATE_PLUGINS_DIR, $file->getClientOriginalName());
                return $this->redirect($this->generateUrl('newscoop_newscoop_plugins_index'));
            }
        }
        // check if private plugins is writable
        $privatePluginsPathWritable = is_writable($pluginService->getPluginsDir() . self::PRIVATE_PLUGINS_DIR);
        // search for private plugins
        $privatePackages = $this->searchForPrivatePlugins($pluginService);
        foreach ($privatePackages as $resultKey => $package) {
            $package['installed'] = false;
            foreach ($pluginService->getAllAvailablePlugins() as $key => $plugin) {
                if ($package['name'] == $plugin->getName()) {
                    $package['installed'] = true;
                }
            }
            $privatePackages[$resultKey] = $package;
        }
        return array('allAvailablePlugins' => $allAvailablePlugins, 'privatePackages' => $privatePackages, 'form' => $form->createView(), 'newscoopPath' => realpath($pluginService->getPluginsDir() . '/../'), 'privatePluginsPath' => $pluginService->getPluginsDir() . self::PRIVATE_PLUGINS_DIR, 'privatePluginsPathWritable' => $privatePluginsPathWritable);
    }