vito/app/SiteTypes/AbstractSiteType.php
Dimitar Yanakiev 97e20206e8
ite Commands (#298) (#519)
* feat: Implement Site Commands (#298)

- Introduced a Commands widget/table for Site view, allowing users to create, edit, delete, and execute commands.
- Each Site Type now has a predefined set of commands inserted upon site creation.
- A migration script ensures commands are created for existing sites.
- Implemented necessary policies for command management.
- Added feature tests to validate functionality.

* I'm trying to fix the tests, but it seems like it might not work. I'm having trouble running the tests locally for some reason.

* I'm trying to fix the tests, but it seems like it might not work. I'm having trouble running the tests locally for some reason.

* I'm trying to fix the tests, but it seems like it might not work. I'm having trouble running the tests locally for some reason.

* I'm trying to fix the tests, but it seems like it might not work. I'm having trouble running the tests locally for some reason.

* Remove feature tests for commands due to inconsistencies for now

* fixes

* add tests for commands

* ui fix and add to wordpress

---------

Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
2025-03-02 10:43:26 +01:00

95 lines
2.1 KiB
PHP
Executable File

<?php
namespace App\SiteTypes;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\SSHError;
use App\Models\Site;
use App\SSH\Services\PHP\PHP;
use Illuminate\Support\Str;
abstract class AbstractSiteType implements SiteType
{
protected Site $site;
public function __construct(Site $site)
{
$this->site = $site;
}
public function createRules(array $input): array
{
return [];
}
public function createFields(array $input): array
{
return [];
}
public function data(array $input): array
{
return [];
}
public function editRules(array $input): array
{
return $this->createRules($input);
}
public function baseCommands(): array
{
return [];
}
protected function progress(int $percentage): void
{
$this->site->progress = $percentage;
$this->site->save();
}
/**
* @throws FailedToDeployGitKey
* @throws SSHError
*/
protected function deployKey(): void
{
$os = $this->site->server->os();
$os->generateSSHKey($this->site->getSshKeyName(), $this->site);
$this->site->ssh_key = $os->readSSHKey($this->site->getSshKeyName(), $this->site);
$this->site->save();
$this->site->sourceControl?->provider()?->deployKey(
$this->site->domain.'-key-'.$this->site->id,
$this->site->repository,
$this->site->ssh_key
);
}
/**
* @throws SSHError
*/
protected function isolate(): void
{
if (! $this->site->isIsolated()) {
return;
}
$this->site->server->os()->createIsolatedUser(
$this->site->user,
Str::random(15),
$this->site->id
);
// Generate the FPM pool
if ($this->site->php_version) {
/** @var PHP $php */
$php = $this->site->php()->handler();
$php->createFpmPool(
$this->site->user,
$this->site->php_version,
$this->site->id
);
}
}
}