Update BackupResource.php

This commit is contained in:
Bozhidar 2024-05-16 11:47:19 +03:00
parent 19044ca3f5
commit 8bd55a3156

View file

@ -106,12 +106,26 @@ class BackupResource extends Resource
Tables\Actions\Action::make('cancel')
->icon('heroicon-o-x-mark')
->hidden(function (Backup $backup) {
return $backup->status !== BackupStatus::Processing;
})
// ->hidden(function (Backup $backup) {
// return $backup->status !== BackupStatus::Processing;
// })
->action(function (Backup $backup) {
try {
$processIds = shell_exec('ps aux | grep -i ' . $backup->file_name . ' | grep -v grep | awk \'{print $2}\'');
if (!empty($processIds)) {
$processIds = explode("\n", $processIds);
foreach ($processIds as $processId) {
$processId = trim($processId);
if (!empty($processId)) {
shell_exec('kill -9 ' . $processId);
}
}
}
shell_exec('kill -9 ' . $backup->process_id);
} catch (\Exception $e) {
// do nothing
}
$backup->update([
'status' => BackupStatus::Cancelled,