From b1e28a0e06e960ac12c7589a7b668dbb3795db29 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 19 Aug 2024 21:56:12 +0100 Subject: [PATCH] settings: fix firstrun_complete handling if preset to false before wiki initialisation --- Changelog.md | 1 + core/01-settings.fragment.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 34b17f5..3c0f853 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ This is the next release of Pepperminty Wiki, that hasn't been released yet. - **Fixed:** Fixed link to the interwiki links documentation on the help page if interwiki links have not yet been setup. - **Fixed:** Fixed typos in system text +- **Fixed:** Fixed handling of [`firstrun_complete`](https://starbeamrainbowlabs.com/labs/peppermint/peppermint-config-info.php#config_firstrun_complete) setting if `peppermint.json` is prefilled with a `firstrun_complete` directive but the Wiki hasn't been initialised for the first time yet - useful for installations inside Docker - **Changed:** Catch and deal with more unpacking issues on first run (thanks, @daveschroeter in [#249](https://github.com/sbrl/Pepperminty-Wiki/issues/249)) diff --git a/core/01-settings.fragment.php b/core/01-settings.fragment.php index 766ae23..5147661 100644 --- a/core/01-settings.fragment.php +++ b/core/01-settings.fragment.php @@ -55,18 +55,27 @@ if($settings === null) { // Fill in any missing properties $settings_upgraded = false; +$did_upgrade_firstrun_key = false; foreach($guiConfig as $key => $propertyData) { if(!property_exists($settings, $key)) { error_log("[PeppermintyWiki/$settings->sitename/settings] Upgrading $key"); $settings->$key = $propertyData->default; $settings_upgraded = true; + if($key == "firstrun_complete") + $did_upgrade_firstrun_key = true; } } 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) { +// If: +// * The first-run wizard hasn't been completed +// * We've filled in 1 or more new settings +// * One of those new settings was firstrun_complete +// ...then we must be a pre-existing wiki upgrading from a previous version. We can guarantee this because if the firstrun_complete setting didn't exist before but it was added to an EXISTING peppermint.json (creating a NEW peppermint.json would add firstrun_complete to a new peppermint.json file, which is handled separately above) +// This is very important for when a Pepperminty Wiki instance didn't have the firstrun wizard previously but does now. This avoids the first run wizard running when it shouldn't. +// Note we added this additional specific check because in Docker containers we recommend that firstrun_complete be manually preset to false, which would previously get autset to true as we thought it was a pre-existing wiki when it isn't! Note also we don't yet have access to the pageindex at this stage, so we can't check that either. +if(!$settings->firstrun_complete && $settings_upgraded && $did_upgrade_firstrun_key) { $settings->firstrun_complete = true; file_put_contents("peppermint.json", json_encode($settings, JSON_PRETTY_PRINT)); }