From 575b3d4f7407ae76ac4fa5d083ae1389d919be63 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:29:38 +0300 Subject: [PATCH] removed not used `last_check_time` field (#375) Also drops no longer used field `api_scopes` from the DB Signed-off-by: Alexander Piskun --- lib/Db/ExApp.php | 6 --- lib/Db/ExAppMapper.php | 3 -- .../Version3200Date20240905080316.php | 38 +++++++++++++++++++ lib/Service/AppAPIService.php | 7 +--- lib/Service/ExAppService.php | 14 ++----- 5 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 lib/Migration/Version3200Date20240905080316.php diff --git a/lib/Db/ExApp.php b/lib/Db/ExApp.php index 13f087ad..9970b66c 100644 --- a/lib/Db/ExApp.php +++ b/lib/Db/ExApp.php @@ -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() @@ -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) @@ -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']); } @@ -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(), diff --git a/lib/Db/ExAppMapper.php b/lib/Db/ExAppMapper.php index 6b9d2ec6..6455c376 100644 --- a/lib/Db/ExAppMapper.php +++ b/lib/Db/ExAppMapper.php @@ -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' => [], @@ -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(); diff --git a/lib/Migration/Version3200Date20240905080316.php b/lib/Migration/Version3200Date20240905080316.php new file mode 100644 index 00000000..41b5b871 --- /dev/null +++ b/lib/Migration/Version3200Date20240905080316.php @@ -0,0 +1,38 @@ +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; + } +} diff --git a/lib/Service/AppAPIService.php b/lib/Service/AppAPIService.php index d09c2d34..cc391b36 100644 --- a/lib/Service/AppAPIService.php +++ b/lib/Service/AppAPIService.php @@ -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; @@ -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); } diff --git a/lib/Service/ExAppService.php b/lib/Service/ExAppService.php index 112336da..d3afdac7 100644 --- a/lib/Service/ExAppService.php +++ b/lib/Service/ExAppService.php @@ -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); @@ -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 { @@ -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(), ]; } @@ -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'); @@ -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 {