-
app/Models/PendingDeploymentException.php
Open in GitHubuse Exception; use ProtoneMedia\Splade\Facades\Toast; class PendingDeploymentException extends Exception { public function __construct( private Site $site, string $message = '', int $code = 0, Exception $previous = null, ) { parent::__construct($message, $code, $previous); } public function render() { Toast::warning(__('The site is already being deployed.')); return back(fallback: route('servers.sites.show', [$this->site->server, $this->site])); } }
-
app/Models/Site.php
Open in GitHubuse App\Jobs\DeploySite; use Illuminate\Database\Eloquent\Model; class Site extends Model { // ... public function deploy(array $environmentVariables = [], User $user = null): Deployment { if ($this->fresh()->latestDeployment?->status === DeploymentStatus::Pending) { throw new PendingDeploymentException($this); } /** @var Deployment */ $deployment = $this->deployments()->create([ 'status' => DeploymentStatus::Pending, 'user_id' => $user?->exists ? $user->id : null, ]); $this->server->team->activityLogs()->create([ 'subject_id' => $this->getKey(), 'subject_type' => $this->getMorphClass(), 'description' => __(__("Deployed site ':address' on server ':server'", ['address' => $this->address, 'server' => $this->server->name])), 'user_id' => $user?->exists ? $user->id : null, ]); dispatch(new DeploySite($deployment, $environmentVariables)); return $deployment; } // ... }