mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 00:58:48 +02:00
N°5559 - Prevent obsolete replica to lock iTop object (#376)
* N°5559 prevent obsolete replica to lock iTop object * N°5559 - new config param for ignoring obsolete replica * N°5559 - new config param for ignoring obsolete replica (2)
This commit is contained in:
@@ -449,7 +449,7 @@ JS
|
||||
$bCanBeDeletedByTask = false;
|
||||
$bCanBeDeletedByUser = true;
|
||||
$aMasterSources = array();
|
||||
$aSyncData = $this->GetSynchroData();
|
||||
$aSyncData = $this->GetSynchroData(MetaModel::GetConfig()->Get('synchro_obsolete_replica_locks_object'));
|
||||
if (count($aSyncData) > 0) {
|
||||
foreach ($aSyncData as $iSourceId => $aSourceData) {
|
||||
$oDataSource = $aSourceData['source'];
|
||||
|
||||
@@ -456,7 +456,7 @@ class Config
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
],
|
||||
'log_filename_builder_impl' => [
|
||||
'log_filename_builder_impl' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Name of the iLogFileNameBuilder to use',
|
||||
'default' => 'MonthlyRotatingLogFileNameBuilder',
|
||||
@@ -464,39 +464,47 @@ class Config
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
],
|
||||
'log_rest_service' => [
|
||||
'type' => 'bool',
|
||||
'description' => 'Log the usage of the REST/JSON service',
|
||||
'default' => false,
|
||||
'value' => false,
|
||||
'source_of_value' => '',
|
||||
'log_rest_service' => [
|
||||
'type' => 'bool',
|
||||
'description' => 'Log the usage of the REST/JSON service',
|
||||
'default' => false,
|
||||
'value' => false,
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
],
|
||||
'synchro_trace' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Synchronization details: none, display, save (includes \'display\')',
|
||||
'default' => 'none',
|
||||
'value' => 'none',
|
||||
'source_of_value' => '',
|
||||
'synchro_trace' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Synchronization details: none, display, save (includes \'display\')',
|
||||
'default' => 'none',
|
||||
'value' => 'none',
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => true,
|
||||
],
|
||||
'link_set_item_separator' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Link set from string: line separator',
|
||||
'default' => '|',
|
||||
'value' => '|',
|
||||
'source_of_value' => '',
|
||||
'synchro_obsolete_replica_locks_object' => [
|
||||
'type' => 'bool',
|
||||
'description' => 'Obsolete synchro replicas prevent object modification by any mean (eg. anonymization)',
|
||||
'default' => 'true',
|
||||
'value' => '',
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => true,
|
||||
],
|
||||
'link_set_attribute_separator' => [
|
||||
'type' => 'string',
|
||||
'link_set_item_separator' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Link set from string: line separator',
|
||||
'default' => '|',
|
||||
'value' => '|',
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => true,
|
||||
],
|
||||
'link_set_attribute_separator' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Link set from string: attribute separator',
|
||||
'default' => ';',
|
||||
'value' => ';',
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => true,
|
||||
],
|
||||
'link_set_value_separator' => [
|
||||
'link_set_value_separator' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Link set from string: value separator (between the attcode and the value itself',
|
||||
'default' => ':',
|
||||
|
||||
@@ -5063,28 +5063,27 @@ abstract class DBObject implements iDisplay
|
||||
* @throws \MySQLException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function GetSynchroData()
|
||||
public function GetSynchroData($bIncludeObsolete = true)
|
||||
{
|
||||
if (is_null($this->m_aSynchroData))
|
||||
{
|
||||
if (is_null($this->m_aSynchroData)) {
|
||||
$sOQL = "SELECT replica,datasource FROM SynchroReplica AS replica JOIN SynchroDataSource AS datasource ON replica.sync_source_id=datasource.id WHERE replica.dest_class = :dest_class AND replica.dest_id = :dest_id";
|
||||
if (!$bIncludeObsolete) {
|
||||
$sOQL .= " AND replica.status != 'obsolete'";
|
||||
}
|
||||
$oReplicaSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array() /* order by*/, array('dest_class' => get_class($this), 'dest_id' => $this->GetKey()));
|
||||
$this->m_aSynchroData = array();
|
||||
while($aData = $oReplicaSet->FetchAssoc())
|
||||
{
|
||||
while ($aData = $oReplicaSet->FetchAssoc()) {
|
||||
/** @var \DBObject[] $aData */
|
||||
$iSourceId = $aData['datasource']->GetKey();
|
||||
if (!array_key_exists($iSourceId, $this->m_aSynchroData))
|
||||
{
|
||||
if (!array_key_exists($iSourceId, $this->m_aSynchroData)) {
|
||||
$aAttributes = array();
|
||||
$oAttrSet = $aData['datasource']->Get('attribute_list');
|
||||
while($oSyncAttr = $oAttrSet->Fetch())
|
||||
{
|
||||
while ($oSyncAttr = $oAttrSet->Fetch()) {
|
||||
/** @var \DBObject $oSyncAttr */
|
||||
$aAttributes[$oSyncAttr->Get('attcode')] = $oSyncAttr;
|
||||
}
|
||||
$this->m_aSynchroData[$iSourceId] = array(
|
||||
'source' => $aData['datasource'],
|
||||
'source' => $aData['datasource'],
|
||||
'attributes' => $aAttributes,
|
||||
'replica' => array()
|
||||
);
|
||||
@@ -5113,18 +5112,15 @@ abstract class DBObject implements iDisplay
|
||||
public function GetSynchroReplicaFlags($sAttCode, &$aReason)
|
||||
{
|
||||
$iFlags = OPT_ATT_NORMAL;
|
||||
foreach ($this->GetSynchroData() as $iSourceId => $aSourceData)
|
||||
{
|
||||
if ($iSourceId == SynchroExecution::GetCurrentTaskId())
|
||||
{
|
||||
foreach ($this->GetSynchroData(MetaModel::GetConfig()->Get('synchro_obsolete_replica_locks_object')) as $iSourceId => $aSourceData) {
|
||||
if ($iSourceId == SynchroExecution::GetCurrentTaskId()) {
|
||||
// Ignore the current task (check to write => ok)
|
||||
continue;
|
||||
}
|
||||
// Assumption: one replica - take the first one!
|
||||
$oReplica = reset($aSourceData['replica']);
|
||||
$oSource = $aSourceData['source'];
|
||||
if (array_key_exists($sAttCode, $aSourceData['attributes']))
|
||||
{
|
||||
if (array_key_exists($sAttCode, $aSourceData['attributes'])) {
|
||||
/** @var \DBObject $oSyncAttr */
|
||||
$oSyncAttr = $aSourceData['attributes'][$sAttCode];
|
||||
if (($oSyncAttr->Get('update') == 1) && ($oSyncAttr->Get('update_policy') == 'master_locked'))
|
||||
|
||||
Reference in New Issue
Block a user