Skip to content

Commit

Permalink
Process an additional parameter on core update
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Aug 28, 2018
1 parent d1c8ca3 commit ecf5b70
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
10 changes: 9 additions & 1 deletion lib/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ public function __construct(array $urlParams = array()) {
IRepairStep::class . '::upgradeAppStoreApp',
function ($event) use ($listener) {
if ($event instanceof GenericEvent) {
$listener->upgradeAppStoreApp($event->getSubject());
try {
$isMajorUpdate = $event->getArgument('isMajorUpdate');
} catch (\InvalidArgumentException $e) {
$isMajorUpdate = false;
}
$listener->upgradeAppStoreApp(
$event->getSubject(),
$isMajorUpdate
);
}
}
);
Expand Down
9 changes: 6 additions & 3 deletions lib/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ public function __construct(MarketService $marketService) {
$this->marketService = $marketService;
}

public function upgradeAppStoreApp($app){
$updateVersion = $this->marketService->getAvailableUpdateVersion($app);
public function upgradeAppStoreApp($app, $isMajorUpdate) {
$updateVersion = $this->marketService->getAvailableUpdateVersion(
$app,
$isMajorUpdate
);
if ($updateVersion !== false) {
$this->marketService->updateApp($app);
$this->marketService->updateApp($app, $isMajorUpdate);
} else {
throw new AppUpdateNotFoundException();
}
Expand Down
20 changes: 17 additions & 3 deletions lib/MarketService.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,12 @@ public function isAppInstalled($appId) {
* Returns the version for the app if an update is available
*
* @param string $appId
* @param bool $isMajorUpdate are major app updates allowed
* @return bool|string
* @throws AppNotFoundException
* @throws AppNotInstalledException
*/
public function getAvailableUpdateVersion($appId) {
public function getAvailableUpdateVersion($appId, $isMajorUpdate = false) {
$info = $this->getInstalledAppInfo($appId);
if (is_null($info)) {
throw new AppNotInstalledException($this->l10n->t('App (%s) is not installed', $appId));
Expand All @@ -202,8 +203,15 @@ public function getAvailableUpdateVersion($appId) {
}
$releases = $marketInfo['releases'];
$currentVersion = (string) $info['version'];
$releases = array_filter($releases, function($r) use ($currentVersion) {
$releases = array_filter($releases, function($r) use ($currentVersion, $isMajorUpdate) {
$marketVersion = $r['version'];
$marketVersionMajor = $this->getMajorVersion($marketVersion);
$currentVersionMajor = $this->getMajorVersion($currentVersion);
if ($isMajorUpdate === false
&& $marketVersionMajor > $currentVersionMajor
) {
return false;
}
return version_compare($marketVersion, $currentVersion, '>');
});
usort($releases, function ($a, $b) {
Expand All @@ -215,6 +223,12 @@ public function getAvailableUpdateVersion($appId) {
return false;
}

public function getMajorVersion($version) {
$versionArray = \explode('.', $version);
return $versionArray[0];
}


public function getAppInfo($appId) {
$data = $this->getApps();
$data = array_filter($data, function($element) use ($appId) {
Expand Down Expand Up @@ -249,7 +263,7 @@ public function getInstalledAppInfo($appId) {
* @throws AppManagerException
* @throws AppNotInstalledException
*/
public function updateApp($appId) {
public function updateApp($appId, $isMajorUpdate = false) {
if (!$this->canInstall()) {
throw new \Exception("Installing apps is not supported because the app folder is not writable.");
}
Expand Down

0 comments on commit ecf5b70

Please sign in to comment.