1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-25 05:22:59 +00:00

Handle pre-existing wikis

This commit is contained in:
Starbeamrainbowlabs 2019-05-11 15:39:55 +01:00
parent dc310850a6
commit a49ccccbcc
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 25 additions and 7 deletions

View file

@ -46,16 +46,22 @@ if($settings === null) {
}
// Fill in any missing properties
$settingsUpgraded = false;
$settings_upgraded = false;
foreach($guiConfig as $key => $propertyData) {
if(!isset($settings->$key)) {
$settings->$key = $propertyData->default;
$settingsUpgraded = true;
$settings_upgraded = true;
}
}
if($settingsUpgraded)
if($settings_upgraded)
file_put_contents("peppermint.json", json_encode($settings, JSON_PRETTY_PRINT));
// If the first-run wizard hasn't been completed but we've filled in 1 or more new settings, then we must be a pre-existing wiki upgrading from a previous version. We can guarantee this because of the new firstrun_complete setting
if(!$settings->firstrun_complete && $settings_upgraded) {
$settings->firstrun_complete = true;
file_put_contents("peppermint.json", json_encode($settings, JSON_PRETTY_PRINT));
}
// Insert the default CSS if requested
$defaultCSS = <<<THEMECSS
{default-css}
@ -67,4 +73,5 @@ THEMECSS;
// often, and even if it does it shouldn't matter :P
if($settings->sessionprefix == "auto")
$settings->sessionprefix = "pepperminty-wiki-" . preg_replace('/[^a-z0-9\-_]/', "-", strtolower($settings->sitename));
?>

View file

@ -8,10 +8,7 @@ register_module([
"id" => "feature-firstrun",
"code" => function() {
// TODO: Remove this line once it's ready
return true; // Stop this module from actually being executed - it's not ready yet!
// TODO: Figure out how to detect pre-existing wikis here
// NOTE: We auto-detect pre-existing wikis in 01-settings.fragment.php
/**
* @api {get} ?action=firstrun Display the firstrun page
@ -104,6 +101,19 @@ register_module([
});
/**
* @api {post} ?action=firstrun-complete Complete the first-run wizard.
* @apiName FirstRunComplete
* @apiGroup Settings
* @apiPermission Anonymous
*
* @apiParam {string} username The username for the first admin account
* @apiParam {string} password The password for the first admin account
* @apiParam {string} password-again The password repeated for the first admin account
* @apiParam {string} email-address The email address for the first admin account
* @apiParam {string} wiki-name The name of the wiki. Saved to $settings->sitename
* @apiParam {string} data-dir The directory on the server to save the wiki data to. Saved to $settings->data_storage_dir.
*/
add_action("firstrun-complete", function() {
global $version, $commit, $settings;
@ -154,6 +164,7 @@ register_module([
$user_data->emailAddress = $_POST["email-address"];
$settings->users = new stdClass();
$settings->users->{$_POST["username"]} = $user_data;
$settings->admins = [ $_POST["username"] ]; // Don't forget to mark them as a mod
// Apply the settings
$settings->firstrun_complete = true;