mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-24 10:44:45 +02:00

* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Files;
|
|
|
|
use App\Models\Server;
|
|
use App\Repositories\Daemon\DaemonFileRepository;
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
use Illuminate\Support\Str;
|
|
|
|
readonly class DeleteFilesService
|
|
{
|
|
public function __construct(
|
|
private DaemonFileRepository $daemonFileRepository
|
|
) {}
|
|
|
|
/**
|
|
* Deletes the given files.
|
|
*
|
|
* @param string[] $files
|
|
*
|
|
* @throws ConnectionException
|
|
*/
|
|
public function handle(Server $server, array $files): void
|
|
{
|
|
$filesToDelete = collect();
|
|
foreach ($files as $line) {
|
|
$path = dirname($line);
|
|
$pattern = basename($line);
|
|
collect($this->daemonFileRepository->setServer($server)->getDirectory($path))->each(function ($item) use ($path, $pattern, $filesToDelete) {
|
|
if (Str::is($pattern, $item['name'])) {
|
|
$filesToDelete->push($path . '/' . $item['name']);
|
|
}
|
|
});
|
|
}
|
|
|
|
if ($filesToDelete->isNotEmpty()) {
|
|
$this->daemonFileRepository->setServer($server)->deleteFiles('/', $filesToDelete->toArray());
|
|
}
|
|
}
|
|
}
|