54 $this->db = $DIC->database();
70 final public function init($a_entity, $a_schema_version)
72 $this->entity = $a_entity;
73 $this->schema_version = $a_schema_version;
92 abstract protected function getTypes($a_entity, $a_version);
98 abstract protected function getXmlNamespace($a_entity, $a_schema_version);
106 abstract public function readData($a_entity, $a_version, $a_ids);
116 $this->relative_export_dir = $a_relative;
117 $this->absolute_export_dir = $a_absolute;
127 $this->import_directory = $a_val;
137 return $this->import_directory;
179 $set =
$ilDB->query($a_query);
182 while ($rec =
$ilDB->fetchAssoc($set)) {
183 if ($a_convert_to_leading_upper) {
185 foreach ($rec as $k => $v) {
193 $this->
data[] = $rec;
208 $a_str = strtoupper(substr($a_str, 0, 1)) . substr($a_str, 1);
209 while (is_int($pos = strpos($a_str,
"_"))) {
210 $a_str = substr($a_str, 0, $pos) .
211 strtoupper(substr($a_str, $pos+1, 1)) .
212 substr($a_str, $pos+2);
223 if ($this->version ===
false) {
229 $arr[
"install_id"] = IL_INST_ID;
230 $arr[
"install_url"] = ILIAS_HTTP_PATH;
232 $arr[
"set"] =
array();
233 foreach ($this->
data as
$d) {
237 include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
268 $a_omit_header =
false,
269 $a_omit_types =
false 278 include_once
"./Services/Xml/classes/class.ilXmlWriter.php";
280 if (!$a_omit_header) {
281 $writer->xmlHeader();
285 $namespaces = $prefixes =
array();
286 $this->
getNamespaces($namespaces, $a_entity, $a_schema_version);
287 $atts =
array(
"InstallationId" => IL_INST_ID,
288 "InstallationUrl" => ILIAS_HTTP_PATH,
"TopEntity" => $a_entity);
290 foreach ($namespaces as $entity => $ns) {
291 $prefix =
"ns" . $cnt;
292 $prefixes[$entity] = $prefix;
297 $this->ds_log->debug(
"Start writing Dataset, entity: " . $a_entity .
", schema version: " . $a_schema_version .
298 ", ids: " . print_r($a_ids,
true));
302 if (!$a_omit_types) {
303 $this->ds_log->debug(
"...write types");
304 $this->
addTypesXml($writer, $a_entity, $a_schema_version);
308 $this->ds_log->debug(
"...write records");
309 $this->
addRecordsXml($writer, $prefixes, $a_entity, $a_schema_version, $a_ids, $a_field);
317 return $writer->xmlDumpMem(
false);
327 public function addRecordsXml($a_writer, $a_prefixes, $a_entity, $a_schema_version, $a_ids, $a_field =
"")
329 $types = $this->
getXmlTypes($a_entity, $a_schema_version);
331 $this->ds_log->debug(
"...read data");
332 $this->
readData($a_entity, $a_schema_version, $a_ids, $a_field);
333 $this->ds_log->debug(
"...data: " . print_r($this->
data,
true));
334 if (is_array($this->
data)) {
335 foreach ($this->
data as
$d) {
336 $a_writer->xmlStartTag(
338 array(
"Entity" => $this->getXmlEntityName($a_entity, $a_schema_version))
342 $a_writer->xmlStartTag($this->getXmlEntityTag($a_entity, $a_schema_version));
344 $rec = $this->
getXmlRecord($a_entity, $a_schema_version, $d);
345 foreach ($rec as $f => $c) {
346 switch ($types[$f]) {
348 if ($this->absolute_export_dir !=
"" && $this->relative_export_dir !=
"") {
350 ilUtil::rCopy($c, $this->absolute_export_dir .
"/dsDir_" . $this->dircnt);
360 $a_writer->xmlElement($f,
array(), $c);
363 $a_writer->xmlEndTag($this->getXmlEntityTag($a_entity, $a_schema_version));
370 $this->ds_log->debug(
"...get dependencies");
371 $deps = $this->getDependencies($a_entity, $a_schema_version, $rec, $a_ids);
372 $this->ds_log->debug(
"...dependencies: " . print_r($deps,
true));
373 if (is_array($deps)) {
374 foreach ($deps as $dp => $par) {
375 $this->
addRecordsXml($a_writer, $a_prefixes, $dp, $a_schema_version, $par[
"ids"], $par[
"field"]);
379 } elseif ($this->
data ===
false) {
381 $this->ds_log->debug(
"...get dependencies (no record)");
382 $deps = $this->getDependencies($a_entity, $a_schema_version, null, $a_ids);
383 if (is_array($deps)) {
384 foreach ($deps as $dp => $par) {
385 $this->
addRecordsXml($a_writer, $a_prefixes, $dp, $a_schema_version, $par[
"ids"], $par[
"field"]);
406 private function addTypesXml($a_writer, $a_entity, $a_schema_version)
408 $types = $this->
getXmlTypes($a_entity, $a_schema_version);
411 if (is_array($types)) {
412 $a_writer->xmlStartTag(
414 array(
"Entity" => $this->getXmlEntityName($a_entity, $a_schema_version),
415 "SchemaVersion" => $a_schema_version)
417 foreach ($this->
getXmlTypes($a_entity, $a_schema_version) as $f =>
$t) {
418 $a_writer->xmlElement(
420 array(
"Name" => $f,
"Type" =>
$t)
427 $deps = $this->getDependencies($a_entity, $a_schema_version, null, null);
428 if (is_array($deps)) {
429 foreach ($deps as $dp =>
$w) {
430 $this->
addTypesXml($a_writer, $dp, $a_schema_version);
446 $namespaces[$a_entity] = $ns;
449 $deps = $this->getDependencies($a_entity, $a_schema_version, null, null);
450 if (is_array($deps)) {
451 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_") {
593 $parts = explode(
"_", $a_id);
594 $inst_id = $parts[1];
599 if (($inst_id == 0 || IL_INST_ID == 0) && !DEVMODE) {
600 return array(
"type"=>self::EXPORT_NO_INST_ID,
"id"=>$a_fallback_id);
604 if ($inst_id == IL_INST_ID) {
607 return array(
"type"=>self::EXPORT_ID_ILIAS_LOCAL,
"id"=>
$id);
611 return array(
"type"=>self::EXPORT_ID_ILIAS_LOCAL_INVALID,
"id"=>$a_fallback_id);
619 return array(
"type"=>self::EXPORT_ID_ILIAS_REMOTE,
"id"=>
$id);
623 return array(
"type"=>self::EXPORT_ID_ILIAS_REMOTE_INVALID,
"id"=>$a_fallback_id);
631 return array(
"type"=>self::EXPORT_ID,
"id"=>
$id);
633 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.
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
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
if(!array_key_exists('StateId', $_REQUEST)) $id
createObjectExportId($a_type, $a_id)
Build ilias export id.
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.
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
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...
static encode($mixed, $suppress_native=false)
const EXPORT_ID_ILIAS_LOCAL
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
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.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
getXmlTypes($a_entity, $a_version)
Get xml types.
setImport($a_val)
Set import object.
static getLogger($a_component_id)
Get component logger.
parseObjectExportId($a_id, $a_fallback_id=null)
Parse export id.
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.
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
addRecordsXml($a_writer, $a_prefixes, $a_entity, $a_schema_version, $a_ids, $a_field="")
Add records xml.
static _getIdForImportId($a_import_id)
get current object id for import id (static)