Skip to content

Commit

Permalink
Adjust database name and site url when restoring a site (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjmead authored Nov 4, 2024
1 parent 04f1b90 commit bcd9a9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Commands/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function handle()
message: 'Running installation',
command: 'wp core ' . ($template->enable_multisite() ? 'multisite-install' : 'install'),
arguments: [
'url' => "http://{$slug}.test",
'url' => $site->url(),
'title' => $template->get_site_title() ?? $selected_template_name,
'admin_user' => $template->get_admin_username(),
'admin_password' => $template->get_admin_password(),
Expand Down Expand Up @@ -259,6 +259,6 @@ public function handle()

info('Opening site...');

exec("open http://{$slug}.test/wp-admin");
exec("open {$site->url('/wp-admin')}");
}
}
2 changes: 1 addition & 1 deletion app/Commands/Open.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function handle()
{
$site = $this->ask_user_for_site('Select a site to open');

exec("open http://{$site->slug()}.test/wp-admin");
exec("open {$site->url('/wp-admin')}");
}
}
24 changes: 23 additions & 1 deletion app/Domain/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,23 @@ public function restore(Backup $backup): bool
return false;
}

// TODO I should know if a call to execute succeeded or failed
$this->set_config('DB_NAME', $this->slug);

$this->execute(
message: 'Importing database',
command: 'wp db import ' . $backup->database_path(),
);

$this->execute(
message: "Setting option \"siteurl\"",
command: "wp option update siteurl {$this->url()}",
);

$this->execute(
message: "Setting option \"home\"",
command: "wp option update home {$this->url()}",
);

return true;
}

Expand All @@ -151,6 +162,17 @@ public function set_config(string $key, mixed $value, bool $cleanup_on_error = f
}
}

public function url(?string $path = null): string
{
$url = "http://{$this->slug}.test";

if(is_string($path)) {
$url .= Str::start($path, '/');
}

return $url;
}

/**
* @return Collection<Site>
*/
Expand Down

0 comments on commit bcd9a9f

Please sign in to comment.