/** * Delete selected theme and its theme folder * * @global type $_ARRAYLANG * @return array status */ function deleteThemeById() { global $_ARRAYLANG; $_ARRAYLANG = \Env::get('init')->loadLanguageData('ViewManager'); $delThemeId = isset($_GET['delThemeId']) ? $_GET['delThemeId'] : 0; $themeRepository = new \Cx\Core\View\Model\Repository\ThemeRepository(); if (!empty($delThemeId)) { $theme = $themeRepository->findById($delThemeId); if (!$theme) { return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_STATUS_CANNOT_DELETE']); } $themeFolderPath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername(); //Check whether the selected theme is selected for any of the active languages $activeLanguages = $theme->getLanguages(); if (!empty($activeLanguages) && file_exists($themeFolderPath)) { return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_STATUS_CANNOT_DELETE']); } // delete whole folder with subfolders in case it exists if (file_exists($themeFolderPath) && !\Cx\Lib\FileSystem\FileSystem::delete_folder($themeFolderPath, true)) { //error return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_STATUS_CANNOT_DELETE']); } //setting 0 for the custom theme for any of the content pages of the active frontend languages $pageRepo = \Env::get('em')->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $pages = $pageRepo->findBy(array('skin' => intval($theme->getId()))); foreach ($pages as $page) { $page->setSkin(0); \Env::get('em')->persist($page); } \Env::get('em')->flush(); //Remove theme details from the database. if ($themeRepository->remove($theme)) { return array('status' => 'success', 'message' => contrexx_raw2xhtml($theme->getThemesname()) . ": " . $_ARRAYLANG['TXT_STATUS_SUCCESSFULLY_DELETE']); } } }