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

@ -14,6 +14,7 @@
use App\Jobs\Site\UpdateBranch;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
@ -32,7 +33,9 @@
* @property string $path
* @property string $php_version
* @property string $source_control
* @property int $source_control_id
* @property string $repository
* @property string $ssh_key
* @property string $branch
* @property string $status
* @property int $port
@ -52,6 +55,7 @@
* @property string $aliases_string
* @property string $deployment_script_text
* @property string $env
* @property string $ssh_key_name
*/
class Site extends AbstractModel
{
@ -67,7 +71,9 @@ class Site extends AbstractModel
'path',
'php_version',
'source_control',
'source_control_id',
'repository',
'ssh_key',
'branch',
'status',
'port',
@ -81,6 +87,7 @@ class Site extends AbstractModel
'progress' => 'integer',
'auto_deployment' => 'boolean',
'aliases' => 'array',
'source_control_id' => 'integer',
];
protected $appends = [
@ -151,22 +158,21 @@ public function ssls(): HasMany
/**
* @throws SourceControlIsNotConnected
*/
public function sourceControl(): SourceControl|HasOne|null
public function sourceControl(): SourceControl|HasOne|null|Model
{
if (! $this->source_control) {
$sourceControl = null;
if (! $this->source_control && ! $this->source_control_id) {
return null;
}
if ($this->source_control == 'custom') {
return new SourceControl([
'user_id' => $this->id,
'provider' => 'custom',
'token' => '',
'connected' => true,
]);
if ($this->source_control) {
$sourceControl = SourceControl::query()->where('provider', $this->source_control)->first();
}
$sourceControl = SourceControl::query()->where('provider', $this->source_control)->first();
if ($this->source_control_id) {
$sourceControl = SourceControl::query()->find($this->source_control_id);
}
if (! $sourceControl) {
throw new SourceControlIsNotConnected($this->source_control);
@ -180,7 +186,7 @@ public function sourceControl(): SourceControl|HasOne|null
*/
public function getFullRepositoryUrlAttribute()
{
return $this->sourceControl()->provider()->fullRepoUrl($this->repository);
return $this->sourceControl()->provider()->fullRepoUrl($this->repository, $this->ssh_key_name);
}
public function getAliasesStringAttribute(): string
@ -394,4 +400,9 @@ public function updateBranch(string $branch): void
{
dispatch(new UpdateBranch($this, $branch))->onConnection('ssh');
}
public function getSshKeyNameAttribute(): string
{
return str('site_'.$this->id)->toString();
}
}