Files
nextcloud-app-api/lib/Migration/DaemonUpdateV2RepairStep.php
Andrey Borysenko 3bf5132211 feat: Test deploy feature (#279)
This PR introduces a "Test deploy" button for each Daemon configuration
to verify each step and identify the error.

Resolves: https://github.com/cloud-py-api/app_api/issues/174

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
2024-04-29 13:36:32 +03:00

72 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\AppAPI\Migration;
use OCA\AppAPI\Db\DaemonConfig;
use OCA\AppAPI\Db\DaemonConfigMapper;
use OCP\DB\Exception;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Psr\Log\LoggerInterface;
class DaemonUpdateV2RepairStep implements IRepairStep {
public function __construct(
private readonly DaemonConfigMapper $daemonConfigMapper,
private readonly LoggerInterface $logger,
) {
}
public function getName(): string {
return 'AppAPI 2.5.0 Daemons configuration update';
}
public function run(IOutput $output): void {
$daemons = $this->daemonConfigMapper->findAll();
$daemonsUpdated = 0;
// Update manual-install daemons
/** @var DaemonConfig $daemon */
foreach ($daemons as $daemon) {
$daemonsUpdated += $this->updateDaemonConfiguration($daemon);
}
$output->info(sprintf('Daemons configurations updated to V2.5.0: %s', $daemonsUpdated));
}
private function updateDaemonConfiguration(DaemonConfig $daemonConfig): int {
$updated = false;
if ($daemonConfig->getAcceptsDeployId() === 'manual-install') {
if ($daemonConfig->getProtocol() == 0) {
$daemonConfig->setProtocol('http');
$updated = true;
}
if ($daemonConfig->getHost() == 0) {
$daemonConfig->setHost('host.docker.internal');
$updated = true;
}
}
if ($daemonConfig->getAcceptsDeployId() === 'docker-install') {
if ($daemonConfig->getProtocol() === 'unix-socket') {
$daemonConfig->setProtocol('http');
$updated = true;
}
}
if ($updated) {
try {
$this->daemonConfigMapper->update($daemonConfig);
return 1;
} catch (Exception $e) {
$this->logger->error(
sprintf('Failed to update Daemon config (%s: %s)',
$daemonConfig->getAcceptsDeployId(), $daemonConfig->getName()),
['exception' => $e]
);
return 0;
}
}
return 0;
}
}