44 public const DATASET_NS =
'http://www.ilias.de/Services/DataSet/ds/4_3';
54 protected \ILIAS\ResourceStorage\Services
$irss;
74 $this->db =
$DIC->database();
76 $this->irss =
$DIC->resourceStorage();
91 final public function init(
string $a_entity,
string $a_schema_version): void
93 $this->entity = $a_entity;
94 $this->schema_version = $a_schema_version;
95 $this->data = array();
107 abstract protected function getTypes(
string $a_entity,
string $a_version): array;
109 abstract protected function getXmlNamespace(
string $a_entity,
string $a_schema_version): string;
123 $this->export = $xml_exporter->
getExport();
128 $this->import_directory = $a_val;
138 $this->ds_prefix = $a_val;
160 bool $a_convert_to_leading_upper =
true,
165 $set =
$ilDB->query($a_query);
166 $this->data = array();
168 while ($rec =
$ilDB->fetchAssoc($set)) {
169 if ($a_convert_to_leading_upper) {
171 foreach ($rec as $k => $v) {
179 $this->data[] = $rec;
191 $a_str = strtoupper(substr($a_str, 0, 1)) . substr($a_str, 1);
192 while (($pos = strpos($a_str,
"_")) !==
false) {
193 $a_str = substr($a_str, 0, $pos) .
194 strtoupper(substr($a_str, $pos + 1, 1)) .
195 substr($a_str, $pos + 2);
224 string $a_schema_version,
226 string $a_field =
"",
227 bool $a_omit_header =
false,
228 bool $a_omit_types =
false
234 if (!$a_omit_header) {
235 $writer->xmlHeader();
239 $namespaces = $prefixes = array();
240 $this->getNamespaces($namespaces, $a_entity, $a_schema_version);
242 "InstallationUrl" => ILIAS_HTTP_PATH,
"TopEntity" => $a_entity);
244 foreach ($namespaces as $entity => $ns) {
245 $prefix =
"ns" . $cnt;
246 $prefixes[$entity] = $prefix;
250 $this->ds_log->debug(
"Start writing Dataset, entity: " . $a_entity .
", schema version: " . $a_schema_version .
251 ", ids: " . print_r($a_ids,
true));
253 if ($this->getDSPrefix() !==
'') {
254 $atts[
'xmlns:' . $this->getDSPrefix()] = self::DATASET_NS;
256 $atts[
'xmlns'] = self::DATASET_NS;
258 $writer->xmlStartTag($this->getDSPrefixString() .
'DataSet', $atts);
260 if (!$a_omit_types) {
261 $this->ds_log->debug(
"...write types");
262 $this->addTypesXml($writer, $a_entity, $a_schema_version);
265 $this->ds_log->debug(
"...write records");
266 $this->addRecordsXml($writer, $prefixes, $a_entity, $a_schema_version, $a_ids, $a_field);
268 $writer->xmlEndTag($this->getDSPrefixString() .
"DataSet");
270 return $writer->xmlDumpMem(
false);
281 if (str_contains($exp_dir,
"components/")) {
282 $exp_dir = substr($exp_dir, strpos($exp_dir,
"components/"));
291 string $a_schema_version,
293 ?
string $a_field =
""
295 $types = $this->getXmlTypes($a_entity, $a_schema_version);
296 $this->ds_log->debug(
"...read data");
297 $this->readData($a_entity, $a_schema_version, $a_ids);
298 $this->ds_log->debug(
"...data: " . print_r($this->data,
true));
299 foreach ($this->data as
$d) {
301 $this->getDSPrefixString() .
"Rec",
302 array(
"Entity" => $this->getXMLEntityName($a_entity, $a_schema_version))
304 $a_writer->
xmlStartTag($this->getXMLEntityTag($a_entity,
''));
305 $rec = $this->getXmlRecord($a_entity, $a_schema_version,
$d);
306 foreach ($rec as
$f =>
$c) {
307 if (isset($this->export) and ($types[
$f] ??
"") ===
"directory") {
308 $sdir = realpath(
$c);
309 $path_in_container = $this->export->getPathToComponentExpDirInContainer() .
"/dsDir_" . $this->dircnt;
310 $this->export->getExportWriter()->writeDirectory(
314 $c = $this->getExportDirInContainer($path_in_container);
317 if (isset($this->export) and ($types[
$f] ??
"") ===
"rscollection") {
318 $path_in_container = $this->export->getPathToComponentExpDirInContainer() .
"/dsDir_" . $this->dircnt;
319 $collection = $this->getCollection($rec, $a_entity, $a_schema_version,
$f,
$c);
320 if (!is_null($collection)) {
321 $this->export->getExportWriter()->writeFilesByResourceCollection(
327 $c = $this->getExportDirInContainer($path_in_container);
330 if (isset($this->export) and ($types[
$f] ??
"") ===
"rscontainer") {
331 $path_in_container =
"/dsDir_" . $this->dircnt;
332 if ($this->export->isContainerExport()) {
333 $path_in_container = $this->export->getPathToComponentExpDirInContainerWithLeadingSetNumber() . $path_in_container;
335 $path_in_container = $this->export->getPathToComponentExpDirInContainer() . $path_in_container;
337 if ($config = $this->getContainerExportConfig($rec, $a_entity, $a_schema_version,
$f,
$c)) {
338 $this->export->getExportWriter()->writeFilesByResourceContainer(
339 $this->getIRSSContainerExportConfig(
340 $config->getSourceContainer(),
341 $config->getSourcePath(),
346 $c = $this->getExportDirInContainer($path_in_container);
355 $a_writer->
xmlEndTag($this->getXMLEntityTag($a_entity,
''));
357 $a_writer->
xmlEndTag($this->getDSPrefixString() .
"Rec");
359 $this->afterXmlRecordWriting($a_entity, $a_schema_version,
$d);
362 $this->ds_log->debug(
"...get dependencies");
363 $deps = $this->getDependencies($a_entity, $a_schema_version, $rec, $a_ids);
364 $this->ds_log->debug(
"...dependencies: " . print_r($deps,
true));
365 foreach ($deps as $dp => $par) {
366 $ids = !is_array($par[
"ids"])
369 $this->addRecordsXml($a_writer, $a_prefixes, $dp, $a_schema_version, $ids, $par[
"field"] ??
null);
377 string $target_path =
""
389 ?array $a_rec =
null,
403 $types = $this->getXmlTypes($a_entity, $a_schema_version);
406 if (count($types) > 0) {
408 $this->getDSPrefixString() .
"Types",
409 array(
"Entity" => $this->getXMLEntityName($a_entity, $a_schema_version),
410 "SchemaVersion" => $a_schema_version)
412 foreach ($this->getXmlTypes($a_entity, $a_schema_version) as
$f => $t) {
414 $this->getDSPrefixString() .
'FieldType',
415 array(
"Name" =>
$f,
"Type" => $t)
418 $a_writer->
xmlEndTag($this->getDSPrefixString() .
"Types");
422 $deps = $this->getDependencies($a_entity, $a_schema_version,
null,
null);
423 foreach ($deps as $dp => $w) {
424 $this->addTypesXml($a_writer, $dp, $a_schema_version);
429 public function getNamespaces(array &$namespaces,
string $a_entity,
string $a_schema_version): void
431 $ns = $this->getXmlNamespace($a_entity, $a_schema_version);
433 $namespaces[$a_entity] = $ns;
436 $deps = $this->getDependencies($a_entity, $a_schema_version,
null,
null);
437 foreach ($deps as $dp => $w) {
438 $this->getNamespaces($namespaces, $dp, $a_schema_version);
446 public function getXmlRecord(
string $a_entity,
string $a_version, array $a_set): array
455 public function getXmlTypes(
string $a_entity,
string $a_version): array
457 return $this->getTypes($a_entity, $a_version);
474 return $this->convertToLeadingUpper($a_entity);
479 $this->
import = $a_val;
484 return $this->import;
489 $this->current_installation_id = $a_val;
494 return $this->current_installation_id;
502 return "il_" .
IL_INST_ID .
"_" . $a_type .
"_" . $a_id;
512 if (strpos($a_id,
"il_") === 0) {
513 $parts = explode(
"_", $a_id);
514 if (count(
$parts) !== 4) {
515 throw new ilException(
"Invalid import ID '" . $a_id .
"'.");
522 if (($inst_id == 0 ||
IL_INST_ID ===
"0") && !DEVMODE) {
523 return array(
"type" => self::EXPORT_NO_INST_ID,
"id" => $a_fallback_id);
530 return array(
"type" => self::EXPORT_ID_ILIAS_LOCAL,
"id" =>
$id);
534 return array(
"type" => self::EXPORT_ID_ILIAS_LOCAL_INVALID,
"id" => $a_fallback_id);
542 return array(
"type" => self::EXPORT_ID_ILIAS_REMOTE,
"id" =>
$id);
546 return array(
"type" => self::EXPORT_ID_ILIAS_REMOTE_INVALID,
"id" => $a_fallback_id);
553 return array(
"type" => self::EXPORT_ID,
"id" =>
$id);
555 return array(
"type" => self::EXPORT_ID_INVALID,
"id" => $a_fallback_id);
568 string $a_schema_version
572 public function getCollection(
575 string $schema_version,
585 string $schema_version,
592 protected function stripTags(array $rec, array $omit_keys = []): array
595 foreach ($rec as $k => $v) {
596 if (in_array($k, $omit_keys,
true)) {
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class ResourceCollection.
Class ResourceIdentification.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
const EXPORT_ID_ILIAS_REMOTE_INVALID
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
getXMLEntityName(string $a_entity, string $a_version)
Get entity name for xml (may be overwritten)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
ILIAS ResourceStorage Services $irss
stripTags(array $rec, array $omit_keys=[])
getIRSSContainerExportConfig(StorableResource $source_container, string $source_path, string $target_path="")
convertToLeadingUpper(string $a_str)
Make xyz_abc a XyzAbc string.
addRecordsXml(ilXmlWriter $a_writer, array $a_prefixes, string $a_entity, string $a_schema_version, array $a_ids, ?string $a_field="")
getXmlTypes(string $a_entity, string $a_version)
Get xml types.
const EXPORT_ID_ILIAS_LOCAL_INVALID
getContainerExportConfig(array $record, string $entity, string $schema_version, string $field, string $value)
getNamespaces(array &$namespaces, string $a_entity, string $a_schema_version)
string $current_installation_id
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
setDSPrefix(string $a_val)
init(string $a_entity, string $a_schema_version)
Init.
parseObjectExportId(string $a_id, ?string $a_fallback_id=null)
Parse export id.
createObjectExportId(string $a_type, string $a_id)
Build ilias export id.
addTypesXml(ilXmlWriter $a_writer, string $a_entity, string $a_schema_version)
getCurrentInstallationId()
string $component_export_dir
getXmlRepresentation(string $a_entity, string $a_schema_version, ?array $a_ids, string $a_field="", bool $a_omit_header=false, bool $a_omit_types=false)
Get xml representation <dataset install_id="123" install_url="..."> <types entity="table_name" versio...
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
const EXPORT_ID_ILIAS_REMOTE
getXmlNamespace(string $a_entity, string $a_schema_version)
getXMLEntityTag(string $a_entity, string $a_schema_version)
Get entity tag.
initByExporter(ilXmlExporter $xml_exporter)
setImport(ilSurveyImporter $a_val)
afterXmlRecordWriting(string $a_entity, string $a_version, array $a_set)
setImportDirectory(string $a_val)
const EXPORT_ID_ILIAS_LOCAL
setCurrentInstallationId(string $a_val)
getXmlRecord(string $a_entity, string $a_version, array $a_set)
Get xml record for version.
getExportDirInContainer(string $exp_dir)
Base class for ILIAS Exception handling.
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static _lookupType(int $id, bool $reference=false)
static _getIdForImportId(string $import_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface StorageResource.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts