public function DoCheckToWrite() { parent::DoCheckToWrite(); // Check that there is at least one reconciliation key defined if ($this->Get('reconciliation_policy') == 'use_attributes') { $oSet = $this->Get('attribute_list'); $oSynchroAttributeList = $oSet->ToArray(); $bReconciliationKey = false; foreach ($oSynchroAttributeList as $oSynchroAttribute) { if ($oSynchroAttribute->Get('reconcile') == 1) { $bReconciliationKey = true; // At least one key is defined break; } } if (!$bReconciliationKey) { $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:AtLeastOneReconciliationKeyMustBeSpecified'); } } // If 'update_then_delete' is specified there must be a delete_retention_period if ($this->Get('delete_policy') == 'update_then_delete' && $this->Get('delete_policy_retention') == 0) { $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:DeleteRetentionDurationMustBeSpecified'); } // If update is specified, then something to update must be defined if (($this->Get('delete_policy') == 'update_then_delete' || $this->Get('delete_policy') == 'update') && $this->Get('delete_policy_update') == '') { $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:DeletePolicyUpdateMustBeSpecified'); } // When creating the data source with a specified database_table_name, this table must NOT exist if ($this->IsNew()) { $sDataTable = $this->GetDataTable(); if (!empty($sDataTable) && CMDBSource::IsTable($this->GetDataTable())) { // Hmm, the synchro_data_xxx table already exists !! $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:DataTableAlreadyExists', $this->GetDataTable()); } } }
public function DoCheckToWrite() { parent::DoCheckToWrite(); // Note: This MUST be factorized later: declare unique keys (set of columns) in the data model $aChanges = $this->ListChanges(); if (array_key_exists('login', $aChanges)) { if (strcasecmp($this->Get('login'), $this->GetOriginal('login')) !== 0) { $sNewLogin = $aChanges['login']; $oSearch = DBObjectSearch::FromOQL_AllData("SELECT User WHERE login = :newlogin"); if (!$this->IsNew()) { $oSearch->AddCondition('id', $this->GetKey(), '!='); } $oSet = new DBObjectSet($oSearch, array(), array('newlogin' => $sNewLogin)); if ($oSet->Count() > 0) { $this->m_aCheckIssues[] = Dict::Format('Class:User/Error:LoginMustBeUnique', $sNewLogin); } } } // Check that this user has at least one profile assigned $oSet = $this->Get('profile_list'); if ($oSet->Count() == 0) { $this->m_aCheckIssues[] = Dict::Format('Class:User/Error:AtLeastOneProfileIsNeeded'); } }