🔨 N°5779 update-xml : if XML files already at current version, tries to convert from previous one

This commit is contained in:
Pierre Goiffon
2022-12-08 16:32:34 +01:00
parent 7f88a6aa1a
commit 3270c3f775
4 changed files with 112 additions and 8 deletions

View File

@@ -202,6 +202,13 @@ class DatamodelsXmlFiles extends AbstractGlobFileVersionUpdater
$oFileXml->loadXML($sFileContent);
$oFileItopFormat = new iTopDesignFormat($oFileXml);
$sDesignVersionToSet = static::GetDesignVersionToSet($oFileItopFormat->GetVersion());
if (false === is_null($sDesignVersionToSet)) {
// N°5779 if same as target version, we will try to convert from version below
$oFileItopFormat->GetITopDesignNode()->setAttribute('version', $sDesignVersionToSet);
}
$bConversionResult = $oFileItopFormat->Convert($sVersionLabel);
if (false === $bConversionResult) {
@@ -210,4 +217,16 @@ class DatamodelsXmlFiles extends AbstractGlobFileVersionUpdater
return $oFileItopFormat->GetXmlAsString();
}
/**
* @return ?string version to use : if file version is same as current version then return previous version, else return null
* @since 3.1.0 N°5779
*/
protected static function GetDesignVersionToSet($sFileDesignVersion):?string {
if ($sFileDesignVersion !== ITOP_DESIGN_LATEST_VERSION) {
return null;
}
return iTopDesignFormat::GetPreviousDesignVersion(ITOP_DESIGN_LATEST_VERSION);
}
}