Improve installer

This commit is contained in:
grandeljay 2021-11-14 09:12:49 +01:00
parent 38ace568a1
commit 44c1d26d89

View file

@ -11,40 +11,21 @@ use wishthis\{Page, Database};
$page = new page(__FILE__, 'Home'); $page = new page(__FILE__, 'Home');
$page->header(); $page->header();
if (isset($_POST['action']) && 'install' === $_POST['action']) { $step = isset($_POST['step']) ? $_POST['step'] : 1;
$configDirectory = 'includes/config';
$configPath = $configDirectory . '/config.php';
$configSamplePath = $configDirectory . '/config-sample.php';
$configContents = file_get_contents($configSamplePath);
foreach ($_POST as $key => $value) { switch ($step) {
if ('DATABASE' === substr($key, 0, 8)) { case 1:
$configContents = preg_replace('/(' . $key . '.+?\').*?(\')/', '$1' . $value . '$2', $configContents);
}
}
file_put_contents($configPath, $configContents);
?>
<main>
<section>
<h1>Success</h1>
<p>wishthis has been successfully installed.</p>
<a class="button primary" href="">Continue</a>
</section>
</main>
<?php
} else {
?> ?>
<main> <main>
<section> <section>
<h1>Install</h1> <h1>Install</h1>
<h2>Step <? $step ?></h2>
<p>Welcome to the wishthis installer.</p> <p>Welcome to the wishthis installer.</p>
<p>wishthis needs a database to function properly. Please enter your credentials.</p> <p>wishthis needs a database to function properly. Please enter your credentials.</p>
<form method="post"> <form method="post">
<input type="hidden" name="action" value="install" /> <input type="hidden" name="action" value="install" />
<input type="hidden" name="step" value="<?= $step + 1; ?>" />
<fieldset> <fieldset>
<label>Host</label> <label>Host</label>
@ -71,6 +52,33 @@ if (isset($_POST['action']) && 'install' === $_POST['action']) {
</section> </section>
</main> </main>
<?php <?php
break;
case 2:
$configDirectory = 'includes/config';
$configPath = $configDirectory . '/config.php';
$configSamplePath = $configDirectory . '/config-sample.php';
$configContents = file_get_contents($configSamplePath);
foreach ($_POST as $key => $value) {
if ('DATABASE' === substr($key, 0, 8)) {
$configContents = preg_replace('/(' . $key . '.+?\').*?(\')/', '$1' . $value . '$2', $configContents);
}
}
file_put_contents($configPath, $configContents);
?>
<main>
<section>
<h1>Success</h1>
<p>wishthis has been successfully installed.</p>
<a class="button primary" href="">Continue</a>
</section>
</main>
<?php
break;
} }
$page->footer(); $page->footer();