58 final public function init($a_entity, $a_schema_version)
60 $this->entity = $a_entity;
61 $this->schema_version = $a_schema_version;
62 $this->data = array();
80 abstract protected function getTypes($a_entity, $a_version);
86 abstract protected function getXmlNamespace($a_entity, $a_schema_version);
94 abstract function readData($a_entity, $a_version, $a_ids);
104 $this->relative_export_dir = $a_relative;
105 $this->absolute_export_dir = $a_absolute;
115 $this->import_directory = $a_val;
125 return $this->import_directory;
167 $set = $ilDB->query($a_query);
168 $this->data = array();
169 while ($rec = $ilDB->fetchAssoc($set))
171 if ($a_convert_to_leading_upper)
174 foreach ($rec as $k => $v)
182 $this->data[] = $rec;
194 $a_str = strtoupper(substr($a_str, 0, 1)).substr($a_str, 1);
195 while (is_int($pos = strpos($a_str,
"_")))
197 $a_str = substr($a_str, 0, $pos).
198 strtoupper(substr($a_str, $pos+1, 1)).
199 substr($a_str, $pos+2);
210 if ($this->version ===
false)
216 $arr[
"version"] = $this->version;
217 $arr[
"install_id"] = IL_INST_ID;
218 $arr[
"install_url"] = ILIAS_HTTP_PATH;
220 $arr[
"set"] = array();
221 foreach ($this->data as
$d)
226 include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
253 $a_ids, $a_field =
"", $a_omit_header =
false, $a_omit_types =
false)
262 include_once
"./Services/Xml/classes/class.ilXmlWriter.php";
266 $writer->xmlHeader();
270 $namespaces = $prefixes = array();
271 $this->
getNamespaces($namespaces, $a_entity, $a_schema_version);
272 $atts = array(
"InstallationId" => IL_INST_ID,
273 "InstallationUrl" => ILIAS_HTTP_PATH,
"TopEntity" => $a_entity);
275 foreach ($namespaces as $entity => $ns)
278 $prefixes[$entity] = $prefix;
283 $this->ds_log->debug(
"Start writing Dataset, entity: ".$a_entity.
", schema version: ".$a_schema_version.
284 ", ids: ".print_r($a_ids,
true));
290 $this->ds_log->debug(
"...write types");
291 $this->
addTypesXml($writer, $a_entity, $a_schema_version);
295 $this->ds_log->debug(
"...write records");
296 $this->
addRecordsXml($writer, $prefixes, $a_entity, $a_schema_version, $a_ids, $a_field);
304 return $writer->xmlDumpMem(
false);
314 function addRecordsXml($a_writer, $a_prefixes, $a_entity, $a_schema_version, $a_ids, $a_field =
"")
316 $types = $this->
getXmlTypes($a_entity, $a_schema_version);
318 $this->ds_log->debug(
"...read data");
319 $this->
readData($a_entity, $a_schema_version, $a_ids, $a_field);
320 $this->ds_log->debug(
"...data: ".print_r($this->data,
true));
321 if (is_array($this->data))
323 foreach ($this->data as
$d)
326 array(
"Entity" => $this->getXmlEntityName($a_entity, $a_schema_version)));
329 $a_writer->xmlStartTag($this->getXmlEntityTag($a_entity, $a_schema_version));
331 $rec = $this->
getXmlRecord($a_entity, $a_schema_version, $d);
332 foreach ($rec as $f => $c)
337 if ($this->absolute_export_dir !=
"" && $this->relative_export_dir !=
"")
340 ilUtil::rCopy($c, $this->absolute_export_dir.
"/dsDir_".$this->dircnt);
350 $a_writer->xmlElement($f, array(), $c);
353 $a_writer->xmlEndTag($this->getXmlEntityTag($a_entity, $a_schema_version));
360 $this->ds_log->debug(
"...get dependencies");
361 $deps = $this->getDependencies($a_entity, $a_schema_version, $rec, $a_ids);
362 $this->ds_log->debug(
"...dependencies: ".print_r($deps,
true));
365 foreach ($deps as $dp => $par)
367 $this->
addRecordsXml($a_writer, $a_prefixes, $dp, $a_schema_version, $par[
"ids"], $par[
"field"]);
372 else if ($this->data ===
false)
375 $this->ds_log->debug(
"...get dependencies (no record)");
376 $deps = $this->getDependencies($a_entity, $a_schema_version, null, $a_ids);
379 foreach ($deps as $dp => $par)
381 $this->
addRecordsXml($a_writer, $a_prefixes, $dp, $a_schema_version, $par[
"ids"], $par[
"field"]);
402 private function addTypesXml($a_writer, $a_entity, $a_schema_version)
404 $types = $this->
getXmlTypes($a_entity, $a_schema_version);
407 if (is_array($types))
410 array(
"Entity" => $this->getXmlEntityName($a_entity, $a_schema_version),
411 "SchemaVersion" => $a_schema_version));
412 foreach ($this->
getXmlTypes($a_entity, $a_schema_version) as $f =>
$t)
415 array(
"Name" => $f,
"Type" =>
$t));
421 $deps = $this->getDependencies($a_entity, $a_schema_version, null, null);
424 foreach ($deps as $dp =>
$w)
426 $this->
addTypesXml($a_writer, $dp, $a_schema_version);
444 $namespaces[$a_entity] = $ns;
447 $deps = $this->getDependencies($a_entity, $a_schema_version, null, null);
450 foreach ($deps as $dp =>
$w)
486 return $this->
getTypes($a_entity, $a_version);
496 return $this->
getTypes($a_entity, $a_version);
537 $this->
import = $a_val;
547 return $this->import;
557 $this->current_installation_id = $a_val;
579 return "il_".IL_INST_ID.
"_".$a_type.
"_".$a_id;
592 if(substr($a_id, 0, 3) ==
"il_")
594 $parts = explode(
"_", $a_id);
595 $inst_id = $parts[1];
600 if(($inst_id == 0 || IL_INST_ID == 0) && !DEVMODE)
602 return array(
"type"=>self::EXPORT_NO_INST_ID,
"id"=>$a_fallback_id);
606 if($inst_id == IL_INST_ID)
611 return array(
"type"=>self::EXPORT_ID_ILIAS_LOCAL,
"id"=>$id);
616 return array(
"type"=>self::EXPORT_ID_ILIAS_LOCAL_INVALID,
"id"=>$a_fallback_id);
626 return array(
"type"=>self::EXPORT_ID_ILIAS_REMOTE,
"id"=>$id);
631 return array(
"type"=>self::EXPORT_ID_ILIAS_REMOTE_INVALID,
"id"=>$a_fallback_id);
640 return array(
"type"=>self::EXPORT_ID,
"id"=>$id);
644 return array(
"type"=>self::EXPORT_ID_INVALID,
"id"=>$a_fallback_id);
getJsonEntityName($a_entity, $a_version)
Get entity name for json (may be overwritten)
static makeDirParents($a_dir)
Create a new directory and all parent directories.
init($a_entity, $a_schema_version)
Init.
const EXPORT_ID_ILIAS_REMOTE
setExportDirectories($a_relative, $a_absolute)
Set export directories.
setImportDirectory($a_val)
Set import directory.
getTypes($a_entity, $a_version)
Get (abstract) types for (abstract) field names.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
const EXPORT_ID_ILIAS_LOCAL_INVALID
createObjectExportId($a_type, $a_id)
Build ilias export id.
_getIdForImportId($a_import_id)
get current object id for import id (static)
afterXmlRecordWriting($a_entity, $a_version, $a_set)
After xml record writing hook record.
addTypesXml($a_writer, $a_entity, $a_schema_version)
Add types to xml writer.
getDSPrefix()
Get XML dataset namespace prefix.
getImportDirectory()
Get import directory.
readData($a_entity, $a_version, $a_ids)
Read data from DB.
__construct()
Constructor.
getJsonTypes($a_entity, $a_version)
Get json types.
parseObjectExportId($a_id, $a_fallback_id=NULL)
Parse export id.
getXMLEntityName($a_entity, $a_version)
Get entity name for xml (may be overwritten)
convertToLeadingUpper($a_str)
Make xyz_abc a XyzAbc string.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record for version.
getImport()
Get import object.
const EXPORT_ID_ILIAS_REMOTE_INVALID
static encode($mixed, $suppress_native=false)
const EXPORT_ID_ILIAS_LOCAL
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
getJsonRepresentation()
Get json representation.
getSupportedVersions()
Get supported version.
getNamespaces(&$namespaces, $a_entity, $a_schema_version)
Get xml namespaces.
setCurrentInstallationId($a_val)
Set current installation id.
getCurrentInstallationId()
Get current installation id.
getJsonRecord($a_set)
Get json record for version.
static _lookupType($a_id, $a_reference=false)
lookup object type
getXmlTypes($a_entity, $a_version)
Get xml types.
getXmlRepresentation($a_entity, $a_schema_version, $a_ids, $a_field="", $a_omit_header=false, $a_omit_types=false)
Get xml representation <dataset install_id="123" install_url="..."> <types entity="table_name" versio...
setImport($a_val)
Set import object.
static getLogger($a_component_id)
Get component logger.
getXMLEntityTag($a_entity, $a_schema_version)
Get entity tag.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
setDSPrefix($a_val)
Set XML dataset namespace prefix.
addRecordsXml($a_writer, $a_prefixes, $a_entity, $a_schema_version, $a_ids, $a_field="")
Add records xml.