Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed not used last_check_time field #375

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/Db/ExApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @method array getStatus()
* @method int getEnabled()
* @method int getCreatedTime()
* @method int getLastCheckTime()
* @method array getDeployConfig()
* @method string getAcceptsDeployId()
* @method array getRoutes()
Expand All @@ -38,7 +37,6 @@
* @method void setStatus(array $status)
* @method void setEnabled(int $enabled)
* @method void setCreatedTime(int $createdTime)
* @method void setLastCheckTime(int $lastCheckTime)
* @method void setDeployConfig(array $deployConfig)
* @method void setAcceptsDeployId(string $acceptsDeployId)
* @method void setRoutes(array $routes)
Expand Down Expand Up @@ -116,9 +114,6 @@ public function __construct(array $params = []) {
if (isset($params['created_time'])) {
$this->setCreatedTime($params['created_time']);
}
if (isset($params['last_check_time'])) {
$this->setLastCheckTime($params['last_check_time']);
}
if (isset($params['deploy_config'])) {
$this->setDeployConfig($params['deploy_config']);
}
Expand All @@ -144,7 +139,6 @@ public function jsonSerialize(): array {
'status' => $this->getStatus(),
'enabled' => $this->getEnabled(),
'created_time' => $this->getCreatedTime(),
'last_check_time' => $this->getLastCheckTime(),
'deploy_config' => $this->getDeployConfig(),
'accepts_deploy_id' => $this->getAcceptsDeployId(),
'routes' => $this->getRoutes(),
Expand Down
3 changes: 0 additions & 3 deletions lib/Db/ExAppMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ private function buildExAppWithRoutes(array $result): array {
'status' => $row['status'],
'enabled' => $row['enabled'],
'created_time' => $row['created_time'],
'last_check_time' => $row['last_check_time'],
'deploy_config' => $row['deploy_config'],
'accepts_deploy_id' => $row['accepts_deploy_id'],
'routes' => [],
Expand Down Expand Up @@ -181,8 +180,6 @@ public function updateExApp(ExApp $exApp, array $fields): int {
$qb = $qb->set('status', $qb->createNamedParameter($exApp->getStatus(), IQueryBuilder::PARAM_JSON));
} elseif ($field === 'enabled') {
$qb = $qb->set('enabled', $qb->createNamedParameter($exApp->getEnabled(), IQueryBuilder::PARAM_INT));
} elseif ($field === 'last_check_time') {
$qb = $qb->set('last_check_time', $qb->createNamedParameter($exApp->getLastCheckTime(), IQueryBuilder::PARAM_INT));
}
}
return $qb->where($qb->expr()->eq('appid', $qb->createNamedParameter($exApp->getAppid())))->executeStatement();
Expand Down
38 changes: 38 additions & 0 deletions lib/Migration/Version3200Date20240905080316.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\AppAPI\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version3200Date20240905080316 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('ex_apps');
if ($table->hasColumn('last_check_time')) {
$table->dropColumn('last_check_time');
}
if ($table->hasColumn('api_scopes')) {
$table->dropColumn('api_scopes');
}

return $schema;
}
}
7 changes: 2 additions & 5 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,7 @@ public function enableExApp(ExApp $exApp): bool {
$exAppEnabled = $this->requestToExApp($exApp, '/enabled?enabled=1', null, 'PUT', options: ['timeout' => 30]);
if ($exAppEnabled instanceof IResponse) {
$response = json_decode($exAppEnabled->getBody(), true);
if (empty($response['error'])) {
$this->exAppService->updateExApp($exApp, ['last_check_time']);
} else {
if (!empty($response['error'])) {
$this->logger->error(sprintf('Failed to enable ExApp %s. Error: %s', $exApp->getAppid(), $response['error']));
$this->exAppService->disableExAppInternal($exApp);
return false;
Expand Down Expand Up @@ -633,8 +631,7 @@ public function setAppInitProgress(ExApp $exApp, int $progress, string $error =
$status['type'] = '';
}
$exApp->setStatus($status);
$exApp->setLastCheckTime(time());
$this->exAppService->updateExApp($exApp, ['status', 'last_check_time']);
$this->exAppService->updateExApp($exApp, ['status']);
if ($progress === 100) {
$this->enableExApp($exApp);
}
Expand Down
14 changes: 4 additions & 10 deletions lib/Service/ExAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function registerExApp(array $appInfo): ?ExApp {
'secret' => $appInfo['secret'],
'status' => json_encode(['deploy' => 0, 'init' => 0, 'action' => '', 'type' => 'install', 'error' => '']),
'created_time' => time(),
'last_check_time' => time(),
]);
try {
$this->exAppMapper->insert($exApp);
Expand Down Expand Up @@ -152,14 +151,12 @@ public function enableExAppInternal(ExApp $exApp): bool {
$status = $exApp->getStatus();
$status['error'] = '';
$exApp->setStatus($status);
$exApp->setLastCheckTime(time());
return $this->updateExApp($exApp, ['enabled', 'status', 'last_check_time']);
return $this->updateExApp($exApp, ['enabled', 'status']);
}

public function disableExAppInternal(ExApp $exApp): void {
$exApp->setEnabled(0);
$exApp->setLastCheckTime(time());
$this->updateExApp($exApp, ['enabled', 'last_check_time']);
$this->updateExApp($exApp, ['enabled']);
}

public function getExAppsByDaemonName(string $daemonName): array {
Expand Down Expand Up @@ -191,7 +188,6 @@ public function formatExAppInfo(ExApp $exApp): array {
'name' => $exApp->getName(),
'version' => $exApp->getVersion(),
'enabled' => filter_var($exApp->getEnabled(), FILTER_VALIDATE_BOOLEAN),
'last_check_time' => $exApp->getLastCheckTime(),
'status' => $exApp->getStatus(),
];
}
Expand All @@ -211,7 +207,7 @@ public function updateExAppInfo(ExApp $exApp, array $appInfo): bool {
return true;
}

public function updateExApp(ExApp $exApp, array $fields = ['version', 'name', 'port', 'status', 'enabled', 'last_check_time']): bool {
public function updateExApp(ExApp $exApp, array $fields = ['version', 'name', 'port', 'status', 'enabled']): bool {
try {
$this->exAppMapper->updateExApp($exApp, $fields);
$this->cache?->remove('/ex_apps');
Expand Down Expand Up @@ -335,13 +331,11 @@ public function setAppDeployProgress(ExApp $exApp, int $progress, string $error
}
$status['deploy'] = $progress;
}
unset($status['active']); # TO-DO: Remove in AppAPI 2.4.0
if ($progress === 100) {
$status['action'] = 'healthcheck';
}
$exApp->setStatus($status);
$exApp->setLastCheckTime(time());
$this->updateExApp($exApp, ['status', 'last_check_time']);
$this->updateExApp($exApp, ['status']);
}

public function waitInitStepFinish(string $appId): string {
Expand Down
Loading