public function generateTheme(Request $request)
{
$theme = $request->get('theme');
$newName = $request->get('name');
if (empty($theme)) {
return new Response(Trans::__('page.extend.theme.generation.missing.name'));
}
if (!$newName) {
$newName = basename($theme);
}
$source = $this->resources()->getPath('extensions/vendor/' . $theme);
$destination = $this->resources()->getPath('themebase/' . $newName);
if (is_dir($source)) {
$filesystem = new Filesystem();
try {
$filesystem->mkdir($destination);
$filesystem->mirror($source, $destination);
if (file_exists($destination . '/config.yml.dist')) {
$filesystem->copy($destination . '/config.yml.dist', $destination . '/config.yml');
}
return new Response(Trans::__('page.extend.theme.generation.success'));
} catch (\Exception $e) {
return new Response(Trans::__('page.extend.theme.generation.failure'));
}
}
return $this->getJsonException(new PackageManagerException(Trans::__('page.extend.message.invalid-theme-source-dir', ['%SOURCE%', $source])));
}