coolify/app/Events/S3RestoreJobFinished.php

59 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace App\Events;
use App\Models\Server;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class S3RestoreJobFinished
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct($data)
{
2025-11-17 09:05:18 +00:00
$containerName = data_get($data, 'containerName');
$serverTmpPath = data_get($data, 'serverTmpPath');
$scriptPath = data_get($data, 'scriptPath');
2025-11-17 09:05:18 +00:00
$containerTmpPath = data_get($data, 'containerTmpPath');
$container = data_get($data, 'container');
$serverId = data_get($data, 'serverId');
2025-11-17 09:05:18 +00:00
// Clean up helper container and temporary files
if (filled($serverId)) {
$commands = [];
// Stop and remove helper container
if (filled($containerName)) {
$commands[] = "docker rm -f {$containerName} 2>/dev/null || true";
}
// Clean up downloaded file from server /tmp
if (isSafeTmpPath($serverTmpPath)) {
$commands[] = "rm -f {$serverTmpPath} 2>/dev/null || true";
}
// Clean up script from server
if (isSafeTmpPath($scriptPath)) {
$commands[] = "rm -f {$scriptPath} 2>/dev/null || true";
}
2025-11-17 09:05:18 +00:00
// Clean up files from database container
if (filled($container)) {
if (isSafeTmpPath($containerTmpPath)) {
$commands[] = "docker exec {$container} rm -f {$containerTmpPath} 2>/dev/null || true";
}
if (isSafeTmpPath($scriptPath)) {
$commands[] = "docker exec {$container} rm -f {$scriptPath} 2>/dev/null || true";
}
}
2025-11-17 09:05:18 +00:00
$server = Server::find($serverId);
if ($server) {
instant_remote_process($commands, $server, throwError: false);
}
}
}
}