diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 7e2df2d18bb8fd87e541e47869a35dd67713d4b2..87bcf4d060c4786af944b5923eb2b611c51d9aaa 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -403,6 +403,15 @@ private function parseSemVer($versionString) { $versionArray = explode(".", $versionString); + if(empty($versionArray[0])) { + $versionArray[0] = 0; + } + if(empty($versionArray[1])) { + $versionArray[1] = 0; + } + if(empty($versionArray[2])) { + $versionArray[2] = 0; + } return array_map("intval", $versionArray); } @@ -532,9 +541,9 @@ * @param type $params The params dictionary inside the current POST request * @return boolean True if valid, False if not. */ - public function includeInResults($params) + public function includeInResults($params, $currenteOSVersion) { - return $this->isValid($params) && $this->checkRollout() && $this->getSize() > 0; + return $this->isValid($params) && $this->checkRollout() && $this->checkRequirements($currenteOSVersion) && $this->getSize() > 0; } /** @@ -555,10 +564,36 @@ return ($configFilePath) ? json_decode( file_get_contents($configFilePath) , true) : array(); } + /** + * Return if requirements are met or not for a build + * @return boolean + */ + public function checkRequirements($currenteOSVersion="") + { + $minimalVersion = isset($this->confProp['requirements']) ? $this->confProp['requirements']['minOSVersion'] : null; + $isCompatible = true; + if(isset($minimalVersion)){ + $currenteOSVersionSemantic = $this->parseSemVer($currenteOSVersion); + $minimalSemanticVersion = $this->parseSemVer($minimalVersion); + $isCompatible = false; + if($currenteOSVersionSemantic[0] == $minimalSemanticVersion[0]){ + if($currenteOSVersionSemantic[1] == $minimalSemanticVersion[1]){ + $isCompatible = $currenteOSVersionSemantic[2] >= $minimalSemanticVersion[2]; + } + else + $isCompatible = $currenteOSVersionSemantic[1] > $minimalSemanticVersion[1]; + } + else + $isCompatible = $currenteOSVersionSemantic[0] > $minimalSemanticVersion[0]; + } + return $isCompatible; + } + /** * Return if rollout successful or not for a build * @return boolean */ + public function checkRollout() { $rolloutpercentage = isset($this->confProp['rollout']['percentage']) ? (int) $this->confProp['rollout']['percentage'] : 100; diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index 0c8d8e53cf45e7f0178ebd8609cb341e882a7996..b7e84b44fa29272fa8258344d052ec0b1f65b7a9 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -162,6 +162,7 @@ $params = $this->postData['params']; preg_match_all('/.*(eOS) v([0-9\.]+)-?((alpha|beta|rc)(\.\d)?)?.*/', $_SERVER['HTTP_USER_AGENT'], $currentTokens); $shouldDisplayPatch=false; + $this->currenteOSVersion = -1; if(isset($currentTokens[2]) && count($currentTokens[2])>0){ $this->currenteOSVersion = $currentTokens[2][0]; $versionArray = explode(".", $this->currenteOSVersion); @@ -204,7 +205,7 @@ $build = new Build($file, $dir, $this->logger, $shouldDisplayPatch); } - if ($build->includeInResults($this->postData['params'])) { + if ($build->includeInResults($this->postData['params'], $this->currenteOSVersion)) { array_push($this->builds, $build); }