/** * Generate a component.yml for one theme available on the system * * @param \Cx\Core\View\Model\Entity\Theme $theme */ public function convertThemeToComponent(\Cx\Core\View\Model\Entity\Theme $theme) { if ($theme->getComponentData()) { return; } $themePath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername(); $infoFile = null; $themeInformation = array('DlcInfo' => array()); if (file_exists($themePath . '/info.xml')) { try { // check for old info file $infoFile = new \Cx\Lib\FileSystem\File($themePath . '/info.xml'); $this->xmlParseFile($infoFile); $themeInformation['DlcInfo'] = array('name' => $theme->getThemesname(), 'description' => $this->xmlDocument['THEME']['DESCRIPTION']['cdata'], 'type' => 'template', 'publisher' => $this->xmlDocument['THEME']['AUTHORS']['AUTHOR']['USER']['cdata'], 'subtype' => null, 'versions' => array('state' => 'stable', 'number' => $this->xmlDocument['THEME']['VERSION']['cdata'], 'releaseDate' => '')); unset($this->xmlDocument); } catch (\Exception $e) { // not critical, ignore } } else { // create new data for new component.yml file $themeInformation['DlcInfo'] = array('name' => $theme->getThemesname(), 'description' => '', 'type' => 'template', 'publisher' => 'Cloudrexx AG', 'subtype' => null, 'versions' => array('state' => 'stable', 'number' => '1.0.0', 'releaseDate' => '')); } // Add default dependencies $themeInformation['DlcInfo']['dependencies'] = array(array('name' => 'jquery', 'type' => 'lib', 'minimumVersionNumber' => '1.6.1', 'maximumVersionNumber' => '1.6.1')); // write components yaml $theme->setComponentData($themeInformation['DlcInfo']); try { $this->saveComponentData($theme); } catch (\Exception $e) { // could not write new component.yml file, try next time throw new $e(); } if ($infoFile) { try { // delete existing info.xml file $infoFile->delete(); } catch (\Exception $e) { // not critical, ignore } } }
/** * Writes the component.yml file with the data defined in component data array * * @param \Cx\Core\View\Model\Entity\Theme $theme the theme object */ public function saveComponentData(\Cx\Core\View\Model\Entity\Theme $theme) { global $_ARRAYLANG; if (!file_exists(\Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername())) { if (!\Cx\Lib\FileSystem\FileSystem::make_folder(\Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername())) { \Message::add($theme->getFoldername() . " : " . $_ARRAYLANG['TXT_THEME_UNABLE_TO_CREATE']); } } $filePath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername() . '/component.yml'; try { $file = new \Cx\Lib\FileSystem\File($filePath); $file->touch(); $yaml = new \Symfony\Component\Yaml\Yaml(); $file->write($yaml->dump(array('DlcInfo' => $theme->getComponentData()))); } catch (\Exception $e) { \DBG::log($e->getMessage()); throw new $e(); } }