<?php
namespace App\Updater; class NewVersion extends \App\Updater\Base { public function checkNextVersion() { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $msgs = new \App\MessagesCollector(); if (!\DB::isInsideTransaction()) { throw new \Exception("Must start a transaction before starting working with database"); } if ($this->getCurrentStatus() != 'START') { throw new \App\MessagesException($msgs->addError('Invalid current status')); } $versions = $this->getVersionsDetails(); if (!$versions) { $this->saveMessages($msgs->addInfo('There is no available version for this instance')); } else { $updaterCfg = \App\Config\UpdaterVars::getAdmin(); $currentBuild = $CFG['global']['application']['versionBuild']; $versions = array_filter($versions, function($value) use ($currentBuild) { return $value['build'] > $currentBuild; }); if (!$versions) { $this->saveMessages($msgs->addInfo('There is no available version for this instance')); } else { foreach ($versions as $key => $row) { $build[$key] = $row['build']; $idInstanceKit[$key] = $row['idInstanceKit']; } array_multisort($build, SORT_ASC, $idInstanceKit, SORT_DESC, $versions); $updaterCfg->set('status', 'AVAILABLE_VERSION'); $updaterCfg->set('currentBuild', $currentBuild); $updaterCfg->set('nextVersion', $versions[0]['version']); $updaterCfg->set('nextBuild', $versions[0]['build']); $updaterCfg->set('versionClosingDate', $versions[0]['closeDate']); $updaterCfg->set('requestTime', \Engine\DateTime::create()->formatDatetimeIso()); $updaterCfg->set('addTime', $versions[0]['addTime']); $updaterCfg->set('fileSize', $versions[0]['fileSize']); $updaterCfg->set('md5File', $versions[0]['md5File']); $updaterCfg->set('productVersionComments', $versions[0]['productVersionComments']); if ($versions[0]['productVersionPatchComments']) { $updaterCfg->set('productVersionPatchComments', $versions[0]['productVersionPatchComments']); } $updaterCfg->set('newIdInstanceKit', $versions[0]['idInstanceKit']); $updaterCfg->set('newIdProductVersionPatch', (String)$versions[0]['idProductVersionPatch']); $updaterCfg->delete('message'); $updaterCfg->save(); } } } }