/** * Store an object in the database and remember the mapping * between its original ID and the newly created ID in the database */ protected function StoreObject($sClass, $oTargetObj, $iSrcId, $bSearch = false, $bUpdateKeyCacheOnly = false) { $iObjId = 0; try { if ($bSearch) { // Check if the object does not already exist, based on its usual reconciliation keys... $aReconciliationKeys = MetaModel::GetReconcKeys($sClass); if (count($aReconciliationKeys) > 0) { // Some reconciliation keys have been defined, use them to search for the object $oSearch = new DBObjectSearch($sClass); $iConditionsCount = 0; foreach ($aReconciliationKeys as $sAttCode) { if ($oTargetObj->Get($sAttCode) != '') { $oSearch->AddCondition($sAttCode, $oTargetObj->Get($sAttCode), '='); $iConditionsCount++; } } if ($iConditionsCount > 0) { $oSet = new DBObjectSet($oSearch); if ($oSet->count() == 1) { // The object already exists, reuse it $oExistingObject = $oSet->Fetch(); $iObjId = $oExistingObject->GetKey(); } } } } if ($iObjId == 0) { if ($oTargetObj->IsNew()) { if (!$bUpdateKeyCacheOnly) { $iObjId = $oTargetObj->DBInsertNoReload(); $this->m_iCountCreated++; } } else { $iObjId = $oTargetObj->GetKey(); if (!$bUpdateKeyCacheOnly) { $oTargetObj->DBUpdate(); } } } } catch (Exception $e) { SetupPage::log_error("An object could not be recorded - {$sClass}/{$iSrcId} - " . $e->getMessage()); $this->m_aErrors[] = "An object could not be recorded - {$sClass}/{$iSrcId} - " . $e->getMessage(); } $aParentClasses = MetaModel::EnumParentClasses($sClass); $aParentClasses[] = $sClass; foreach ($aParentClasses as $sObjClass) { $this->m_aKeys[$sObjClass][$iSrcId] = $iObjId; } $this->m_aObjectsCache[$sClass][$iObjId] = $oTargetObj; }
/** * Determine if the current user can be considered as being a portal power user */ function IsPowerUSer() { $iUserID = UserRights::GetUserId(); $sOQLprofile = "SELECT URP_Profiles AS p JOIN URP_UserProfile AS up ON up.profileid=p.id WHERE up.userid = :user AND p.name = :profile"; $oProfileSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQLprofile), array(), array('user' => $iUserID, 'profile' => PORTAL_POWER_USER_PROFILE)); $bRes = $oProfileSet->count() > 0; return $bRes; }
protected function DeleteConnectedNetworkDevice() { $iNetworkDeviceID = $this->Get('networkdevice_id'); $iDeviceID = $this->Get('connectableci_id'); $oDevice = MetaModel::GetObject('ConnectableCI', $this->Get('connectableci_id')); $sOQL = "SELECT lnkConnectableCIToNetworkDevice WHERE connectableci_id = :device AND networkdevice_id = :network AND network_port = :nwport AND device_port = :devport"; $oConnectionSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array('network' => $this->Get('connectableci_id'), 'device' => $this->Get('networkdevice_id'), 'devport' => $this->Get('network_port'), 'nwport' => $this->Get('device_port'))); $iAlreadyExist = $oConnectionSet->count(); if (get_class($oDevice) == 'NetworkDevice' && $iAlreadyExist != 0) { $oMyChange = MetaModel::NewObject("CMDBChange"); $oMyChange->Set("date", time()); if (UserRights::IsImpersonated()) { $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser()); } else { $sUserString = UserRights::GetUser(); } $oMyChange->Set("userinfo", $sUserString); $iChangeId = $oMyChange->DBInsert(); $oConnection = $oConnectionSet->Fetch(); $oConnection->DBDeleteTracked($oMyChange); } }