SupervisorMaker new

This commit is contained in:
salam committed 2026-02-19 14:10:20 +01:00
1 parent e7814b4ddd
commit 35f1dae5e3
17 files changed
+21 -74

No files matched your search

+20 -14
View File
@@ -4,6 +4,7 @@ namespace App\Actions;
use App\Models\Supervisor;
use App\Utilities\Notice;
use Illuminate\Filesystem\Filesystem;
class SupervisorMaker
{
@@ -15,23 +16,32 @@ class SupervisorMaker
{
$supervisors = Supervisor::all();
$path = base_path().'/supervisor/nuh';
if (! is_dir($path)) {
mkdir($path, 0777);
}
$file = new Filesystem;
$file->cleanDirectory($path);
foreach ($supervisors as $supervisor) {
$dirname = self::fix_string($supervisor->provider->name);
$path = base_path().'/supervisor/'.strtolower($dirname);
if (! is_dir($path)) {
mkdir($path, 0777);
$parts = [];
$parts[] = 'p'.$supervisor->id;
$parts[] = $supervisor->sport->name ?? 'all';
$parts[] = self::fix_string($supervisor->provider->name);
if ($supervisor->name) {
$parts[] = self::fix_string($supervisor->name);
}
$sport = self::fix_string($supervisor->sport?->name) ?? 'all';
$process = 'p'.$supervisor->id.'_'.self::fix_string($supervisor->name).'_'.$sport;
if ($supervisor->days_to) {
$process .= '_'.$supervisor->days_from;
$process .= '_'.$supervisor->days_to;
$parts[] = 'day'.$supervisor->days_from;
$parts[] = 'day'.$supervisor->days_to;
}
$process = strtolower(implode('_', $parts));
$content = '[program:'.$process.']'.PHP_EOL;
if ($supervisor->commandline_options != '') {
$content .= 'command=/usr/bin/php '.base_path().'/artisan nuh '.$supervisor->id.' '.$supervisor->commandline_options.PHP_EOL;
@@ -45,10 +55,6 @@ class SupervisorMaker
if ($supervisor->is_active && $supervisor->is_supervisor) {
file_put_contents($file, $content);
chmod($file, 0777);
} else {
if (is_file($file)) {
unlink($file);
}
}
}