Skip to content
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

Always dropping and rebuilding the config file on a new run #27

Merged
merged 1 commit into from
Mar 22, 2024
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
103 changes: 49 additions & 54 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,74 +220,69 @@ public static function init(string $wp_version): void

echo PHP_EOL;

if (self::configExsists() === false) {
self::displayLine(
'A test config file for the WordPress test environment was ' .
'not found.',
'👀'
);
if (self::configExsists() === true) {
self::displayLine('Dropping the older config file.', '♻️');
}

$config = new Config(wp_version: $wp_version);
$config = new Config(wp_version: $wp_version);

if ($config->save() === true) {
$path = Config::path();
self::displayLine("A fresh config was saved to '$path'.");
echo PHP_EOL;
}
if ($config->save() === true) {
$path = Config::path();
self::displayLine("A fresh config was saved to '$path'.");
echo PHP_EOL;
}

if (
Database::testConnection(
$config->db_host,
$config->db_user,
$config->db_password,
$config->db_name
) === true
) {
self::displayLine(
'Connection to the database server was successful.'
);
} else {
self::displayLine(
'Unable to connect to the database. Check if the ' .
'database name, hostname, username or password are valid ' .
'and correct.',
'👎'
);
}
if (
Database::testConnection(
$config->db_host,
$config->db_user,
$config->db_password,
$config->db_name
) === true
) {
self::displayLine(
'Connection to the database server was successful.'
);
} else {
self::displayLine(
'Unable to connect to the database. Check if the ' .
'database name, hostname, username or password are valid ' .
'and correct.',
'👎'
);
}

if (
Database::exsists(
$config->db_host,
$config->db_user,
$config->db_password,
$config->db_name
) === true
) {
self::displayLine(
"The '$config->db_name' database exsists."
);
} else {
self::displayLine(
"The '$config->db_name' database does not exist." .
'Attempting to create it...',
'😰'
);
if (
Database::exsists(
Database::create(
$config->db_host,
$config->db_user,
$config->db_password,
$config->db_name
) === true
) {
self::displayLine(
"The '$config->db_name' database exsists."
);
} else {
self::displayLine(
"The '$config->db_name' database does not exist." .
'Attempting to create it...',
'😰'
);
if (
Database::create(
$config->db_host,
$config->db_user,
$config->db_password,
$config->db_name
) === true
) {
self::displayLine('The database was created.');
}
self::displayLine('The database was created.');
}

echo PHP_EOL;

}

echo PHP_EOL;

if (FetchWP::isInstalled('develop-trunk', 'wordpress') === false) {
self::displayLine(
'A WordPress develop-trunk environment was not found.',
Expand Down
8 changes: 8 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ public function save(): bool
return false;
}

/**
* Delete the config file
*/
public function drop(): bool
{
return unlink(self::path());
}

/**
* Format a comment block for the configuration file
*/
Expand Down
Loading