/** * Helper to remove selected objects without calling any handler * Surpasses BulkDelete as it can handle abstract classes, but has the other limitation as it bypasses standard objects handlers * * @param string $oFilter Scope of objects to wipe out * @return The count of deleted objects */ public static function PurgeData($oFilter) { $sTargetClass = $oFilter->GetClass(); $oSet = new DBObjectSet($oFilter); $oSet->OptimizeColumnLoad(array($sTargetClass => array('finalclass'))); $aIdToClass = $oSet->GetColumnAsArray('finalclass', true); $aIds = array_keys($aIdToClass); if (count($aIds) > 0) { $aQuotedIds = CMDBSource::Quote($aIds); $sIdList = implode(',', $aQuotedIds); $aTargetClasses = array_merge(self::EnumChildClasses($sTargetClass, ENUM_CHILD_CLASSES_ALL), self::EnumParentClasses($sTargetClass, ENUM_PARENT_CLASSES_EXCLUDELEAF)); foreach ($aTargetClasses as $sSomeClass) { $sTable = MetaModel::DBGetTable($sSomeClass); $sPKField = MetaModel::DBGetKey($sSomeClass); $sDeleteSQL = "DELETE FROM `{$sTable}` WHERE `{$sPKField}` IN ({$sIdList})"; CMDBSource::DeleteFrom($sDeleteSQL); } } return count($aIds); }
protected function GetObjectActionGrant($oUser, $sClass, $iActionCode, $oObject = null) { if (is_null($oObject)) { $iObjectRef = -999; } else { $iObjectRef = $oObject->GetKey(); } // load and cache permissions for the current user on the given object // $aTest = @$this->m_aObjectActionGrants[$oUser->GetKey()][$sClass][$iObjectRef][$iActionCode]; if (is_array($aTest)) { return $aTest; } $sAction = self::$m_aActionCodes[$iActionCode]; $iInstancePermission = UR_ALLOWED_NO; $aAttributes = array(); foreach ($this->GetMatchingProfiles($oUser, $sClass, $oObject) as $iProfile) { $oGrantRecord = $this->GetClassActionGrant($iProfile, $sClass, $sAction); if (is_null($oGrantRecord)) { continue; // loop to the next profile } else { $iInstancePermission = UR_ALLOWED_YES; // update the list of attributes with those allowed for this profile // $oSearch = DBObjectSearch::FromOQL_AllData("SELECT URP_AttributeGrant WHERE actiongrantid = :actiongrantid"); $oSet = new DBObjectSet($oSearch, array(), array('actiongrantid' => $oGrantRecord->GetKey())); $aProfileAttributes = $oSet->GetColumnAsArray('attcode', false); if (count($aProfileAttributes) == 0) { $aAllAttributes = array_keys(MetaModel::ListAttributeDefs($sClass)); $aAttributes = array_merge($aAttributes, $aAllAttributes); } else { $aAttributes = array_merge($aAttributes, $aProfileAttributes); } } } $aRes = array('permission' => $iInstancePermission, 'attributes' => $aAttributes); $this->m_aObjectActionGrants[$oUser->GetKey()][$sClass][$iObjectRef][$iActionCode] = $aRes; return $aRes; }
public static function GetCreationForm($sOQL = null, $sTableSettings = null) { $oForm = new DesignerForm(); // Find a unique default name // -> The class of the query + an index if necessary if ($sOQL == null) { $sDefault = ''; } else { $oBMSearch = new DBObjectSearch('Shortcut'); $oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '='); $oBMSet = new DBObjectSet($oBMSearch); $aNames = $oBMSet->GetColumnAsArray('name'); $oSearch = DBObjectSearch::FromOQL($sOQL); $sDefault = utils::MakeUniqueName($oSearch->GetClass(), $aNames); } $oField = new DesignerTextField('name', Dict::S('Class:Shortcut/Attribute:name'), $sDefault); $oField->SetMandatory(true); $oForm->AddField($oField); /* $oField = new DesignerComboField('auto_reload', Dict::S('Class:ShortcutOQL/Attribute:auto_reload'), 'none'); $oAttDef = MetaModel::GetAttributeDef(__class__, 'auto_reload'); $oField->SetAllowedValues($oAttDef->GetAllowedValues()); $oField->SetMandatory(true); $oForm->AddField($oField); */ $oField = new DesignerBooleanField('auto_reload', Dict::S('Class:ShortcutOQL/Attribute:auto_reload'), false); $oForm->AddField($oField); $oField = new DesignerTextField('auto_reload_sec', Dict::S('Class:ShortcutOQL/Attribute:auto_reload_sec'), MetaModel::GetConfig()->GetStandardReloadInterval()); $oField->SetValidationPattern('^$|^0*([5-9]|[1-9][0-9]+)$'); // Can be empty, or a number > 4 $oField->SetMandatory(false); $oForm->AddField($oField); $oField = new DesignerHiddenField('oql', '', $sOQL); $oForm->AddField($oField); $oField = new DesignerHiddenField('table_settings', '', $sTableSettings); $oForm->AddField($oField); return $oForm; }