public function clearProducts() { if ($this->id > 0) { $objProducts = AccountProduct::getByAccountId($this->id); foreach ($objProducts as $objProduct) { $objProduct->delete(); } } }
public static function export($intAccountId = 0, $exportFiles = true) { global $objLiveAdmin, $_CONF, $_PATHS; //*** Init DOM object. $objDoc = new DOMDocument("1.0", "UTF-8"); $objDoc->formatOutput = false; $objDoc->preserveWhiteSpace = true; //*** Init Zip archive. $strZipName = $_PATHS['upload'] . "exportZip_" . rand() . ".zip"; $objZip = new dZip($strZipName, true); //*** ACL. Users, groups and rights. $objAcl = self::exportAcl($objDoc, $intAccountId); //*** Products. $_CONF['app']['account'] = Account::getById($intAccountId); $objAccountProducts = AccountProduct::getByAccountId($intAccountId); $objProducts = $objDoc->createElement('products'); foreach ($objAccountProducts as $objAccountProduct) { switch ($objAccountProduct->getProductId()) { case PRODUCT_PCMS: $arrFiles = array(); //*** Settings. $objSettings = $objDoc->createElement('settings'); $objDbSettings = SettingTemplate::select("SELECT * FROM pcms_setting_tpl ORDER BY section, sort"); foreach ($objDbSettings as $objDbSetting) { $objSetting = $objDoc->createElement('setting'); $objSetting->setAttribute("name", $objDbSetting->getName()); $objSetting->setAttribute("value", Setting::getValueByName($objDbSetting->getName(), $intAccountId)); $objSetting->setAttribute("section", $objDbSetting->getSection()); $objSettings->appendChild($objSetting); } //*** Languages. $objLanguages = $objDoc->createElement('languages'); $objContentLangs = ContentLanguage::select(); foreach ($objContentLangs as $objContentLang) { $objLanguage = $objDoc->createElement('language'); $objLanguage->setAttribute("id", $objContentLang->getId()); $objLanguage->setAttribute("name", $objContentLang->getName()); $objLanguage->setAttribute("abbr", $objContentLang->getAbbr()); $objLanguage->setAttribute("default", $objContentLang->default); $objLanguage->setAttribute("active", $objContentLang->getActive()); $objLanguage->setAttribute("sort", $objContentLang->getSort()); $objLanguage->setAttribute("username", $objContentLang->getUsername()); $objLanguages->appendChild($objLanguage); } //*** External feeds. $objFeeds = $objDoc->createElement('feeds'); $objDbFeeds = Feed::select(); foreach ($objDbFeeds as $objDbFeed) { $objFeed = $objDoc->createElement('feed'); $objFeed->setAttribute("id", $objDbFeed->getId()); $objFeed->setAttribute("name", $objDbFeed->getName()); $objFeed->setAttribute("feed", $objDbFeed->getFeed()); $objFeed->setAttribute("basepath", $objDbFeed->getBasepath()); $objFeed->setAttribute("refresh", $objDbFeed->getRefresh()); $objFeed->setAttribute("lastUpdate", $objDbFeed->getLastUpdate()); $objFeed->setAttribute("active", $objDbFeed->getActive()); $objFeed->setAttribute("sort", $objDbFeed->getSort()); $objFeed->setAttribute("created", $objDbFeed->getCreated()); $objFeed->setAttribute("modified", $objDbFeed->getModified()); $objFeeds->appendChild($objFeed); } //*** Storage items. $objStorage = self::exportStorage($objDoc, $intAccountId, 0, $arrFiles); //*** Templates. $objTemplates = self::exportTemplate($objDoc, $intAccountId, 0); //*** Elements. $objElements = self::exportElement($objDoc, $intAccountId, 0, $arrFiles); //*** Aliases. $objAliases = $objDoc->createElement('aliases'); $objDbAliases = Alias::select(); foreach ($objDbAliases as $objDbAlias) { $objAlias = $objDoc->createElement('alias'); $objAlias->setAttribute("language", $objDbAlias->getLanguageId()); $objAlias->setAttribute("cascade", $objDbAlias->getCascade()); $objAlias->setAttribute("alias", $objDbAlias->getAlias()); $objAlias->setAttribute("url", $objDbAlias->getUrl()); $objAlias->setAttribute("active", $objDbAlias->getActive()); $objAlias->setAttribute("sort", $objDbAlias->getSort()); $objAlias->setAttribute("created", $objDbAlias->getCreated()); $objAlias->setAttribute("modified", $objDbAlias->getModified()); $objAliases->appendChild($objAlias); } //*** Product. $objProduct = $objDoc->createElement('pcms'); $objProduct->setAttribute("version", APP_VERSION); $objProduct->setAttribute("expires", $objAccountProduct->getExpires()); $objProduct->appendChild($objSettings); $objProduct->appendChild($objLanguages); $objProduct->appendChild($objFeeds); $objProduct->appendChild($objStorage); $objProduct->appendChild($objTemplates); $objProduct->appendChild($objElements); $objProduct->appendChild($objAliases); $objProducts->appendChild($objProduct); //*** Files. if ($exportFiles) { $strServer = Setting::getValueByName("ftp_server"); if ($strServer != "localhost") { $strLocation = "http://" . Setting::getValueByName("ftp_server") . Setting::getValueByName("file_folder"); $objZip = self::exportFilesToZip($objZip, $arrFiles, $strLocation); } } break; } } //*** Account. $objDbAccount = Account::selectByPk($intAccountId); $objAccount = $objDoc->createElement('account'); $objAccount->setAttribute("punchId", $objDbAccount->getPunchId()); $objAccount->setAttribute("name", $objDbAccount->getName()); $objAccount->setAttribute("uri", $objDbAccount->getUri()); $objAccount->appendChild($objAcl); $objAccount->appendChild($objProducts); $objPunch = $objDoc->createElement('Punch'); $objPunch->appendChild($objAccount); $objRoot = $objDoc->appendChild($objPunch); //*** Destroy temporary account object. unset($_CONF['app']['account']); //*** Return XML. $objZip->addFile(NULL, 'data.xml', "", $objDoc->saveXML()); $objZip->save(); return $strZipName; }