public function updateTheme(Theme $theme)
{
Validation::notEmpty($theme, 'theme');
$allConfigs = $this->findAllThemesConfigPaths();
$config = $allConfigs[$theme->getId()];
if (!isset($config)) {
throw new \Exception("Unknown theme id '.{$theme->getId}().' to update.");
}
// We have to check if there is no other theme by the new theme name.
$inFolder = $this->filterThemesConfigPathsInSameFolder($config, $allConfigs);
// Remove the theme to be updated.
unset($inFolder[$theme->getId()]);
$themes = $this->loadThemes($inFolder);
foreach ($themes as $th) {
/* @var $th Theme */
if (trim($th->getName()) === trim($theme->getName())) {
throw new DuplicateNameException();
}
}
$xml = $this->loadXML($this->toFullPath($config));
$xml[self::ATTR_THEME_NAME] = $theme->getName();
$xml[self::ATTR_THEME_DESIGNER] = $theme->getDesigner();
$xml[self::ATTR_THEME_VERSION] = $theme->getVersion();
$xml[self::ATTR_THEME_NEWSCOOP_VERSION] = Version::VERSION;
$xml->{self::TAG_DESCRIPTION} = $theme->getDescription();
$xml->asXML($this->toFullPath($theme, $this->themeConfigFileName));
}