/**
  * Export current configuration as XML profile
  * @param string $ps_name Name of the profile, used for "profileName" element
  * @param string $ps_description Description of the profile, used for "profileDescription" element
  * @param string $ps_base Base profile
  * @param string $ps_info_url Info URL for the profile
  * @return string string profile as XML string
  */
 public static function exportConfigurationAsXML($ps_name = "", $ps_description = "", $ps_base = "", $ps_info_url = "")
 {
     $o_exporter = new ConfigurationExporter();
     $vo_root = $o_exporter->getDOM()->createElement('profile');
     $o_exporter->getDOM()->appendChild($vo_root);
     // "profile" attributes
     $vo_root->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
     $vo_root->setAttribute("xsi:noNamespaceSchemaLocation", "profile.xsd");
     $vo_root->setAttribute("useForConfiguration", 1);
     if (strlen($ps_base) > 0) {
         $vo_root->setAttribute("base", $ps_base);
     }
     $vo_root->setAttribute("infoUrl", $ps_info_url);
     if (strlen($ps_name) > 0) {
         $vo_root->appendChild($o_exporter->getDOM()->createElement("profileName", $ps_name));
     } else {
         $vo_root->appendChild($o_exporter->getDOM()->createElement("profileName", __CA_APP_NAME__));
     }
     if (strlen($ps_description) > 0) {
         $vo_root->appendChild($o_exporter->getDOM()->createElement("profileDescription", $ps_description));
     } else {
         $vo_root->appendChild($o_exporter->getDOM()->createElement("profileDescription"));
     }
     $vo_root->appendChild($o_exporter->getLocalesAsDOM());
     $vo_root->appendChild($o_exporter->getListsAsDOM());
     $vo_root->appendChild($o_exporter->getElementsAsDOM());
     if ($o_dict = $o_exporter->getMetadataDictionaryAsDOM()) {
         $vo_root->appendChild($o_dict);
     }
     $vo_root->appendChild($o_exporter->getUIsAsDOM());
     $vo_root->appendChild($o_exporter->getRelationshipTypesAsDOM());
     $vo_root->appendChild($o_exporter->getRolesAsDOM());
     $vo_root->appendChild($o_exporter->getGroupsAsDOM());
     /* hack to import string XML to existing document, have to rewrite display exporter at some point */
     $vo_fragment = $o_exporter->getDOM()->createDocumentFragment();
     $vo_fragment->appendXML($o_exporter->getDisplaysAsXML());
     $o_exporter->getDOM()->getElementsByTagName('profile')->item(0)->appendChild($vo_fragment);
     $vo_root->appendChild($o_exporter->getSearchFormsAsDOM());
     /* hack for decent formatting */
     $vs_string = $o_exporter->getDOM()->saveXML();
     $vo_dom = new DOMDocument('1.0', 'utf-8');
     $vo_dom->preserveWhiteSpace = false;
     $vo_dom->loadXML($vs_string);
     $vo_dom->formatOutput = true;
     return $vo_dom->saveXML();
 }
 public function Export()
 {
     set_time_limit(3600);
     $vs_xml = ConfigurationExporter::exportConfigurationAsXML($this->request->config->get('app_name'), _t('Profile created on %1 by %2', caGetLocalizedDate(), $this->request->user->get('fname') . ' ' . $this->request->user->get('lname')), 'base', '');
     $this->view->setVar('profile', $vs_xml);
     $this->view->setVar('profile_file_name', $this->request->config->get('app_name') . '_config.xml');
     $this->render('export_configuration_binary.php');
     return;
 }
Ejemplo n.º 3
0
 /**
  * Export current system configuration as an XML installation profile
  */
 public static function export_profile($po_opts = null)
 {
     require_once __CA_LIB_DIR__ . "/ca/ConfigurationExporter.php";
     if (!class_exists("DOMDocument")) {
         CLIUtils::addError(_t("The PHP DOM extension is required to export profiles"));
         return false;
     }
     $vs_output = $po_opts->getOption("output");
     $va_output = explode("/", $vs_output);
     array_pop($va_output);
     if ($vs_output && !is_dir(join("/", $va_output))) {
         CLIUtils::addError(_t("Cannot write profile to '%1'", $vs_output));
         return false;
     }
     $vs_profile = ConfigurationExporter::exportConfigurationAsXML($po_opts->getOption("name"), $po_opts->getOption("description"), $po_opts->getOption("base"), $po_opts->getOption("infoURL"));
     if ($vs_output) {
         file_put_contents($vs_output, $vs_profile);
     } else {
         print $vs_profile;
     }
     return true;
 }