Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions core/restclient.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,29 @@ protected static function ExecOperation($aOperation, $sVersion = '1.0')
return $aResults;
}

public static function GetNewestKnownVersion()
{
$sNewestVersion = '1.0';

/**
* Gets the iTop API version in use. It tries all the known versions, starting from the newest one.
*
* @return void
* @throws Exception If no supported version is found.
*/
public static function GetNewestKnownVersion() {

$oC = new RestClient();
$aKnownVersions = array('1.0', '1.1', '1.2', '2.0');
// Order: Put the newest versions first.
$aKnownVersions = array('1.4', '1.3', '1.2', '1.1', '1.0');
foreach ($aKnownVersions as $sVersion) {
$oC->SetVersion($sVersion);
$aRet = $oC->ListOperations();
if ($aRet['code'] == 0) {
// Supported version
$sNewestVersion = $sVersion;
// A non-error code (0) means the version is supported.
return $sVersion;
}
}

return $sNewestVersion;
throw new Exception("No supported iTop API version found (tried: ".implode(', ', $aKnownVersions).")");

}

/**
Expand Down