diff --git a/config/services.yaml b/config/services.yaml index 38d3aa23..b59e8008 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -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 diff --git a/src/Controller/CustomerAppAPI/AppController.php b/src/Controller/CustomerAppAPI/AppController.php index c78eba43..553036dd 100644 --- a/src/Controller/CustomerAppAPI/AppController.php +++ b/src/Controller/CustomerAppAPI/AppController.php @@ -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, ]); }