28 $this->stats = array(
"created" => 0,
"updated" => 0,
"deleted" => 0);
29 $a = file_get_contents($file_path,
"r");
30 $xml =
new SimpleXMLElement(
$a);
32 if (!count(
$xml->OrgUnit)) {
37 foreach (
$xml->OrgUnit as $o) {
46 $title = (string) $o->title;
47 $description = (
string) $o->description;
48 $external_id = (string) $o->external_id;
55 $ou_parent_id_type = (string)
$attributes->ou_parent_id_type;
58 $this->
addWarning(
"cannot_change_root_node", $ou_id ? $ou_id : $external_id, $action);
63 if ($ou_parent_id ==
"__ILIAS") {
65 $ou_parent_id_type =
"reference_id";
69 if ($ou_id_type ==
'external_id') {
70 if (strlen($external_id) == 0) {
71 $external_id = $ou_id;
75 $this->
addError(
"ou_more_than_one_match_found", $external_id, $action);
82 $parent_ref_id = $this->
buildRef($ou_parent_id, $ou_parent_id_type);
84 if ($action ==
"delete") {
85 if (!$parent_ref_id) {
86 $this->
addError(
"ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
91 $this->
addError(
"ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
97 $ru->deleteObjects($parent_ref_id, array(
$ref_id)) !==
false;
98 $this->stats[
"deleted"]++;
100 $this->
addWarning(
"orgu_already_deleted", $ou_id ? $ou_id : $external_id, $action);
104 } elseif ($action ==
"update") {
105 if (!$parent_ref_id) {
106 $this->
addError(
"ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
111 $this->
addError(
"ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
116 $object->setTitle($title);
118 $object->updateTranslation($title, $description,
$ilUser->getLanguage(),
"");
120 $object->setDescription($description);
122 $object->setImportId($external_id);
125 $this->stats[
"updated"]++;
126 } elseif ($action ==
"create") {
127 if (!$parent_ref_id) {
128 $this->
addError(
"ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
135 $this->
addError(
"ou_external_id_exists", $ou_id ? $ou_id : $external_id, $action);
141 $object->setTitle($title);
142 $object->setDescription($description);
143 $object->setImportId($external_id);
145 $object->createReference();
146 $object->putInTree($parent_ref_id);
147 $object->setPermissions($parent_ref_id);
148 $this->stats[
"created"]++;
150 $this->
addError(
"no_valid_action_given", $ou_id, $action);
158 protected function moveObject(
int $ref_id,
int $parent_ref_id,
string $ou_id,
string $external_id)
161 $tree = $DIC[
'tree'];
162 if ($parent_ref_id != $tree->getParentId($ref_id)) {
164 $path = $tree->getPathId($parent_ref_id);
165 if (in_array($ref_id,
$path)) {
166 $this->
addWarning(
"not_movable_to_subtree", $ou_id ? $ou_id : $external_id,
"update");
168 $tree->moveTree($ref_id, $parent_ref_id);
172 $ilLog = $DIC[
'ilLog'];
173 $this->
addWarning(
"not_movable", $ou_id ? $ou_id : $external_id,
"update");
174 $ilLog->write($e->getMessage() .
"\\n" . $e->getTraceAsString());
175 error_log($e->getMessage() .
"\\n" . $e->getTraceAsString());
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
hasMoreThanOneMatch(string $external_id)
buildRef($id, string $type)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
moveObject(int $ref_id, int $parent_ref_id, string $ou_id, string $external_id)
simpleImportElement(SimpleXMLElement $o)
static _lookupType(int $id, bool $reference=false)
simpleImport(string $file_path)
addError(string $lang_var, string $import_id, ?string $action=null)
addWarning(string $lang_var, string $import_id, ?string $action=null)