public function generateTheme(Request $request)
    {
        $theme = $request->query->get('theme');
        $newName = $request->query->get('name');

        if (empty($theme)) {
            return new Response(Trans::__('page.extend.theme.generation.missing.name'));
        }

        if (!$newName) {
            $newName = basename($theme);
        }

        $source = $this->filesystem()->getDir('extensions://vendor/' . $theme);
        if (!$source->exists()) {
            return $this->getJsonException(new PackageManagerException(Trans::__('page.extend.message.invalid-theme-source-dir', ['%SOURCE%', $source])));
        }

        try {
            $this->filesystem()->mirror('extensions://vendor/' . $theme, 'themes://' . $newName);

            try {
                $this->filesystem()->copy("themes://$newName/config.yml.dist", "themes://$newName/config.yml");
            } catch (FileNotFoundException $e) {
                // Ignore if there's no dist file
            }
        } catch (IOException $e) {
            return new Response(Trans::__('page.extend.theme.generation.failure'));
        }

        return new Response(Trans::__('page.extend.theme.generation.success'));
    }