refactoring

This commit is contained in:
Saeed Vaziry
2023-08-04 18:28:04 +02:00
parent 8444323cf4
commit 643318fcfc
349 changed files with 3189 additions and 2729 deletions

View File

@ -6,7 +6,7 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\CronJob;
use App\SSHCommands\UpdateCronJobsCommand;
use App\SSHCommands\CronJob\UpdateCronJobsCommand;
use Throwable;
class AddToServer extends Job

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\CronJob;
use App\SSHCommands\UpdateCronJobsCommand;
use App\SSHCommands\CronJob\UpdateCronJobsCommand;
use Throwable;
class RemoveFromServer extends Job

View File

@ -25,6 +25,11 @@ public function handle(): void
);
$this->databaseUser->status = DatabaseUserStatus::READY;
$this->databaseUser->save();
if (count($this->databaseUser->databases) > 0) {
(new LinkUser($this->databaseUser))->handle();
}
event(
new Broadcast('create-database-user-finished', [
'id' => $this->databaseUser->id,

View File

@ -3,8 +3,8 @@
namespace App\Jobs\Installation;
use App\Models\Server;
use App\SSHCommands\CreateUserCommand;
use App\SSHCommands\GetPublicKeyCommand;
use App\SSHCommands\System\CreateUserCommand;
use App\SSHCommands\System\GetPublicKeyCommand;
use Throwable;
class Initialize extends InstallationJob
@ -13,13 +13,10 @@ class Initialize extends InstallationJob
protected ?string $asUser;
protected bool $defaultKeys;
public function __construct(Server $server, string $asUser = null, bool $defaultKeys = false)
public function __construct(Server $server, string $asUser = null)
{
$this->server = $server->refresh();
$this->asUser = $asUser;
$this->defaultKeys = $defaultKeys;
}
/**
@ -38,7 +35,7 @@ public function handle(): void
protected function authentication(): void
{
$this->server
->ssh($this->asUser ?? $this->server->ssh_user, $this->defaultKeys)
->ssh($this->asUser ?? $this->server->ssh_user)
->exec(
new CreateUserCommand(
$this->server->authentication['user'],

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation;
use App\Models\Server;
use App\SSHCommands\InstallCertbotCommand;
use App\SSHCommands\SSL\InstallCertbotCommand;
use Throwable;
class InstallCertbot extends InstallationJob

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation;
use App\Models\Server;
use App\SSHCommands\InstallComposerCommand;
use App\SSHCommands\PHP\InstallComposerCommand;
use Throwable;
class InstallComposer extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\InstallMariadbCommand;
use App\SSHCommands\ServiceStatusCommand;
use App\SSHCommands\Database\InstallMariadbCommand;
use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable;
class InstallMariadb extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\InstallMysqlCommand;
use App\SSHCommands\ServiceStatusCommand;
use App\SSHCommands\Database\InstallMysqlCommand;
use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable;
class InstallMysql extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\InstallNginxCommand;
use App\SSHCommands\ServiceStatusCommand;
use App\SSHCommands\Nginx\InstallNginxCommand;
use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable;
class InstallNginx extends InstallationJob

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation;
use App\Models\Server;
use App\SSHCommands\InstallNodejsCommand;
use App\SSHCommands\Installation\InstallNodejsCommand;
use Throwable;
class InstallNodejs extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\InstallPHPCommand;
use App\SSHCommands\ServiceStatusCommand;
use App\SSHCommands\PHP\InstallPHPCommand;
use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable;
class InstallPHP extends InstallationJob

View File

@ -6,8 +6,8 @@
use App\Jobs\Job;
use App\Models\FirewallRule;
use App\Models\Service;
use App\SSHCommands\CreateNginxPHPMyAdminVHostCommand;
use App\SSHCommands\DownloadPHPMyAdminCommand;
use App\SSHCommands\PHPMyAdmin\CreateNginxPHPMyAdminVHostCommand;
use App\SSHCommands\PHPMyAdmin\DownloadPHPMyAdminCommand;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Throwable;
@ -76,7 +76,7 @@ private function downloadSource(): void
*/
private function setUpVHost(): void
{
$vhost = File::get(base_path('system/command-templates/nginx/phpmyadmin-vhost.conf'));
$vhost = File::get(resource_path('commands/webserver/nginx/phpmyadmin-vhost.conf'));
$vhost = Str::replace('__php_version__', $this->service->server->defaultService('php')->version, $vhost);
$this->service->server->ssh()->exec(
new CreateNginxPHPMyAdminVHostCommand($vhost),

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\InstallRedisCommand;
use App\SSHCommands\ServiceStatusCommand;
use App\SSHCommands\Installation\InstallRedisCommand;
use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable;
class InstallRedis extends InstallationJob

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation;
use App\Models\Server;
use App\SSHCommands\InstallRequirementsCommand;
use App\SSHCommands\Installation\InstallRequirementsCommand;
use Throwable;
class InstallRequirements extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\InstallSupervisorCommand;
use App\SSHCommands\ServiceStatusCommand;
use App\SSHCommands\Service\ServiceStatusCommand;
use App\SSHCommands\Supervisor\InstallSupervisorCommand;
use Throwable;
class InstallSupervisor extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\InstallUfwCommand;
use App\SSHCommands\ServiceStatusCommand;
use App\SSHCommands\Firewall\InstallUfwCommand;
use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable;
class InstallUfw extends InstallationJob

View File

@ -4,7 +4,7 @@
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\UninstallPHPCommand;
use App\SSHCommands\PHP\UninstallPHPCommand;
use Throwable;
class UninstallPHP extends InstallationJob

View File

@ -5,7 +5,7 @@
use App\Jobs\Job;
use App\Models\FirewallRule;
use App\Models\Service;
use App\SSHCommands\DeleteNginxPHPMyAdminVHost;
use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHost;
use Exception;
use Throwable;

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation;
use App\Models\Server;
use App\SSHCommands\UpgradeCommand;
use App\SSHCommands\System\UpgradeCommand;
use Throwable;
class Upgrade extends InstallationJob

View File

@ -6,7 +6,7 @@
use App\Exceptions\ProcessFailed;
use App\Jobs\Job;
use App\Models\Service;
use App\SSHCommands\InstallPHPExtensionCommand;
use App\SSHCommands\PHP\InstallPHPExtensionCommand;
use Illuminate\Support\Str;
use Throwable;

View File

@ -6,7 +6,7 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\Service;
use App\SSHCommands\ChangeDefaultPHPCommand;
use App\SSHCommands\PHP\ChangeDefaultPHPCommand;
use Throwable;
class SetDefaultCli extends Job

View File

@ -1,58 +0,0 @@
<?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,
])
);
}
}

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\Server;
use App\SSHCommands\RebootCommand;
use App\SSHCommands\System\RebootCommand;
use Throwable;
class RebootServer extends Job

View File

@ -5,9 +5,9 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\Service;
use App\SSHCommands\RestartServiceCommand;
use App\SSHCommands\StartServiceCommand;
use App\SSHCommands\StopServiceCommand;
use App\SSHCommands\Service\RestartServiceCommand;
use App\SSHCommands\Service\StartServiceCommand;
use App\SSHCommands\Service\StopServiceCommand;
use Exception;
use Throwable;

View File

@ -4,7 +4,7 @@
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\CloneRepositoryCommand;
use App\SSHCommands\Website\CloneRepositoryCommand;
use Throwable;
class CloneRepository extends Job
@ -25,7 +25,8 @@ public function handle(): void
new CloneRepositoryCommand(
$this->site->full_repository_url,
$this->site->path,
$this->site->branch
$this->site->branch,
$this->site->ssh_key_name
),
'clone-repository',
$this->site->id

View File

@ -5,7 +5,7 @@
use App\Exceptions\ComposerInstallFailed;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\ComposerInstallCommand;
use App\SSHCommands\Website\ComposerInstallCommand;
use Throwable;
class ComposerInstall extends Job

View File

@ -7,7 +7,7 @@
use App\Helpers\SSH;
use App\Jobs\Job;
use App\Models\Deployment;
use App\SSHCommands\RunScript;
use App\SSHCommands\System\RunScript;
use Throwable;
class Deploy extends Job

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\EditFileCommand;
use App\SSHCommands\System\EditFileCommand;
use Throwable;
class DeployEnv extends Job

42
app/Jobs/Site/DeployKey.php Executable file
View File

@ -0,0 +1,42 @@
<?php
namespace App\Jobs\Site;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\System\GenerateSshKeyCommand;
use App\SSHCommands\System\ReadSshKeyCommand;
use Throwable;
class DeployKey extends Job
{
protected Site $site;
public function __construct(Site $site)
{
$this->site = $site;
}
/**
* @throws Throwable
*/
public function handle(): void
{
$this->site->server->ssh()->exec(
new GenerateSshKeyCommand($this->site->ssh_key_name),
'generate-ssh-key',
$this->site->id
);
$this->site->ssh_key = $this->site->server->ssh()->exec(
new ReadSshKeyCommand($this->site->ssh_key_name),
'read-public-key',
$this->site->id
);
$this->site->save();
$this->site->sourceControl()->provider()->deployKey(
$this->site->domain.'-key-' . $this->site->id,
$this->site->repository,
$this->site->ssh_key
);
}
}

View File

@ -7,7 +7,7 @@
use App\Models\Database;
use App\Models\DatabaseUser;
use App\Models\Site;
use App\SSHCommands\InstallWordpressCommand;
use App\SSHCommands\Wordpress\InstallWordpressCommand;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Throwable;

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\UpdateBranchCommand;
use App\SSHCommands\Website\UpdateBranchCommand;
use Throwable;
class UpdateBranch extends Job

View File

@ -1,41 +0,0 @@
<?php
namespace App\Jobs\Site;
use App\Jobs\Job;
use App\Models\Site;
use App\Models\SourceControl;
use Throwable;
class UpdateSourceControlsRemote extends Job
{
protected SourceControl $sourceControl;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(SourceControl $sourceControl)
{
$this->sourceControl = $sourceControl;
}
/**
* Execute the job.
*
* @throws Throwable
*/
public function handle(): void
{
$sites = Site::query()
->where('user_id', $this->sourceControl->user_id)
->where('source_control', $this->sourceControl->provider)
->get();
foreach ($sites as $site) {
$site->server->ssh()->exec(
'cd '.$site->path.' && git remote set-url origin '.$site->full_repository_url
);
}
}
}

View File

@ -6,7 +6,7 @@
use App\Jobs\Job;
use App\Models\Server;
use App\Models\SshKey;
use App\SSHCommands\DeleteSshKeyCommand;
use App\SSHCommands\System\DeleteSshKeyCommand;
use Throwable;
class DeleteSshKeyFromServer extends Job

View File

@ -7,7 +7,7 @@
use App\Jobs\Job;
use App\Models\Server;
use App\Models\SshKey;
use App\SSHCommands\DeploySshKeyCommand;
use App\SSHCommands\System\DeploySshKeyCommand;
use Throwable;
class DeploySshKeyToServer extends Job