mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
init
This commit is contained in:
58
app/Jobs/PHP/InstallPHPExtension.php
Executable file
58
app/Jobs/PHP/InstallPHPExtension.php
Executable file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\PHP;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Exceptions\ProcessFailed;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Service;
|
||||
use App\SSHCommands\InstallPHPExtensionCommand;
|
||||
use Illuminate\Support\Str;
|
||||
use Throwable;
|
||||
|
||||
class InstallPHPExtension extends Job
|
||||
{
|
||||
protected Service $service;
|
||||
|
||||
protected string $name;
|
||||
|
||||
public function __construct(Service $service, string $name)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ProcessFailed
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$result = $this->service->server->ssh()->exec(
|
||||
new InstallPHPExtensionCommand($this->service->version, $this->name),
|
||||
'install-php-extension'
|
||||
);
|
||||
$result = Str::substr($result, strpos($result, '[PHP Modules]'));
|
||||
if (! Str::contains($result, $this->name)) {
|
||||
throw new ProcessFailed('Extension failed');
|
||||
}
|
||||
$typeData = $this->service->type_data;
|
||||
$typeData['extensions'][] = $this->name;
|
||||
$this->service->type_data = $typeData;
|
||||
$this->service->save();
|
||||
event(
|
||||
new Broadcast('install-php-extension-finished', [
|
||||
'service' => $this->service,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
event(
|
||||
new Broadcast('install-php-extension-failed', [
|
||||
'service' => $this->service,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
46
app/Jobs/PHP/SetDefaultCli.php
Normal file
46
app/Jobs/PHP/SetDefaultCli.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\PHP;
|
||||
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Service;
|
||||
use App\SSHCommands\ChangeDefaultPHPCommand;
|
||||
use Throwable;
|
||||
|
||||
class SetDefaultCli extends Job
|
||||
{
|
||||
protected Service $service;
|
||||
|
||||
public function __construct(Service $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
new ChangeDefaultPHPCommand($this->service->version),
|
||||
'change-default-php'
|
||||
);
|
||||
$this->service->server->defaultService('php')->update(['is_default' => 0]);
|
||||
$this->service->update(['is_default' => 1]);
|
||||
$this->service->update(['status' => ServiceStatus::READY]);
|
||||
event(
|
||||
new Broadcast('set-default-cli-finished', [
|
||||
'defaultPHP' => $this->service->server->defaultService('php'),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
event(new Broadcast('set-default-cli-failed', [
|
||||
'defaultPHP' => $this->service->server->defaultService('php'),
|
||||
]));
|
||||
}
|
||||
}
|
58
app/Jobs/PHP/UpdatePHPSettings.php
Executable file
58
app/Jobs/PHP/UpdatePHPSettings.php
Executable file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\PHP;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Service;
|
||||
use App\SSHCommands\UpdatePHPSettingsCommand;
|
||||
use Throwable;
|
||||
|
||||
class UpdatePHPSettings extends Job
|
||||
{
|
||||
protected Service $service;
|
||||
|
||||
protected array $settings;
|
||||
|
||||
public function __construct(Service $service, array $settings)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$commands = [];
|
||||
foreach ($this->settings as $key => $value) {
|
||||
$commands[] = new UpdatePHPSettingsCommand(
|
||||
$this->service->version,
|
||||
$key,
|
||||
$value.' '.config('core.php_settings_unit')[$key]
|
||||
);
|
||||
}
|
||||
$this->service->server->ssh()->exec($commands, 'update-php-settings');
|
||||
$typeData = $this->service->type_data;
|
||||
$typeData['settings'] = $this->settings;
|
||||
$this->service->type_data = $typeData;
|
||||
$this->service->save();
|
||||
event(
|
||||
new Broadcast('update-php-settings-finished', [
|
||||
'service' => $this->service,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
event(
|
||||
new Broadcast('update-php-settings-failed', [
|
||||
'service' => $this->service,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user