Update apiv2 app version check to include OS #746

This commit is contained in:
Ramon Gutierrez 2023-08-02 16:37:29 +08:00
parent e212e2d29a
commit f3992f05fc
2 changed files with 15 additions and 9 deletions

View file

@ -13,6 +13,8 @@ parameters:
cvu_brand_id: "%env(CVU_BRAND_ID)%"
country_code: "%env(COUNTRY_CODE)%"
api_version: "%env(API_VERSION)%"
android_app_version: "%env(ANDROID_APP_VERSION)%"
ios_app_version: "%env(IOS_APP_VERSION)%"
services:
# default configuration for services in *this* file

View file

@ -12,6 +12,7 @@ class AppController extends ApiController
// validate params
$missing = $this->hasMissingParams($req, [
'version',
'os',
]);
if ($missing) {
@ -21,21 +22,23 @@ class AppController extends ApiController
$need_update = false;
$msg = 'Version is up to date.';
$api_version = $this->getParameter('api_version');
$app_version = $req->query->get('version');
// putting this in for the future, in case we have diverging versions
$os = $req->query->get('os');
$platform = $req->query->get('platform');
$api_v = explode('.', $api_version);
$app_v = explode('.', $app_version);
// putting this in for the future, in case we have diverging versions
//$platform = $req->query->get('platform');
if ($api_v[0] < $app_v[0]) {
// get only the major version numbers
$app_version = $req->query->get('version');
$app_major = substr($app_version, 0, strripos($app_version, "."));
$latest_version = $this->getParameter($os . '_app_version');
$latest_major = substr($latest_version, 0, strripos($latest_version, "."));
if ($latest_major < $app_major) {
return new ApiResponse(false, 'Invalid application version: ' . $app_version);
}
if ($api_v[0] > $app_v[0]) {
if ($latest_major > $app_major) {
$need_update = true;
$msg = 'Your version is outdated and needs an update to use the latest features RES-Q has to offer.';
}
@ -43,6 +46,7 @@ class AppController extends ApiController
// response
return new ApiResponse(true, '', [
'need_update' => $need_update,
'latest_version' => $latest_version,
'message' => $msg,
]);
}