2025-11-02 17:11:24 +00:00
|
|
|
<?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');
|
2025-11-02 17:11:24 +00:00
|
|
|
$scriptPath = data_get($data, 'scriptPath');
|
2025-11-17 09:05:18 +00:00
|
|
|
$containerTmpPath = data_get($data, 'containerTmpPath');
|
2025-11-02 17:11:24 +00:00
|
|
|
$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-02 17:11:24 +00:00
|
|
|
}
|
|
|
|
|
|
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-02 17:11:24 +00:00
|
|
|
}
|
2025-11-17 09:05:18 +00:00
|
|
|
|
2025-11-17 13:13:10 +00:00
|
|
|
$server = Server::find($serverId);
|
|
|
|
|
if ($server) {
|
|
|
|
|
instant_remote_process($commands, $server, throwError: false);
|
|
|
|
|
}
|
2025-11-02 17:11:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|