Exemplo n.º 1
0
 /**
  * @param $id
  * @param $type
  *
  * @return bool|int
  */
 protected function buildRef($id, $type)
 {
     if ($type == 'reference_id') {
         if (!ilObjOrgUnit::_exists($id, true)) {
             return false;
         }
         return $id;
     } elseif ($type == 'external_id') {
         $obj_id = ilObject::_lookupObjIdByImportId($id);
         if (!ilObject::_hasUntrashedReference($obj_id)) {
             return false;
         }
         $ref_ids = ilObject::_getAllReferences($obj_id);
         if (!count($ref_ids)) {
             return false;
         }
         foreach ($ref_ids as $ref_id) {
             if (!ilObject::_isInTrash($ref_id)) {
                 return $ref_id;
             }
         }
         return false;
     } else {
         return false;
     }
 }
 protected function buildRef($id, $type)
 {
     if ($type == "reference_id") {
         if (!ilObjOrgUnit::_exists($id, true)) {
             return false;
         }
         return $id;
     } elseif ($type == "external_id") {
         $obj_id = ilObject::_lookupObjIdByImportId($id);
         $ref_ids = ilObject::_getAllReferences($obj_id);
         if (!count($ref_ids)) {
             return false;
         }
         return array_shift($ref_ids);
     } else {
         return false;
     }
 }
 function removeFromSystemByImportId($sid, $import_id)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!strlen($import_id)) {
         return $this->__raiseError('No import id given. Aborting!', 'Client');
     }
     global $rbacsystem, $tree, $ilLog;
     // get obj_id
     if (!($obj_id = ilObject::_lookupObjIdByImportId($import_id))) {
         return $this->__raiseError('No object found with import id: ' . $import_id, 'Client');
     }
     // Check access
     $permission_ok = false;
     foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
         if ($rbacsystem->checkAccess('delete', $ref_id)) {
             $permission_ok = true;
             break;
         }
     }
     if (!$permission_ok) {
         return $this->__raiseError('No permission to delete the object with import id: ' . $import_id, 'Server');
     }
     // Delete all references (delete permssions and entries in object_reference)
     foreach ($ref_ids as $ref_id) {
         // All subnodes
         $node_data = $tree->getNodeData($ref_id);
         $subtree_nodes = $tree->getSubtree($node_data);
         foreach ($subtree_nodes as $node) {
             $ilLog->write('Soap: removeFromSystemByImportId(). Deleting object with title id: ' . $node['title']);
             $tmp_obj = ilObjectFactory::getInstanceByRefId($node['ref_id']);
             if (!is_object($tmp_obj)) {
                 return $this->__raiseError('Cannot create instance of reference id: ' . $node['ref_id'], 'Server');
             }
             $tmp_obj->delete();
         }
         // Finally delete tree
         $tree->deleteTree($node_data);
     }
     return true;
 }
 protected function initRole($import_id)
 {
     if ($this->getRole()) {
         return true;
     }
     $obj_id = ilObject::_lookupObjIdByImportId($import_id);
     include_once './Services/Object/classes/class.ilObjectFactory.php';
     if ($obj_id) {
         $this->role = ilObjectFactory::getInstanceByObjId($obj_id, false);
     }
     if (!$this->getRole() instanceof ilObjRole or !$this->getRole() instanceof ilObjRoleTemplate) {
         include_once './Services/AccessControl/classes/class.ilObjRoleTemplate.php';
         $this->role = new ilObjRoleTemplate();
     }
     return true;
 }
Exemplo n.º 5
0
 static final function _lookupObjIdByImportId($a_import_id)
 {
     return parent::_lookupObjIdByImportId($a_import_id);
 }
 /** 
  * Called from base class after successful login
  *
  * @param string username
  */
 public function loginObserver($a_username, $a_auth)
 {
     include_once './Services/WebServices/ECS/classes/class.ilECSUser.php';
     $user = new ilECSUser($_GET);
     if (!($usr_id = ilObject::_lookupObjIdByImportId($user->getImportId()))) {
         $username = $this->createUser($user);
     } else {
         $username = $this->updateUser($user, $usr_id);
     }
     // set user imported
     include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
     $import = new ilECSImport($this->getCurrentServer()->getServerId(), $usr_id);
     $import->save();
     $a_auth->setAuth($username);
     $this->log->write(__METHOD__ . ': Login succesesful');
     return true;
 }
Exemplo n.º 7
0
 /** 
  * Called from base class after successful login
  *
  * @param string username
  */
 public function loginObserver($a_username, $a_auth)
 {
     include_once './Services/WebServices/ECS/classes/class.ilECSUser.php';
     $user = new ilECSUser($_GET);
     if (!($usr_id = ilObject::_lookupObjIdByImportId($user->getImportId()))) {
         $username = $this->createUser($user);
     } else {
         $username = $this->updateUser($user, $usr_id);
     }
     // set user imported
     include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
     $import = new ilECSImport($this->getCurrentServer()->getServerId(), $usr_id);
     $import->save();
     // Store remote user data
     include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
     $remote = new ilECSRemoteUser();
     $remote->setServerId($this->getCurrentServer()->getServerId());
     $remote->setMid($this->getMID());
     $remote->setRemoteUserId($user->getImportId());
     $remote->setUserId(ilObjUser::_lookupId($username));
     $GLOBALS['ilLog']->write(__METHOD__ . ': Current username ' . $username);
     if (!$remote->exists()) {
         $remote->create();
     }
     $a_auth->setAuth($username);
     $this->log->write(__METHOD__ . ': Login succesesful');
     return true;
 }
 public function simpleImportElement(SimpleXMLElement $o)
 {
     global $tree, $tpl, $ilUser;
     $title = $o->title;
     $description = $o->description;
     $external_id = $o->external_id;
     $create_mode = true;
     $attributes = $o->attributes();
     $action = (string) $attributes->action;
     $ou_id = (string) $attributes->ou_id;
     $ou_id_type = (string) $attributes->ou_id_type;
     $ou_parent_id = (string) $attributes->ou_parent_id;
     $ou_parent_id_type = (string) $attributes->ou_parent_id_type;
     if ($ou_id == ilObjOrgUnit::getRootOrgRefId()) {
         $this->addWarning("cannot_change_root_node", $ou_id ? $ou_id : $external_id, $action);
         return;
     }
     if ($ou_parent_id == "__ILIAS") {
         $ou_parent_id = ilObjOrgUnit::getRootOrgRefId();
         $ou_parent_id_type = "reference_id";
     }
     $ref_id = $this->buildRef($ou_id, $ou_id_type);
     $parent_ref_id = $this->buildRef($ou_parent_id, $ou_parent_id_type);
     if ($action == "delete") {
         if (!$parent_ref_id) {
             $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         if (!$ref_id) {
             $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         include_once "./Services/Repository/classes/class.ilRepUtil.php";
         $ru = new ilRepUtil($this);
         try {
             $ru->deleteObjects($parent_ref_id, array($ref_id)) !== false;
             $this->stats["deleted"]++;
         } catch (Excpetion $e) {
             $this->addWarning("orgu_already_deleted", $ou_id ? $ou_id : $external_id, $action);
         }
         return;
     } elseif ($action == "update") {
         if (!$parent_ref_id) {
             $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         if (!$ref_id) {
             $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         $object = new ilObjOrgUnit($ref_id);
         $object->setTitle($title);
         $arrTranslations = $object->getTranslations();
         $object->updateTranslation($title, $description, $ilUser->getLanguage(), "");
         $object->setDescription($description);
         $object->update();
         $object->setImportId($external_id);
         if ($parent_ref_id != $tree->getParentId($ref_id)) {
             try {
                 $tree->moveTree($ref_id, $parent_ref_id);
             } catch (Exception $e) {
                 global $ilLog;
                 $this->addWarning("not_movable", $ou_id ? $ou_id : $external_id, $action);
                 $ilLog->write($e->getMessage() . "\\n" . $e->getTraceAsString());
             }
         }
         $this->stats["updated"]++;
     } elseif ($action == "create") {
         if (!$parent_ref_id) {
             $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         if ($external_id) {
             $obj_id = ilObject::_lookupObjIdByImportId($external_id);
             if (ilObject::_hasUntrashedReference($obj_id)) {
                 $this->addError("ou_external_id_exists", $ou_id ? $ou_id : $external_id, $action);
                 return;
             }
         }
         $object = new ilObjOrgUnit();
         $object->setTitle($title);
         $object->setDescription($description);
         $object->setImportId($external_id);
         $object->create();
         $object->createReference();
         $object->putInTree($parent_ref_id);
         $object->setPermissions($ou_parent_id);
         $this->stats["created"]++;
     } else {
         $this->addError("no_valid_action_given", $ou_id, $action);
     }
 }
Exemplo n.º 9
0
 public function testSetGetLookup()
 {
     global $ilUser;
     $obj = new ilObject();
     $obj->setType("");
     // otherwise type check will fail
     $obj->setTitle("TestObject");
     $obj->setDescription("TestDescription");
     $obj->setImportId("imp_44");
     $obj->create();
     $obj->createReference();
     $id = $obj->getId();
     $ref_id = $obj->getRefId();
     $obj = new ilObject($id, false);
     if ($obj->getType() == "") {
         $value .= "sg1-";
     }
     if ($obj->getTitle() == "TestObject") {
         $value .= "sg2-";
     }
     if ($obj->getDescription() == "TestDescription") {
         $value .= "sg3-";
     }
     if ($obj->getImportId() == "imp_44") {
         $value .= "sg4-";
     }
     if ($obj->getOwner() == $ilUser->getId()) {
         $value .= "sg5-";
     }
     $obj = new ilObject($ref_id);
     if ($obj->getTitle() == "TestObject") {
         $value .= "sg6-";
     }
     if ($obj->getCreateDate() == ($lu = $obj->getLastUpdateDate())) {
         $value .= "sg7-";
     }
     $obj->setTitle("TestObject2");
     sleep(2);
     // we want a different date here...
     $obj->update();
     $obj = new ilObject($ref_id);
     if ($lu != ($lu2 = $obj->getLastUpdateDate())) {
         $value .= "up1-";
     }
     if ($obj->getTitle() == "TestObject2") {
         $value .= "up2-";
     }
     if ($id == ilObject::_lookupObjIdByImportId("imp_44")) {
         $value .= "lu1-";
     }
     if ($ilUser->getFullname() == ilObject::_lookupOwnerName(ilObject::_lookupOwner($id))) {
         $value .= "lu2-";
     }
     if (ilObject::_lookupTitle($id) == "TestObject2") {
         $value .= "lu3-";
     }
     if (ilObject::_lookupDescription($id) == "TestDescription") {
         $value .= "lu4-";
     }
     if (ilObject::_lookupLastUpdate($id) == $lu2) {
         $value .= "lu5-";
     }
     if (ilObject::_lookupObjId($ref_id) == $id) {
         $value .= "lu6-";
     }
     if (ilObject::_lookupType($id) == "") {
         $value .= "lu7-";
     }
     if (ilObject::_lookupObjectId($ref_id) == $id) {
         $value .= "lu8-";
     }
     $ar = ilObject::_getAllReferences($id);
     if (is_array($ar) && count($ar) == 1 && $ar[$ref_id] == $ref_id) {
         $value .= "lu9-";
     }
     $ids = ilObject::_getIdsForTitle("TestObject2");
     foreach ($ids as $i) {
         if ($i == $id) {
             $value .= "lu10-";
         }
     }
     $obs = ilObject::_getObjectsByType("usr");
     foreach ($obs as $ob) {
         if ($ob["obj_id"] == $ilUser->getId()) {
             $value .= "lu11-";
         }
     }
     $d1 = ilObject::_lookupDeletedDate($ref_id);
     ilObject::_setDeletedDate($ref_id);
     $d2 = ilObject::_lookupDeletedDate($ref_id);
     ilObject::_resetDeletedDate($ref_id);
     $d3 = ilObject::_lookupDeletedDate($ref_id);
     if ($d1 != $d2 && $d1 == $d3 && $d3 == null) {
         $value .= "dd1-";
     }
     $obj->delete();
     $this->assertEquals("sg1-sg2-sg3-sg4-sg5-sg6-sg7-up1-up2-" . "lu1-lu2-lu3-lu4-lu5-lu6-lu7-lu8-lu9-lu10-lu11-dd1-", $value);
 }