mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
refactoring
This commit is contained in:
@ -4,33 +4,23 @@
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BackupDatabaseCommand extends Command
|
||||
{
|
||||
protected $provider;
|
||||
|
||||
protected $database;
|
||||
|
||||
protected $fileName;
|
||||
|
||||
public function __construct($provider, $database, $fileName)
|
||||
public function __construct(protected string $provider, protected string $database, protected string $fileName)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->database = $database;
|
||||
$this->fileName = $fileName;
|
||||
}
|
||||
|
||||
public function file(string $os): string
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(base_path('system/commands/database/'.$this->provider.'/backup.sh'));
|
||||
return File::get(resource_path(sprintf("commands/database/%s/backup.sh", $this->provider)));
|
||||
}
|
||||
|
||||
public function content(string $os): string
|
||||
public function content(): string
|
||||
{
|
||||
$command = $this->file($os);
|
||||
$command = Str::replace('__database__', $this->database, $command);
|
||||
|
||||
return Str::replace('__file__', $this->fileName, $command);
|
||||
return str($this->file())
|
||||
->replace('__database__', $this->database)
|
||||
->replace('__file__', $this->fileName)
|
||||
->toString();
|
||||
}
|
||||
}
|
||||
|
@ -4,33 +4,22 @@
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function __construct($provider, $name)
|
||||
public function __construct(protected string $provider, protected string $name)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function file(string $os): string
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(base_path('system/commands/database/'.$this->provider.'/create.sh'));
|
||||
return File::get(resource_path(sprintf("commands/database/%s/create.sh", $this->provider)));
|
||||
}
|
||||
|
||||
public function content(string $os): string
|
||||
public function content(): string
|
||||
{
|
||||
return Str::replace('__name__', $this->name, $this->file($os));
|
||||
return str($this->file())
|
||||
->replace('__name__', $this->name)
|
||||
->toString();
|
||||
}
|
||||
}
|
||||
|
@ -4,48 +4,28 @@
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateUserCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $username;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $host;
|
||||
|
||||
public function __construct($provider, $username, $password, $host)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->host = $host;
|
||||
public function __construct(
|
||||
protected string $provider,
|
||||
protected string $username,
|
||||
protected string $password,
|
||||
protected string $host
|
||||
) {
|
||||
}
|
||||
|
||||
public function file(string $os): string
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(base_path('system/commands/database/'.$this->provider.'/create-user.sh'));
|
||||
return File::get(resource_path(sprintf("commands/database/%s/create-user.sh", $this->provider)));
|
||||
}
|
||||
|
||||
public function content(string $os): string
|
||||
public function content(): string
|
||||
{
|
||||
$command = Str::replace('__username__', $this->username, $this->file($os));
|
||||
$command = Str::replace('__password__', $this->password, $command);
|
||||
|
||||
return Str::replace('__host__', $this->host, $command);
|
||||
return str($this->file())
|
||||
->replace('__username__', $this->username)
|
||||
->replace('__password__', $this->password)
|
||||
->replace('__host__', $this->host)
|
||||
->toString();
|
||||
}
|
||||
}
|
||||
|
@ -4,33 +4,22 @@
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeleteCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function __construct($provider, $name)
|
||||
public function __construct(protected string $provider, protected string $name)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function file(string $os): string
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(base_path('system/commands/database/'.$this->provider.'/delete.sh'));
|
||||
return File::get(resource_path(sprintf("commands/database/%s/delete.sh", $this->provider)));
|
||||
}
|
||||
|
||||
public function content(string $os): string
|
||||
public function content(): string
|
||||
{
|
||||
return Str::replace('__name__', $this->name, $this->file($os));
|
||||
return str($this->file())
|
||||
->replace('__name__', $this->name)
|
||||
->toString();
|
||||
}
|
||||
}
|
||||
|
@ -4,41 +4,23 @@
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeleteUserCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $username;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $host;
|
||||
|
||||
public function __construct($provider, $username, $host)
|
||||
public function __construct(protected string $provider, protected string $username, protected string $host)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->username = $username;
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
public function file(string $os): string
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(base_path('system/commands/database/'.$this->provider.'/delete-user.sh'));
|
||||
return File::get(resource_path(sprintf("commands/database/%s/delete-user.sh", $this->provider)));
|
||||
}
|
||||
|
||||
public function content(string $os): string
|
||||
public function content(): string
|
||||
{
|
||||
$command = Str::replace('__username__', $this->username, $this->file($os));
|
||||
|
||||
return Str::replace('__host__', $this->host, $command);
|
||||
return str($this->file())
|
||||
->replace('__username__', $this->username)
|
||||
->replace('__host__', $this->host)
|
||||
->toString();
|
||||
}
|
||||
}
|
||||
|
19
app/SSHCommands/Database/InstallMariadbCommand.php
Executable file
19
app/SSHCommands/Database/InstallMariadbCommand.php
Executable file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class InstallMariadbCommand extends Command
|
||||
{
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(resource_path('commands/database/install-mariadb.sh'));
|
||||
}
|
||||
|
||||
public function content(): string
|
||||
{
|
||||
return $this->file();
|
||||
}
|
||||
}
|
27
app/SSHCommands/Database/InstallMysqlCommand.php
Executable file
27
app/SSHCommands/Database/InstallMysqlCommand.php
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSHCommands\Database;
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class InstallMysqlCommand extends Command
|
||||
{
|
||||
public function __construct(protected string $version)
|
||||
{
|
||||
}
|
||||
|
||||
public function file(): string
|
||||
{
|
||||
if ($this->version == '8.0') {
|
||||
return File::get(resource_path('commands/database/install-mysql-8.sh'));
|
||||
}
|
||||
|
||||
return File::get(resource_path('commands/database/install-mysql.sh'));
|
||||
}
|
||||
|
||||
public function content(): string
|
||||
{
|
||||
return $this->file();
|
||||
}
|
||||
}
|
@ -4,45 +4,28 @@
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LinkCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $username;
|
||||
|
||||
protected $host;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
public function __construct($provider, $username, $host, $database)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->username = $username;
|
||||
$this->host = $host;
|
||||
$this->database = $database;
|
||||
public function __construct(
|
||||
protected string $provider,
|
||||
protected string $username,
|
||||
protected string $host,
|
||||
protected string $database
|
||||
) {
|
||||
}
|
||||
|
||||
public function file(string $os): string
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(base_path('system/commands/database/'.$this->provider.'/link.sh'));
|
||||
return File::get(resource_path(sprintf("commands/database/%s/link.sh", $this->provider)));
|
||||
}
|
||||
|
||||
public function content(string $os): string
|
||||
public function content(): string
|
||||
{
|
||||
$command = Str::replace('__username__', $this->username, $this->file($os));
|
||||
$command = Str::replace('__host__', $this->host, $command);
|
||||
|
||||
return Str::replace('__database__', $this->database, $command);
|
||||
return str($this->file())
|
||||
->replace('__username__', $this->username)
|
||||
->replace('__host__', $this->host)
|
||||
->replace('__database__', $this->database)
|
||||
->toString();
|
||||
}
|
||||
}
|
||||
|
@ -4,33 +4,23 @@
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RestoreDatabaseCommand extends Command
|
||||
{
|
||||
protected $provider;
|
||||
|
||||
protected $database;
|
||||
|
||||
protected $fileName;
|
||||
|
||||
public function __construct($provider, $database, $fileName)
|
||||
public function __construct(protected string $provider, protected string $database, protected string $fileName)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->database = $database;
|
||||
$this->fileName = $fileName;
|
||||
}
|
||||
|
||||
public function file(string $os): string
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(base_path('system/commands/database/'.$this->provider.'/restore.sh'));
|
||||
return File::get(resource_path(sprintf("commands/database/%s/restore.sh", $this->provider)));
|
||||
}
|
||||
|
||||
public function content(string $os): string
|
||||
public function content(): string
|
||||
{
|
||||
$command = $this->file($os);
|
||||
$command = Str::replace('__database__', $this->database, $command);
|
||||
|
||||
return Str::replace('__file__', $this->fileName, $command);
|
||||
return str($this->file())
|
||||
->replace('__database__', $this->database)
|
||||
->replace('__file__', $this->fileName)
|
||||
->toString();
|
||||
}
|
||||
}
|
||||
|
@ -4,38 +4,26 @@
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UnlinkCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $username;
|
||||
|
||||
protected $host;
|
||||
|
||||
public function __construct($provider, $username, $host)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->username = $username;
|
||||
$this->host = $host;
|
||||
public function __construct(
|
||||
protected string $provider,
|
||||
protected string $username,
|
||||
protected string $host
|
||||
) {
|
||||
}
|
||||
|
||||
public function file(string $os): string
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(base_path('system/commands/database/'.$this->provider.'/unlink.sh'));
|
||||
return File::get(resource_path(sprintf("commands/database/%s/unlink.sh", $this->provider)));
|
||||
}
|
||||
|
||||
public function content(string $os): string
|
||||
public function content(): string
|
||||
{
|
||||
$command = Str::replace('__username__', $this->username, $this->file($os));
|
||||
|
||||
return Str::replace('__host__', $this->host, $command);
|
||||
return str($this->file())
|
||||
->replace('__username__', $this->username)
|
||||
->replace('__host__', $this->host)
|
||||
->toString();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user