Skip to content

Fix APP_URL not updating to HTTPS after SSL certification #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions app/Actions/Forge/UpdateForgeEnvironmentVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace App\Actions\Forge;

use App\Actions\MergeEnvironmentVariables;
use App\Actions\TextToArray;
use App\Services\Forge\ForgeService;
use App\Traits\Outputifier;

class UpdateForgeEnvironmentVariables
{
use Outputifier;

/**
* Handle the update of environment variables in a Forge site.
*
* @param ForgeService $service
* @return bool
*/
public function handle(ForgeService $service): bool
{
$newKeys = array_merge(
TextToArray::run($service->setting->envKeys),
$service->database
);

if ($service->setting->sslRequired) {
$newKeys = array_merge($newKeys, ['APP_URL' => $service->getSiteLink()]);
}

if (empty($newKeys)) {
return false;
}

$source = $service->forge->siteEnvironmentFile($service->server->id, $service->site->id);
$mergedEnvs = MergeEnvironmentVariables::run($source, $newKeys);

$service->forge->updateSiteEnvironmentFile(
$service->server->id,
$service->site->id,
$mergedEnvs
);

return true;
}
}
22 changes: 4 additions & 18 deletions app/Services/Forge/Pipeline/UpdateEnvironmentVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

namespace App\Services\Forge\Pipeline;

use App\Actions\MergeEnvironmentVariables;
use App\Actions\TextToArray;
use App\Actions\Forge\UpdateForgeEnvironmentVariables;
use App\Services\Forge\ForgeService;
use App\Traits\Outputifier;
use Closure;
Expand All @@ -25,25 +24,12 @@ class UpdateEnvironmentVariables

public function __invoke(ForgeService $service, Closure $next)
{
$newKeys = array_merge(TextToArray::run($service->setting->envKeys), $service->database);
$updated = resolve(UpdateForgeEnvironmentVariables::class)->handle($service);

if (! empty($newKeys)) {
$this->information('Processing update of environment variables.');

$service->forge->updateSiteEnvironmentFile(
$service->server->id,
$service->site->id,
$this->getBothEnvsMerged($service, $newKeys)
);
if ($updated) {
$this->information('Environment variables have been updated successfully.');
}

return $next($service);
}

protected function getBothEnvsMerged(ForgeService $service, array $newKeys): string
{
$source = $service->forge->siteEnvironmentFile($service->server->id, $service->site->id);

return MergeEnvironmentVariables::run($source, $newKeys);
}
}